zmb 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/bin/zmb CHANGED
@@ -80,7 +80,7 @@ def wizard(zmb, plugin)
80
80
  zmb.setup(plugin.name, instance)
81
81
  obj = zmb.plugin_manager.plugin plugin.name
82
82
  if obj.respond_to?('wizard') then
83
- settings = zmb.settings.setting(instance)
83
+ settings = zmb.settings_manager.setting(instance)
84
84
  settings['plugin'] = plugin.name
85
85
 
86
86
  obj.wizard.each do |key, value|
@@ -90,7 +90,7 @@ def wizard(zmb, plugin)
90
90
  end
91
91
  end
92
92
 
93
- zmb.settings.save(instance, settings)
93
+ zmb.settings_manager.save(instance, settings)
94
94
  end
95
95
  zmb.load instance
96
96
  end
data/lib/zmb.rb CHANGED
@@ -10,11 +10,10 @@ end
10
10
  require 'zmb/plugin'
11
11
  require 'zmb/settings'
12
12
  require 'zmb/event'
13
- require 'zmb/commands'
14
13
  require 'zmb/timer'
15
14
 
16
15
  class Zmb
17
- attr_accessor :instances, :plugin_manager, :settings_manager
16
+ attr_accessor :instances, :plugin_manager, :settings_manager, :plugin_sources
18
17
 
19
18
  def plugin
20
19
  'zmb'
@@ -34,12 +33,16 @@ class Zmb
34
33
  @timers = Array.new
35
34
  timer_add(Timer.new(self, :save, 120.0, true)) # Save every 2 minutes
36
35
 
37
- @settings_manager.get('zmb', 'plugin_sources', []).each{|source| @plugin_manager.add_plugin_source source}
38
-
39
- if @plugin_manager.plugin_sources.empty? then
40
- @plugin_manager.add_plugin_source File.join(File.expand_path(File.dirname(File.dirname(__FILE__))), 'plugins')
36
+ plugin_dir = File.join(@settings_manager.directory, 'plugins')
37
+ if not File.exist?(plugin_dir) then
38
+ FileUtils.makedirs(plugin_dir)
41
39
  end
42
40
 
41
+ @plugin_sources = @settings_manager.get('zmb', 'plugin_sources', [])
42
+ @plugin_sources.each{ |source| @plugin_manager.add_plugin_source source }
43
+ @plugin_manager.add_plugin_source File.join(File.expand_path(File.dirname(File.dirname(__FILE__))), 'plugins')
44
+ @plugin_manager.add_plugin_source plugin_dir
45
+
43
46
  @settings_manager.get('zmb', 'plugin_instances', []).each{|instance| load instance}
44
47
 
45
48
  @running = false
@@ -51,7 +54,7 @@ class Zmb
51
54
 
52
55
  def settings
53
56
  {
54
- 'plugin_sources' => @plugin_manager.plugin_sources,
57
+ 'plugin_sources' => @plugin_sources,
55
58
  'plugin_instances' => @instances.keys,
56
59
  }
57
60
  end
@@ -310,6 +313,7 @@ class Zmb
310
313
  end
311
314
 
312
315
  def addsource_command(e, source)
316
+ @plugin_sources << source
313
317
  @plugin_manager.add_plugin_source source
314
318
  "#{source} added to plugin manager"
315
319
  end
