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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6483fc83799ee9b532e10c4f96a1c7d1b7eb0a29
|
4
|
+
data.tar.gz: 9564a54aa28c251d87b09f72222f63284b7f5d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/BeerBot/01.bot/Bot.rb
CHANGED
@@ -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
|
-
|
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 :
|
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
|
-
|
11
|
+
@instance ||= CronR::Cron.new
|
12
12
|
if timezone then
|
13
|
-
|
14
|
-
Time.use_zone(timezone) {
|
15
|
-
Time.zone.now
|
16
|
-
}
|
17
|
-
}
|
13
|
+
@instance.timezone = timezone
|
18
14
|
end
|
19
|
-
|
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
|
+
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-
|
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.
|
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.
|
54
|
+
version: 0.1.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|