zmb 0.1.3 → 0.2.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,51 @@
1
+ require 'resolv'
2
+ require 'socket'
3
+
4
+ class DNS
5
+ def initialize(sender, s) ;end
6
+
7
+ def commands
8
+ {
9
+ 'dns' => :dns,
10
+ 'rdns' => :rdns,
11
+ 'whois' => [:whois, 1, { :help => 'perform a whois on a domain' }],
12
+ }
13
+ end
14
+
15
+ def dns(e, host)
16
+ Resolv.new.getaddress(host)
17
+ end
18
+
19
+ def rdns(e, ip)
20
+ begin
21
+ Resolv.new.getname(ip)
22
+ rescue Resolv::ResolvError
23
+ ip
24
+ end
25
+ end
26
+
27
+ def whois(e, domain)
28
+ begin
29
+ require 'whois'
30
+ rescue Exception
31
+ 'command depends on whois gem: http://www.ruby-whois.org/'
32
+ end
33
+
34
+ a = Whois.query(domain)
35
+
36
+ if a.available? then
37
+ "#{domain} is availible"
38
+ else
39
+ t = a.technical
40
+ c = "Created on #{a.created_on}"
41
+ c += " by #{t.name}" if t
42
+ c
43
+ end
44
+ end
45
+ end
46
+
47
+ Plugin.define do
48
+ name 'dns'
49
+ description 'resolve dns'
50
+ object DNS
51
+ end
@@ -1,12 +1,8 @@
1
1
  class Idle
2
- def initialize(sender, settings)
2
+ def initialize(sender, s)
3
3
  @channels = Hash.new
4
4
  end
5
5
 
6
- def to_json(*a)
7
- { 'plugin' => 'idle' }.to_json(*a)
8
- end
9
-
10
6
  def event(sender, e)
11
7
  if e.message? and e.respond_to?('channel') then
12
8
  @channels[e.channel] = Time.now if not e.message.include?('idle')
@@ -14,9 +10,8 @@ class Idle
14
10
  end
15
11
 
16
12
  def commands
17
- require 'zmb/commands'
18
13
  {
19
- 'idle' => Command.new(self, :idle, 1, 'How idle has a channel been?'),
14
+ 'idle' => [:idle, 1, { :help => 'How long has this channel been idle?'}],
20
15
  }
21
16
  end
22
17
 
@@ -3,10 +3,10 @@ require 'socket'
3
3
  require 'zmb/timer'
4
4
 
5
5
  class Event
6
- attr_accessor :delegate, :command, :args, :name, :userhost, :message, :channel
6
+ attr_accessor :delegate, :command, :args, :name, :userhost, :message, :channel, :line
7
7
 
8
8
  def initialize(sender, line)
9
- puts line
9
+ @line = line
10
10
 
11
11
  if line[0,1] == ':' then
12
12
  line = line[1..-1] # Remove the :
@@ -25,6 +25,16 @@ class Event
25
25
  @userhost, @channel, @message = args.split(' ', 3)
26
26
  @name, @userhost = @userhost.split('!', 2)
27
27
  @message = @message[1..-1]
28
+ when 'join'
29
+ @userhost, @channel = args.split(' ', 2)
30
+ @name, @userhost = @userhost.split('!', 2)
31
+ when 'part'
32
+ @userhost, @channel = args.split(' ', 2)
33
+ @name, @userhost = @userhost.split('!', 2)
34
+ when 'kick'
35
+ @userhost, @channel, @name, @message = args.split(' ', 4)
36
+ nick, @userhost = @userhost.split('!', 2)
37
+ @message = @message[1..-1]
28
38
  end
29
39
  end
30
40
 
@@ -53,26 +63,26 @@ end
53
63
  class IrcConnection
54
64
  attr_accessor :host, :port, :channels, :nick, :name, :realname, :password, :throttle
55
65
 
56
- def initialize(sender, settings={})
66
+ def initialize(sender, s={})
57
67
  @delegate = sender
58
68
 
59
- @host = settings['host'] if settings.has_key?('host')
69
+ @host = s['host'] if s.has_key?('host')
60
70
  begin
61
- @port = Integer(settings['port']) if settings.has_key?('port')
71
+ @port = Integer(s['port']) if s.has_key?('port')
62
72
  rescue Exception
63
73
  @port = 6667
64
74
  end
65
75
 
66
76
  @channels = Array.new
67
- @channels = settings['channels'] if settings.has_key?('channels')
77
+ @channels = s['channels'] if s.has_key?('channels')
68
78
 
