zmb 0.2.1 → 0.3.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.
@@ -6,16 +6,12 @@ class DNS
6
6
 
7
7
  def commands
8
8
  {
9
- 'dns' => :dns,
9
+ 'dns' => lambda { |e, host| Resolv.new.getaddress(host) },
10
10
  'rdns' => :rdns,
11
11
  'whois' => [:whois, 1, { :help => 'perform a whois on a domain' }],
12
12
  }
13
13
  end
14
14
 
15
- def dns(e, host)
16
- Resolv.new.getaddress(host)
17
- end
18
-
19
15
  def rdns(e, ip)
20
16
  begin
21
17
  Resolv.new.getname(ip)
@@ -12,10 +12,7 @@ class GCalc
12
12
  end
13
13
 
14
14
  def calc(e, search)
15
- http = Net::HTTP.new('www.google.com', 80)
16
- resp, body = http.start do |h|
17
- h.get("/search?q=#{URI.escape(search, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}")
18
- end
15
+ resp, body = 'http://www.google.com/search'.get({ :q => URI.escape(search, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) })
19
16
 
20
17
  if resp.code == '200' then
21
18
  if body.include?('<img src=/images/calc_img.gif width=40 height=30 alt="">')
@@ -4,14 +4,15 @@ class Idle
4
4
  end
5
5
 
6
6
  def event(sender, e)
7
- if e.message? and e.respond_to?('channel') then
7
+ if e.message? and not
8
+ e.message.include?('idle') and e.respond_to?('channel') then
8
9
  @channels[e.channel] = Time.now if not e.message.include?('idle')
9
10
  end
10
11
  end
11
12
 
12
13
  def commands
13
14
  {
14
- 'idle' => [:idle, 1, { :help => 'How long has this channel been idle?'}],
15
+ 'idle' => [:idle, 1, { :help => 'How long has this channel been idle?' }],
15
16
  }
16
17
  end
17
18
 
@@ -20,20 +21,8 @@ class Idle
20
21
 
21
22
  if not @channels.has_key?(channel) then
22
23
  "I have not seen any messages in #{channel}"
23
- else
24
- diff = Time.now - @channels[channel]
25
-
26
- if diff < 60 then
27
- msg = "#{Integer(diff)} seconds ago"
28
- elsif diff < 3600 then
29
- msg = "#{Integer(diff/60)} minutes ago"
30
- elsif diff < 86400 then
31
- msg = "about #{Integer(diff/3600)} hours ago"
32
- else
33
- msg = "#{Integer(diff/86400)} days ago"
34
- end
35
-
36
- "Last message in #{channel} was #{msg}"
24
+ else
25
+ "Last message in #{channel} was #{@channels[channel].since_words}"
37
26
  end
38
27
  end
39
28
  end
@@ -62,7 +62,7 @@ class Event
62
62
  end
63
63
 
64
64
  class IrcConnection
65
- attr_accessor :host, :port, :channels, :nick, :name, :realname, :password, :throttle
65
+ attr_accessor :delegate, :host, :port, :channels, :nick, :name, :realname, :password, :throttle
66
66
 
67
67
  def initialize(sender, s={})
68
68
  @delegate = sender
@@ -85,7 +85,7 @@ class IrcConnection
85
85
  @throttle = 10
86
86
  @throttle = s['throttle'] if s.has_key?('throttle')
87
87
 
88
- sender.timer_add(Timer.new(self, :connect, 0.1, false)) if sender.running?
88
+ @delegate.timer_add(Timer.new(self, :connect, 0.1, false)) if sender.running?
89
89
  end
90
90
 
91
91
  def socket=(value)
@@ -121,16 +121,51 @@ class IrcConnection
121
121
 
122
122
  def commands
