koz 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/README.md +49 -0
- data/Rakefile +8 -0
- data/bin/kozbot.rb +23 -0
- data/kozbot.bat +0 -0
- data/lib/koz/config.rb +116 -0
- data/lib/koz/event.rb +28 -0
- data/lib/koz/import.rb +9 -0
- data/lib/koz/poti.rb +149 -0
- data/lib/koz/version.rb +5 -0
- data/lib/koz.rb +13 -0
- metadata +55 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0ebe61246f28706d241447b6a2ed03844e451d41f565bd657c1384f7297fe977
|
|
4
|
+
data.tar.gz: f8b81184a5fd9348e5b4e127e939141793ed41e2c18960cd2dc9c56f9f190fb6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7724ca35328f42aaa4d774abf0744fef8c7a74f0117deb676fad172c48af4990105a7d9c3c20866ab30819f953227b67c17d56df8f32d98d6c7051e6c69f0590
|
|
7
|
+
data.tar.gz: 5d5609fc8d6678473c425e5a5a2bd367a7101193eda2e1ff99a1722a5925b950e39cf154e600765da648b8fb784f7d9b972a83fff866808837a91f3f611f28c7
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Koz :: 宇宙
|
|
2
|
+
|
|
3
|
+
造反有理,革命无罪。
|
|
4
|
+
|
|
5
|
+
一个不中立,人类可达、科技向善的机器人框架。
|
|
6
|
+
|
|
7
|
+
# 功能
|
|
8
|
+
|
|
9
|
+
- 插件系统
|
|
10
|
+
|
|
11
|
+
- 接入 LLM(大语言模型)
|
|
12
|
+
|
|
13
|
+
- 记忆
|
|
14
|
+
|
|
15
|
+
- WebUI
|
|
16
|
+
|
|
17
|
+
# 安装
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
gem install koz
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
# 启动
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
kozbot
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
默认工作目录为 `~/.kozbot`
|
|
30
|
+
|
|
31
|
+
以当前文件夹为工作目录
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
kozbot -d
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
指定 webui 端口
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
kozbot --port 10100
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
# 安装插件
|
|
44
|
+
|
|
45
|
+
安装 OneBot 适配器
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
gem install kozbot-snowluma
|
|
49
|
+
```
|
data/Rakefile
ADDED
data/bin/kozbot.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'koz'
|
|
4
|
+
require 'ostruct'
|
|
5
|
+
|
|
6
|
+
MY = OpenStruct.new
|
|
7
|
+
|
|
8
|
+
require 'ostruct'
|
|
9
|
+
MY ||= OpenStruct.new
|
|
10
|
+
|
|
11
|
+
MY.home = Dir.home+"/.koz-bot"
|
|
12
|
+
MY.config = Koz::Config.connect_file MY.home+'/config.yaml'
|
|
13
|
+
puts "koz starts!"
|
|
14
|
+
|
|
15
|
+
class App < Koz::Poti
|
|
16
|
+
enter do |r|
|
|
17
|
+
# TODO
|
|
18
|
+
puts "[\e[33mINFO\e[0m] got message: #{r.data.inspect}"
|
|
19
|
+
r.on post_type: 'message' do
|
|
20
|
+
r.reply "Ciallo~(∠・ω< )⌒☆、ここは demo ロボット~谢谢茄子"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/kozbot.bat
ADDED
|
File without changes
|
data/lib/koz/config.rb
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
module Koz
|
|
4
|
+
class Config
|
|
5
|
+
def self.connect_file path
|
|
6
|
+
new(path)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def keys
|
|
10
|
+
@config.keys
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def key? key
|
|
14
|
+
@config.key? key
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def initialize path
|
|
18
|
+
@path = path
|
|
19
|
+
@config = YAML.load_file(path)
|
|
20
|
+
@handler = -> (keys, new_value, old_value) { }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def handle &blk
|
|
24
|
+
@handler = blk
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def reload
|
|
28
|
+
@config = YAML.load_file(@path)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_yaml
|
|
32
|
+
@config.to_yaml
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def save_config
|
|
36
|
+
File.write(@path, @config.to_yaml)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def get key, *rest
|
|
40
|
+
# keys = key.split('/')
|
|
41
|
+
@config.dig(key, *rest)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def set *keys, new_value, yaml: false
|
|
45
|
+
return false if keys.empty?
|
|
46
|
+
# keys = keys.map{_1.split("/")}.flatten
|
|
47
|
+
if yaml
|
|
48
|
+
new_value = YAML.load(value)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
key = keys.last
|
|
52
|
+
if keys.size > 1
|
|
53
|
+
container = @config.dig(*keys[..-2])
|
|
54
|
+
else
|
|
55
|
+
container = @config
|
|
56
|
+
end
|
|
57
|
+
old_value = container[key]
|
|
58
|
+
container[key] = JSON.parse(new_value.to_json)
|
|
59
|
+
@handler.call(keys, new_value, old_value)
|
|
60
|
+
save_config
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def yaml_set(*)
|
|
64
|
+
set(*, yaml: true)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def safe_get(*)
|
|
68
|
+
YAML.load get(*).to_yaml
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# insert an element to a array [key]
|
|
72
|
+
def insert element, at:
|
|
73
|
+
case at
|
|
74
|
+
when String
|
|
75
|
+
if @config.key? at
|
|
76
|
+
@config[at]
|
|
77
|
+
else
|
|
78
|
+
@config.dig(*at.split(/[\/.]/))
|
|
79
|
+
end
|
|
80
|
+
when Array
|
|
81
|
+
@config.dig(*at)
|
|
82
|
+
end.push element
|
|
83
|
+
save_config
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# delete an element at array [key]
|
|
87
|
+
def delete element, at:
|
|
88
|
+
case at
|
|
89
|
+
when String
|
|
90
|
+
if @config.key? at
|
|
91
|
+
@config[at]
|
|
92
|
+
else
|
|
93
|
+
@config.dig(*at.split(/[\/.]/))
|
|
94
|
+
end
|
|
95
|
+
when Array
|
|
96
|
+
@config.dig(*at)
|
|
97
|
+
end.delete element
|
|
98
|
+
save_config
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
alias [] get
|
|
102
|
+
alias []= set
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
class Event
|
|
107
|
+
attr_accessor :config
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
class Box
|
|
111
|
+
def config
|
|
112
|
+
@event.config
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|
data/lib/koz/event.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Koz
|
|
2
|
+
class Event
|
|
3
|
+
attr_accessor :target, :data, :type, :stopped, :box, :path
|
|
4
|
+
def initialize
|
|
5
|
+
@target = nil
|
|
6
|
+
@data = {}
|
|
7
|
+
@type = nil
|
|
8
|
+
@box = Poti
|
|
9
|
+
@path = []
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def dup
|
|
13
|
+
ev = self.class.new
|
|
14
|
+
ev.target = @target
|
|
15
|
+
ev.data = @data.dup
|
|
16
|
+
ev.type = @type.dup
|
|
17
|
+
ev
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def >> photon
|
|
21
|
+
photon.call self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_box
|
|
25
|
+
@box.new(self)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/lib/koz/import.rb
ADDED
data/lib/koz/poti.rb
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
module Koz
|
|
2
|
+
|
|
3
|
+
class BasePoti
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
|
|
7
|
+
def class_initialize
|
|
8
|
+
@_entrance = -> (event) {}
|
|
9
|
+
@_class = 'Poti'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
attr_accessor :_entrance
|
|
13
|
+
|
|
14
|
+
def inheritance(&blk)
|
|
15
|
+
klass = Class.new(self)
|
|
16
|
+
if blk
|
|
17
|
+
case blk.arity
|
|
18
|
+
when 0
|
|
19
|
+
klass.class_eval(&blk)
|
|
20
|
+
when 1
|
|
21
|
+
blk.call(klass)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
klass
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def inherited klass
|
|
28
|
+
klass.class_initialize
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def enter &blk
|
|
32
|
+
@_entrance = blk
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def call event
|
|
36
|
+
_call event
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def _call(event)
|
|
40
|
+
event
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_proc
|
|
44
|
+
-> (event) { self.call(event) }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def inspect
|
|
48
|
+
name ? "#{name} < #{@_class}" : "#{@_class}.inheritance"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class_initialize
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
class Poti < BasePoti
|
|
58
|
+
|
|
59
|
+
class << self
|
|
60
|
+
def _call event
|
|
61
|
+
return event if event.stopped
|
|
62
|
+
event = super(event)
|
|
63
|
+
box = new(event)
|
|
64
|
+
catch :outer_of_enter do
|
|
65
|
+
@_entrance.call(box)
|
|
66
|
+
end
|
|
67
|
+
event
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def >> pot
|
|
71
|
+
-> (event) { pot.call self.call event }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test(**, &blk)
|
|
75
|
+
ev = Event.new
|
|
76
|
+
ev.data = {**}
|
|
77
|
+
yield(ev) if blk
|
|
78
|
+
call(ev)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
attr_accessor :event#, :nowa_block
|
|
84
|
+
|
|
85
|
+
def initialize event
|
|
86
|
+
@event = event
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def data; @event.data; end
|
|
90
|
+
def target; @event.target; end
|
|
91
|
+
def type; @event.type; end
|
|
92
|
+
def type= ano; @event.type= ano; end
|
|
93
|
+
|
|
94
|
+
def stop; @event.stopped = true
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def on(type=true, **kws, &blk)
|
|
98
|
+
case type
|
|
99
|
+
when false, nil
|
|
100
|
+
return type
|
|
101
|
+
when true
|
|
102
|
+
when Array
|
|
103
|
+
type.include?(@event.type)
|
|
104
|
+
else
|
|
105
|
+
type === @event.type
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
s_kws = kws.transform_keys(&:to_s)
|
|
109
|
+
all_match = s_kws.map { |k, v| v === @event.data[k] }.all?
|
|
110
|
+
if all_match && blk
|
|
111
|
+
# orig_block = @nowa_block
|
|
112
|
+
# @nowa_scope = blk
|
|
113
|
+
catch(:outer) { blk.call }
|
|
114
|
+
# @nowa_block = orig_block
|
|
115
|
+
end
|
|
116
|
+
all_match
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def group name=nil, cond=true, &blk
|
|
120
|
+
if cond
|
|
121
|
+
catch :outer do
|
|
122
|
+
if name
|
|
123
|
+
catch :"group_of_#{name}" do
|
|
124
|
+
blk.call
|
|
125
|
+
end
|
|
126
|
+
else
|
|
127
|
+
blk.call
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def pass; throw :outer_of_enter, self
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# def halt; throw :outer_of_pipe, self
|
|
137
|
+
# end
|
|
138
|
+
|
|
139
|
+
def stop; @event.stopped = true
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def out; throw :outer
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
class_initialize
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
end
|
data/lib/koz/version.rb
ADDED
data/lib/koz.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "koz/version"
|
|
4
|
+
|
|
5
|
+
require_relative 'koz/event'
|
|
6
|
+
require_relative 'koz/poti'
|
|
7
|
+
require_relative 'koz/config'
|
|
8
|
+
require_relative 'koz/import'
|
|
9
|
+
|
|
10
|
+
module Koz
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
# Your code goes here...
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: koz
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- 彩穂
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: A bot framework support many protocol and api.
|
|
13
|
+
email:
|
|
14
|
+
- 37037844+Saisui@users.noreply.github.com
|
|
15
|
+
executables:
|
|
16
|
+
- kozbot.rb
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- README.md
|
|
22
|
+
- Rakefile
|
|
23
|
+
- bin/kozbot.rb
|
|
24
|
+
- kozbot.bat
|
|
25
|
+
- lib/koz.rb
|
|
26
|
+
- lib/koz/config.rb
|
|
27
|
+
- lib/koz/event.rb
|
|
28
|
+
- lib/koz/import.rb
|
|
29
|
+
- lib/koz/poti.rb
|
|
30
|
+
- lib/koz/version.rb
|
|
31
|
+
homepage: https://github.com/saisui/koz-ruby
|
|
32
|
+
licenses: []
|
|
33
|
+
metadata:
|
|
34
|
+
allowed_push_host: https://rubygems.org
|
|
35
|
+
homepage_uri: https://github.com/saisui/koz-ruby
|
|
36
|
+
source_code_uri: https://rubygems.org
|
|
37
|
+
changelog_uri: https://github.com/saisui/koz-ruby/CHANGELOG.md
|
|
38
|
+
rdoc_options: []
|
|
39
|
+
require_paths:
|
|
40
|
+
- lib
|
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: 3.2.0
|
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: '0'
|
|
51
|
+
requirements: []
|
|
52
|
+
rubygems_version: 4.0.9
|
|
53
|
+
specification_version: 4
|
|
54
|
+
summary: The Comfortable Bot Framework.
|
|
55
|
+
test_files: []
|