data/plugins/alias.rb ADDED
@@ -0,0 +1,45 @@
1
+ class Alias
2
+ attr_accessor :aliases
3
+
4
+ def initialize(sender, settings)
5
+ @aliases = settings['aliases'] if settings.has_key?('aliases')
6
+ @aliases = Hash.new if not @aliases
7
+ end
8
+
9
+ def settings
10
+ { 'aliases' => @aliases }
11
+ end
12
+
13
+ def commands
14
+ {
15
+ 'alias' => [:add, 2, { :permission => 'admin' }],
16
+ 'unalias' => [:del, 1, { :permission => 'admin' }],
17
+ 'aliases' => [:aliases, 0, { :permission => 'admin' }]
18
+ }
19
+ end
20
+
21
+ def add(e, a, command)
22
+ @aliases[a] = command
23
+ "#{a} aliased"
24
+ end
25
+
26
+ def del(e, command)
27
+ @aliases.delete(command)
28
+ "#{command} deleted"
29
+ end
30
+
31
+ def aliases(e)
32
+ @aliases.keys.join(", ")
33
+ end
34
+
35
+ def pre_event(sender, e)
36
+ if e.message? then
37
+ @aliases.each{ |a, c| e.message.sub!(a, c) if e.message =~ /^#{a}/ }
38
+ end
39
+ end
40
+ end
41
+
42
+ Plugin.define do
43
+ name 'alias'
44
+ object Alias
45
+ end
data/plugins/bank.rb CHANGED
@@ -39,7 +39,11 @@ class Account
39
39
  end
40
40
 
41
41
  class Event
42
- attr_accessor :bank
42
+ attr_accessor :banks
43
+
44
+ def bank
45
+ banks.account(@user.username) if respond_to?('user') and @user.respond_to?('username')
46
+ end
43
47
  end
44
48
 
45
49
  class Bank
@@ -69,7 +73,8 @@ class Bank
69
73
  end
70
74
 
71
75
  def pre_event(sender, e)
72
- e.bank = account(e.user.username) if e.respond_to?('user') and e.user.respond_to?('username')
76
+ e.banks = self
77
+ #e.bank = account(e.user.username) if e.respond_to?('user') and e.user.respond_to?('username')
73
78
  end
74
79
 
75
80
  def commands
data/plugins/commands.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'zmb/commands'
2
-
3
1
  class Commands
4
2
  attr_accessor :cmds, :cc
5
3
 
@@ -8,7 +6,7 @@ class Commands
8
6
  @cmds = Hash.new
9
7
 
10
8
  @cc = s['cc'] if s.has_key?('cc')
11
- @cc = '!' if @cc == nil
9
+ @cc = '.' if @cc == nil
12
10
 
13
11
  sender.instances.each{ |key, instance| plugin_loaded(key, instance) }
14
12
  end
@@ -32,11 +30,10 @@ class Commands
32
30
  line = e.message.clone
33
31
  end
34
32
 
35
- # Encode escaped quotation marks
36
- line.gsub!(/\\"|\\'/) { |m| m =~ /^\\"$/ ? "\000d\000" : "\000s\000" }
37
-
38
- # Encode pipes inside quotation marks
39
- line.gsub!(/"\w*\|\w*"/) { |m| m.sub('|', "\000p\000") }
33
+ # Encode escaped quotation marks and pipes
34
+ line.gsub!('\"', "\000d\000")
35
+ line.gsub!("\\'", "\000s\000")
36
+ line.gsub!('\|', "\000p\000")
40
37
 
41
38
  # Check there are a even amount of "" and ''
42
39
  if ((line.count("'") % 2) == 1) and ((line.count('""') % 2) == 1) then
@@ -55,9 +52,9 @@ class Commands
55
52
 
56
53
  # Decode escape quotation marks and pipes inside the args
57
54
  args.each do |arg|
58
- arg.sub!("\000d\000", '"')
59
- arg.sub!("\000s\000", "'")
60
- arg.sub!("\000p\000", '|')
55
+ arg.gsub!("\000d\000", '"')
56
+ arg.gsub!("\000s\000", "'")
57
+ arg.gsub!("\000p\000", '|')
61
58
  end
62
59
 
63
60
  cmd = args.delete_at(0)
@@ -198,14 +195,18 @@ class Commands
198
195
  if cc then
199
196
  @cc = cc
200
197
  else
201
- @cc = '!'
198
+ @cc = '.'
202
199
  end
203
200
 
204
201
  "Control command set to #{@cc}"
205
202
  end
206
203
 
207
204
  def evaluate(e, string)
208
- "#{eval string}"
205
+ begin
206
+ "#{eval string}"
207
+ rescue Exception
208
+ "#{$!.message}\n#{$!.inspect}"
209
+ end
209
210
  end
210
211
 
211
212
  def count(e, data)
data/plugins/file.rb ADDED
@@ -0,0 +1,57 @@
1
+ class FileIO
2
+ def initialize(sender, s); end
3
+
4
+ def commands
5
+ {
6
+ 'cat' => [:cat, 1, {
7
+ :permission => 'admin',
8
+ :help => 'View a file',
9
+ :usage => '/home/zynox/file' }],
10
+ 'write' => [:write, 2, {
11
+ :permission => 'admin',
12
+ :help => 'Write to a file',
13
+ :usage => '/home/zynox/hello Hello world!' }],
14
+ 'append' => [:append, 2, {
15
+ :permission => 'admin',
16
+ :help => 'Add data to the end of a file',
17
+ :usage => '/home/zynox/hello Another hello world!' }],
18
+ }
19
+ end
20
+
21
+ def cat(e, file)
22
+ begin
23
+ File.read(File.expand_path(file))
24
+ rescue
25
+ "file not found or access denied"
26
+ end
27
+ end
28
+
29
+ def write(e, file, data)
30
+ begin
31
+ f = File.open(File.expand_path(file), 'w')
32
+ f.write(data)
33
+ 'data written'
34
+ rescue
35
+ 'access denied'
36
+ ensure
37
+ f.close unless f.nil?
38
+ end
39
+ end
40
+
41
+ def append(e, file, data)
42
+ begin
43
+ f = File.open(File.expand_path(file), 'a')
44
+ f.write(data)
45
+ 'data written to end of file'
46
+ rescue
47
+ 'access denied'
48
+ ensure
49
+ f.close unless f.nil?
50
+ end
51
+ end
52
+ end
53
+
54
+ Plugin.define do
55
+ name 'file'
56
+ object FileIO
57
+ end
data/plugins/gcalc.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'uri'
2
+
3
+ class GCalc
4
+ def initialize(sender, settings); end
5
+
6
+ def commands
7
+ {
8
+ 'gcalc' => [:calc, 1, {
9
+ :help => 'Execute a expression using google calculator.',
10
+ :example => '1 + 2' }]
11
+ }
12
+ end
13
+
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
19
+
20
+ if resp.code == '200' then
21
+ if body.include?('<img src=/images/calc_img.gif width=40 height=30 alt="">')
22
+ body.split('<img src=/images/calc_img.gif width=40 height=30 alt="">')[1].split('<b>')[1].split('</b>')[0].sub('<font size=-2> </font>', '').sub('&#215;', '*').sub('<sup>', '**').sub('</sup>', '')
23
+ else
24
+ 'Your expression can\'t be evaluated by the google calculator'
25
+ end
26
+ else
27
+ "http error (#{resp.code})"
28
+ end
29
+ end
30
+ end
31
+
32
+ Plugin.define do
33
+ name 'gcalc'
34
+ description 'Execute a expression using google calculator.'
35
+ object GCalc
36
+ end
data/plugins/irc.rb CHANGED
@@ -28,6 +28,7 @@ class Event
28
28
  when 'join'
29
29
  @userhost, @channel = args.split(' ', 2)
30
30
  @name, @userhost = @userhost.split('!', 2)
31
+ @channel = @channel[1..-1]
31
32
  when 'part'
32
33
  @userhost, @channel = args.split(' ', 2)
33
34
  @name, @userhost = @userhost.split('!', 2)
@@ -113,7 +114,7 @@ class IrcConnection
113
114
  'port' => { 'help' => 'Port', 'default' => 6667 },
114
115
  'nick' => { 'help' => 'Nickname', 'default' => 'zmb' },
115
116
  'name' => { 'help' => 'Name', 'default' => 'zmb' },
116
- 'realname' => { 'help' => 'Realname', 'default' => 'zmb' },
117
+ 'realname' => { 'help' => 'Realname', 'default' => 'Unknown' },
117
118
  'password' => { 'help' => 'If the ircd requires a password, enter this here.', 'default' => nil },
118
119
  }
