z4bot 0.1.0 → 0.1.1
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 +4 -4
- data/lib/z4bot/version.rb +2 -1
- data/lib/z4bot.rb +87 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c70fcfcbfc641d475b5a74c9eb9c6f678e9ea0522bb2801761fc72ad8ed3ea6
|
4
|
+
data.tar.gz: e80dee9caea61d3a41b1ca8107567b2af01d9c1a1fbb27d57415da911429c80a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 578a018a84a4297461b04e1ff4b07394e0e8a15d5d7db1a00a36c1fbf0c8770919726d4e31263a20ff904d5c46452faaf83776fa123855b2e2bc3e6e8f3150d1
|
7
|
+
data.tar.gz: be1277fe17f7eec9330a2fd51f542cb17b96fbb6b0eb3e6e6963414eef68678331a5997992061a14d6ad7280fc6a2063fb0e52d3d25ce7d28b35e1be36cb1103
|
data/lib/z4bot/version.rb
CHANGED
data/lib/z4bot.rb
CHANGED
@@ -13,15 +13,15 @@ module Z4bot
|
|
13
13
|
|
14
14
|
@@BOT_ASK = {}
|
15
15
|
@@BOT_CMD = {}
|
16
|
-
@@BOT_INP = {}
|
17
16
|
@@BOT_RES = {}
|
18
17
|
|
19
|
-
|
20
|
-
@@USER_NEW = lambda { |e| {} }
|
21
|
-
@@USER = Hash.new { |h,k| h[k] = @@USER_NEW.call(k) }
|
18
|
+
@@STATE = Hash.new { |h,k| h[k] = {} }
|
22
19
|
|
23
|
-
@@
|
24
|
-
|
20
|
+
@@NEW = lambda { |e| @@STATE[e] }
|
21
|
+
|
22
|
+
@@OBJ_NEW = Hash.new { |h,k| h[k] = @@NEW }
|
23
|
+
|
24
|
+
@@OBJ = Hash.new { |h,k| h[k] = @@OBJ_NEW[k] }
|
25
25
|
|
26
26
|
@@FIELDS = {
|
27
27
|
discord: 'passport_control',
|
@@ -40,20 +40,26 @@ module Z4bot
|
|
40
40
|
host: [ :desc ]
|
41
41
|
};
|
42
42
|
|
43
|
-
def
|
43
|
+
def self.default &b
|
44
|
+
@@NEW = b
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.obj *u, &b
|
44
48
|
if block_given?
|
45
|
-
@@
|
49
|
+
@@OBJ_NEW[u[0]] = b
|
46
50
|
else
|
47
|
-
|
51
|
+
if u.length > 1
|
52
|
+
@@OBJ[u[0]].call(u[1])
|
53
|
+
elsif u.length > 0
|
54
|
+
@@OBJ[u[0]]
|
55
|
+
else
|
56
|
+
@@OBJ
|
57
|
+
end
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
51
|
-
def
|
52
|
-
|
53
|
-
@@CHAN_NEW = b
|
54
|
-
else
|
55
|
-
@@CHAN[c[0]]
|
56
|
-
end
|
61
|
+
def self.state
|
62
|
+
@@STATE
|
57
63
|
end
|
58
64
|
|
59
65
|
def self.client
|
@@ -78,10 +84,6 @@ module Z4bot
|
|
78
84
|
@@BOT_ASK[r] = [h, b]
|
79
85
|
end
|
80
86
|
|
81
|
-
# create a regex input handler.
|
82
|
-
def self.input(r, h={}, &b)
|
83
|
-
@@BOT_INP[r] = [h, b]
|
84
|
-
end
|
85
87
|
# create a regex input mask for pre-defined responses.
|
86
88
|
def self.response(r, h={}, &b)
|
87
89
|
@@BOT_RES[r] = [h, b]
|
@@ -187,14 +189,7 @@ module Z4bot
|
|
187
189
|
o << b[1].call(e, m, h, b[0]);
|
188
190
|
end
|
189
191
|
}
|
190
|
-
else
|
191
|
-
# imply messages from regex &block
|
192
|
-
@@BOT_INP.each_pair { |r,b|
|
193
|
-
if m = r.match(h[:msg]);
|
194
|
-
o << b[1].call(e, m, h, b[0]);
|
195
|
-
end
|
196
|
-
}
|
197
|
-
|
192
|
+
else
|
198
193
|
# construct response by regex &block
|
199
194
|
@@BOT_RES.each_pair { |r,b|
|
200
195
|
if m = r.match(h[:msg]);
|
@@ -217,7 +212,7 @@ end
|
|
217
212
|
Z4bot.command(:'i', usage: "#i [<key> <value>]", description: "Use this to see your current settings within this channel. (@everyone)") do |e|
|
218
213
|
o = [%[]]
|
219
214
|
h = Z4bot.event(e)
|
220
|
-
u =
|
215
|
+
u = Z4bot.obj :user, h[:user]
|
221
216
|
[ :chan, :channel, :nick, :lvl ].each { |e| u[e] = h[e] }
|
222
217
|
if "#{h[:msg]}".length > 0
|
223
218
|
# set k: v
|
@@ -243,9 +238,9 @@ Z4bot.command(:set, usage: "#set <obj> <key> <value>", description: "update chan
|
|
243
238
|
o = []
|
244
239
|
t = h[:words].shift.to_sym;
|
245
240
|
h = Z4bot.event(e)
|
246
|
-
u =
|
247
|
-
if
|
248
|
-
x =
|
241
|
+
u = Z4bot.obj :user, h[:user]
|
242
|
+
if h[:lvl] >= 3
|
243
|
+
x = Z4bot.obj t, h[t]
|
249
244
|
if h[:words].length > 0
|
250
245
|
k = h[:words].shift; v = h[:words].join(" "); x[k.to_sym] = v
|
251
246
|
o << %[set -> #{k}: #{v}]
|
@@ -254,9 +249,69 @@ Z4bot.command(:set, usage: "#set <obj> <key> <value>", description: "update chan
|
|
254
249
|
e.respond(%[#{o.join("\n")}])
|
255
250
|
end
|
256
251
|
|
252
|
+
Z4bot.command(:flag, usage: "#flag <emoji>... + image", description: "flag image. (@everyone)") do |e|
|
253
|
+
h = BOT.event(e)
|
254
|
+
u = Z4bot.obj :user, h[:user]
|
255
|
+
c = Z4bot.obj :chan, h[:chan]
|
256
|
+
o = []
|
257
|
+
if h[:attachments].length > 0
|
258
|
+
[h[:attachments]].flatten.each do |attachment|
|
259
|
+
[h[:words]].flatten.each do |flag|
|
260
|
+
#c.add(flag.to_sym, attachment, :uniq)
|
261
|
+
#u.tick(:xp)
|
262
|
+
#u.tick(:gp)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
o << %[flagged #{h[:attachments].length} attachments.\n(h[:words])]
|
266
|
+
else
|
267
|
+
[:words].flatten.each_with_index { |e, i| o << %[#{e}: #{c[e.to_sym]}] }
|
268
|
+
end
|
269
|
+
o.join("\n")
|
270
|
+
end
|
271
|
+
|
272
|
+
Z4bot.command(:add, usage: "#add <list> <item>", description: "simple list manager (@everyone)") do |e|
|
273
|
+
h = BOT.event(e)
|
274
|
+
k = h[:words].shift.to_sym
|
275
|
+
v = h[:words].join(" ")
|
276
|
+
u = Z4bot :user, h[:user];
|
277
|
+
[ :chan, :channel, :nick, :lvl ].each { |e| u[e] = h[e] }
|
278
|
+
if "#{v}".length > 0
|
279
|
+
#u.add(k,BOT.calendar(h[:words], :uniq))
|
280
|
+
end
|
281
|
+
e.respond("#{k}: #{u[k]}");
|
282
|
+
end
|
283
|
+
|
284
|
+
# chan / host list managment
|
285
|
+
Z4bot.command(:op, usage: "#op <obj> <list> <item>", description: "Used for operation. (operators only)") do |e|
|
286
|
+
h = BOT.event(e)
|
287
|
+
if h[:lvl] == 5
|
288
|
+
t = h[:words].shift.to_sym
|
289
|
+
k = h[:words].shift.to_sym
|
290
|
+
v = h[:words].join(" ")
|
291
|
+
u = Z4bot.obj :user, h[:user];
|
292
|
+
# [ :chan, :channel, :nick, :lvl ].each { |e| u[e] = h[e] }
|
293
|
+
x = Z4bot.obj t, h[t]
|
294
|
+
if "#{v}".length > 0
|
295
|
+
#x.add(k,BOT.calendar(h[:words]))
|
296
|
+
end
|
297
|
+
e.respond("#{t}[#{k}]: #{x[k]}");
|
298
|
+
else
|
299
|
+
e.respond("You do not have the privledge for that.")
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
# example input mask handler.
|
304
|
+
Z4bot.response(/Hello, (.+)!/) do |e, m, h, opts|
|
305
|
+
if m[1] != 'zyphr'
|
306
|
+
%[#{m[1]} isn't my name.]
|
307
|
+
else
|
308
|
+
%[Hi.]
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
257
312
|
if File.exist? 'bot.rb'
|
258
313
|
load 'bot.rb'
|
259
|
-
puts "[z4bot][config]
|
314
|
+
puts "[z4bot][config] bot.rb"
|
260
315
|
else
|
261
316
|
puts "[z4bot][config] default."
|
262
317
|
end
|