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.
@@ -0,0 +1,94 @@
1
+ class Vouch
2
+ attr_accessor :settings
3
+
4
+ def defaults
5
+ { 'votes' => Hash.new, 'archive' => Hash.new, 'limit' => 2 }
6
+ end
7
+
8
+ def initialize(sender, s)
9
+ @settings = defaults.merge(s)
10
+ end
11
+
12
+ def votes
13
+ @settings['votes']
14
+ end
15
+
16
+ def archive
17
+ @settings['archive']
18
+ end
19
+
20
+ def limit
21
+ @settings['limit']
22
+ end
23
+
24
+ def commands
25
+ {
26
+ 'vouch' => [:vouch, 1, {
27
+ :permission => 'authenticated',
28
+ :help => 'Vouch for a user',
29
+ :usage => 'username',
30
+ :example => 'zynox' }],
31
+ 'vouch-limit' => [:limit_command, 1, {
32
+ :permission => 'admin',
33
+ :help => 'Change the vouch limit' }],
34
+ 'stats' => [:stats, 1, {
35
+ :help => 'View status of a vouch' }],
36
+ }
37
+ end
38
+
39
+ def vouch(e, username)
40
+ if user = e.users.user!(username, false) then
41
+ votes[username] = Array.new unless votes.has_key?(username)
42
+ votes[username] << {
43
+ 'username' => e.user.username,
44
+ 'time' => Time.now,
45
+ }
46
+
47
+ if votes[username].size >= limit then
48
+ user.activate
49
+ archive[username] = votes[username]
50
+ votes.delete(username)
51
+ "User #{username} now active"
52
+ else
53
+ "You have vouched for #{username}"
54
+ end
55
+ else
56
+ "No such user #{username}, or user already active"
57
+ end
58
+ end
59
+
60
+ def limit_command(e, l=nil)
61
+ if l == nil then
62
+ "Limit is #{limit}"
63
+ else
64
+ @settings['limit'] = Integer(l)
65
+ "Limit set to #{limit}"
66
+ end
67
+ end
68
+
69
+ def stats(e, username=nil)
70
+ if username then
71
+ user = e.users.user!(username, false)
72
+
73
+ if user then
74
+ votes[username] = Array.new unless votes.has_key?(username)
75
+ "#{username} has #{votes[username].size}/#{limit} votes"
76
+ else
77
+ "No such user or user already active"
78
+ end
79
+ else
80
+ users = e.users.users.reject{ |u| u.active? }
81
+
82
+ if users.size > 0 then
83
+ users.join(', ')
84
+ else
85
+ "no users need vouches"
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ Plugin.define do
92
+ name 'vouch'
93
+ object Vouch
94
+ end
@@ -0,0 +1,48 @@
1
+ require 'net/http'
2
+ require 'rexml/document'
3
+
4
+ class Weather
5
+ def initialize(sender, s) ;end
6
+
7
+ def commands
8
+ {
9
+ 'weather' => [:weather, 1],
10
+ }
11
+ end
12
+
13
+ def weather(e, location=nil)
14
+ if not location then
15
+ if not (e.respond_to?('user') and e.user and e.user.authenticated?) then
16
+ return 'Please supply a location'
17
+ elsif e.user.location and e.user.location != '' then
18
+ location = e.user.location
19
+ else
20
+ return "No location set for #{e.user}"
21
+ end
22
+ end
23
+
24
+ location = location.sub(' ', '+')
25
+ xml_data = 'http://www.google.com/ig/api'.get({ :weather => location }).body
26
+ doc = REXML::Document.new(xml_data)
27
+
28
+ info = doc.root.elements['weather/forecast_information']
29
+ city = info.elements['city'].attributes['data']
30
+
31
+ current = doc.root.elements['weather/current_conditions']
32
+ condition = current.elements['condition'].attributes['data']
33
+ temp = current.elements['temp_c'].attributes['data']
34
+ humidity = current.elements['humidity'].attributes['data']
35
+ wind_condition = current.elements['wind_condition'].attributes['data']
36
+
37
+ tomorrow = doc.root.elements['weather/forecast_conditions']
38
+ tomorrow_cond = tomorrow.elements['condition'].attributes['data']
39
+
40
+ "#{condition} #{temp}c #{humidity} #{wind_condition} for #{city}\n"+
41
+ "Forcast for tomorrow #{tomorrow_cond}"
42
+ end
43
+ end
44
+
45
+ Plugin.define do
46
+ name 'weather'
47
+ object Weather
48
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{zmb}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.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-18}
12
+ s.date = %q{2010-05-25}
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,11 +31,13 @@ Gem::Specification.new do |s|
31
31
  "lib/zmb/plugin.rb",
32
32
  "lib/zmb/settings.rb",
33
33
  "lib/zmb/timer.rb",
34
+ "lib/zmb/utils.rb",
34
35
  "plugins/alias.rb",
35
36
  "plugins/announce.rb",
36
37
  "plugins/autorejoin.rb",
37
38
  "plugins/bank.rb",
38
39
  "plugins/commands.rb",
40
+ "plugins/countdown.rb",
39
41
  "plugins/dns.rb",
40
42
  "plugins/file.rb",
41
43
  "plugins/gcalc.rb",
@@ -48,10 +50,13 @@ Gem::Specification.new do |s|
48
50
  "plugins/random.rb",
49
51
  "plugins/relay.rb",
50
52
  "plugins/security.rb",
53
+ "plugins/sed.rb",
51
54
  "plugins/system.rb",
52
55
  "plugins/url.rb",
53
56
  "plugins/usermodes.rb",
54
57
  "plugins/users.rb",
58
+ "plugins/vouch.rb",
59
+ "plugins/weather.rb",
55
60
  "test/helper.rb",
56
61
  "test/test_zmb.rb",
57
62
  "zmb.gemspec"
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.1
4
+ version: 0.3.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-18 00:00:00 +00:00
12
+ date: 2010-05-25 00:00:00 +01:00
13
13
  default_executable: zmb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -54,11 +54,13 @@ files:
54
54
  - lib/zmb/plugin.rb
55
55
  - lib/zmb/settings.rb
56
56
  - lib/zmb/timer.rb
57
+ - lib/zmb/utils.rb
57
58
  - plugins/alias.rb
58
59
  - plugins/announce.rb
59
60
  - plugins/autorejoin.rb
60
61
  - plugins/bank.rb
61
62
  - plugins/commands.rb
63
+ - plugins/countdown.rb
62
64
  - plugins/dns.rb
63
65
  - plugins/file.rb
64
66
  - plugins/gcalc.rb
@@ -71,10 +73,13 @@ files:
71
73
  - plugins/random.rb
72
74
  - plugins/relay.rb
73
75
  - plugins/security.rb
76
+ - plugins/sed.rb
74
77
  - plugins/system.rb
75
78
  - plugins/url.rb
76
79
  - plugins/usermodes.rb
77
80
  - plugins/users.rb
81
+ - plugins/vouch.rb
82
+ - plugins/weather.rb
78
83
  - test/helper.rb
79
84
  - test/test_zmb.rb
80
85
  - zmb.gemspec