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.
@@ -1,15 +1,11 @@
1
1
  class System
2
- def initialize(sender, settings) ;end
3
-
4
- def to_json(*a)
5
- { 'plugin' => 'system' }.to_json(*a)
6
- end
2
+ def initialize(sender, s) ;end
7
3
 
8
4
  def commands
9
5
  require 'zmb/commands'
10
6
  {
11
- 'uptime' => Command.new(self, :uptime, 0, 'Server uptime'),
12
- 'date' => Command.new(self, :date, 0, 'Display the server date/time'),
7
+ 'uptime' => [:uptime, 0, { :help => 'Server uptime' }],
8
+ 'date' => [:date, 0, { :help => 'Display the server date/time' }],
13
9
  }
14
10
  end
15
11
 
@@ -0,0 +1,110 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'cgi'
4
+
5
+ class URL
6
+ def initialize(sender, s) ;end
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 commands
33
+ {
34
+ 'head' => :head,
35
+ 'bitly' => :bitly,
36
+ 'isgd' => :isgd,
37
+ 'tinyurl' => :tinyurl,
38
+ 'dpaste' => :dpaste,
39
+ 'pastie' => :pastie_command,
40
+ 'ppastie' => [:private_pastie_command, 1, { :help => 'Create a private pastie' }],
41
+ }
42
+ end
43
+
44
+ def head(e, url)
45
+ u = URI.parse(url)
46
+ u.path = '/' if u.path.size == 0
47
+ u.query = '' if not u.query
48
+
49
+ resp = http(u.host, u.port, u.path, 'head', u.query)
50
+ if resp.code == "301" or resp.code == "302" then
51
+ "#{resp.code} - #{resp['location']}"
52
+ elsif resp.code == "404" then
53
+ "404 - Page not found"
54
+ else
55
+ "#{resp.code}"
56
+ end
57
+ end
58
+
59
+ def bitly(e, link)
60
+ resp, body = http('bit.ly', 80, '/api', 'get', { :url => link })
61
+ body
62
+ end
63
+
64
+ def isgd(e, link)
65
+ resp, body = http('is.gd', 80, '/api.php', 'get', { :longurl => link })
66
+ body
67
+ end
68
+
69
+ def tinyurl(e, link)
70
+ resp, body = http('tinyurl.com', 80, '/api-create.php', 'get', { :url => link })
71
+ body
72
+ end
73
+
74
+ def dpaste(e, data)
75
+ resp, body = http('dpaste.de', 80, '/api/', 'post', { :content => data })
76
+ body = body[1..-2] if body =~ /^".+"$/ # Remove any quotation marks if there are any
77
+ body
78
+ end
79
+
80
+ def pastie(data, is_private=false, format='plaintext')
81
+ resp, body = http('pastie.org', 80, '/pastes', 'post', { :paste => {
82
+ :body => CGI.escape(data),
83
+ :parser => format,
84
+ :restricted => is_private,
85
+ :authorization => 'burger'
86
+ }})
87
+
88
+ puts resp.code
89
+
90
+ if resp.code == '302' then
91
+ resp['location']
92
+ else
93
+ body
94
+ end
95
+ end
96
+
97
+ def pastie_command(e, data)
98
+ pastie(data)
99
+ end
100
+
101
+ def private_pastie_command(e, data)
102
+ pastie(data, true)
103
+ end
104
+ end
105
+
106
+ Plugin.define do
107
+ name 'url'
108
+ description 'URL shortening and paste websites'
109
+ object URL
110
+ end
@@ -0,0 +1,90 @@
1
+ class Usermodes
2
+ def initialize(sender, s)
3
+ @usermodes = Hash.new
4
+ @usermodes = s['usermodes'] if s.has_key?('usermodes')
5
+ end
6
+
7
+ def settings
8
+ { 'usermodes' => @usermodes }
9
+ end
10
+
11
+ def add(instance, channel, username, mode)
12
+ k = instance + ':' + channel
13
+ @usermodes[k] = Hash.new if not @usermodes.has_key?(k)
14
+ @usermodes[k][username] = Array.new if not @usermodes[k].has_key?(username)
15
+ @usermodes[k][username] << mode
16
+ end
17
+
18
+ def remove(instance, channel, username=nil, mode=nil)
19
+ k = instance + ':' + channel
20
+ @usermodes.delete(k) if @usermodes.has_key?(k) and username == nil
21
+
22
+ if @usermodes.has_key?(k) and @usermodes[k].has_key?(username) then
23
+ @usermodes[k][username].delete(mode)
24
+ @usermodes[k].delete(username) if not mode or @usermodes[k][username].empty?
25
+ @usermodes.delete(k) if @usermodes[k].empty?
26
+ end
27
+ end
28
+
29
+ def event(sender, e)
30
+ if e.command == 'join' and e.respond_to?('user') then
31
+ if @usermodes.has_key?(k = e.delegate.instance + ':' + e.channel) then
32
+ if @usermodes[k].has_key?(e.user.username) then
33
+ @usermodes[k][e.user.username].each{ |mode| e.delegate.write "MODE #{e.channel} +#{mode} #{e.name}" }
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def commands
40
+ {
41
+ 'usermode-add' => [:usermode_add, 4, {
42
+ :permission => 'admin',
43
+ :help => 'Apply a usermode to a user when they join a channel',
44
+ :usage => 'instance channel user mode',
45
+ :example => 'efnet #zmb zynox o' }],
46
+ 'usermode-del' => [:usermode_del, 4 , {
47
+ :permission => 'admin',
48
+ :help => 'Delete a usermode',
49
+ :usage => 'instance channel user mode',
50
+ :example => 'efnet #zmb zynox o' }],
51
+ 'usermodes' => [:usermodes, 2 , {
52
+ :permission => 'admin',
53
+ :help => 'List all usermodes for a channel',
54
+ :usage => 'instance channel',
55
+ :example => 'efnet #zmb' }],
56
+ 'usermodes-ls' => [:usermodes_ls , {
57
+ :permission => 'admin',
58
+ :help => 'List all channels usermodes are applied to' }],
59
+ }
60
+ end
61
+
62
+ def usermode_add(e, *args)
63
+ add(*args)
64
+ "usermode added"
65
+ end
66
+
67
+ def usermode_del(e, *args)
68
+ remove(*args)
69
+ "usermode deleted"
70
+ end
71
+
72
+ def usermodes(e, instance, channel)
73
+ k = instance + ':' + channel
74
+ if @usermodes.has_key?(k) then
75
+ @usermodes[k].map{ |k,v| "#{k} +#{v.join('')}" }.join("\n")
76
+ else
77
+ 'no usermodes found for instance/channel'
78
+ end
79
+ end
80
+
81
+ def usermodes_ls(e)
82
+ @usermodes.keys.map{ |k| k.split(':', 2) }.map{ |i,c| "#{i} - #{c}" }.join("\n")
83
+ end
84
+ end
85
+
86
+ Plugin.define do
87
+ name 'usermodes'
88
+ description 'Auto opping, voicing users in a channel'
89
+ object Usermodes
90
+ end
@@ -13,7 +13,8 @@ class User
13
13
 