69
- @nick = settings['nick'] if settings.has_key?('nick')
70
- @name = settings['name'] if settings.has_key?('name')
71
- @realname = settings['realname'] if settings.has_key?('realname')
72
- @password = settings['password'] if settings.has_key?('password')
79
+ @nick = s['nick'] if s.has_key?('nick')
80
+ @name = s['name'] if s.has_key?('name')
81
+ @realname = s['realname'] if s.has_key?('realname')
82
+ @password = s['password'] if s.has_key?('password')
73
83
 
74
84
  @throttle = 10
75
- @throttle = settings['throttle'] if settings.has_key?('throttle')
85
+ @throttle = s['throttle'] if s.has_key?('throttle')
76
86
 
77
87
  sender.timer_add(Timer.new(self, :connect, 0.1, false)) if sender.running?
78
88
  end
@@ -81,7 +91,7 @@ class IrcConnection
81
91
  @socket = value
82
92
  end
83
93
 
84
- def to_json(*a)
94
+ def settings
85
95
  {
86
96
  'host' => @host,
87
97
  'port' => @port,
@@ -94,8 +104,7 @@ class IrcConnection
94
104
  'password' => @password,
95
105
 
96
106
  'throttle' => @throttle,
97
- 'plugin' => 'irc',
98
- }.to_json(*a)
107
+ }
99
108
  end
100
109
 
101
110
  def self.wizard
@@ -110,18 +119,17 @@ class IrcConnection
110
119
  end
111
120
 
112
121
  def commands
113
- require 'zmb/commands'
114
122
  {
115
- 'join' => PermCommand.new('admin', self, :join_command),
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),
121
- 'raw' => PermCommand.new('admin', self, :raw_command),
122
- 'nick' => PermCommand.new('admin', self, :nick_command),
123
- 'tell' => PermCommand.new('admin', self, :tell_command, 2),
124
- 'reconnect' => PermCommand.new('admin', self, :reconnect_command),
123
+ 'join' => [:join_command, 1, { :permission => 'admin' }],
124
+ 'part' => [:part_command, 1, { :permission => 'admin' }],
125
+ 'cycle' => [:cycle_command, 1, { :permission => 'admin' }],
126
+ 'topic' => [:topic_command, 2, { :permission => 'admin' }],
127
+ 'kick' => [:kick_command, 2, { :permission => 'admin' }],
128
+ 'channels' => [:channels_command, 1, { :permission => 'admin' }],
129
+ 'raw' => [:raw_command, 1, { :permission => 'admin' }],
130
+ 'nick' => [:nick_command, 1, { :permission => 'admin' }],
131
+ 'tell' => [:tell_command, 2, { :permission => 'admin' }],
132
+ 'reconnect' => [:reconnect_command, 1, { :permission => 'admin' }],
125
133
  }
126
134
  end
127
135
 
@@ -165,7 +173,26 @@ class IrcConnection
165
173
  end
166
174
 
167
175
  def message(recipient, msg)
168
- write "PRIVMSG #{recipient} :#{msg}"
176
+ if msg.size >= (total = 510 - (recipient.size + 10)) then
177
+ words = msg.split(' ')
178
+ line = words.shift
179
+ length = line.size
180
+
181
+ words.each do |word|
182
+ if (length += (word.size + 1)) >= total then
183
+ write "PRIVMSG #{recipient} :#{line}"
184
+ sleep 0.1
185
+ line = word
186
+ length = word.size
187
+ else
188
+ line += " #{word}"
189
+ end
190
+ end
191
+
192
+ write "PRIVMSG #{recipient} :#{line}" if line.size > 0
193
+ else
194
+ write "PRIVMSG #{recipient} :#{msg}"
195
+ end
169
196
  end
170
197
 
171
198
  def join(channel)
@@ -0,0 +1,25 @@
1
+ require 'ftools'
2
+
3
+ class Log
4
+ def initialize(sender, s)
5
+ @delegate = sender
6
+ end
7
+
8
+ def log_file(instance, channel)
9
+ path = File.join(@delegate.settings_manager.directory, 'logs', instance)
10
+ File.makedirs(path)
11
+ File.join(path, "#{channel}-#{Time.now.strftime('%d%m%Y')}.log")
12
+ end
13
+
14
+ def event(sender, e)
15
+ if e.respond_to?('channel') and e.respond_to?('line') and e.channel then
16
+ File.open(log_file(e.delegate.instance, e.channel), 'a+') { |f| f.write(e.line + "\n") }
17
+ end
18
+ end
19
+ end
20
+
21
+ Plugin.define do
22
+ name 'log'
23
+ description 'log everything received from irc'
24
+ object Log
25
+ end
@@ -1,10 +1,10 @@
1
1
  class NickServ
2
- def initialize(sender, settings)
3
- @password = settings['password'] if settings.has_key?('password')
2
+ def initialize(sender, s)
3
+ @password = s['password'] if s.has_key?('password')
4
4
  end
