zmb 0.3.0 → 0.3.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.
- data/VERSION +1 -1
- data/bin/zmb +16 -2
- data/lib/zmb.rb +8 -0
- data/lib/zmb/utils.rb +8 -0
- data/plugins/commands.rb +90 -34
- data/plugins/httpwatch.rb +64 -0
- data/plugins/linecount.rb +48 -0
- data/plugins/poll.rb +5 -5
- data/plugins/quote.rb +5 -5
- data/plugins/relay.rb +4 -4
- data/plugins/rss.rb +116 -0
- data/plugins/security.rb +5 -5
- data/plugins/sed.rb +3 -1
- data/plugins/translate.rb +34 -0
- data/plugins/url.rb +2 -2
- data/plugins/usermodes.rb +3 -3
- data/plugins/vouch.rb +3 -3
- data/zmb.gemspec +6 -2
- metadata +6 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/bin/zmb
CHANGED
@@ -28,7 +28,7 @@ class AdminUser
|
|
28
28
|
end
|
29
29
|
|
30
30
|
class Event
|
31
|
-
attr_accessor :message, :user
|
31
|
+
attr_accessor :message, :user, :delegate
|
32
32
|
|
33
33
|
def initialize(message)
|
34
34
|
@message = message
|
@@ -46,6 +46,10 @@ class Event
|
|
46
46
|
def reply(msg)
|
47
47
|
puts "> #{msg}"
|
48
48
|
end
|
49
|
+
|
50
|
+
def name
|
51
|
+
"admin"
|
52
|
+
end
|
49
53
|
end
|
50
54
|
|
51
55
|
def ask(question)
|
@@ -125,6 +129,11 @@ optparse = OptionParser.new do |opts|
|
|
125
129
|
opts.on('-l', '--line LINE', 'Execute a command') do |line|
|
126
130
|
options[:command] = line
|
127
131
|
end
|
132
|
+
|
133
|
+
options[:fork] = false
|
134
|
+
opts.on('-f', '--fork', 'Detach (fork) ZMB (for use with -d daemon)') do
|
135
|
+
options[:fork] = true
|
136
|
+
end
|
128
137
|
end
|
129
138
|
|
130
139
|
optparse.parse!
|
@@ -182,5 +191,10 @@ if options[:shell] then
|
|
182
191
|
end
|
183
192
|
|
184
193
|
if options[:daemon] then
|
185
|
-
|
194
|
+
if options[:fork] then
|
195
|
+
Process.detach(fork { STDOUT.reopen(File.open('/dev/null','w')); zmb.run })
|
196
|
+
puts "ZMB detached"
|
197
|
+
else
|
198
|
+
zmb.run
|
199
|
+
end
|
186
200
|
end
|
data/lib/zmb.rb
CHANGED
@@ -220,6 +220,7 @@ class Zmb
|
|
220
220
|
'reset' => [:reset_command, 1, { :permission => 'admin' }],
|
221
221
|
'addsource' => [:addource_command, 1, { :permission => 'admin' }],
|
222
222
|
'refresh' => [:refresh_command, 1, { :permission => 'admin' }],
|
223
|
+
'quit' => [:quit_command, 0, { :permission => 'admin' }],
|
223
224
|
}
|
224
225
|
end
|
225
226
|
|
@@ -323,4 +324,11 @@ class Zmb
|
|
323
324
|
@plugin_manager.refresh_plugin_sources
|
324
325
|
"Refreshed plugin sources"
|
325
326
|
end
|
327
|
+
|
328
|
+
def quit_command(e)
|
329
|
+
e.reply "Quitting"
|
330
|
+
save
|
331
|
+
@running = false
|
332
|
+
instances.keys.each{ |i| unload(i) }
|
333
|
+
end
|
326
334
|
end
|
data/lib/zmb/utils.rb
CHANGED
data/plugins/commands.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
class Commands
|
2
|
-
attr_accessor :cmds, :cc
|
2
|
+
attr_accessor :cmds, :cc, :definitions
|
3
3
|
|
4
4
|
def initialize(sender, s={})
|
5
5
|
@delegate = sender
|
6
6
|
@cmds = Hash.new
|
7
|
+
@definitions = Hash.new
|
7
8
|
|
8
9
|
@cc = s['cc'] if s.has_key?('cc')
|
9
10
|
@cc = '.' if @cc == nil
|
11
|
+
@definitions = s['definitions'] if s.has_key?('definitions')
|
10
12
|
|
11
13
|
sender.instances.each{ |key, instance| plugin_loaded(key, instance) }
|
14
|
+
|
15
|
+
@definitions.each do |k,v|
|
16
|
+
@cmds[k] = {
|
17
|
+
:args => v[0],
|
18
|
+
:proc => (eval v[1])
|
19
|
+
}
|
20
|
+
end
|
12
21
|
end
|
13
22
|
|
14
23
|
def settings
|
15
|
-
{ 'cc' => @cc }
|
24
|
+
{ 'cc' => @cc, 'definitions' => @definitions }
|
16
25
|
end
|
17
26
|
|
18
27
|
def self.wizard
|
@@ -91,30 +100,30 @@ class Commands
|
|
91
100
|
|
92
101
|
c = @cmds[cmd]
|
93
102
|
|
94
|
-
if c[
|
103
|
+
if c[:args] == 0 then
|
95
104
|
args = Array.new
|
96
|
-
elsif args.size > c[
|
97
|
-
a = args.first c[
|
98
|
-
a << args[c[
|
105
|
+
elsif args.size > c[:args]
|
106
|
+
a = args.first c[:args]-1 # Take one under amount of commands
|
107
|
+
a << args[c[:args]-1..-1].join(' ')
|
99
108
|
args = a
|
100
109
|
end
|
101
110
|
|
102
111
|
# User permissions
|
103
|
-
if
|
112
|
+
if c.has_key?(:permission) then
|
104
113
|
if not e.respond_to?('user')
|
105
114
|
return 'user module not loaded'
|
106
|
-
elsif
|
115
|
+
elsif c[:permission] == 'authenticated' then
|
107
116
|
return 'permission denied' if not e.user.authenticated?
|
108
|
-
elsif not e.user.permission?(
|
117
|
+
elsif not e.user.permission?(c[:permission])
|
109
118
|
return 'permission denied'
|
110
119
|
end
|
111
120
|
end
|
112
121
|
|
113
122
|
begin
|
114
|
-
if c
|
115
|
-
c[
|
116
|
-
elsif c
|
117
|
-
|
123
|
+
if c.has_key?(:instance) and c.has_key?(:symbol) then
|
124
|
+
c[:instance].send(c[:symbol], e, *args)
|
125
|
+
elsif c.has_key?(:proc) then
|
126
|
+
c[:proc].call(e, *args)
|
118
127
|
else
|
119
128
|
"Bad command definition"
|
120
129
|
end
|
@@ -132,39 +141,53 @@ class Commands
|
|
132
141
|
def plugin_loaded(key, instance)
|
133
142
|
if instance.respond_to?('commands') then
|
134
143
|
instance.commands.each do |k,v|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
144
|
+
@cmds[k] = {
|
145
|
+
:instance => instance,
|
146
|
+
:args => 1
|
147
|
+
}
|
148
|
+
|
149
|
+
if v.class == Hash then
|
150
|
+
@cmds[k].merge(v)
|
151
|
+
else
|
152
|
+
v = [v] if v.class != Array
|
153
|
+
v.each do |item|
|
154
|
+
@cmds[k][:args] = item if item.class == Fixnum
|
155
|
+
@cmds[k].merge!(item) if item.class == Hash
|
156
|
+
@cmds[k][:symbol] = item if item.class == Symbol
|
157
|
+
@cmds[k][:proc] = item if item.class == Proc
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
@cmds[k][:args] = @cmds[k][:usage].split(' ').count if @cmds[k].has_key?(:usage)
|
139
162
|
end
|
140
163
|
end
|
141
164
|
end
|
142
165
|
|
143
166
|
def plugin_unloaded(key, instance)
|
144
|
-
@cmds = @cmds.reject{ |k,v| v[
|
167
|
+
@cmds = @cmds.reject{ |k,v| v[:instance] == instance }
|
145
168
|
end
|
146
169
|
|
147
170
|
def commands
|
148
171
|
{
|
149
172
|
'help' => :help,
|
150
|
-
'instance' => [:instance_command,
|
151
|
-
'which' => [:which,
|
152
|
-
'cc' => [:control_command,
|
153
|
-
'eval' => [:evaluate,
|
173
|
+
'instance' => [:instance_command, { :help => 'List all commands availible for a instance.'}],
|
174
|
+
'which' => [:which, { :help => 'Find which plugin handles a command' }],
|
175
|
+
'cc' => [:control_command, { :permission => 'admin' }],
|
176
|
+
'eval' => [:evaluate, { :permission => 'admin' }],
|
154
177
|
'ieval' => [:instance_evaluate, 2, { :permission => 'admin' }],
|
155
178
|
'count' => lambda { |e, data| "#{data.split_seperators.size}" },
|
156
179
|
'grep' => [:grep, 2],
|
157
180
|
'not' => [:not_command, 2],
|
158
181
|
'tail' => :tail,
|
159
|
-
'echo' => [:echo,
|
182
|
+
'echo' => [:echo, { :example => 'Hello, {username}' }],
|
160
183
|
'reverse' => lambda { |e, data| data.reverse },
|
161
184
|
'first' => lambda { |e, data| data.split_seperators.first },
|
162
185
|
'last' => lambda { |e, data| data.split_seperators.last },
|
163
|
-
'sub' => [:sub,
|
186
|
+
'sub' => [:sub, {
|
164
187
|
:help => 'Replace all occurances of a pattern',
|
165
188
|
:usage => 'pattern replacement data',
|
166
189
|
:example => 'l * Hello World!' }],
|
167
|
-
'tr' => [:tr,
|
190
|
+
'tr' => [:tr, {
|
168
191
|
:help => 'Returns a copy of str with the characters in from_str replaced by the corresponding characters in to_str',
|
169
192
|
:usage => 'from_str to_str data',
|
170
193
|
:example => 'aeiou * hello' }],
|
@@ -172,6 +195,18 @@ class Commands
|
|
172
195
|
'upcase' => lambda { |e, data| data.upcase },
|
173
196
|
'swapcase' => lambda { |e, data| data.swapcase },
|
174
197
|
'capitalize' => lambda { |e, data| data.capitalize },
|
198
|
+
'define' => [:define, {
|
199
|
+
:permission => 'admin',
|
200
|
+
:help => 'Dynamically define a command',
|
201
|
+
:usage => 'command arguments block',
|
202
|
+
:example => 'ping nil "pong"'
|
203
|
+
}],
|
204
|
+
'undefine' => [:undefine, {
|
205
|
+
:permission => 'admin',
|
206
|
+
:help => 'Undefine a command',
|
207
|
+
:usage => 'command',
|
208
|
+
:example => 'ping'
|
209
|
+
}]
|
175
210
|
}
|
176
211
|
end
|
177
212
|
|
@@ -179,10 +214,10 @@ class Commands
|
|
179
214
|
if command then
|
180
215
|
h = []
|
181
216
|
|
182
|
-
if @cmds.has_key?(command)
|
183
|
-
h << "#{command}: #{
|
184
|
-
h << "Usage: #{command} #{
|
185
|
-
h << "Example: #{command} #{
|
217
|
+
if @cmds.has_key?(command) then
|
218
|
+
h << "#{command}: #{@cmds[command][:help]}" if @cmds[command].has_key?(:help)
|
219
|
+
h << "Usage: #{command} #{@cmds[command][:usage]}" if @cmds[command].has_key?(:usage)
|
220
|
+
h << "Example: #{command} #{@cmds[command][:example]}" if @cmds[command].has_key?(:example)
|
186
221
|
end
|
187
222
|
|
188
223
|
if h.size == 0 then
|
@@ -191,7 +226,7 @@ class Commands
|
|
191
226
|
h.join("\n")
|
192
227
|
end
|
193
228
|
else
|
194
|
-
cmds = @cmds.reject{ |k,v| (
|
229
|
+
cmds = @cmds.reject{ |k,v| (v.has_key?(:permission)) and not e.user.permission?(v[:permission]) }
|
195
230
|
cmds.keys.join(', ')
|
196
231
|
end
|
197
232
|
end
|
@@ -210,11 +245,10 @@ class Commands
|
|
210
245
|
|
211
246
|
def which(e, command)
|
212
247
|
if @cmds.has_key?(command) then
|
213
|
-
|
214
|
-
|
215
|
-
"#{c.plugin} (#{c.instance})"
|
248
|
+
if @cmds[command].has_key?(:instance) and @cmds[command][:instance].plugin != @cmds[command][:instance].instance then
|
249
|
+
"#{@cmds[command][:instance].plugin} (#{@cmds[command][:instance].instance})"
|
216
250
|
else
|
217
|
-
|
251
|
+
@cmds[command][:instance].plugin
|
218
252
|
end
|
219
253
|
else
|
220
254
|
'command not found'
|
@@ -274,6 +308,28 @@ class Commands
|
|
274
308
|
def tr(e, from_str, to_str, data)
|
275
309
|
data.tr(from_str, to_str)
|
276
310
|
end
|
311
|
+
|
312
|
+
def define(e, command, arguments, block)
|
313
|
+
arguments = arguments.split_seperators
|
314
|
+
arguments = [] if arguments.include?('nil') or arguments.include?('none')
|
315
|
+
arguments.insert(0, 'e')
|
316
|
+
|
317
|
+
@cmds[command] = {
|
318
|
+
:args => arguments.count - 1,
|
319
|
+
:proc => (eval "lambda {|#{arguments.join(',')}| #{block}}")
|
320
|
+
}
|
321
|
+
|
322
|
+
@definitions[command] = [arguments.count-1, "lambda {|#{arguments.join(',')}| #{block}}"]
|
323
|
+
|
324
|
+
"#{command} has been defined"
|
325
|
+
end
|
326
|
+
|
327
|
+
def undefine(e, command)
|
328
|
+
@cmds.delete(command)
|
329
|
+
@definitions.delete(command)
|
330
|
+
|
331
|
+
"#{command} removed"
|
332
|
+
end
|
277
333
|
end
|
278
334
|
|
279
335
|
Plugin.define do
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'zmb/timer'
|
3
|
+
|
4
|
+
class HttpWatch
|
5
|
+
attr_accessor :settings
|
6
|
+
|
7
|
+
def initialize(sender, s)
|
8
|
+
@delegate = sender
|
9
|
+
@settings = s
|
10
|
+
@settings['urls'] = Array.new unless @settings.has_key?('urls')
|
11
|
+
@settings['interval'] = 60*5 unless @settings.has_key?('interval')
|
12
|
+
|
13
|
+
@delegate.timer_add(Timer.new(self, :check, @settings['interval'], true))
|
14
|
+
end
|
15
|
+
|
16
|
+
def check
|
17
|
+
@settings['urls'].each do |url|
|
18
|
+
hash = Digest::SHA256.hexdigest(url['url'].get.body)
|
19
|
+
|
20
|
+
if hash != url['hash'] then
|
21
|
+
@delegate.instances[url['instance']].message(url['sender'], "#{url['url']} has been changed")
|
22
|
+
end
|
23
|
+
|
24
|
+
url['hash'] = hash
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def commands
|
29
|
+
{
|
30
|
+
'watch' => [:watch, 1, {}],
|
31
|
+
'stop-watching' => :remove
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def watch(e, url)
|
36
|
+
@settings['urls'] << {
|
37
|
+
'instance' => e.delegate.instance,
|
38
|
+
'sender' => e.sender,
|
39
|
+
'url' => url,
|
40
|
+
'hash' => Digest::SHA256.hexdigest(url.get.body)
|
41
|
+
}
|
42
|
+
|
43
|
+
"#{url} is now being watched"
|
44
|
+
end
|
45
|
+
|
46
|
+
def remove(e, url)
|
47
|
+
u = @settings['urls'].find do |u|
|
48
|
+
(u['url'] == url) and (u['instance'] == e.delegate.instance) and (u['sender'] == e.sender)
|
49
|
+
end
|
50
|
+
|
51
|
+
if u then
|
52
|
+
@settings['urls'].delete(u)
|
53
|
+
"#{url} is no longer being watched"
|
54
|
+
else
|
55
|
+
"No url match for this url on this irc server from user/channel"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
Plugin.define do
|
61
|
+
name 'httpwatch'
|
62
|
+
description 'Watch a url for changes'
|
63
|
+
object HttpWatch
|
64
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class LineCount
|
2
|
+
attr_accessor :users
|
3
|
+
|
4
|
+
def initialize(sender, s)
|
5
|
+
@users = s['users'] if s.has_key?('users')
|
6
|
+
@users = Hash.new if not @users
|
7
|
+
end
|
8
|
+
|
9
|
+
def settings
|
10
|
+
{ 'users' => @users }
|
11
|
+
end
|
12
|
+
|
13
|
+
def commands
|
14
|
+
{
|
15
|
+
'linecount' => :linecount,
|
16
|
+
'lines' => [:lines, 0],
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def event(sender, e)
|
21
|
+
if e.message? and not e.private? and e.respond_to?('user') and e.user.authenticated? then
|
22
|
+
if @users.has_key?(e.user.username) then
|
23
|
+
@users[e.user.username] += 1
|
24
|
+
else
|
25
|
+
@users[e.user.username] = 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def linecount(e, user=nil)
|
31
|
+
user = e.user.username if not user and e.respond_to?('user')
|
32
|
+
|
33
|
+
if @users.has_key?(user) then
|
34
|
+
"#{user} has said #{@users[user]} lines"
|
35
|
+
else
|
36
|
+
"#{user} has not said anything"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def lines(e)
|
41
|
+
@users.invert.sort.reverse[0..5].map{ |l,u| "#{u} (#{l})"}.join(', ')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Plugin.define do
|
46
|
+
name 'linecount'
|
47
|
+
object LineCount
|
48
|
+
end
|
data/plugins/poll.rb
CHANGED
@@ -30,28 +30,28 @@ class Poll
|
|
30
30
|
|
31
31
|
def commands
|
32
32
|
{
|
33
|
-
'poll-add' => [:add_command,
|
33
|
+
'poll-add' => [:add_command, {
|
34
34
|
:permission => 'admin',
|
35
35
|
:help => 'Add a poll',
|
36
36
|
:usage => 'id poll',
|
37
37
|
:example => 'colour Red, yellow or blue?' }],
|
38
|
-
'poll-opt' => [:opt_command,
|
38
|
+
'poll-opt' => [:opt_command, {
|
39
39
|
:permission => 'admin',
|
40
40
|
:help => 'Add a option to a poll',
|
41
41
|
:usage => 'id option',
|
42
42
|
:example => 'colour Red' }],
|
43
|
-
'poll-del' => [:del_command,
|
43
|
+
'poll-del' => [:del_command, {
|
44
44
|
:permission => 'admin',
|
45
45
|
:help => 'Delete a poll',
|
46
46
|
:usage => 'id',
|
47
47
|
:example => 'colour' }],
|
48
|
-
'vote' => [:vote_command,
|
48
|
+
'vote' => [:vote_command, {
|
49
49
|
:help => 'Vote on a poll',
|
50
50
|
:usage => 'id option',
|
51
51
|
:example => 'colour 1' }],
|
52
52
|
'polls' => [:polls_command, 0, {
|
53
53
|
:help => 'List all poll\'s' }],
|
54
|
-
'poll' => [:poll_command,
|
54
|
+
'poll' => [:poll_command, {
|
55
55
|
:help => 'List a poll',
|
56
56
|
:usage => 'id',
|
57
57
|
:example => 'colour' }],
|
data/plugins/quote.rb
CHANGED
@@ -29,19 +29,19 @@ class Quote
|
|
29
29
|
|
30
30
|
def commands
|
31
31
|
{
|
32
|
-
'quote' => [:quote_command,
|
32
|
+
'quote' => [:quote_command, {
|
33
33
|
:help => 'Show a random quote or the quote with matching id',
|
34
|
-
:usage => '
|
35
|
-
'quote-add' => [:add_command,
|
34
|
+
:usage => 'id' }],
|
35
|
+
'quote-add' => [:add_command, {
|
36
36
|
:help => 'Add a quote',
|
37
37
|
:example => 'zynox: Hello!' }],
|
38
|
-
'quote-del' => [:del_command,
|
38
|
+
'quote-del' => [:del_command, {
|
39
39
|
:help => 'Delete a quote by id',
|
40
40
|
:example => '7'}],
|
41
41
|
'quote-count' =>[lambda { |e| "#{count} quotes" }, 0, {
|
42
42
|
:help => 'Show amount of quotes' }],
|
43
43
|
'quote-last' => [:last_command, 0, { :help => 'Show the last quote' }],
|
44
|
-
'quote-search' => [:search_command,
|
44
|
+
'quote-search' => [:search_command, {
|
45
45
|
:help => 'Search to find a quote',
|
46
46
|
:usage => 'search' }],
|
47
47
|
}
|
data/plugins/relay.rb
CHANGED
@@ -27,15 +27,15 @@ class Relay
|
|
27
27
|
{
|
28
28
|
'relays' => [:relays_command, 0, {
|
29
29
|
:help => 'Show all relays' }],
|
30
|
-
'relay-add' => [:add_command,
|
30
|
+
'relay-add' => [:add_command, {
|
31
31
|
:permission => 'admin',
|
32
32
|
:help => 'Add a relay',
|
33
33
|
:usage => 'instance:channel instance:channel',
|
34
34
|
:example => 'efnet:#zmb efnet:#zmb2' }],
|
35
|
-
'relay-del' => [:del_command,
|
36
|
-
:permission => 'admin'
|
35
|
+
'relay-del' => [:del_command, {
|
36
|
+
:permission => 'admin',
|
37
37
|
:help => 'Delete a relay',
|
38
|
-
:usage => 'instance:channel'
|
38
|
+
:usage => 'instance:channel',
|
39
39
|
:example => 'efnet:#zmb' }],
|
40
40
|
}
|
41
41
|
end
|
data/plugins/rss.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'rss/1.0'
|
2
|
+
require 'rss/2.0'
|
3
|
+
require 'rss/atom'
|
4
|
+
require 'zmb/timer'
|
5
|
+
|
6
|
+
class Feeds
|
7
|
+
attr_accessor :settings
|
8
|
+
|
9
|
+
def initialize(sender, s={})
|
10
|
+
@delegate = sender
|
11
|
+
@settings = s
|
12
|
+
@settings['interval'] = 10 unless settings.has_key?('interval')
|
13
|
+
@settings['instances'] = Array.new unless settings.has_key?('instances')
|
14
|
+
@settings['feeds'] = Array.new unless settings.has_key?('feeds')
|
15
|
+
|
16
|
+
setup_timer
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup_timer
|
20
|
+
@delegate.timer_delete(self)
|
21
|
+
@delegate.timer_add(Timer.new(self, :timer, (@settings['interval'] * 60), true))
|
22
|
+
end
|
23
|
+
|
24
|
+
def timer(e=nil)
|
25
|
+
@settings['feeds'].each do |feed|
|
26
|
+
begin
|
27
|
+
rss = RSS::Parser.parse(feed['feed'].get().body, false)
|
28
|
+
rss.items.each do |item|
|
29
|
+
link = item.link.to_s
|
30
|
+
link = $1 if link =~ /href="([\w:\/\.\?]*)"/
|
31
|
+
|
32
|
+
break if feed['link'] == link
|
33
|
+
@delegate.instances[feed['instance']].message(feed['sender'], "RSS: #{item.title.to_s.gsub(/<\/?[^>]*>/, "")} (#{link})")
|
34
|
+
end
|
35
|
+
|
36
|
+
link = rss.items[0].link.to_s
|
37
|
+
link = $1 if link =~ /href="([\w:\/\.\?]*)"/
|
38
|
+
feed['link'] = link
|
39
|
+
rescue Exception
|
40
|
+
@delegate.instances[feed['instance']].message(feed['sender'], "RSS: #{feed['feed']} failed")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def commands
|
46
|
+
{
|
47
|
+
'rss-interval' => [:interval, 1, {
|
48
|
+
:permission => 'admin',
|
49
|
+
:help => 'Set the interval to automatically check rss feeds',
|
50
|
+
:usage => 'minutes',
|
51
|
+
:example => '15' }],
|
52
|
+
'rss-list' => [:list, 0 , {
|
53
|
+
:permission => 'admin' }],
|
54
|
+
'rss-subscribe' => [:add, 1, {
|
55
|
+
:permission => 'admin',
|
56
|
+
:help => 'Subscribe to a rss feed' }],
|
57
|
+
'rss-scan' => [:timer, 0, { :permission => 'admin', :help => 'Rescan RSS feeds for news' }],
|
58
|
+
'rss-unsubscribe' => [:remove, 1, {
|
59
|
+
:permission => 'admin',
|
60
|
+
:help => 'Unsubscribe from a rss feed' }],
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def interval(e, i)
|
65
|
+
@settings['interval'] = Integer(i)
|
66
|
+
setup_timer
|
67
|
+
"RSS interval set to #{@settings['interval']}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def list(e)
|
71
|
+
if @settings['feeds'].count > 0 then
|
72
|
+
count = 0
|
73
|
+
@settings['feeds'].map{ |feed| "#{count+=1}: #{feed['feed']} (#{feed['instance']}/#{feed['sender']})" }.join("\n")
|
74
|
+
else
|
75
|
+
"No feeds"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def add(e, feed)
|
80
|
+
@settings['feeds'] << {
|
81
|
+
'feed' => feed,
|
82
|
+
'link' => nil,
|
83
|
+
'instance' => e.delegate.instance,
|
84
|
+
'sender' => e.sender
|
85
|
+
}
|
86
|
+
|
87
|
+
"Feed #{feed} added"
|
88
|
+
end
|
89
|
+
|
90
|
+
def remove(e, feed)
|
91
|
+
begin
|
92
|
+
feed_id = Integer(feed) - 1
|
93
|
+
f = @settings['feeds'].at(feed_id)
|
94
|
+
|
95
|
+
if feed then
|
96
|
+
@settings['feeds'].delete_at(feed_id)
|
97
|
+
"#{f['feed']} deleted"
|
98
|
+
else
|
99
|
+
"No feed with index: #{feed}"
|
100
|
+
end
|
101
|
+
rescue ArgumentError
|
102
|
+
count = 0
|
103
|
+
@settings['feeds'].reject{ |f| not ((f['feed'] == feed) and (f['instance'] == e.delegate.instance) and (f['sender'] == e.sender)) }.map do |f|
|
104
|
+
count =+ 1
|
105
|
+
@settings['feeds'].delete(f)
|
106
|
+
end
|
107
|
+
|
108
|
+
"#{count} feeds removed"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
Plugin.define do
|
114
|
+
name 'rss'
|
115
|
+
object Feeds
|
116
|
+
end
|
data/plugins/security.rb
CHANGED
@@ -69,11 +69,11 @@ class Security
|
|
69
69
|
:example => '.... . .-.. .-.. --- / .-- --- .-. .-.. -..' }],
|
70
70
|
|
71
71
|
'rot13' => :rot13,
|
72
|
-
'sha1' => [lambda { |e, data| Digest::SHA1.hexdigest(data) },
|
73
|
-
'sha256' => [lambda { |e, data| Digest::SHA256.hexdigest(data) },
|
74
|
-
'md5' => [lambda { |e, data| Digest::MD5.hexdigest(data) },
|
75
|
-
'base64' => [lambda { |e, data| Base64.b64encode(data) },
|
76
|
-
'decode64' => [lambda { |e, data| Base64.decode64(data) },
|
72
|
+
'sha1' => [lambda { |e, data| Digest::SHA1.hexdigest(data) }, { :help => 'Create a sha1 hash of some text' }],
|
73
|
+
'sha256' => [lambda { |e, data| Digest::SHA256.hexdigest(data) }, { :help => 'Create a sha256 hash of some text' }],
|
74
|
+
'md5' => [lambda { |e, data| Digest::MD5.hexdigest(data) }, { :help => 'Create a md5 hash of some text' }],
|
75
|
+
'base64' => [lambda { |e, data| Base64.b64encode(data) }, { :help => 'Encode a string as base64' }],
|
76
|
+
'decode64' => [lambda { |e, data| Base64.decode64(data) }, { :help => 'Decode a string with base64' }],
|
77
77
|
}
|
78
78
|
end
|
79
79
|
|
data/plugins/sed.rb
CHANGED
@@ -3,9 +3,11 @@ class Sed
|
|
3
3
|
@messages = Hash.new
|
4
4
|
end
|
5
5
|
|
6
|
-
def
|
6
|
+
def pre_event(sender, e)
|
7
7
|
if e.message =~ /^s\/(\S+)\/(\S+)\/$/ then
|
8
8
|
e.reply("#{e.name} meant " + @messages[e.userhost].sub($1, $2))
|
9
|
+
elsif e.message =~ /^!!(.+)/ then
|
10
|
+
e.message = @messages[e.userhost] + $1
|
9
11
|
else
|
10
12
|
@messages[e.userhost] = e.message if e.message?
|
11
13
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Translate
|
2
|
+
def initialize(sender, s) ;end
|
3
|
+
|
4
|
+
def commands
|
5
|
+
{
|
6
|
+
'translate' => [:translate, {
|
7
|
+
:usage => 'to from message',
|
8
|
+
:example => 'en fr Hello',
|
9
|
+
}],
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def translate(e, to, from, message)
|
14
|
+
request = JSON.parse("http://ajax.googleapis.com/ajax/services/language/translate".get({
|
15
|
+
:v => '1.0',
|
16
|
+
:key => 'ABQIAAAAhwR5TtcQxY9fSuKy7yrBJhQ-sC4I4KvMQ8RG81t2M9sVc21w2xQUb9Dipx99m8XrHBsa3OctXe2rQw',
|
17
|
+
:langpair => "#{to}%7C#{from}",
|
18
|
+
:q => message
|
19
|
+
}).body)
|
20
|
+
|
21
|
+
if request['responseStatus'] == 200 then
|
22
|
+
request['responseData']['translatedText']
|
23
|
+
elsif request['responseStatus'] == 400
|
24
|
+
request['responseDetails']
|
25
|
+
else
|
26
|
+
"Unknown error occured"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Plugin.define do
|
32
|
+
name 'translate'
|
33
|
+
object Translate
|
34
|
+
end
|
data/plugins/url.rb
CHANGED
@@ -8,13 +8,13 @@ class URL
|
|
8
8
|
def commands
|
9
9
|
{
|
10
10
|
'head' => :head,
|
11
|
-
'url' => [:get,
|
11
|
+
'url' => [:get, { :permission => 'admin' }],
|
12
12
|
'bitly' => :bitly,
|
13
13
|
'isgd' => :isgd,
|
14
14
|
'tinyurl' => :tinyurl,
|
15
15
|
'dpaste' => :dpaste,
|
16
16
|
'pastie' => :pastie_command,
|
17
|
-
'ppastie' => [:private_pastie_command,
|
17
|
+
'ppastie' => [:private_pastie_command, { :help => 'Create a private pastie' }],
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
data/plugins/usermodes.rb
CHANGED
@@ -38,17 +38,17 @@ class Usermodes
|
|
38
38
|
|
39
39
|
def commands
|
40
40
|
{
|
41
|
-
'usermode-add' => [:usermode_add,
|
41
|
+
'usermode-add' => [:usermode_add, {
|
42
42
|
:permission => 'admin',
|
43
43
|
:help => 'Apply a usermode to a user when they join a channel',
|
44
44
|
:usage => 'instance channel user mode',
|
45
45
|
:example => 'efnet #zmb zynox o' }],
|
46
|
-
'usermode-del' => [:usermode_del,
|
46
|
+
'usermode-del' => [:usermode_del, {
|
47
47
|
:permission => 'admin',
|
48
48
|
:help => 'Delete a usermode',
|
49
49
|
:usage => 'instance channel user mode',
|
50
50
|
:example => 'efnet #zmb zynox o' }],
|
51
|
-
'usermodes' => [:usermodes,
|
51
|
+
'usermodes' => [:usermodes, {
|
52
52
|
:permission => 'admin',
|
53
53
|
:help => 'List all usermodes for a channel',
|
54
54
|
:usage => 'instance channel',
|
data/plugins/vouch.rb
CHANGED
@@ -23,15 +23,15 @@ class Vouch
|
|
23
23
|
|
24
24
|
def commands
|
25
25
|
{
|
26
|
-
'vouch' => [:vouch,
|
26
|
+
'vouch' => [:vouch, {
|
27
27
|
:permission => 'authenticated',
|
28
28
|
:help => 'Vouch for a user',
|
29
29
|
:usage => 'username',
|
30
30
|
:example => 'zynox' }],
|
31
|
-
'vouch-limit' => [:limit_command,
|
31
|
+
'vouch-limit' => [:limit_command, {
|
32
32
|
:permission => 'admin',
|
33
33
|
:help => 'Change the vouch limit' }],
|
34
|
-
'stats' => [:stats,
|
34
|
+
'stats' => [:stats, {
|
35
35
|
:help => 'View status of a vouch' }],
|
36
36
|
}
|
37
37
|
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.3.
|
8
|
+
s.version = "0.3.1"
|
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-05
|
12
|
+
s.date = %q{2010-07-05}
|
13
13
|
s.default_executable = %q{zmb}
|
14
14
|
s.description = %q{ZMB, messenger bot}
|
15
15
|
s.email = %q{inbox@kylefuller.co.uk}
|
@@ -41,17 +41,21 @@ Gem::Specification.new do |s|
|
|
41
41
|
"plugins/dns.rb",
|
42
42
|
"plugins/file.rb",
|
43
43
|
"plugins/gcalc.rb",
|
44
|
+
"plugins/httpwatch.rb",
|
44
45
|
"plugins/idle.rb",
|
45
46
|
"plugins/irc.rb",
|
47
|
+
"plugins/linecount.rb",
|
46
48
|
"plugins/log.rb",
|
47
49
|
"plugins/nickserv.rb",
|
48
50
|
"plugins/poll.rb",
|
49
51
|
"plugins/quote.rb",
|
50
52
|
"plugins/random.rb",
|
51
53
|
"plugins/relay.rb",
|
54
|
+
"plugins/rss.rb",
|
52
55
|
"plugins/security.rb",
|
53
56
|
"plugins/sed.rb",
|
54
57
|
"plugins/system.rb",
|
58
|
+
"plugins/translate.rb",
|
55
59
|
"plugins/url.rb",
|
56
60
|
"plugins/usermodes.rb",
|
57
61
|
"plugins/users.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.3.
|
4
|
+
version: 0.3.1
|
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-05
|
12
|
+
date: 2010-07-05 00:00:00 +01:00
|
13
13
|
default_executable: zmb
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -64,17 +64,21 @@ files:
|
|
64
64
|
- plugins/dns.rb
|
65
65
|
- plugins/file.rb
|
66
66
|
- plugins/gcalc.rb
|
67
|
+
- plugins/httpwatch.rb
|
67
68
|
- plugins/idle.rb
|
68
69
|
- plugins/irc.rb
|
70
|
+
- plugins/linecount.rb
|
69
71
|
- plugins/log.rb
|
70
72
|
- plugins/nickserv.rb
|
71
73
|
- plugins/poll.rb
|
72
74
|
- plugins/quote.rb
|
73
75
|
- plugins/random.rb
|
74
76
|
- plugins/relay.rb
|
77
|
+
- plugins/rss.rb
|
75
78
|
- plugins/security.rb
|
76
79
|
- plugins/sed.rb
|
77
80
|
- plugins/system.rb
|
81
|
+
- plugins/translate.rb
|
78
82
|
- plugins/url.rb
|
79
83
|
- plugins/usermodes.rb
|
80
84
|
- plugins/users.rb
|