14
14
  def self.create_settings(data)
15
15
  require 'time'
16
- user = new(data['username'], data['password'])
16
+ user = new(data['username'])
17
+ user.raw_password = data['password']
17
18
  user.userhosts = data['userhosts'] if data.has_key?('userhosts')
18
19
  user.permissions = data['permissions'] if data.has_key?('permissions')
19
20
  user.seen = Time.parse(data['seen']) if data.has_key?('seen') and data['seen']
@@ -33,6 +34,10 @@ class User
33
34
  @userhosts += other_user.userhosts
34
35
  end
35
36
 
37
+ def raw_password=(new_password)
38
+ @password = new_password
39
+ end
40
+
36
41
  def password=(new_password)
37
42
  @password = Digest::SHA1.hexdigest(new_password)
38
43
  end
@@ -79,14 +84,14 @@ end
79
84
  class Users
80
85
  attr_accessor :users
81
86
 
82
- def initialize(sender, settings={})
87
+ def initialize(sender, s={})
83
88
  @delegate = sender
84
- @users = settings['users'].map{ |user| User.create_settings(user) } if settings.has_key?('users')
89
+ @users = s['users'].map{ |user| User.create_settings(user) } if s.has_key?('users')
85
90
  @users = Array.new if not @users
86
91
  end
87
92
 