119
120
  end
@@ -165,7 +166,7 @@ class IrcConnection
165
166
  def perform
166
167
  write "PASS #{@password}" if @password
167
168
  write "NICK #{@nick}" if @nick
168
- write "USER #{@name} 0 0 :#{@realname}" if @name and @realname
169
+ write "USER #{@name} 0 * :#{@realname}" if @name and @realname
169
170
  end
170
171
 
171
172
  def write(line)
@@ -217,7 +218,9 @@ class IrcConnection
217
218
  # Catch some events
218
219
  case e.command
219
220
  when 'ping' then write "PONG #{e.args[1..-1]}"
220
- when '001' then @channels.each{ |channel| write "JOIN #{channel}" }
221
+ when '001' then
222
+ sleep 0.1
223
+ @channels.each{ |channel| write "JOIN #{channel}" }
221
224
  when 'nick' then tmp, @nick = e.args.split(' :', 2)
222
225
  when '433' then
223
226
  @nick="#{@nick}_"
data/plugins/poll.rb CHANGED
@@ -30,12 +30,31 @@ class Poll
30
30
 
31
31
  def commands
32
32
  {
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,
33
+ 'poll-add' => [:add_command, 2, {
34
+ :permission => 'admin',
35
+ :help => 'Add a poll',
36
+ :usage => 'id poll',
37
+ :example => 'colour Red, yellow or blue?' }],
38
+ 'poll-opt' => [:opt_command, 2, {
39
+ :permission => 'admin',
40
+ :help => 'Add a option to a poll',
41
+ :usage => 'id option',
42
+ :example => 'colour Red' }],
43
+ 'poll-del' => [:del_command, 1, {
44
+ :permission => 'admin',
45
+ :help => 'Delete a poll',
46
+ :usage => 'id',
47
+ :example => 'colour' }],
48
+ 'vote' => [:vote_command, 2, {
49
+ :help => 'Vote on a poll',
50
+ :usage => 'id option',
51
+ :example => 'colour 1' }],
52
+ 'polls' => [:polls_command, 0, {
53
+ :help => 'List all poll\'s' }],
54
+ 'poll' => [:poll_command, 1, {
55
+ :help => 'List a poll',
56
+ :usage => 'id',
57
+ :example => 'colour' }],
39
58
  }