123
123
  {
124
- 'join' => [:join_command, 1, { :permission => 'admin' }],
125
- 'part' => [:part_command, 1, { :permission => 'admin' }],
126
- 'cycle' => [:cycle_command, 1, { :permission => 'admin' }],
127
- 'topic' => [:topic_command, 2, { :permission => 'admin' }],
128
- 'kick' => [:kick_command, 2, { :permission => 'admin' }],
129
- 'channels' => [:channels_command, 1, { :permission => 'admin' }],
130
- 'raw' => [:raw_command, 1, { :permission => 'admin' }],
131
- 'nick' => [:nick_command, 1, { :permission => 'admin' }],
132
- 'tell' => [:tell_command, 2, { :permission => 'admin' }],
133
- 'reconnect' => [:reconnect_command, 1, { :permission => 'admin' }],
124
+ 'join' => [:join_command, 1, {
125
+ :permission => 'admin',
126
+ :help => 'Join a channel',
127
+ :usage => 'channel',
128
+ :example => '#zmb' }],
129
+ 'part' => [:part_command, 1, {
130
+ :permission => 'admin',
131
+ :help => 'Leave a channel',
132
+ :usage => 'channel',
133
+ :example => '#zmb' }],
134
+ 'cycle' => [:cycle_command, 1, {
135
+ :permission => 'admin',
136
+ :help => 'Part and rejoin a channel',
137
+ :usage => 'channel',
138
+ :example => '#zmb' }],
139
+ 'topic' => [:topic_command, 2, {
140
+ :permission => 'admin',
141
+ :help => 'Set the topic in a channel',
142
+ :usage => 'channel topic',
143
+ :example => '#zmb' }],
144
+ 'kick' => [:kick_command, 2, {
145
+ :permission => 'admin',
146
+ :help => 'Kick a user from a channel',
147
+ :usage => 'channel user',
148
+ :example => '#zmb zynox' }],
149
+ 'channels' => [:channels_command, 1, {
150
+ :permission => 'admin',
151
+ :help => 'List all the channels this bot is in.' }],
152
+ 'raw' => [:raw_command, 1, {
153
+ :permission => 'admin',
154
+ :help => 'Send raw IRC commands',
155
+ :usage => 'command',
156
+ :example => 'PRIVMSG #zmb :Hello world!' }],
157
+ 'nick' => [:nick_command, 1, {
158
+ :permission => 'admin',
159
+ :help => 'Change the bot\'s nick',
160
+ :usage => 'new-nick',
161
+ :example => 'zmb' }],
162
+ 'tell' => [:tell_command, 2, {
163
+ :permission => 'admin',
164
+ :usage => 'location message',
165
+ :example => '#zmb Hello World!' }],
166
+ 'reconnect' => [:reconnect_command, 1, {
167
+ :permission => 'admin',
168
+ :help => 'Reconnect to the irc server' }],
134
169
  }
135
170
  end
136
171
 
@@ -140,8 +175,8 @@ class IrcConnection
140
175
  end
141
176
 
142
177
  def nick=(value)
143
- @nick = value
144
178
  write "NICK #{@nick}"
179
+ @nick = value
145
180
  end
146
181
 
147
182
  def connected?
@@ -160,7 +195,7 @@ class IrcConnection
160
195
 
161
196
  def disconnected(sender, socket)
162
197
  @socket = nil
163
- sender.timer_add(Timer.new(self, :connect, @throttle))
198
+ @delegate.timer_add(Timer.new(self, :connect, @throttle))
164
199
  end
165
200
 
166
201
  def perform
@@ -170,29 +205,16 @@ class IrcConnection
170
205
  end
171
206
 
172
207
  def write(line)
173
- @socket.write line + "\r\n" if @socket
208
+ begin
209
+ @socket.write line + "\r\n" if @socket
210
+ rescue
211
+ disconnected(self, nil)
212
+ end
174
213
  end
175
214
 
176
215
  def message(recipient, msg)
177
- if msg.size >= (total = 510 - (recipient.size + 10)) then
178
- words = msg.split(' ')
179
- line = words.shift
180
- length = line.size
181
-
182
- words.each do |word|
183
- if (length += (word.size + 1)) >= total then
184
- write "PRIVMSG #{recipient} :#{line}"
185
- sleep 0.1
186
- line = word
187
- length = word.size
188
- else
189
- line += " #{word}"
190
- end
191
- end
192
-
193
- write "PRIVMSG #{recipient} :#{line}" if line.size > 0
194
- else
195
- write "PRIVMSG #{recipient} :#{msg}"
216
+ msg.truncate_words(500-recipient.size).each do |m|
217
+ write "PRIVMSG #{recipient} :#{m}"
196
218
  end
197
219
  end
198
220
 
@@ -221,10 +243,7 @@ class IrcConnection
221
243
  when '001' then
222
244
  sleep 0.1
223
245
  @channels.each{ |channel| write "JOIN #{channel}" }
224
- when 'nick' then tmp, @nick = e.args.split(' :', 2)
225
- when '433' then
226
- @nick="#{@nick}_"
227
- write "NICK #{@nick}"
246
+ when '433' then nick = "#{@nick}_"
228
247
  end
229
248
 
230
249
  @delegate.event(self, e)
@@ -38,7 +38,7 @@ class Quote
38
38
  'quote-del' => [:del_command, 1, {
39
39
  :help => 'Delete a quote by id',
40
40
  :example => '7'}],