88
- def to_json(*a)
89
- {'users' => @users, 'plugin' => 'users'}.to_json(*a)
93
+ def settings
94
+ { 'users' => @users }
90
95
  end
91
96
 
92
97
  def user!(search)
@@ -109,24 +114,54 @@ class Users
109
114
  end
110
115
 
111
116
  def commands
112
- require 'zmb/commands'
113
117
  {
114
- 'meet' => Command.new(self, :meet, 1, 'Meet a new user'),
115
- 'forget' => AuthCommand.new(self, :forget, 0, "Forget about a user"),
116
- 'permit' => PermCommand.new('admin', self, :permit, 2),
117
- 'deny' => PermCommand.new('admin', self, :deny, 2),
118
- 'perms' => AuthCommand.new(self, :perms, 1, 'List all permissions a user has.'),
119
- 'merge' => PermCommand.new('admin', self, :merge, 2, 'Merge two users together'),
120
- 'password' => AuthCommand.new(self, :password, 1, 'Set the password for your account'),
121
- 'login' => Command.new(self, :login, 2, 'Add your current host to the username and password provided.'),
122
- 'logout' => AuthCommand.new(self, :logout, 0, 'Remove your current host from your account.'),
123
- 'whoami' => Command.new(self, :whoami, 0, 'Who are you logged in as?'),
124
- 'userhosts' => AuthCommand.new(self, :userhosts, 0, 'List all the hosts associated with your account'),
125
- 'adduserhost' => AuthCommand.new(self, :adduserhost, 1, 'Add a host to your account'),
126
- 'deluserhost' => AuthCommand.new(self, :deluserhost, 1, 'Remove a host to your account'),
127
- 'names' => Command.new(self, :names, 1, 'List all the users'),
128
- 'seen' => Command.new(self, :seen, 1, 'When was a user last seen'),
129
- 'sudo' => PermCommand.new('admin', self, :sudo, 2, 'Execute a command as another user.'),
118
+ 'meet' => [:meet, 1, { :help => 'Meet a user' }],
119
+ 'forget' => [:forget, 0, {
120
+ :help => 'Forget about a user',
121
+ :permission => 'authenticated' }],
122
+ 'permit' => [:permit, 2, {
123
+ :permission => 'admin',
124
+ :help => 'Add a permission to a user',
125
+ :usage => '<user> <permission>',
126
+ :example => 'zynox admin' }],
127
+ 'deny' => [:deny, 2, {
128
+ :permission => 'admin',
129
+ :help => 'Remove a permission from a user',
130
+ :usage => '<user> <permission>',
131
+ :example => 'zynox admin' }],
132
+ 'perms' => [:perms, 0, {
133
+ :permission => 'authenticated',
134
+ :help => 'List all the permissions you have' }],
135
+ 'merge' => [:merge, 2, {
136
+ :permission => 'admin',
137
+ :help => 'Merge two users together, give user a the permissions and useragents of b and then delete b',
138
+ :usage => 'user_a user_b'}],
139
+ 'password' => [:password, 1, {
140
+ :permission => 'authenticated',
141
+ :help => 'Set the password for your account',
142
+ :usage => 'password' }],
143
+ 'login' => [:login, 2, {
144
+ :help => 'Login to your account, adding your current userhost to your account.',
145
+ :usage => 'username password' }],
146
+ 'logout' => [:logout, 0, {
147
+ :permission => 'authenticated',
148
+ :help => 'Logout from your account, this will remove your current userhost from your account.' }],
149
+ 'whoami' => [:whoami, 0, { :help => 'Who are you logged in as?' }],
150
+ 'userhosts' => [:userhosts, 0, {
151
+ :help => 'List all the userhosts associated with your account.' }],
152
+ 'adduserhost' => [:adduserhost, 1, { :help => 'Add a userhost to your account.' }],
153
+ 'rmuserhost' => [:rmuserhost, 1, { :help => 'Remove a userhost to your account.' }],
154
+ 'names' => [:names, 1, {
155
+ :help => 'List all the users',
156
+ :usage => '<search>' }],
157
+ 'seen' => [:seen, 1, {
158
+ :help => 'When was a user last seen?',
159
+ :usage => 'user' }],
160
+ 'sudo' => [:sudo, 2, {
161
+ :permission => 'admin',
162
+ :help => 'Execute a command as another user.',
163
+ :usage => 'user command',
164
+ :example => 'zynox whoami' }],
130
165
  }
