z4bot 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/z4bot/version.rb +2 -1
  3. data/lib/z4bot.rb +87 -32
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb6e34a1c68b9d003523491ee096c55c75939a6ec07294a337b25b3b9e0814c3
4
- data.tar.gz: 97aa620713b396c149d4a03e2eb5e2b9548e6d81e1bf135aeadb5e43b0768744
3
+ metadata.gz: 5c70fcfcbfc641d475b5a74c9eb9c6f678e9ea0522bb2801761fc72ad8ed3ea6
4
+ data.tar.gz: e80dee9caea61d3a41b1ca8107567b2af01d9c1a1fbb27d57415da911429c80a
5
5
  SHA512:
6
- metadata.gz: 3ae970dd9f0d474b4cb1630dd7a3212a234c0b521117e538db21f725dc1bf371bb65ded62706fd1de51054bcdac958d07cfe0550fea940f2eea08cefc7d61073
7
- data.tar.gz: 982640d7fbf0f80bf8e93085cd8a35ab6254d820343b6e36f7c7ec69551aa93f37798b7519428f377dd108b7c4eccc34cab7a6c60f3b99560e15a13ee2c4fc85
6
+ metadata.gz: 578a018a84a4297461b04e1ff4b07394e0e8a15d5d7db1a00a36c1fbf0c8770919726d4e31263a20ff904d5c46452faaf83776fa123855b2e2bc3e6e8f3150d1
7
+ data.tar.gz: be1277fe17f7eec9330a2fd51f542cb17b96fbb6b0eb3e6e6963414eef68678331a5997992061a14d6ad7280fc6a2063fb0e52d3d25ce7d28b35e1be36cb1103
data/lib/z4bot/version.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Z4bot
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
+ COMMIT = `git log --format="%H" -n 1`.strip
5
6
  end
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
- @@CHAN_NEW = lambda { |e| {} }
24
- @@CHAN = Hash.new { |h,k| h[k] = @@CHAN_NEW.call(k) }
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 user *u, &b
43
+ def self.default &b
44
+ @@NEW = b
45
+ end
46
+
47
+ def self.obj *u, &b
44
48
  if block_given?
45
- @@USER_NEW = b
49
+ @@OBJ_NEW[u[0]] = b
46
50
  else
47
- @@USER[u[0]]
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 chan *c, &b
52
- if block_given?
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 u[:lvl] >= 3
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] app."
314
+ puts "[z4bot][config] bot.rb"
260
315
  else
261
316
  puts "[z4bot][config] default."
262
317
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: z4bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Olson