zmb 0.1.2 → 0.1.3
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.
- data/VERSION +1 -1
- data/bin/zmb +1 -1
- data/lib/zmb.rb +16 -3
- data/lib/zmb/commands.rb +1 -1
- data/lib/zmb/plugin.rb +3 -2
- data/plugins/commands.rb +56 -0
- data/plugins/idle.rb +50 -0
- data/plugins/irc.rb +49 -7
- data/plugins/poll.rb +102 -0
- data/zmb.gemspec +4 -2
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bin/zmb
CHANGED
@@ -76,7 +76,7 @@ def wizard(zmb, plugin)
|
|
76
76
|
|
77
77
|
if not instance then
|
78
78
|
puts "Must supply instance name, if this plugin should only be loaded once such as commands or users then you can call it that."
|
79
|
-
return wizard
|
79
|
+
return wizard(zmb, plugin)
|
80
80
|
end
|
81
81
|
|
82
82
|
zmb.setup(plugin.name, instance)
|
data/lib/zmb.rb
CHANGED
@@ -203,6 +203,7 @@ class Zmb
|
|
203
203
|
'clone' => PermCommand.new('admin', self, :clone_command, 2),
|
204
204
|
'reset' => PermCommand.new('admin', self, :reset_command),
|
205
205
|
'addsource' => PermCommand.new('admin', self, :addsource_command),
|
206
|
+
'refresh' => PermCommand.new('admin', self, :refresh_command),
|
206
207
|
}
|
207
208
|
end
|
208
209
|
|
@@ -236,7 +237,7 @@ class Zmb
|
|
236
237
|
if not @instances.has_key?(instance) then
|
237
238
|
load(instance) ? "#{instance} loaded" : "#{instance} did not load correctly"
|
238
239
|
else
|
239
|
-
"Instance already #{instance}"
|
240
|
+
"Instance already loaded #{instance}"
|
240
241
|
end
|
241
242
|
end
|
242
243
|
|
@@ -249,11 +250,13 @@ class Zmb
|
|
249
250
|
@instances.keys.join(', ')
|
250
251
|
end
|
251
252
|
|
252
|
-
def setup_command(e, plugin, instance)
|
253
|
+
def setup_command(e, plugin, instance=nil)
|
254
|
+
instance = plugin if not instance
|
255
|
+
|
253
256
|
if setup(plugin, instance) then
|
254
257
|
object = @plugin_manager.plugin plugin
|
255
258
|
result = ["Instance saved, please use the set command to override the default configuration for this instance."]
|
256
|
-
result +=
|
259
|
+
result += object.wizard.map{ |k,v| "#{k} - #{v['help']} (default=#{v['default']})" } if object.respond_to? 'wizard'
|
257
260
|
result.join("\n")
|
258
261
|
else
|
259
262
|
"plugin not found"
|
@@ -264,6 +267,11 @@ class Zmb
|
|
264
267
|
settings = @settings.setting(instance)
|
265
268
|
settings[key] = value
|
266
269
|
@settings.save(instance, settings)
|
270
|
+
|
271
|
+
if @instances.has_key?(instance) and @instances[instance].respond_to?('update') then
|
272
|
+
@instances[instance].update(key, value)
|
273
|
+
end
|
274
|
+
|
267
275
|
"#{key} set to #{value} for #{instance}"
|
268
276
|
end
|
269
277
|
|
@@ -293,4 +301,9 @@ class Zmb
|
|
293
301
|
@plugin_manager.add_plugin_source source
|
294
302
|
"#{source} added to plugin manager"
|
295
303
|
end
|
304
|
+
|
305
|
+
def refresh_command(e)
|
306
|
+
@plugin_manager.refresh_plugin_sources
|
307
|
+
"Refreshed plugin sources"
|
308
|
+
end
|
296
309
|
end
|
data/lib/zmb/commands.rb
CHANGED
@@ -27,7 +27,7 @@ class Command
|
|
27
27
|
'incorrect arguments'
|
28
28
|
rescue Exception
|
29
29
|
if e.respond_to?('user') and e.user.respond_to?('admin?') and e.user.admin? and e.private? then
|
30
|
-
"#{$!.message}\n#{$!.inspect}"
|
30
|
+
"#{$!.message}\n#{$!.inspect}\n#{$!.backtrace[0..2].join("\n")}"
|
31
31
|
else
|
32
32
|
"command failed"
|
33
33
|
end
|
data/lib/zmb/plugin.rb
CHANGED
data/plugins/commands.rb
CHANGED
@@ -4,6 +4,7 @@ class Commands
|
|
4
4
|
attr_accessor :cmds, :cc
|
5
5
|
|
6
6
|
def initialize(sender, settings={})
|
7
|
+
@delegate = sender
|
7
8
|
@cmds = Hash.new
|
8
9
|
|
9
10
|
@cc = settings['cc'] if settings.has_key?('cc')
|
@@ -82,10 +83,29 @@ class Commands
|
|
82
83
|
instance.commands.each{|command, cmd| @cmds.delete(command)} if instance.respond_to?('commands')
|
83
84
|
end
|
84
85
|
|
86
|
+
def split_seperators(data)
|
87
|
+
if data.include?("\n") then
|
88
|
+
data.split("\n")
|
89
|
+
elsif data.include?(',') then
|
90
|
+
data.split(',')
|
91
|
+
elsif data.include?(' ') then
|
92
|
+
data.split(' ')
|
93
|
+
else
|
94
|
+
data
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
85
98
|
def commands
|
86
99
|
{
|
87
100
|
'help' => Command.new(self, :help),
|
101
|
+
'instance' => Command.new(self, :instance, 1, 'List all commands availible for a instance.'),
|
88
102
|
'cc' => PermCommand.new('admin', self, :control_command),
|
103
|
+
'eval' => PermCommand.new('admin', self, :evaluate),
|
104
|
+
'count' => Command.new(self, :count),
|
105
|
+
'grep' => Command.new(self, :grep, 2),
|
106
|
+
'not' => Command.new(self, :not_command, 2),
|
107
|
+
'tail' => Command.new(self, :tail),
|
108
|
+
'echo' => Command.new(self, :echo),
|
89
109
|
}
|
90
110
|
end
|
91
111
|
|
@@ -101,6 +121,18 @@ class Commands
|
|
101
121
|
end
|
102
122
|
end
|
103
123
|
|
124
|
+
def instance(e, inst)
|
125
|
+
if @delegate.instances.has_key?(inst) then
|
126
|
+
if @delegate.instances[inst].respond_to?('commands') then
|
127
|
+
@delegate.instances[inst].commands.keys.join(', ')
|
128
|
+
else
|
129
|
+
"No commands availible for #{inst}"
|
130
|
+
end
|
131
|
+
else
|
132
|
+
"No instance found for #{inst}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
104
136
|
def control_command(e, cc=nil)
|
105
137
|
if cc then
|
106
138
|
@cc = cc
|
@@ -110,6 +142,30 @@ class Commands
|
|
110
142
|
|
111
143
|
"Control command set to #{@cc}"
|
112
144
|
end
|
145
|
+
|
146
|
+
def evaluate(e, string)
|
147
|
+
"#{eval string}"
|
148
|
+
end
|
149
|
+
|
150
|
+
def count(e, data)
|
151
|
+
"#{split_seperators(data).size}"
|
152
|
+
end
|
153
|
+
|
154
|
+
def grep(e, search, data)
|
155
|
+
split_seperators(data).reject{ |d| not d.include?(search) }.join(', ')
|
156
|
+
end
|
157
|
+
|
158
|
+
def not_command(e, search, data)
|
159
|
+
split_seperators(data).reject{ |d| d.include?(search) }.join(', ')
|
160
|
+
end
|
161
|
+
|
162
|
+
def tail(e, data)
|
163
|
+
split_seperators(data).reverse[0..2].join(', ')
|
164
|
+
end
|
165
|
+
|
166
|
+
def echo(e, data)
|
167
|
+
"#{data}"
|
168
|
+
end
|
113
169
|
end
|
114
170
|
|
115
171
|
Plugin.define do
|
data/plugins/idle.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
class Idle
|
2
|
+
def initialize(sender, settings)
|
3
|
+
@channels = Hash.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_json(*a)
|
7
|
+
{ 'plugin' => 'idle' }.to_json(*a)
|
8
|
+
end
|
9
|
+
|
10
|
+
def event(sender, e)
|
11
|
+
if e.message? and e.respond_to?('channel') then
|
12
|
+
@channels[e.channel] = Time.now if not e.message.include?('idle')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def commands
|
17
|
+
require 'zmb/commands'
|
18
|
+
{
|
19
|
+
'idle' => Command.new(self, :idle, 1, 'How idle has a channel been?'),
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def idle(e, channel=nil)
|
24
|
+
channel = e.channel if not channel
|
25
|
+
|
26
|
+
if not @channels.has_key?(channel) then
|
27
|
+
"I have not seen any messages in #{channel}"
|
28
|
+
else
|
29
|
+
diff = Time.now - @channels[channel]
|
30
|
+
|
31
|
+
if diff < 60 then
|
32
|
+
msg = "#{Integer(diff)} seconds ago"
|
33
|
+
elsif diff < 3600 then
|
34
|
+
msg = "#{Integer(diff/60)} minutes ago"
|
35
|
+
elsif diff < 86400 then
|
36
|
+
msg = "about #{Integer(diff/3600)} hours ago"
|
37
|
+
else
|
38
|
+
msg = "#{Integer(diff/86400)} days ago"
|
39
|
+
end
|
40
|
+
|
41
|
+
"Last message in #{channel} was #{msg}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Plugin.define do
|
47
|
+
name 'idle'
|
48
|
+
description 'Let\'s you see how idle a channel has been'
|
49
|
+
object Idle
|
50
|
+
end
|
data/plugins/irc.rb
CHANGED
@@ -3,7 +3,7 @@ require 'socket'
|
|
3
3
|
require 'zmb/timer'
|
4
4
|
|
5
5
|
class Event
|
6
|
-
attr_accessor :delegate, :command, :args, :name, :userhost, :message
|
6
|
+
attr_accessor :delegate, :command, :args, :name, :userhost, :message, :channel
|
7
7
|
|
8
8
|
def initialize(sender, line)
|
9
9
|
puts line
|
@@ -114,9 +114,14 @@ class IrcConnection
|
|
114
114
|
{
|
115
115
|
'join' => PermCommand.new('admin', self, :join_command),
|
116
116
|
'part' => PermCommand.new('admin', self, :part_command),
|
117
|
+
'cycle' => PermCommand.new('admin', self, :cycle_command),
|
118
|
+
'topic' => PermCommand.new('admin', self, :topic_command, 2),
|
119
|
+
'kick' => PermCommand.new('admin', self, :kick_command, 2),
|
120
|
+
'channels' => PermCommand.new('admin', self, :channels_command),
|
117
121
|
'raw' => PermCommand.new('admin', self, :raw_command),
|
118
122
|
'nick' => PermCommand.new('admin', self, :nick_command),
|
119
123
|
'tell' => PermCommand.new('admin', self, :tell_command, 2),
|
124
|
+
'reconnect' => PermCommand.new('admin', self, :reconnect_command),
|
120
125
|
}
|
121
126
|
end
|
122
127
|
|
@@ -198,31 +203,68 @@ class IrcConnection
|
|
198
203
|
end
|
199
204
|
|
200
205
|
def join_command(e, channel)
|
201
|
-
join channel
|
206
|
+
e.delegate.join channel
|
202
207
|
"#{channel} joined"
|
203
208
|
end
|
204
209
|
|
205
210
|
def part_command(e, channel)
|
206
|
-
part channel
|
211
|
+
e.delegate.part channel
|
207
212
|
"left #{channel}"
|
208
213
|
end
|
209
214
|
|
215
|
+
def cycle_command(e, channel=nil)
|
216
|
+
channel = e.channel if not channel
|
217
|
+
e.delegate.part channel
|
218
|
+
e.delegate.join channel
|
219
|
+
"#{channel} cycled"
|
220
|
+
end
|
221
|
+
|
222
|
+
def topic_command(e, channel, topic=nil)
|
223
|
+
if not topic then
|
224
|
+
topic = channel
|
225
|
+
channel = e.channel
|
226
|
+
end
|
227
|
+
|
228
|
+
e.delegate.write "TOPIC #{channel} :#{topic}"
|
229
|
+
end
|
230
|
+
|
231
|
+
def kick_command(e, channel, nick=nil)
|
232
|
+
if not nick then
|
233
|
+
nick = channel
|
234
|
+
channel = e.channel
|
235
|
+
end
|
236
|
+
|
237
|
+
e.delegate.write "KICK #{channel} #{nick}"
|
238
|
+
end
|
239
|
+
|
240
|
+
def channels_command(e)
|
241
|
+
if e.delegate.channels.size > 0 then
|
242
|
+
"Channels: #{e.delegate.channels.join(", ")}"
|
243
|
+
else
|
244
|
+
"I am not in any channels"
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
210
248
|
def raw_command(e, line)
|
211
|
-
write line
|
249
|
+
e.delegate.write line
|
212
250
|
nil
|
213
251
|
end
|
214
252
|
|
215
253
|
def nick_command(e, nick)
|
216
|
-
write "NICK #{nick}"
|
254
|
+
e.delegate.write "NICK #{nick}"
|
217
255
|
"Nick changed to #{nick}"
|
218
256
|
end
|
219
257
|
|
220
258
|
def tell_command(e, to, message)
|
221
|
-
|
222
|
-
|
259
|
+
message = message.split("\n") if not message.respond_to?('each')
|
260
|
+
message.each{ |m| e.delegate.message(to, m) }
|
223
261
|
nil
|
224
262
|
end
|
225
263
|
|
264
|
+
def reconnect_command(e, message='Reconnect')
|
265
|
+
e.delegate.write "QUIT :#{message}"
|
266
|
+
end
|
267
|
+
|
226
268
|
def running(sender)
|
227
269
|
connect
|
228
270
|
end
|
data/plugins/poll.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
class Poll
|
2
|
+
def initialize(sender, settings={})
|
3
|
+
@polls = Hash.new
|
4
|
+
@polls = settings['polls'] if settings.has_key?('polls')
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_json(*a)
|
8
|
+
{ 'plugin' => 'poll', 'polls' => @polls }.to_json(*a)
|
9
|
+
end
|
10
|
+
|
11
|
+
def add(slug, poll)
|
12
|
+
@polls[slug] = {'poll' => poll, 'options' => [], 'votes' => {}}
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_opt(slug, option)
|
16
|
+
@polls[slug]['options'] << option
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_vote(username, slug, option)
|
20
|
+
@polls[slug]['votes'][username] = option
|
21
|
+
end
|
22
|
+
|
23
|
+
def poll_opt?(slug, opt)
|
24
|
+
@polls[slug]['options'].values_at(opt)[0] != nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def poll_count(slug, opt)
|
28
|
+
@polls[slug]['votes'].reject{ |k,v| v != opt }.size
|
29
|
+
end
|
30
|
+
|
31
|
+
def commands
|
32
|
+
require 'zmb/commands'
|
33
|
+
{
|
34
|
+
'poll-add' => PermCommand.new('admin', self, :add_command, 2),
|
35
|
+
'poll-opt' => PermCommand.new('admin', self, :opt_command, 2),
|
36
|
+
'poll-del' => PermCommand.new('admin', self, :del_command),
|
37
|
+
'vote' => Command.new(self, :vote_command, 2),
|
38
|
+
'polls' => Command.new(self, :polls_command, 0),
|
39
|
+
'poll' => Command.new(self, :poll_command, 1),
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_command(e, slug, poll)
|
44
|
+
add(slug, poll)
|
45
|
+
"#{poll} added as #{slug}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def opt_command(e, slug, option)
|
49
|
+
add_opt(slug, option)
|
50
|
+
"#{option} added to #{slug}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def del_command(e, slug)
|
54
|
+
@polls.delete(slug)
|
55
|
+
"#{slug} deleted"
|
56
|
+
end
|
57
|
+
|
58
|
+
def vote_command(e, slug, option)
|
59
|
+
return "permission denied" if not e.user.authenticated?
|
60
|
+
|
61
|
+
begin
|
62
|
+
opt = Integer(option)-1
|
63
|
+
rescue ArgumentError
|
64
|
+
return "Option must be a number"
|
65
|
+
end
|
66
|
+
|
67
|
+
if @polls.has_key?(slug) then
|
68
|
+
if poll_opt?(slug, opt) then
|
69
|
+
add_vote(e.user.username, slug, opt)
|
70
|
+
"Vote added"
|
71
|
+
else
|
72
|
+
"Option #{opt+1} doesn't exist for #{slug}"
|
73
|
+
end
|
74
|
+
else
|
75
|
+
"#{slug}: poll doesn't exist"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def polls_command(e)
|
80
|
+
if @polls.size > 0 then
|
81
|
+
@polls.map{ |k,v| "#{k}: #{v['poll']}"}.join("\n")
|
82
|
+
else
|
83
|
+
"No polls found"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def poll_command(e, slug)
|
88
|
+
if @polls.has_key?(slug) then
|
89
|
+
poll = @polls[slug]
|
90
|
+
x = 0
|
91
|
+
"#{poll['poll']}\n" + poll['options'].map{ |o| "#{x += 1}: #{o} (#{poll_count(slug, x-1)})" }.join("\n")
|
92
|
+
else
|
93
|
+
"#{slug}: poll doesn't exist"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
Plugin.define do
|
99
|
+
name 'poll'
|
100
|
+
description 'voting plugin'
|
101
|
+
object Poll
|
102
|
+
end
|
data/zmb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{zmb}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kylef"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-03}
|
13
13
|
s.default_executable = %q{zmb}
|
14
14
|
s.description = %q{ZMB, messenger bot}
|
15
15
|
s.email = %q{inbox@kylefuller.co.uk}
|
@@ -34,8 +34,10 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/zmb/timer.rb",
|
35
35
|
"plugins/bank.rb",
|
36
36
|
"plugins/commands.rb",
|
37
|
+
"plugins/idle.rb",
|
37
38
|
"plugins/irc.rb",
|
38
39
|
"plugins/nickserv.rb",
|
40
|
+
"plugins/poll.rb",
|
39
41
|
"plugins/quote.rb",
|
40
42
|
"plugins/relay.rb",
|
41
43
|
"plugins/system.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zmb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kylef
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-03 00:00:00 +00:00
|
13
13
|
default_executable: zmb
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -57,8 +57,10 @@ files:
|
|
57
57
|
- lib/zmb/timer.rb
|
58
58
|
- plugins/bank.rb
|
59
59
|
- plugins/commands.rb
|
60
|
+
- plugins/idle.rb
|
60
61
|
- plugins/irc.rb
|
61
62
|
- plugins/nickserv.rb
|
63
|
+
- plugins/poll.rb
|
62
64
|
- plugins/quote.rb
|
63
65
|
- plugins/relay.rb
|
64
66
|
- plugins/system.rb
|