beerbot 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36f864e883bbc7374b90bc57465a35e14ebc9f7d
4
- data.tar.gz: df19b2f182e991e2db92400d0dd29764a751f237
3
+ metadata.gz: 6483fc83799ee9b532e10c4f96a1c7d1b7eb0a29
4
+ data.tar.gz: 9564a54aa28c251d87b09f72222f63284b7f5d35
5
5
  SHA512:
6
- metadata.gz: fa4f36bd206392242e866a96756e57a38a8e9178bb1928b4eaf6f45ec608b6a368cea96c19aab781f7e2b7c71c12b0a5f52502741dca3f6755df2f2941a54547
7
- data.tar.gz: 4201d0fc06a58b7cc6cdd6dbb91ef7d680600eefb52b6f74963cd3753dbbe41b3945099d45ddd77292b1b3817da894cbc3efa04bf6c669228aef4398c816f7e6
6
+ metadata.gz: d857137c3322faabef1fc1da6a9155c0acd4c185a18de60cb87d57404ba67896b48137bd72de91ea2d157224da0cbefce57aa880465ada41f5c59ce30ddb24ef
7
+ data.tar.gz: 452fca254f50a355a141dab0c4ea7d758c85debde316eb8023e257424913e52f4f85b3e7e12afe06e26756169db693961285eb40e05076ae300b351506961780
@@ -61,6 +61,32 @@ module BeerBot
61
61
  }x
62
62
  end
63
63
 
64
+ # Could use in a botmsg
65
+ #
66
+ # [to:to,msg:weighted_sample({90=>['yes','ok','fine'],10=>[...]})]
67
+
68
+ def weighted_sample thing
69
+ case thing
70
+ when Hash
71
+ keys = thing.keys
72
+ total = keys.reduce{|s,i|s+i}
73
+ i = Kernel.rand(total)
74
+ k = keys.reduce{|s,k|s+=k; if s>=i then break k; else s end}
75
+ case thing[k]
76
+ when Array
77
+ thing[k].sample
78
+ when String
79
+ thing[k]
80
+ when Hash
81
+ weight_sample(thing[k])
82
+ else
83
+ nil
84
+ end
85
+ else
86
+ nil
87
+ end
88
+ end
89
+
64
90
  end
65
91
 
66
92
  end
@@ -120,6 +120,10 @@ module BeerBot
120
120
  end
121
121
  end
122
122
 
123
+ def action action,from:nil,to:nil,me:false,world:nil
124
+ self.run(:action,action,from:from,to:to,me:me,world:world)
125
+ end
126
+
123
127
  # Handle events other than being messaged.
124
128
  #
125
129
  # IRC events like joining channels, changing nicks etc.
@@ -115,7 +115,11 @@ module BeerBot
115
115
  msg = m[:trailing].strip
116
116
  from = m[:prefix][:nick].strip
117
117
  to = m[:params][0].strip unless m[:params].empty?
118
- result = [:msg,from,to,msg]
118
+ if action = self.match_action(msg) then
119
+ result = [:action,from,to,action]
120
+ else
121
+ result = [:msg,from,to,msg]
122
+ end
119
123
 
120
124
  else # command we don't handle
121
125
  result = [:default,m]
@@ -272,6 +276,22 @@ module BeerBot
272
276
  "PRIVMSG #{to} :\u0001#{'ACTION'} #{str}\u0001"
273
277
  end
274
278
 
279
+ ACTION_REGEX = /\u0001ACTION\s+(.+)\u0001/
280
+
281
+ # Returns string matching the action (the bit after ACTION) or nil.
282
+ #
283
+ # eg
284
+ # danb does something => "does something"
285
+
286
+ def self.match_action str
287
+ m = ACTION_REGEX.match(str)
288
+ if m then
289
+ m[1].strip
290
+ else
291
+ nil
292
+ end
293
+ end
294
+
275
295
  # Join a channel
276
296
 
277
297
  def self.join chan
@@ -90,6 +90,7 @@ module BeerBot
90
90
  when :quit
91
91
  nick,msg = args
92
92
  @world.quit(nick) if @world
93
+ replies = @bot.event(event,nick:nick,msg:msg)
93
94
  when :part
94
95
  nick,channel = args
95
96
  @world.part(nick,channel) if @world
@@ -110,8 +111,12 @@ module BeerBot
110
111
  when :chanlistend
111
112
  # ignore
112
113
 
113
- when :msg
114
+ when :action
115
+ from,to,action = args
116
+ me = (@nickrx === to)
117
+ replies = @bot.action(action,from:from,to:to,me:me,world:world)
114
118
 
119
+ when :msg
115
120
  from,to,msg = args
116
121
 
117
122
  # Somebody messaging us privately:
@@ -8,15 +8,11 @@
8
8
  module BeerBot
9
9
  module Scheduler
10
10
  def self.instance timezone=nil
11
- @@instance ||= CronR::Cron.new
11
+ @instance ||= CronR::Cron.new
12
12
  if timezone then
13
- @@instance.time {
14
- Time.use_zone(timezone) {
15
- Time.zone.now
16
- }
17
- }
13
+ @instance.timezone = timezone
18
14
  end
19
- @@instance
15
+ @instance
20
16
  end
21
17
  end
22
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beerbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bush
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-26 00:00:00.000000000 Z
11
+ date: 2014-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: CronR
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.3
47
+ version: 0.1.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.3
54
+ version: 0.1.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement