ronimopi 0.1.1 → 0.1.2
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.
- data/VERSION +1 -1
- data/bin/ronimopi.rb +1 -0
- data/examples/commands.d/lounas.rb +31 -7
- data/lib/ronimopi.rb +22 -8
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/bin/ronimopi.rb
CHANGED
@@ -15,14 +15,31 @@
|
|
15
15
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
18
|
+
|
19
|
+
@lounas_places = {}
|
20
|
+
LOUNAS_DATEFMT = '%Y%m%d'
|
21
|
+
@lounas_date = Time::now.localtime.strftime(LOUNAS_DATEFMT)
|
22
|
+
|
23
|
+
# open up Array and add count if not there
|
24
|
+
class Array
|
25
|
+
def count
|
26
|
+
return length
|
27
|
+
end
|
28
|
+
end unless Array.method_defined? "count"
|
29
|
+
|
19
30
|
def handle_lounas(channel, nick, args)
|
20
31
|
puts "Handling lunch for #{channel} where #{nick} requested #{args}"
|
32
|
+
datenow = Time::now.localtime.strftime(LOUNAS_DATEFMT)
|
33
|
+
if @lounas_date != datenow
|
34
|
+
puts "Date changed, wiping places"
|
35
|
+
@lounas_places.clear
|
36
|
+
@lounas_date = datenow
|
37
|
+
end
|
21
38
|
if args.nil?
|
22
39
|
puts "Sorting places"
|
23
|
-
str = @
|
40
|
+
str = @lounas_places.keys.sort {|a,b| @lounas_places[b].count <=> @lounas_places[a].count }.inject('') do |s,p|
|
24
41
|
s << "; " unless s.empty?
|
25
|
-
s << "#{p}: #{@
|
42
|
+
s << "#{p}: #{@lounas_places[p].join(', ')}"
|
26
43
|
end
|
27
44
|
puts "Outputting: #{str}"
|
28
45
|
msg channel, str
|
@@ -32,13 +49,20 @@ def handle_lounas(channel, nick, args)
|
|
32
49
|
puts "Place: #{place}"
|
33
50
|
if place =~ /^\^/
|
34
51
|
place = place[1..-1]
|
52
|
+
return if place.empty?
|
35
53
|
puts "Deleting #{nick} from #{place}"
|
36
|
-
@
|
37
|
-
|
54
|
+
if ! @lounas_places[place].nil?
|
55
|
+
@lounas_places[place].delete(nick)
|
56
|
+
if @lounas_places[place].empty?
|
57
|
+
@lounas_places.delete(place)
|
58
|
+
end
|
59
|
+
end
|
38
60
|
else
|
39
61
|
puts "Adding #{nick} to #{place} if not there already"
|
40
|
-
@
|
41
|
-
|
62
|
+
if @lounas_places[place].nil?
|
63
|
+
@lounas_places[place] = []
|
64
|
+
end
|
65
|
+
@lounas_places[place] << nick unless @lounas_places[place].include? nick
|
42
66
|
end
|
43
67
|
end
|
44
68
|
end
|
data/lib/ronimopi.rb
CHANGED
@@ -17,9 +17,11 @@
|
|
17
17
|
require 'isaac/bot'
|
18
18
|
CFGDIR=File::join(ENV['HOME'], '.config', 'ronimopi')
|
19
19
|
|
20
|
-
|
20
|
+
$ronimopi = Isaac::Bot.new do
|
21
|
+
|
21
22
|
@channels = []
|
22
|
-
|
23
|
+
@owner = ''
|
24
|
+
|
23
25
|
configure do |cfg|
|
24
26
|
File::open(File::join(CFGDIR, 'config.yml')) do |yf|
|
25
27
|
YAML.each_document(yf) do |ydoc|
|
@@ -27,17 +29,27 @@ bot = Isaac::Bot.new do
|
|
27
29
|
cfg.server = ydoc["server"] if ydoc.key? "server"
|
28
30
|
cfg.port = ydoc["port"] if ydoc.key? "port"
|
29
31
|
@channels += ydoc["channels"] if ydoc.key? "channels"
|
32
|
+
@owner = ydoc["owner"] if ydoc.key? "owner"
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
34
37
|
helpers do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
helperstr << line
|
38
|
+
def helpers_as_string
|
39
|
+
Dir::glob(File::join(CFGDIR, 'commands.d', '*.rb')).inject('') do |str,fn|
|
40
|
+
str << File.new(fn).read
|
39
41
|
end
|
40
42
|
end
|
43
|
+
|
44
|
+
def helper_method_names
|
45
|
+
methods.select {|name| name =~ /^handle_/}
|
46
|
+
end
|
47
|
+
|
48
|
+
def help_text
|
49
|
+
"Commands: " + helper_method_names.map {|name| name[7..-1]}.join(', ')
|
50
|
+
end
|
51
|
+
|
52
|
+
helperstr = helpers_as_string
|
41
53
|
eval helperstr
|
42
54
|
end
|
43
55
|
|
@@ -48,6 +60,10 @@ bot = Isaac::Bot.new do
|
|
48
60
|
end
|
49
61
|
end
|
50
62
|
|
63
|
+
on :channel, /^[!]help/ do
|
64
|
+
msg nick, help_text
|
65
|
+
end
|
66
|
+
|
51
67
|
on :channel, /^[!](.+)/ do |cmdstr|
|
52
68
|
parts = cmdstr.split(/\s+/, 2)
|
53
69
|
cmd = "handle_#{parts[0]}".to_sym
|
@@ -63,5 +79,3 @@ bot = Isaac::Bot.new do
|
|
63
79
|
# catchall, do nothing
|
64
80
|
end
|
65
81
|
end
|
66
|
-
|
67
|
-
bot.start
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ronimopi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilkka Laukkanen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-12 00:00:00 +02:00
|
13
13
|
default_executable: ronimopi.rb
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|