5
5
 
6
- def to_json(*a)
7
- { 'plugin' => 'nickserv', 'password' => @password }.to_json(*a)
6
+ def settings
7
+ { 'password' => @password }
8
8
  end
9
9
 
10
10
  def self.wizard
@@ -18,9 +18,11 @@ class NickServ
18
18
  end
19
19
 
20
20
  def commands
21
- require 'zmb/commands'
22
21
  {
23
- 'nickserv' => PermCommand.new('admin', self, :set, 1, 'Set your NickServ password.'),
22
+ 'nickserv' => [:set, 1, {
23
+ :help => 'Set the NickServ password for the bot to login with.',
24
+ :usage => 'password',
25
+ }],
24
26
  }
25
27
  end
26
28
 
@@ -1,11 +1,11 @@
1
1
  class Poll
2
- def initialize(sender, settings={})
2
+ def initialize(sender, s={})
3
3
  @polls = Hash.new
4
- @polls = settings['polls'] if settings.has_key?('polls')
4
+ @polls = s['polls'] if s.has_key?('polls')
5
5
  end
6
6
 
7
- def to_json(*a)
8
- { 'plugin' => 'poll', 'polls' => @polls }.to_json(*a)
7
+ def settings
8
+ { 'polls' => @polls }
9
9
  end
10
10
 
11
11
  def add(slug, poll)
@@ -29,14 +29,13 @@ class Poll
29
29
  end
30
30
 
31
31
  def commands
32
- require 'zmb/commands'
33
32
  {
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),
33
+ 'poll-add' => [:add_command, 2, { :permission => 'admin' }],
34
+ 'poll-opt' => [:opt_command, 2, { :permission => 'admin' }],
35
+ 'poll-del' => [:del_command, 1, { :permission => 'admin' }],
36
+ 'vote' => [:vote_command, 2],
37
+ 'polls' => [:polls_command, 0],
38
+ 'poll' => :poll_command,
40
39
  }
41
40
  end
42
41
 
@@ -1,19 +1,15 @@
1
1
  class Quote
2
2
  attr_accessor :quotes, :autoindex
3
3
 
4
- def initialize(sender, settings={})
4
+ def initialize(sender, s={})
5
5
  @quotes = Hash.new
6
- @quotes = settings['quotes'] if settings.has_key?('quotes')
6
+ @quotes = s['quotes'] if s.has_key?('quotes')
7
7
  @autoindex = 1
8
- @autoindex = settings['autoindex'] if settings.has_key?('autoindex')
8
+ @autoindex = s['autoindex'] if s.has_key?('autoindex')
9
9
  end
10
10
 
11
- def to_json(*a)
12
- {
13
- 'plugin' => 'quote',
14
- 'quotes' => @quotes,
15
- 'autoindex' => @autoindex,
16
- }.to_json(*a)
11
+ def settings
12
+ { 'quotes' => @quotes, 'autoindex' => @autoindex }
17
13
  end
18
14
 
19
15
  def add(quote, username=nil)
@@ -32,14 +28,22 @@ class Quote
32
28
  end
33
29
 
34
30
  def commands