40
59
  end
41
60
 
data/plugins/quote.rb CHANGED
@@ -33,14 +33,14 @@ class Quote
33
33
  :help => 'Show a random quote or the quote with matching id',
34
34
  :usage => '<id>' }],
35
35
  'quote-add' => [:add_command, 1, {
36
- :help => 'Add a quote'
37
- :example => 'zynox: Hello!'}],
36
+ :help => 'Add a quote',
37
+ :example => 'zynox: Hello!' }],
38
38
  'quote-del' => [:del_command, 1, {
39
39
  :help => 'Delete a quote by id',
40
40
  :example => '7'}],
41
41
  'quote-count' =>[:count_command, 0, {
42
42
  :help => 'Show amount of quotes' }],
43
- 'quote-last' => [:last_command, 0, { :help => 'Show the last quote'),
43
+ 'quote-last' => [:last_command, 0, { :help => 'Show the last quote' }],
44
44
  'quote-search' => [:search_command, 1, {
45
45
  :help => 'Search to find a quote',
46
46
  :usage => 'search' }],
data/plugins/random.rb ADDED
@@ -0,0 +1,49 @@
1
+ class Random
2
+ def initialize(sender, settings); end
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
+ def commands
19
+ {
20
+ 'random' => :random,
21
+ 'yesno' => [:yesno, 0],
22
+ 'headstails' => [:coinflip, 0],
23
+ 'coinflip' => [:coinflip, 0],
24
+ 'dice' => [:dice, 0],
25
+ }
26
+ end
27
+
28
+ def random(e, args)
29
+ items = split_seperators(args)
30
+ "#{items[rand(items.size)]}"
31
+ end
32
+
33
+ def yesno(e)
34
+ random(e, ['yes', 'no'])
35
+ end
36
+
37
+ def coinflip(e)
38
+ random(e, ['heads', 'tails'])
39
+ end
40
+
41
+ def dice(e)
42
+ "#{rand(6) + 1}"
43
+ end
44
+ end
45
+
46
+ Plugin.define do
47
+ name 'random'
48
+ object Random
49
+ end
data/plugins/system.rb CHANGED
@@ -2,7 +2,6 @@ class System
2
2
  def initialize(sender, s) ;end
3
3
 
4
4
  def commands
5
- require 'zmb/commands'
6
5
  {
7
6
  'uptime' => [:uptime, 0, { :help => 'Server uptime' }],
8
7
  'date' => [:date, 0, { :help => 'Display the server date/time' }],
data/plugins/url.rb CHANGED
@@ -29,9 +29,17 @@ class URL
29
29
  end
30
30
  end
31
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
+
32
39
  def commands
33
40
  {
34
41
  'head' => :head,
42
+ 'url' => [:get, 1, { :permission => 'admin' }],
35
43
  'bitly' => :bitly,
36
44
  'isgd' => :isgd,
37
45
  'tinyurl' => :tinyurl,
@@ -42,11 +50,8 @@ class URL
42
50
  end
43
51
 
44
52
  def head(e, url)
45
- u = URI.parse(url)
46
- u.path = '/' if u.path.size == 0
47
- u.query = '' if not u.query
53
+ resp = http_uri(url, 'head')
48
54
 
49
- resp = http(u.host, u.port, u.path, 'head', u.query)
50
55
  if resp.code == "301" or resp.code == "302" then
51
56
  "#{resp.code} - #{resp['location']}"
52
57
  elsif resp.code == "404" then
@@ -56,6 +61,11 @@ class URL
56
61
  end
57
62
  end
58
63
 
64
+ def get(e, url)
65
+ resp, body = http_uri(url)
66
+ body
67
+ end
68
+
59
69
  def bitly(e, link)
60
70
  resp, body = http('bit.ly', 80, '/api', 'get', { :url => link })
61
71
  body
@@ -85,8 +95,6 @@ class URL
85
95
  :authorization => 'burger'
86
96
  }})
