tinyirc 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.
@@ -0,0 +1,501 @@
1
+ #
2
+ # Groups
3
+ #
4
+
5
+ group('chanop').tap do |g|
6
+ g.perm @name, 'kick', 'kick'
7
+ g.perm @name, 'remove', 'remove'
8
+
9
+ g.perm @name, 'ban', 'here'
10
+ g.perm @name, 'unban', 'here'
11
+
12
+ g.perm @name, 'exempt', 'here'
13
+ g.perm @name, 'unexempt', 'here'
14
+
15
+ g.perm @name, 'quiet', 'here'
16
+ g.perm @name, 'unquiet', 'here'
17
+
18
+ g.perm @name, 'voice', 'invoker'
19
+ g.perm @name, 'voice', 'here'
20
+
21
+ g.perm @name, 'devoice', 'invoker'
22
+ g.perm @name, 'devoice', 'here'
23
+
24
+ g.perm @name, 'op', 'invoker'
25
+ g.perm @name, 'op', 'here'
26
+
27
+ g.perm @name, 'deop', 'invoker'
28
+ g.perm @name, 'deop', 'here'
29
+
30
+ g.perm @name, 'hop', 'invoker'
31
+ g.perm @name, 'hop', 'here'
32
+
33
+ g.perm @name, 'dehop', 'invoker'
34
+ g.perm @name, 'dehop', 'here'
35
+ end
36
+
37
+ group('admin').tap do |g|
38
+ g.perm @name, 'raw', 'raw'
39
+
40
+ g.perm @name, 'join', 'root'
41
+
42
+ g.perm @name, 'part', 'root'
43
+ g.perm @name, 'part', 'targeted'
44
+
45
+ g.perm @name, 'ban', 'in'
46
+ g.perm @name, 'unban', 'in'
47
+
48
+ g.perm @name, 'exempt', 'in'
49
+ g.perm @name, 'unexempt', 'in'
50
+
51
+ g.perm @name, 'quiet', 'in'
52
+ g.perm @name, 'unquiet', 'in'
53
+
54
+ g.perm @name, 'voice', 'in'
55
+ g.perm @name, 'devoice', 'in'
56
+
57
+ g.perm @name, 'op', 'in'
58
+ g.perm @name, 'deop', 'in'
59
+
60
+ g.perm @name, 'hop', 'in'
61
+ g.perm @name, 'dehop', 'in'
62
+ end
63
+
64
+ #
65
+ # raw command
66
+ #
67
+
68
+ cmd('raw').branch('raw', '...') do |e, c|
69
+ e[:socket].write(c.extra.join(' '))
70
+ end.description = 'Sends the given message to the server'
71
+
72
+ #
73
+ # join command
74
+ #
75
+
76
+ join_cmd = cmd 'join'
77
+
78
+ join_cmd.branch('root', 'chan --pass=PASS') do |e, c|
79
+ e[:socket].join(c.positionals['chan'], c.options['pass'] || nil)
80
+ end.tap do |b|
81
+ b.description = 'Joins given channel'
82
+ b.definition.description :option, 'pass', 'Channel password'
83
+ end
84
+
85
+ #
86
+ # part command
87
+ #
88
+
89
+ part_cmd = cmd 'part'
90
+
91
+ part_cmd.branch('root', '--reason=REASON') do |e, c|
92
+ e[:socket].part(e[:target], c.options['reason'] || 'Bye!')
93
+ end
94
+
95
+ part_cmd.branch('targeted', 'chan --reason=REASON') do |e, c|
96
+ e[:socket].part(c.positionals['chan'], c.options['reason'] || 'Bye!')
97
+ end.tap do |b|
98
+ b.description = 'Parts given channel'
99
+ b.definition.description :option, 'reason', 'Part reason'
100
+ end
101
+
102
+ #
103
+ # get target func
104
+ #
105
+
106
+ def get_target(e, c, raw)
107
+ host = e[:socket].usercache.get(c.positionals['who'], false)[:host]
108
+ if raw || host == nil
109
+ c.positionals['who']
110
+ else
111
+ "*!*@#{host}"
112
+ end
113
+ end
114
+
115
+ #
116
+ # kick command
117
+ #
118
+
119
+ cmd('kick').branch('kick', 'who --ban --reason=REASON') do |e, c|
120
+ s = e[:socket]
121
+ if c.flags['ban']
122
+ to_ban = get_target(e, c, false)
123
+ s.mode(e[:reply_to], "+b #{to_ban}")
124
+ end
125
+ s.kick(e[:reply_to], c.positionals['who'])
126
+ end.tap do |b|
127
+ b.description = 'Kicks the given user from the current channel'
128
+ b.definition.tap do |d|
129
+ d.description :positional, 'who', 'User to be kicked'
130
+ d.description :flag, 'ban', 'Ban the given user'
131
+ d.description :option, 'reason', 'Kick reason'
132
+ end
133
+ end
134
+
135
+ #
136
+ # remove command
137
+ #
138
+
139
+ cmd('remove').branch('remove', 'who --ban --reason=REASON') do |e, c|
140
+ s = e[:socket]
141
+ if c.flags['ban']
142
+ to_ban = get_target(e, c, false)
143
+ s.mode(e[:reply_to], "+b #{to_ban}")
144
+ end
145
+ s.remove(e[:reply_to], c.positionals['who'])
146
+ end.tap do |b|
147
+ b.description = 'Removes the given user from the current channel'
148
+ b.definition.tap do |d|
149
+ d.description :positional, 'who', 'User to be removed'
150
+ d.description :flag, 'ban', 'Ban the given user'
151
+ d.description :option, 'reason', 'Remove reason'
152
+ end
153
+ end
154
+
155
+ #
156
+ # ban command
157
+ #
158
+
159
+ ban_cmd = cmd('ban')
160
+
161
+ ban_cmd.branch('here', 'who --raw') do |e, c|
162
+ e[:socket].mode(e[:target], "+b #{get_target(e, c, c.flags['raw'])}")
163
+ end.tap do |b|
164
+ b.description = 'Bans the given user from the current channel'
165
+ b.definition.tap do |d|
166
+ d.description :positional, 'who', 'User to be banned'
167
+ d.description :flag, 'raw', 'Ban the given hostmask instead of the user\'s one'
168
+ end
169
+ end
170
+
171
+ ban_cmd.branch('in', 'where who --raw') do |e, c|
172
+ e[:socket].mode(c.positionals['where'], "+b #{get_target(e, c, c.flags['raw'])}")
173
+ end.tap do |b|
174
+ b.description = 'Bans the given user from the given channel'
175
+ b.definition.tap do |d|
176
+ d.description :positional, 'where', 'Channel to ban in'
177
+ d.description :positional, 'who', 'User to be banned'
178
+ d.description :flag, 'raw', 'Ban the given hostmask instead of the user\'s one'
179
+ end
180
+ end
181
+
182
+ #
183
+ # unban command
184
+ #
185
+
186
+ unban_cmd = cmd('unban')
187
+
188
+ unban_cmd.branch('here', 'who --raw') do |e, c|
189
+ e[:socket].mode(e[:target], "-b #{get_target(e, c, c.flags['raw'])}")
190
+ end.tap do |b|
191
+ b.description = 'Unbans the given user in the current channel'
192
+ b.definition.tap do |d|
193
+ d.description :positional, 'who', 'User to be unbanned'
194
+ d.description :flag, 'raw', 'Unban the given hostmask instead of the user\'s one'
195
+ end
196
+ end
197
+
198
+ unban_cmd.branch('in', 'where who --raw') do |e, c|
199
+ e[:socket].mode(c.positionals['where'], "-b #{get_target(e, c, c.flags['raw'])}")
200
+ end.tap do |b|
201
+ b.description = 'Unbans the given user in the given channel'
202
+ b.definition.tap do |d|
203
+ d.description :positional, 'where', 'Channel to unban in'
204
+ d.description :positional, 'who', 'User to be unbanned'
205
+ d.description :flag, 'raw', 'Unban the given hostmask instead of the user\'s one'
206
+ end
207
+ end
208
+
209
+ #
210
+ # exempt command
211
+ #
212
+
213
+ exempt_cmd = cmd('exempt')
214
+
215
+ exempt_cmd.branch('here', 'who --raw') do |e, c|
216
+ e[:socket].mode(e[:target], "+e #{get_target(e, c, c.flags['raw'])}")
217
+ end.tap do |b|
218
+ b.description = 'Exempts the given user in the current channel'
219
+ b.definition.tap do |d|
220
+ d.description :positional, 'who', 'User to be exempted'
221
+ d.description :flag, 'raw', 'Exempt the given hostmask instead of the user\'s one'
222
+ end
223
+ end
224
+
225
+ exempt_cmd.branch('in', 'where who --raw') do |e, c|
226
+ e[:socket].mode(c.positionals['where'], "+e #{get_target(e, c, c.flags['raw'])}")
227
+ end.tap do |b|
228
+ b.description = 'Exempts the given user in the given channel'
229
+ b.definition.tap do |d|
230
+ d.description :positional, 'where', 'Channel to exempt in'
231
+ d.description :positional, 'who', 'User to be exempted'
232
+ d.description :flag, 'raw', 'Exempt the given hostmask instead of the user\'s one'
233
+ end
234
+ end
235
+
236
+ #
237
+ # unexempt command
238
+ #
239
+
240
+ unexempt_cmd = cmd('unexempt')
241
+
242
+ unexempt_cmd.branch('here', 'who --raw') do |e, c|
243
+ e[:socket].mode(e[:target], "-e #{get_target(e, c, c.flags['raw'])}")
244
+ end.tap do |b|
245
+ b.description = 'Unexempts the given user in the current channel'
246
+ b.definition.tap do |d|
247
+ d.description :positional, 'who', 'User to be exempted'
248
+ d.description :flag, 'raw', 'Unexempt the given hostmask instead of the user\'s one'
249
+ end
250
+ end
251
+
252
+ unexempt_cmd.branch('in', 'where who --raw') do |e, c|
253
+ e[:socket].mode(c.positionals['where'], "-e #{get_target(e, c, c.flags['raw'])}")
254
+ end.tap do |b|
255
+ b.description = 'Unexempts the given user in the given channel'
256
+ b.definition.tap do |d|
257
+ d.description :positional, 'where', 'Channel to exempt in'
258
+ d.description :positional, 'who', 'User to be exempted'
259
+ d.description :flag, 'raw', 'Unexempt the given hostmask instead of the user\'s one'
260
+ end
261
+ end
262
+
263
+ #
264
+ # quiet command
265
+ #
266
+
267
+ quiet_cmd = cmd('quiet')
268
+
269
+ quiet_cmd.branch('here', 'who --raw') do |e, c|
270
+ e[:socket].mode(e[:target], "+q #{get_target(e, c, c.flags['raw'])}")
271
+ end.tap do |b|
272
+ b.description = 'Quiets the given user in the current channel'
273
+ b.definition.tap do |d|
274
+ d.description :positional, 'who', 'User to be exempted'
275
+ d.description :flag, 'raw', 'Quiet the given hostmask instead of the user\'s one'
276
+ end
277
+ end
278
+
279
+ quiet_cmd.branch('in', 'where who --raw') do |e, c|
280
+ e[:socket].mode(c.positionals['where'], "-q #{get_target(e, c, c.flags['raw'])}")
281
+ end.tap do |b|
282
+ b.description = 'Quiets the given user in the given channel'
283
+ b.definition.tap do |d|
284
+ d.description :positional, 'where', 'Channel to exempt in'
285
+ d.description :positional, 'who', 'User to be exempted'
286
+ d.description :flag, 'raw', 'Quiet the given hostmask instead of the user\'s one'
287
+ end
288
+ end
289
+
290
+ #
291
+ # unquiet command
292
+ #
293
+
294
+ unquiet_cmd = cmd('unquiet')
295
+
296
+ unquiet_cmd.branch('here', 'who --raw') do |e, c|
297
+ e[:socket].mode(e[:target], "-q #{get_target(e, c, c.flags['raw'])}")
298
+ end.tap do |b|
299
+ b.description = 'Unquiets the given user in the current channel'
300
+ b.definition.tap do |d|
301
+ d.description :positional, 'who', 'User to be exempted'
302
+ d.description :flag, 'raw', 'Unquiet the given hostmask instead of the user\'s one'
303
+ end
304
+ end
305
+
306
+ unquiet_cmd.branch('in', 'where who --raw') do |e, c|
307
+ e[:socket].mode(c.positionals['where'], "-q #{get_target(e, c, c.flags['raw'])}")
308
+ end.tap do |b|
309
+ b.description = 'Unquiets the given user in the given channel'
310
+ b.definition.tap do |d|
311
+ d.description :positional, 'where', 'Channel to exempt in'
312
+ d.description :positional, 'who', 'User to be exempted'
313
+ d.description :flag, 'raw', 'Unquiet the given hostmask instead of the user\'s one'
314
+ end
315
+ end
316
+
317
+ #
318
+ # voice command
319
+ #
320
+
321
+ voice_cmd = cmd('voice')
322
+
323
+ voice_cmd.branch('invoker', '') do |e, c|
324
+ e[:socket].mode(e[:target], "+v #{e[:nick]}")
325
+ end.tap do |b|
326
+ b.description = 'Voices you in the current channel'
327
+ end
328
+
329
+ voice_cmd.branch('here', 'who') do |e, c|
330
+ e[:socket].mode(e[:target], "+v #{c.positionals['who']}")
331
+ end.tap do |b|
332
+ b.description = 'Voices the given user in the current channel'
333
+ b.definition.tap do |d|
334
+ d.description :positional, 'who', 'User to be voiced'
335
+ end
336
+ end
337
+
338
+ voice_cmd.branch('in', 'where who') do |e, c|
339
+ e[:socket].mode(c.positionals['where'], "+v #{c.positionals['who']}")
340
+ end.tap do |b|
341
+ b.description = 'Voices the given user in the given channel'
342
+ b.definition.tap do |d|
343
+ d.description :positional, 'where', 'Channel to voice in'
344
+ d.description :positional, 'who', 'User to be voiced'
345
+ end
346
+ end
347
+
348
+ #
349
+ # devoice command
350
+ #
351
+
352
+ devoice_cmd = cmd('devoice')
353
+
354
+ devoice_cmd.branch('invoker', '') do |e, c|
355
+ e[:socket].mode(e[:target], "-v #{e[:nick]}")
356
+ end.tap do |b|
357
+ b.description = 'Devoices you in the current channel'
358
+ end
359
+
360
+ devoice_cmd.branch('here', 'who') do |e, c|
361
+ e[:socket].mode(e[:target], "-v #{c.positionals['who']}")
362
+ end.tap do |b|
363
+ b.description = 'Devoices the given user in the current channel'
364
+ b.definition.tap do |d|
365
+ d.description :positional, 'who', 'User to be devoiced'
366
+ end
367
+ end
368
+
369
+ devoice_cmd.branch('in', 'where who') do |e, c|
370
+ e[:socket].mode(c.positionals['where'], "-v #{c.positionals['who']}")
371
+ end.tap do |b|
372
+ b.description = 'Deoices the given user in the given channel'
373
+ b.definition.tap do |d|
374
+ d.description :positional, 'where', 'Channel to voice in'
375
+ d.description :positional, 'who', 'User to be devoiced'
376
+ end
377
+ end
378
+
379
+ #
380
+ # op command
381
+ #
382
+
383
+ op_cmd = cmd('op')
384
+
385
+ op_cmd.branch('invoker', '') do |e, c|
386
+ e[:socket].mode(e[:target], "+o #{e[:nick]}")
387
+ end.tap do |b|
388
+ b.description = 'Ops you in the current channel'
389
+ end
390
+
391
+ op_cmd.branch('here', 'who') do |e, c|
392
+ e[:socket].mode(e[:target], "+o #{c.positionals['who']}")
393
+ end.tap do |b|
394
+ b.description = 'Ops the given user in the current channel'
395
+ b.definition.tap do |d|
396
+ d.description :positional, 'who', 'User to be opd'
397
+ end
398
+ end
399
+
400
+ op_cmd.branch('in', 'where who') do |e, c|
401
+ e[:socket].mode(c.positionals['where'], "+o #{c.positionals['who']}")
402
+ end.tap do |b|
403
+ b.description = 'Ops the given user in the given channel'
404
+ b.definition.tap do |d|
405
+ d.description :positional, 'where', 'Channel to op in'
406
+ d.description :positional, 'who', 'User to be opd'
407
+ end
408
+ end
409
+
410
+ #
411
+ # deop command
412
+ #
413
+
414
+ deop_cmd = cmd('deop')
415
+
416
+ deop_cmd.branch('invoker', '') do |e, c|
417
+ e[:socket].mode(e[:target], "-o #{e[:nick]}")
418
+ end.tap do |b|
419
+ b.description = 'Deops you in the current channel'
420
+ end
421
+
422
+ deop_cmd.branch('here', 'who') do |e, c|
423
+ e[:socket].mode(e[:target], "-o #{c.positionals['who']}")
424
+ end.tap do |b|
425
+ b.description = 'Deops the given user in the current channel'
426
+ b.definition.tap do |d|
427
+ d.description :positional, 'who', 'User to be deopped'
428
+ end
429
+ end
430
+
431
+ deop_cmd.branch('in', 'where who') do |e, c|
432
+ e[:socket].mode(c.positionals['where'], "-o #{c.positionals['who']}")
433
+ end.tap do |b|
434
+ b.description = 'Deops the given user in the given channel'
435
+ b.definition.tap do |d|
436
+ d.description :positional, 'where', 'Channel to deop in'
437
+ d.description :positional, 'who', 'User to be deopped'
438
+ end
439
+ end
440
+
441
+ #
442
+ # hop command
443
+ #
444
+
445
+ hop_cmd = cmd('hop')
446
+
447
+ hop_cmd.branch('invoker', '') do |e, c|
448
+ e[:socket].mode(e[:target], "+h #{e[:nick]}")
449
+ end.tap do |b|
450
+ b.description = 'Half-Ops you in the current channel'
451
+ end
452
+
453
+ hop_cmd.branch('here', 'who') do |e, c|
454
+ e[:socket].mode(e[:target], "+h #{c.positionals['who']}")
455
+ end.tap do |b|
456
+ b.description = 'Half-Ops the given user in the current channel'
457
+ b.definition.tap do |d|
458
+ d.description :positional, 'who', 'User to be half-oppedd'
459
+ end
460
+ end
461
+
462
+ hop_cmd.branch('in', 'where who') do |e, c|
463
+ e[:socket].mode(c.positionals['where'], "+h #{c.positionals['who']}")
464
+ end.tap do |b|
465
+ b.description = 'Half-Ops the given user in the given channel'
466
+ b.definition.tap do |d|
467
+ d.description :positional, 'where', 'Channel to half-op in'
468
+ d.description :positional, 'who', 'User to be half-oppedd'
469
+ end
470
+ end
471
+
472
+ #
473
+ # dehop command
474
+ #
475
+
476
+ dehop_cmd = cmd('dehop')
477
+
478
+ dehop_cmd.branch('invoker', '') do |e, c|
479
+ e[:socket].mode(e[:target], "-h #{e[:nick]}")
480
+ end.tap do |b|
481
+ b.description = 'Dehalf-ops you in the current channel'
482
+ end
483
+
484
+ dehop_cmd.branch('here', 'who') do |e, c|
485
+ e[:socket].mode(e[:target], "-h #{c.positionals['who']}")
486
+ end.tap do |b|
487
+ b.description = 'Dehalf-ops the given user in the current channel'
488
+ b.definition.tap do |d|
489
+ d.description :positional, 'who', 'User to be dehalf-opped'
490
+ end
491
+ end
492
+
493
+ dehop_cmd.branch('in', 'where who') do |e, c|
494
+ e[:socket].mode(c.positionals['where'], "-h #{c.positionals['who']}")
495
+ end.tap do |b|
496
+ b.description = 'Dehalf-ops the given user in the given channel'
497
+ b.definition.tap do |d|
498
+ d.description :positional, 'where', 'Channel to dehalf-op in'
499
+ d.description :positional, 'who', 'User to be dehalf-opped'
500
+ end
501
+ end
@@ -0,0 +1,77 @@
1
+ @cookie_qualities = {
2
+ 'normal' => '',
3
+ 'uncommon' => '%C%LBLUEuncommon ',
4
+ 'rare' => '%C%BLUErare ',
5
+ 'epic' => '%C%PURPLEepic ',
6
+ 'legendary' => '%C%YELLOWlegendary ',
7
+ 'holy' => '%C%ORANGEholy ',
8
+ 'hi-tech' => '%C%CYANhi-tech ',
9
+ 'quantum' => '%C%LBLUEquantum ',
10
+ 'evil' => '%C%BLACKevil ',
11
+ 'magical' => '%C%PURPLEmagical ',
12
+ 'ancient' => '%C%LBLUEancient ',
13
+ 'vampiric' => '%C%REDvampiric '
14
+ }
15
+
16
+ @cookie_types = {
17
+ 'normal' => '',
18
+ 'blazing' => '%C%ORANGEblazing ',
19
+ 'hot' => '%C%REDhot ',
20
+ 'frozen' => '%C%CYANfrozen ',
21
+ 'chilling' => '%C%LBLUEchilling ',
22
+ 'shocking' => '%C%YELLOWshocking ',
23
+ 'aerial' => '%C%LGREYaerial ',
24
+ 'stone' => '%C%GREYstone ',
25
+ 'mud' => '%C%BROWNmud ',
26
+ 'void' => '%C%BLACKvoid ',
27
+ 'ghostly' => '%C%WHITEghostly ',
28
+ 'bloody' => '%C%REDbloody ',
29
+ 'nyan' => '%C%REDn%C%GREENy%C%BLUEa%C%CYANn ',
30
+ 'teleporting' => '%C%CYANteleporting ',
31
+ 'wild' => '%C%BROWNwild ',
32
+ 'alient' => '%C%GREENalien ',
33
+ 'spacious' => '%C%BLACKspacious ',
34
+ 'atomic' => '%C%REDatomic ',
35
+ 'chocolate' => '%C%BROWNchocolate '
36
+ }
37
+
38
+ group('world') do |g|
39
+ g.perm @name, 'cookie', 'invoker'
40
+ g.perm @name, 'cookie', 'targeted'
41
+ end
42
+
43
+ def generate(e, c, targeted)
44
+ quality = @cookie_qualities[c.options['quality']] || @cookie_qualities.values.sample
45
+ type = @cookie_types[c.options['type']] || @cookie_types.values.sample
46
+ target = if targeted
47
+ c.positionals['who']
48
+ else
49
+ e[:nick]
50
+ end
51
+ "ACTION %Ngives %B#{target}%N a %B#{quality}#{type}%N%B%C%BROWNcookie%N"
52
+ end
53
+
54
+ cookie_cmd = cmd 'cookie'
55
+
56
+ cookie_cmd.branch('invoker', '--quality=QUALITY --type=TYPE') do |e, c|
57
+ e[:socket].ctcp(e[:reply_to], generate(e, c, false))
58
+ end.tap do |b|
59
+ b.cooldown = 10
60
+ b.description = 'Gives you a cookie'
61
+ b.definition.tap do |d|
62
+ d.description :option, 'quality', 'The cookie quality (optional)'
63
+ d.description :option, 'type', 'The cookie type (optional)'
64
+ end
65
+ end
66
+
67
+ cookie_cmd.branch('targeted', 'who --quality=QUALITY --type=TYPE') do |e, c|
68
+ e[:socket].ctcp(e[:reply_to], generate(e, c, true))
69
+ end.tap do |b|
70
+ b.cooldown = 10
71
+ b.description = 'Gives a cookie to the given user'
72
+ b.definition.tap do |d|
73
+ d.description :positional, 'who', 'User to give cookie to'
74
+ d.description :option, 'quality', 'The cookie quality (optional)'
75
+ d.description :option, 'type', 'The cookie type (optional)'
76
+ end
77
+ end