131
166
  end
132
167
 
@@ -168,7 +203,7 @@ class Users
168
203
  end
169
204
  end
170
205
 
171
- def perms(e, username=nil)
206
+ def perms(e)
172
207
  e.user.permissions.empty? ? "#{e.user.username} has no permissions" : e.user.permissions.join(', ')
173
208
  end
174
209
 
@@ -193,19 +228,17 @@ class Users
193
228
  def login(e, username, password)
194
229
  user = user!(username)
195
230
 
196
- if e.user.authenticated? then
197
- 'already logged in'
198
- elsif user and user.password?(password) then
199
- user.hosts << e.userhost
200
- "#{request.hostname} added to your account #{user.username}"
231
+ if user and user.password?(password) then
232
+ user.userhosts << e.userhost
233
+ "#{e.userhost} added to your account #{user.username}"
201
234
  else
202
235
  'user and/or password is incorrect'
203
236
  end
204
237
  end
205
238
 
206
239
  def logout(e)
207
- e.user.hosts.delete(e.userhost)
208
- "userhost #{e.hostname} removed from your account."
240
+ e.user.userhosts.delete(e.userhost)
241
+ "userhost #{e.userhost} removed from your account."
209
242
  end
210
243
 
211
244
  def whoami(e)
@@ -221,7 +254,7 @@ class Users
221
254
  "#{userhost} added to #{e.user.username}"
222
255
  end
223
256
 
224
- def deluserhost(e, userhost)
257
+ def rmuserhost(e, userhost)
225
258
  if e.user.userhosts.delete(userhost) then
226
259
  "#{userhost} deleted from #{e.user.username}"
227
260
  else
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{zmb}
8
- s.version = "0.1.3"
8
+ s.version = "0.2.0"
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-03-03}
12
+ s.date = %q{2010-03-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}
@@ -27,20 +27,26 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "bin/zmb",
29
29
  "lib/zmb.rb",
30
- "lib/zmb/commands.rb",
31
30
  "lib/zmb/event.rb",
32
31
  "lib/zmb/plugin.rb",
33
32
  "lib/zmb/settings.rb",
34
33
  "lib/zmb/timer.rb",
34
+ "plugins/announce.rb",
35
+ "plugins/autorejoin.rb",
35
36
  "plugins/bank.rb",
36
37
  "plugins/commands.rb",
38
+ "plugins/dns.rb",
37
39
  "plugins/idle.rb",
38
40
  "plugins/irc.rb",
41
+ "plugins/log.rb",
39
42
  "plugins/nickserv.rb",
40
43
  "plugins/poll.rb",
41
44
  "plugins/quote.rb",
42
45
  "plugins/relay.rb",
46
+ "plugins/security.rb",
43
47
  "plugins/system.rb",
48
+ "plugins/url.rb",
49
+ "plugins/usermodes.rb",
44
50
  "plugins/users.rb",
45
51
  "test/helper.rb",
46
52
  "test/test_zmb.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.3
4
+ version: 0.2.0
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-03-03 00:00:00 +00:00
12
+ date: 2010-03-05 00:00:00 +00:00
13
13
  default_executable: zmb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,20 +50,26 @@ files:
50
50
  - VERSION
51
51
  - bin/zmb
52
52
  - lib/zmb.rb
53
- - lib/zmb/commands.rb
54
53
  - lib/zmb/event.rb
55
54
  - lib/zmb/plugin.rb
56
55
  - lib/zmb/settings.rb
57
56
  - lib/zmb/timer.rb
57
+ - plugins/announce.rb
58
+ - plugins/autorejoin.rb
58
59
  - plugins/bank.rb
59
60
  - plugins/commands.rb
61
+ - plugins/dns.rb
60
62
  - plugins/idle.rb
61
63
  - plugins/irc.rb
64
+ - plugins/log.rb
62
65
  - plugins/nickserv.rb
63
66
  - plugins/poll.rb
64
67
  - plugins/quote.rb
65
68
  - plugins/relay.rb
69
+ - plugins/security.rb
66
70
  - plugins/system.rb
71
+ - plugins/url.rb
72
+ - plugins/usermodes.rb
67
73
  - plugins/users.rb
68
74
  - test/helper.rb
69
75
  - test/test_zmb.rb