41
- 'quote-count' =>[:count_command, 0, {
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
44
  'quote-search' => [:search_command, 1, {
@@ -77,10 +77,6 @@ class Quote
77
77
  end
78
78
  end
79
79
 
80
- def count_command(e)
81
- "#{count} quotes"
82
- end
83
-
84
80
  def last_command(e)
85
81
  return "no quotes" if count < 1
86
82
  quote_command(e, @quotes.keys.sort.reverse[0])
@@ -1,32 +1,18 @@
1
1
  class Random
2
2
  def initialize(sender, settings); end
3
3
 
4
- def split_seperators(data)
5
- if data.class == Array then
6
- data
7
- elsif data.include?("\n") then
8
- data.split("\n").map{ |arg| arg.strip }
9
- elsif data.include?(',') then
10
- data.split(',').map{ |arg| arg.strip }
11
- elsif data.include?(' ') then
12
- data.split(' ')
13
- else
14
- data
15
- end
16
- end
17
-
18
4
  def commands
19
5
  {
20
6
  'random' => :random,
21
7
  'yesno' => [:yesno, 0],
22
8
  'headstails' => [:coinflip, 0],
23
9
  'coinflip' => [:coinflip, 0],
24
- 'dice' => [:dice, 0],
10
+ 'dice' => [lambda { |e| "#{rand(6) + 1}" }, 0],
25
11
  }
26
12
  end
27
13
 
28
14
  def random(e, args)
29
- items = split_seperators(args)
15
+ items = args.split_seperators
30
16
  "#{items[rand(items.size)]}"
31
17
  end
32
18
 
@@ -37,10 +23,6 @@ class Random
37
23
  def coinflip(e)
38
24
  random(e, ['heads', 'tails'])
39
25
  end
40
-
41
- def dice(e)
42
- "#{rand(6) + 1}"
43
- end
44
26
  end
45
27
 
46
28
  Plugin.define do
@@ -28,11 +28,15 @@ class Relay
28
28
  'relays' => [:relays_command, 0, {
29
29
  :help => 'Show all relays' }],
30
30
  'relay-add' => [:add_command, 2, {
31
+ :permission => 'admin',
31
32
  :help => 'Add a relay',
32
- :permission => 'admin' }],
33
+ :usage => 'instance:channel instance:channel',
34
+ :example => 'efnet:#zmb efnet:#zmb2' }],
33
35
  'relay-del' => [:del_command, 1, {
36
+ :permission => 'admin'
34
37
  :help => 'Delete a relay',
35
- :permission => 'admin' }],
38
+ :usage => 'instance:channel'
39
+ :example => 'efnet:#zmb' }],
36
40
  }
37
41
  end
38
42
 
@@ -68,7 +72,7 @@ class Relay
68
72
  end
69
73
 
70
74
  Plugin.define do
71
- name "relay"
72
- description "This plugin allows you to relay messages from one channel/server to another."
75
+ name 'relay'
76
+ description 'This plugin allows you to relay messages from one channel/server to another.'
73
77
  object Relay
74
78
  end
@@ -69,11 +69,11 @@ class Security
69
69
  :example => '.... . .-.. .-.. --- / .-- --- .-. .-.. -..' }],
70
70
 
71
71
  'rot13' => :rot13,
72
- 'sha1' => [:sha1, 1, { :help => 'Create a sha1 hash of some text' }],
73
- 'sha256' => [:sha256, 1, { :help => 'Create a sha256 hash of some text' }],
74
- 'md5' => [:md5, 1, { :help => 'Create a md5 hash of some text' }],
75
- 'base64' => [:base64, 1, { :help => '' }],
76
- 'decode64' => [:decode64, 1, { :help => '' }],
72
+ 'sha1' => [lambda { |e, data| Digest::SHA1.hexdigest(data) }, 1, { :help => 'Create a sha1 hash of some text' }],
73
+ 'sha256' => [lambda { |e, data| Digest::SHA256.hexdigest(data) }, 1, { :help => 'Create a sha256 hash of some text' }],
74
+ 'md5' => [lambda { |e, data| Digest::MD5.hexdigest(data) }, 1, { :help => 'Create a md5 hash of some text' }],
75
+ 'base64' => [lambda { |e, data| Base64.b64encode(data) }, 1, { :help => '' }],
76
+ 'decode64' => [lambda { |e, data| Base64.decode64(data) }, 1, { :help => '' }],
77
77
  }
78
78
  end
79
79
 
@@ -88,26 +88,6 @@ class Security
88
88
  def rot13(e, data)