35
- require 'zmb/commands'
36
31
  {
37
- 'quote' => Command.new(self, :quote_command, 1, 'Show a random quote or the quote with matching id'),
38
- 'quote-add' => Command.new(self, :add_command, 1, 'Add a quote'),
39
- 'quote-del' => PermCommand.new('quote', self, :del_command, 1, 'Delete a quote by id'),
40
- 'quote-count' => Command.new(self, :count_command, 0, 'Show amount of quotes'),
41
- 'quote-last' => Command.new(self, :last_command, 0, 'Show the last quote'),
42
- 'quote-search' => Command.new(self, :search_command, 1, 'Search to find a quote'),
32
+ 'quote' => [:quote_command, 1, {
33
+ :help => 'Show a random quote or the quote with matching id',
34
+ :usage => '<id>' }],
35
+ 'quote-add' => [:add_command, 1, {
36
+ :help => 'Add a quote'
37
+ :example => 'zynox: Hello!'}],
38
+ 'quote-del' => [:del_command, 1, {
39
+ :help => 'Delete a quote by id',
40
+ :example => '7'}],
41
+ 'quote-count' =>[:count_command, 0, {
42
+ :help => 'Show amount of quotes' }],
43
+ 'quote-last' => [:last_command, 0, { :help => 'Show the last quote'),
44
+ 'quote-search' => [:search_command, 1, {
45
+ :help => 'Search to find a quote',
46
+ :usage => 'search' }],
43
47
  }
44
48
  end
45
49
 
@@ -1,15 +1,15 @@
1
1
  class Relay
2
2
  attr_accessor :relays
3
3
 
4
- def initialize(sender, settings={})
5
- @relays = settings['relays'] if settings.has_key?('relays')
4
+ def initialize(sender, s={})
5
+ @relays = s['relays'] if s.has_key?('relays')
6
6
  @relays = Hash.new if not @relays
7
7
 
8
8
  @delegate = sender
9
9
  end
10
10
 
11
- def to_json(*a)
12
- { 'relays' => @relays, 'plugin' => 'relay' }.to_json(*a)
11
+ def settings
12
+ { 'relays' => @relays }
13
13
  end
14
14
 
15
15
  def event(sender, e)
@@ -24,11 +24,15 @@ class Relay
24
24
  end
25
25
 
26
26
  def commands
27
- require 'zmb/commands'
28
27
  {
29
- 'relays' => PermCommand.new('admin', self, :relays_command, 0, 'Show all relays'),
30
- 'relay-add' => PermCommand.new('admin', self, :add_command, 2, 'Add a relay'),
31
- 'relay-del' => PermCommand.new('admin', self, :del_command, 1, 'Delete a relay'),
28
+ 'relays' => [:relays_command, 0, {
29
+ :help => 'Show all relays' }],
30
+ 'relay-add' => [:add_command, 2, {
31
+ :help => 'Add a relay',
32
+ :permission => 'admin' }],
33
+ 'relay-del' => [:del_command, 1, {
34
+ :help => 'Delete a relay',
35
+ :permission => 'admin' }],
32
36
  }
33
37
  end
34
38
 
@@ -0,0 +1,117 @@
1
+ require 'digest'
2
+ require 'base64'
3
+
4
+ MORSE = {
5
+ '-----' => '0',
6
+ '.----' => '1',
7
+ '..---' => '2',
8
+ '...--' => '3',
9
+ '....-' => '4',
10
+ '.....' => '5',
11
+ '-....' => '6',
12
+ '--...' => '7',
13
+ '---..' => '8',
14
+ '----.' => '9',
15
+ '.-' => 'a',
16
+ '-...' => 'b',
17
+ '-.-.' => 'c',
18
+ '-..' => 'd',
19
+ '.' => 'e',
20
+ '..-.' => 'f',
21
+ '--.' => 'g',
22
+ '....' => 'h',
23
+ '..' => 'i',
24
+ '.---' => 'j',
25
+ '-.-' => 'k',
26
+ '.-..' => 'l',
27
+ '--' => 'm',
28
+ '-.' => 'n',
29
+ '---' => 'o',
30
+ '.--.' => 'p',
31
+ '--.-' => 'q',
32
+ '.-.' => 'r',
33
+ '...' => 's',
34
+ '-' => 't',
35
+ '..-' => 'u',
36
+ '...-' => 'v',
37
+ '.--' => 'w',
38
+ '-..-' => 'x',
39
+ '-.--' => 'y',
40
+ '--..' => 'z',
41
+ '-..-.' => '/',
42
+ '.-.-.' => '+',
43
+ '-...-' => '=',
44
+ '.-.-.-' => '.',
45
+ '--..--' => ',',
46
+ '..--..' => '?',
47
+ '-.--.' => '(',
48
+ '-.--.-' => ')',
49
+ '-....-' => '-',
50
+ '.-..-.' => '"',
51
+ '..--.-' => '_',
52
+ '.----.' => "'",
53
+ '---...' => ':',
54
+ '-.-.-.' => ';',
55
+ '...-..-' => '$',
56
+ '/' => ' ',
57
+ }
58
+
59
+ class Security
60
+ def initialize(sender, s) ;end
61
+
62
+ def commands
63
+ {
64
+ 'morse' => [:morse, 1, {
65
+ :help => 'Encode text into morse code',
66
+ :example => 'Hello World' }],
67
+ 'decode-morse' => [:demorse, 1, {
68
+ :help => 'Convert morse code into text',
69
+ :example => '.... . .-.. .-.. --- / .-- --- .-. .-.. -..' }],
70
+
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 => '' }],
77
+ }
78
+ end
79
+
80
+ def morse(e, data)
81
+ data.downcase.split('').map{ |c| MORSE.index(c) }.join(' ')
82
+ end
83
+
84
+ def demorse(e, data)
85
+ data.split(' ').map{ |m| MORSE.fetch(m, '-') }.join
86
+ end
87
+
88
+ def rot13(e, data)
89
+ data.tr('A-Ma-mN-Zn-z', 'N-Zn-zA-Ma-m')
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
+ end
112
+
113
+ Plugin.define do
114
+ name 'security'
115
+ description 'Hashes, morse code and base64.'
116
+ object Security
117
+ end