87
97
 
88
- puts resp.code
89
-
90
98
  if resp.code == '302' then
91
99
  resp['location']
92
100
  else
data/plugins/usermodes.rb CHANGED
@@ -43,19 +43,21 @@ class Usermodes
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, 4 , {
46
+ 'usermode-del' => [:usermode_del, 4, {
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, 2 , {
51
+ 'usermodes' => [:usermodes, 2, {
52
52
  :permission => 'admin',
53
53
  :help => 'List all usermodes for a channel',
54
54
  :usage => 'instance channel',
55
55
  :example => 'efnet #zmb' }],
56
- 'usermodes-ls' => [:usermodes_ls , {
56
+ 'usermodes-ls' => [:usermodes_ls, {
57
57
  :permission => 'admin',
58
58
  :help => 'List all channels usermodes are applied to' }],
59
+ 'enforce' => [:enforce, 0, { :permission => 'authenticated' }],
60
+ 'vanish' => [:vanish, 0, { :permission => 'authenticated' }],
59
61
  }
60
62
  end
61
63
 
@@ -81,6 +83,22 @@ class Usermodes
81
83
  def usermodes_ls(e)
82
84
  @usermodes.keys.map{ |k| k.split(':', 2) }.map{ |i,c| "#{i} - #{c}" }.join("\n")
83
85
  end
86
+
87
+ def enforce(e)
88
+ if @usermodes.has_key?(k = e.delegate.instance + ':' + e.channel) and e.user.authenticated? and @usermodes[k].has_key?(e.user.username) then
89
+ @usermodes[k][e.user.username].each{ |mode| e.delegate.write "MODE #{e.channel} +#{mode} #{e.name}" }
90
+ end
91
+
92
+ "usermodes enforced"
93
+ end
94
+
95
+ def vanish(e)
96
+ if @usermodes.has_key?(k = e.delegate.instance + ':' + e.channel) and e.user.authenticated? and @usermodes[k].has_key?(e.user.username) then
97
+ @usermodes[k][e.user.username].each{ |mode| e.delegate.write "MODE #{e.channel} -#{mode} #{e.name}" }
98
+ end
99
+
100
+ "usermodes vanished"
101
+ end
84
102
  end
85
103
 
86
104
  Plugin.define do
data/plugins/users.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  class Event
2
- attr_accessor :user
2
+ attr_accessor :user, :users
3
3
  end
4
4
 
5
5
  class User
6
6
  require 'digest/sha1'
7
7
 
8
- attr_accessor :username, :password, :userhosts, :permissions, :seen
8
+ attr_accessor :username, :password, :userhosts, :permissions, :seen, :users
9
9
 
10
10
  def to_json(*a)
11
11
  {'username' => @username, 'password' => @password, 'userhosts' => @userhosts, 'permissions' => @permissions, 'seen' => @seen}.to_json(*a)
@@ -21,6 +21,10 @@ class User
21
21
  user
22
22
  end
23
23
 
24
+ def to_s
25
+ @username
26
+ end
27
+
24
28
  def initialize(username=nil, password=nil, userhost=nil)
25
29
  @username = username
26
30
  @password = Digest::SHA1.hexdigest(password) if password
@@ -51,7 +55,7 @@ class User
51
55
  end
52
56
 
53
57
  def admin?
54
- @permissions.include?("owner") or @permissions.include?("admin")
58
+ @permissions.include?('owner') or @permissions.include?('admin')
55
59
  end
56
60
 
57
61
  def permission?(permission)
@@ -103,20 +107,18 @@ class Users
103
107
  end
104
108
 
105
109
  def pre_event(sender, e)
106
- e.user = user(e.userhost) if e.respond_to?('userhost') and not e.user
107
- e.user.seen = Time.now if e.user.respond_to?('seen')
108
- end
109
-
110
- def create_user(username, password=nil, userhost=nil)
111
- user = User.new(username, password, userhost)
112
- @users << user
113
- user
110
+ e.user = user(e.userhost) if not e.user and e.respond_to?('userhost')
111
+ e.user.seen = Time.now if e.user.respond_to?('seen=')
112
+ e.users = self
113
+
114
+ #e.instance_variable_set(:@user, user(e.userhost)) if e.respond_to?('userhost')
115
+ #def e.user; user(e.userhost); end
114
116
  end
115
117
 
116
118
  def commands
117
119
  {
118
120
  'meet' => [:meet, 1, { :help => 'Meet a user' }],
119
- 'forget' => [:forget, 0, {
121
+ 'forget' => [:forget, 1, {
120
122
  :help => 'Forget about a user',
121
123
  :permission => 'authenticated' }],
122
124
  'permit' => [:permit, 2, {
@@ -132,6 +134,8 @@ class Users
132
134
  'perms' => [:perms, 0, {
133
135
  :permission => 'authenticated',
134
136
  :help => 'List all the permissions you have' }],
137
+ 'group' => [:group, 1, {
138
+ :permission => 'admin' }],
135
139
  'merge' => [:merge, 2, {
136
140
  :permission => 'admin',
137
141
  :help => 'Merge two users together, give user a the permissions and useragents of b and then delete b',
@@ -148,9 +152,14 @@ class Users
148
152
  :help => 'Logout from your account, this will remove your current userhost from your account.' }],
149
153
  'whoami' => [:whoami, 0, { :help => 'Who are you logged in as?' }],
150
154
  'userhosts' => [:userhosts, 0, {
155
+ :permission => 'authenticated',
151
156
  :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.' }],
157
+ 'adduserhost' => [:adduserhost, 1, {
158
+ :permission => 'authenticated',
159
+ :help => 'Add a userhost to your account.' }],
160
+ 'rmuserhost' => [:rmuserhost, 1, {
161
+ :permission => 'authenticated',
162
+ :help => 'Remove a userhost to your account.' }],
154
163
  'names' => [:names, 1, {
155
164
  :help => 'List all the users',
156
165
  :usage => '<search>' }],
@@ -166,23 +175,23 @@ class Users
166
175
  end
167
176
 
168
177
  def meet(e, username=nil)
169
- if e.user.admin? and username then
170
- return "#{username} already exists" if user!(username)
171
- user = create_user(username)
172
- "Hello #{username}"
173
- elsif not e.user.authenticated? then
174
- return "#{e.sender} already exists" if user!(e.sender)
175
- if e.respond_to?('userhost') and e.respond_to?('user') then
176
- user = create_user(e.name, nil, e.userhost)
177
- end
178
- "Hello #{user.username}"
178
+ username = e.name if not e.user.admin?
179
+
180
+ if not user!(username) then
181
+ @users << user = User.new(username)
182
+ user.userhosts << e.userhost if not e.user.admin? and e.respond_to?('userhost')
183
+ "Hello #{e.user}"
179
184
  else
180
- "You already have an account #{e.user.username}"
185
+ "You already have an account #{e.user}"
181
186
  end
182
187
  end
183
188
 
184
- def forget(e)
185
- "user #{@e.users.delete(e.user).username} deleted"
189
+ def forget(e, username=nil)
190
+ if e.user.admin? and username then
191
+ "user #{@users.delete(user(username))} deleted"
192
+ else
193
+ "user #{@users.delete(e.user)} deleted"
194
+ end
186
195
  end
187
196
 
188
197
  def permit(e, username, permission)
@@ -204,7 +213,11 @@ class Users
204
213
  end
205
214
 
206
215
  def perms(e)
207
- e.user.permissions.empty? ? "#{e.user.username} has no permissions" : e.user.permissions.join(', ')
216
+ e.user.permissions.empty? ? "#{e.user} has no permissions" : e.user.permissions.join(', ')
217
+ end
218
+
219
+ def group(e, group)
220
+ @users.reject{ |user| not user.permissions.include?(group) }.join(', ')
208
221
  end
209
222
 
210
223
  def merge(e, username, other_username)
@@ -214,7 +227,7 @@ class Users
214
227
  if user and other_user then
215
228
  user.concat other_user
216
229
  @users.delete other_user
217
- "#{other_user.username} now merged into #{user.username}"
230
+ "#{other_user} now merged into #{user}"
218
231
  else
219
232
  'User(s) do not exist'
220
233
  end
@@ -222,7 +235,7 @@ class Users
222
235
 
223
236
  def password(e, password)
224
237
  e.user.password = password
225
- "#{e.user.username} password has been set to #{password}"
238
+ "#{e.user} password has been set to #{password}"
226
239
  end
227
240
 
228
241
  def login(e, username, password)
@@ -230,7 +243,7 @@ class Users
230
243
 
231
244
  if user and user.password?(password) then
232
245
  user.userhosts << e.userhost
233
- "#{e.userhost} added to your account #{user.username}"
246
+ "#{e.userhost} added to your account #{user}"
234
247
  else
235
248
  'user and/or password is incorrect'
236
249
  end
@@ -242,28 +255,28 @@ class Users
242
255
  end
243
256
 
244
257
  def whoami(e)
245
- e.user.authenticated? ? "#{e.user.username}" : 'nobody'
258
+ e.user.authenticated? ? "#{e.user}" : 'nobody'
246
259
  end
247
260
 
248
261
  def userhosts(e)
249
- e.user.userhosts.empty? ? "#{e.user.username} has no userhosts" : e.user.userhosts.join(', ')
262
+ e.user.userhosts.empty? ? "#{e.user} has no userhosts" : e.user.userhosts.join(', ')
250
263
  end
251
264
 
252
265
  def adduserhost(e, userhost)
253
266
  e.user.userhosts << userhost
254
- "#{userhost} added to #{e.user.username}"
267
+ "#{userhost} added to #{e.user}"
255
268
  end
256
269
 
257
270
  def rmuserhost(e, userhost)
258
271
  if e.user.userhosts.delete(userhost) then
259
- "#{userhost} deleted from #{e.user.username}"
272
+ "#{userhost} deleted from #{e.user}"
260
273
  else
261
- "#{e.user.username} doesn't have #{userhost}"
274
+ "#{e.user} doesn't have #{userhost}"
262
275
  end
263
276
  end
264
277
 
265
278
  def names(e, search=nil)
266
- users = @users.map{|user| user.username}
279
+ users = @users.map{ |user| user.username }
267
280
  users = users.grep(/#{search}/i) if search
268
281
 
269
282
  if users.empty? then
@@ -273,7 +286,7 @@ class Users
273
286
  end
274
287
  end
275
288
 
276
- def seen(e, username=nil)
289
+ def seen(e, username)
277
290
  if user = user!(username) and user.seen then
278
291
  diff = Time.now - user.seen
279
292
 
@@ -293,21 +306,21 @@ class Users
293
306
  end
294
307
  end
295
308
 
296
- def sudo(e, search, command)
297
- if user = user!(search) then
309
+ def sudo(e, username, command)
310
+ if user = user!(username) then
298
311
  new_event = e.clone
299
312
  new_event.user = user
300
313
  new_event.message = @delegate.instances['commands'].cc + command
301
314
  @delegate.event(self, new_event)
302
315
  nil
303
316
  else
304
- "#{search}: Username or userhost not found"
317
+ "#{username}: User not found"
305
318
  end
306
319
  end
307
320
  end
308
321
 
309
322
  Plugin.define do
310
- name "users"
311
- description "users manager"
323
+ name 'users'
324
+ description 'user accounts/permissions system'
312
325
  object Users
313
326
  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.2.0"
8
+ s.version = "0.2.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-03-05}
12
+ s.date = %q{2010-03-18}
13
13
  s.default_executable = %q{zmb}
14
14
  s.description = %q{ZMB, messenger bot}
15
15
  s.email = %q{inbox@kylefuller.co.uk}
@@ -31,17 +31,21 @@ Gem::Specification.new do |s|
31
31
  "lib/zmb/plugin.rb",
32
32
  "lib/zmb/settings.rb",
33
33
  "lib/zmb/timer.rb",
34
+ "plugins/alias.rb",
34
35
  "plugins/announce.rb",
35
36
  "plugins/autorejoin.rb",
36
37
  "plugins/bank.rb",
37
38
  "plugins/commands.rb",
38
39
  "plugins/dns.rb",
40
+ "plugins/file.rb",
41
+ "plugins/gcalc.rb",
39
42
  "plugins/idle.rb",
40
43
  "plugins/irc.rb",
41
44
  "plugins/log.rb",
42
45
  "plugins/nickserv.rb",
43
46
  "plugins/poll.rb",
44
47
  "plugins/quote.rb",
48
+ "plugins/random.rb",
45
49
  "plugins/relay.rb",
46
50
  "plugins/security.rb",
47
51
  "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.2.0
4
+ version: 0.2.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-03-05 00:00:00 +00:00
12
+ date: 2010-03-18 00:00:00 +00:00
13
13
  default_executable: zmb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -54,17 +54,21 @@ files:
54
54
  - lib/zmb/plugin.rb
55
55
  - lib/zmb/settings.rb
56
56
  - lib/zmb/timer.rb
57
+ - plugins/alias.rb
57
58
  - plugins/announce.rb
58
59
  - plugins/autorejoin.rb
59
60
  - plugins/bank.rb
60
61
  - plugins/commands.rb
61
62
  - plugins/dns.rb
63
+ - plugins/file.rb
64
+ - plugins/gcalc.rb
62
65
  - plugins/idle.rb
63
66
  - plugins/irc.rb
64
67
  - plugins/log.rb
65
68
  - plugins/nickserv.rb
66
69
  - plugins/poll.rb
67
70
  - plugins/quote.rb
71
+ - plugins/random.rb
68
72
  - plugins/relay.rb
69
73
  - plugins/security.rb
70
74
  - plugins/system.rb