89
89
  data.tr('A-Ma-mN-Zn-z', 'N-Zn-zA-Ma-m')
90
90
  end
91
-
92
- def sha1(e, data)
93
- Digest::SHA1.hexdigest(data)
94
- end
95
-
96
- def sha256(e, data)
97
- Digest::SHA256.hexdigest(data)
98
- end
99
-
100
- def md5(e, data)
101
- Digest::MD5.hexdigest(data)
102
- end
103
-
104
- def base64(e, data)
105
- Base64.b64encode(data)
106
- end
107
-
108
- def decode64(e, data)
109
- Base64.decode64(data)
110
- end
111
91
  end
112
92
 
113
93
  Plugin.define do
@@ -0,0 +1,18 @@
1
+ class Sed
2
+ def initialize(sender, settings)
3
+ @messages = Hash.new
4
+ end
5
+
6
+ def event(sender, e)
7
+ if e.message =~ /^s\/(\S+)\/(\S+)\/$/ then
8
+ e.reply("#{e.name} meant " + @messages[e.userhost].sub($1, $2))
9
+ else
10
+ @messages[e.userhost] = e.message if e.message?
11
+ end
12
+ end
13
+ end
14
+
15
+ Plugin.define do
16
+ name 'sed'
17
+ object Sed
18
+ end
@@ -5,37 +5,6 @@ require 'cgi'
5
5
  class URL
6
6
  def initialize(sender, s) ;end
7
7
 
8
- def to_query_string(h)
9
- h.map { |k, v|
10
- if v.instance_of?(Hash)
11
- v.map { |sk, sv|
12
- "#{k}[#{sk}]=#{sv}"
13
- }.join('&')
14
- else
15
- "#{k}=#{v}"
16
- end
17
- }.join('&')
18
- end
19
-
20
- def http(host, port=80, path='/', type='get', query_string={})
21
- http = Net::HTTP.new(host, port)
22
- query_string = to_query_string(query_string) if query_string.class == Hash
23
- http.start do |h|
24
- case type
25
- when 'get' then h.get(path + '?' + query_string)
26
- when 'post' then h.post(path, query_string)
27
- when 'head' then h.head(path + '?' + query_string)
28
- end
29
- end
30
- end
31
-
32
- def http_uri(url, type='get')
33
- u = URI.parse(url)
34
- u.path = '/' if u.path.size == 0
35
- u.query = '' if not u.query
36
- http(u.host, u.port, u.path, type, u.query)
37
- end
38
-
39
8
  def commands
40
9
  {
41
10
  'head' => :head,
@@ -50,7 +19,7 @@ class URL
50
19
  end
51
20
 
52
21
  def head(e, url)
53
- resp = http_uri(url, 'head')
22
+ resp = url.http('head')
54
23
 
55
24
  if resp.code == "301" or resp.code == "302" then
56
25
  "#{resp.code} - #{resp['location']}"
@@ -62,33 +31,29 @@ class URL
62
31
  end
63
32
 
64
33
  def get(e, url)
65
- resp, body = http_uri(url)
66
- body
34
+ url.get.body
67
35
  end
68
36
 
69
37
  def bitly(e, link)
70
- resp, body = http('bit.ly', 80, '/api', 'get', { :url => link })
71
- body
38
+ 'http://bit.ly/api'.get({ :url => link }).body
72
39
  end
73
40
 
74
41
  def isgd(e, link)
75
- resp, body = http('is.gd', 80, '/api.php', 'get', { :longurl => link })
76
- body
42
+ 'http://is.gd/api.php'.get({ :longurl => link }).body
77
43
  end
78
44
 
79
45
  def tinyurl(e, link)
80
- resp, body = http('tinyurl.com', 80, '/api-create.php', 'get', { :url => link })
81
- body
46
+ 'http://tinyurl.com/api-create.php'.get({ :url => link }).body
82
47
  end
83
48
 
84
49
  def dpaste(e, data)
85
- resp, body = http('dpaste.de', 80, '/api/', 'post', { :content => data })
50
+ resp, body = 'http://dpaste.de/api/'.post({ :content => data })
86
51
  body = body[1..-2] if body =~ /^".+"$/ # Remove any quotation marks if there are any
87
52
  body
88
53
  end
89
54
 
90
55
  def pastie(data, is_private=false, format='plaintext')
91
- resp, body = http('pastie.org', 80, '/pastes', 'post', { :paste => {
56
+ resp, body = 'http://pastie.org/pastes'.post({ :paste => {
92
57
  :body => CGI.escape(data),
93
58
  :parser => format,
94
59
  :restricted => is_private,