ponder 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +3 -7
- data/examples/redis_last_seen.rb +140 -0
- data/lib/ponder/thaum.rb +5 -14
- data/lib/ponder/version.rb +1 -1
- data/ponder.gemspec +2 -2
- data/test/test_callback.rb +0 -1
- metadata +4 -8
- data/test/all_tests.rb +0 -7
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010 Tobias Bühlmann
|
1
|
+
Copyright (c) 2010, 2011 Tobias Bühlmann
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
4
|
|
data/README.md
CHANGED
@@ -72,7 +72,7 @@ Besides the configuration for nick, server and port as shown in the **Getting St
|
|
72
72
|
|
73
73
|
You can access the logger instances via `@ponder.traffic_logger` or `@ponder.error_logger`, so you could do: `@ponder.traffic_logger.info('I did this and that right now')`.
|
74
74
|
|
75
|
-
It defaults to `false`. (
|
75
|
+
It defaults to `false`. (TODO: write about "other" logger methods)
|
76
76
|
|
77
77
|
* `reconnect`
|
78
78
|
|
@@ -82,10 +82,6 @@ Besides the configuration for nick, server and port as shown in the **Getting St
|
|
82
82
|
|
83
83
|
If `reconnect` is set to `true`, `reconnect_interval` describes the time in seconds, which the Thaum will wait before trying to reconnect. It defaults to `30`.
|
84
84
|
|
85
|
-
* `auto_rename`
|
86
|
-
|
87
|
-
If `auto_rename` is set to `true`, the Thaum will try to rename if the chosen `nick` is already in use. It will try to take a random nick from "nick000" to "nick999".
|
88
|
-
|
89
85
|
For further information, have a look at the examples.
|
90
86
|
|
91
87
|
## Advanced Event Handling
|
@@ -323,13 +319,13 @@ If you don't always want to use `Ponder::Formatting`, use `include Ponder::Forma
|
|
323
319
|
## Source
|
324
320
|
The source can be found at GitHub: [tbuehlmann/ponder](http://github.com/tbuehlmann/ponder "Ponder").
|
325
321
|
|
326
|
-
You can contact me through GitHub and IRC (
|
322
|
+
You can contact me through [GitHub](http://github.com/tbuehlmann/ "GitHub") and IRC (named tbuehlmann in the Freenode network).
|
327
323
|
|
328
324
|
## Discworld Context
|
329
325
|
So, why all that silly names? Ponder Stibbons? Thaum? Twoflogger (referring to Twoflower), BlindIO? What's the Mended Drum? Who's the Librarian? Simply put, I freaking enshrine Terry Pratchett's Discworld Novels and there were no better name for this project than Ponder. Ponder Stibbons is the Head of Inadvisably Applied Magic at the Unseen University of Ankh Morpork. He researched the Thaum, like the atom, just for magic. And I just love that character, so there we are. If you're a fan too or want to talk about the Discworld, the framework, whatever, don't hesitate to contact me.
|
330
326
|
|
331
327
|
## License
|
332
|
-
Copyright (c) 2010 Tobias Bühlmann
|
328
|
+
Copyright (c) 2010, 2011 Tobias Bühlmann
|
333
329
|
|
334
330
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
335
331
|
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# This Thaum remembers users' actions and is able to quote them.
|
2
|
+
# Go for it with `!seen <nick>`. You can even use wildcards with "*".
|
3
|
+
#
|
4
|
+
# The redis server version needs to be >= 1.3.10 for hash support.
|
5
|
+
|
6
|
+
require 'pathname'
|
7
|
+
$LOAD_PATH.unshift Pathname.new(__FILE__).dirname.expand_path.join('..', 'lib')
|
8
|
+
require 'ponder'
|
9
|
+
require 'rubygems'
|
10
|
+
require 'redis'
|
11
|
+
|
12
|
+
FORMAT = '%Y-%m-%d %H:%M:%S'
|
13
|
+
|
14
|
+
class String
|
15
|
+
def escape_redis
|
16
|
+
self.gsub(/([\|\[\]\?])/, '\\\\\1')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
@last_seen = Redis.new(:thread_safe => true)
|
21
|
+
|
22
|
+
def remember(lowercase_nick, nick, user, host, channel, action,
|
23
|
+
action_content)
|
24
|
+
@last_seen.hmset(lowercase_nick,
|
25
|
+
'nick', nick,
|
26
|
+
'user', user,
|
27
|
+
'host', host,
|
28
|
+
'channel', channel,
|
29
|
+
'action', action,
|
30
|
+
'action_content', action_content,
|
31
|
+
'updated_at', Time.now.to_i)
|
32
|
+
end
|
33
|
+
|
34
|
+
@ponder = Ponder::Thaum.new
|
35
|
+
|
36
|
+
@ponder.configure do |c|
|
37
|
+
c.server = 'chat.freenode.org'
|
38
|
+
c.port = 6667
|
39
|
+
c.nick = 'Ponder'
|
40
|
+
c.verbose = true
|
41
|
+
c.logging = false
|
42
|
+
end
|
43
|
+
|
44
|
+
@ponder.on :connect do
|
45
|
+
@ponder.join '#ponder'
|
46
|
+
end
|
47
|
+
|
48
|
+
@ponder.on :channel do |event_data|
|
49
|
+
remember(event_data[:nick].downcase, event_data[:nick], event_data[:user],
|
50
|
+
event_data[:host], event_data[:channel], event_data[:type],
|
51
|
+
event_data[:message])
|
52
|
+
end
|
53
|
+
|
54
|
+
@ponder.on [:join, :part, :quit] do |event_data|
|
55
|
+
remember(event_data[:nick].downcase, event_data[:nick], event_data[:user],
|
56
|
+
event_data[:host], event_data[:channel], event_data[:type],
|
57
|
+
(event_data[:message] || event_data[:channel]))
|
58
|
+
end
|
59
|
+
|
60
|
+
@ponder.on :nickchange do |event_data|
|
61
|
+
remember(event_data[:nick].downcase, event_data[:nick], event_data[:user],
|
62
|
+
event_data[:host], '', 'nickchange_old', event_data[:new_nick])
|
63
|
+
|
64
|
+
remember(event_data[:new_nick].downcase, event_data[:new_nick],
|
65
|
+
event_data[:user], event_data[:host], '', 'nickchange_new',
|
66
|
+
event_data[:nick])
|
67
|
+
end
|
68
|
+
|
69
|
+
@ponder.on :kick do |event_data|
|
70
|
+
remember(event_data[:nick].downcase, event_data[:nick], event_data[:user],
|
71
|
+
event_data[:host], event_data[:channel], 'kicker',
|
72
|
+
"#{event_data[:victim]} #{event_data[:reason]}")
|
73
|
+
|
74
|
+
remember(event_data[:victim].downcase, event_data[:victim],
|
75
|
+
'', '', event_data[:channel], 'victim',
|
76
|
+
"#{event_data[:nick]} #{event_data[:reason]}")
|
77
|
+
end
|
78
|
+
|
79
|
+
def last_seen(nick, event_data)
|
80
|
+
data = @last_seen.hgetall nick
|
81
|
+
|
82
|
+
case data['action']
|
83
|
+
when 'channel'
|
84
|
+
"#{data['nick']} wrote something in #{data['channel']} at #{Time.at(data['updated_at'].to_i).strftime(FORMAT)}."
|
85
|
+
when 'join'
|
86
|
+
"#{data['nick']} joined #{data['channel']} at #{Time.at(data['updated_at'].to_i).strftime(FORMAT)}."
|
87
|
+
when 'part'
|
88
|
+
"#{data['nick']} left #{data['channel']} at #{Time.at(data['updated_at'].to_i).strftime(FORMAT)} (#{data['action_content']})."
|
89
|
+
when 'quit'
|
90
|
+
"#{data['nick']} quit at #{Time.at(data['updated_at'].to_i).strftime(FORMAT)} (#{data['action_content']})."
|
91
|
+
when 'nickchange_old'
|
92
|
+
"#{data['nick']} renamed to #{data['action_content']}} at #{Time.at(data['updated_at'].to_i).strftime(FORMAT)}."
|
93
|
+
when 'nickchange_new'
|
94
|
+
"#{data['nick']} renamed to #{data['action_content']} at #{Time.at(data['updated_at'].to_i).strftime(FORMAT)}."
|
95
|
+
when 'kicker'
|
96
|
+
"#{data['nick']} kicked #{data['action_content'].split(' ')[0]} at #{Time.at(data['updated_at'].to_i).strftime(FORMAT)} from #{data['channel']} (#{data['action_content'].split(' ')[1]})."
|
97
|
+
when 'victim'
|
98
|
+
"#{data['nick']} was kicked by #{data['action_content'].split(' ')[0]} at #{Time.at(data['updated_at'].to_i).strftime(FORMAT)} from #{data['channel']} (#{data['action_content'].split(' ')[1]})."
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
@ponder.on :channel, /^!seen \S+$/ do |event_data|
|
103
|
+
nick = event_data[:message].split(' ')[1].downcase
|
104
|
+
|
105
|
+
# wildcards
|
106
|
+
if nick =~ /\*/
|
107
|
+
users = @last_seen.keys nick.escape_redis
|
108
|
+
results = users.length
|
109
|
+
|
110
|
+
case results
|
111
|
+
when 0
|
112
|
+
@ponder.message event_data[:channel], 'No such nick found.'
|
113
|
+
when 1
|
114
|
+
@ponder.message last_seen(users[0])
|
115
|
+
when 2..5
|
116
|
+
nicks = []
|
117
|
+
users.each do |user|
|
118
|
+
nicks << @last_seen.hgetall(user)['nick']
|
119
|
+
end
|
120
|
+
nicks = nicks.join(', ')
|
121
|
+
@ponder.message event_data[:channel], "#{results} nicks found (#{nicks})."
|
122
|
+
else
|
123
|
+
@ponder.message event_data[:channel], "Too many results (#{results})."
|
124
|
+
end
|
125
|
+
# single search
|
126
|
+
elsif @last_seen.exists nick
|
127
|
+
msg = last_seen(nick, event_data)
|
128
|
+
if online_nick = @ponder.whois(nick)
|
129
|
+
msg = "#{online_nick[:nick]} is online. (#{msg})"
|
130
|
+
end
|
131
|
+
@ponder.message event_data[:channel], msg
|
132
|
+
elsif online_nick = @ponder.whois(nick)
|
133
|
+
@ponder.message event_data[:channel], "#{online_nick[:nick]} is online."
|
134
|
+
else
|
135
|
+
@ponder.message event_data[:channel], "#{nick} not found."
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
@ponder.connect
|
140
|
+
|
data/lib/ponder/thaum.rb
CHANGED
@@ -27,8 +27,7 @@ module Ponder
|
|
27
27
|
:verbose => true,
|
28
28
|
:logging => false,
|
29
29
|
:reconnect => true,
|
30
|
-
:reconnect_interval => 30
|
31
|
-
:auto_rename => true
|
30
|
+
:reconnect_interval => 30
|
32
31
|
)
|
33
32
|
|
34
33
|
@empty_logger = Logger::BlindIo.new
|
@@ -58,10 +57,6 @@ module Ponder
|
|
58
57
|
notice env[:nick], "\001TIME #{Time.now.strftime('%a %b %d %H:%M:%S %Y')}\001"
|
59
58
|
end
|
60
59
|
|
61
|
-
on 433 do
|
62
|
-
rename "#{@config.nick}#{rand(10)}#{rand(10)}#{rand(10)}"
|
63
|
-
end
|
64
|
-
|
65
60
|
# before and after filter
|
66
61
|
@before_filters = Hash.new { |hash, key| hash[key] = [] }
|
67
62
|
@after_filters = Hash.new { |hash, key| hash[key] = [] }
|
@@ -80,11 +75,6 @@ module Ponder
|
|
80
75
|
unless @config.verbose
|
81
76
|
@console_logger = @empty_logger
|
82
77
|
end
|
83
|
-
|
84
|
-
# remove auto_rename callback (if differing from initialize)
|
85
|
-
unless @config.auto_rename
|
86
|
-
@callbacks.delete(433)
|
87
|
-
end
|
88
78
|
end
|
89
79
|
end
|
90
80
|
|
@@ -229,14 +219,15 @@ module Ponder
|
|
229
219
|
process_callbacks(event_type, event_data)
|
230
220
|
end
|
231
221
|
|
232
|
-
def filter(filter_type, event_types = :all, match = //, block)
|
222
|
+
def filter(filter_type, event_types = :all, match = //, &block)
|
233
223
|
if event_types.is_a?(Array)
|
234
224
|
event_types.each do |event_type|
|
235
225
|
filter_type[event_type] << Filter.new(event_type, match, block)
|
236
226
|
end
|
237
|
-
|
227
|
+
else
|
238
228
|
filter_type[event_types] << Filter.new(event_types, match, block)
|
239
229
|
end
|
240
230
|
end
|
241
231
|
end
|
242
|
-
end
|
232
|
+
end
|
233
|
+
|
data/lib/ponder/version.rb
CHANGED
data/ponder.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'ponder'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.2'
|
4
4
|
s.summary = 'IRC bot framework'
|
5
5
|
s.description = 'Ponder (Stibbons) is a Domain Specific Language for writing IRC Bots using the EventMachine library.'
|
6
6
|
|
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.add_dependency('eventmachine', '>= 0.12.10')
|
13
13
|
s.files = ['examples/echo.rb',
|
14
14
|
'examples/github_blog.rb',
|
15
|
+
'examples/redis_last_seen.rb',
|
15
16
|
'lib/ponder/async_irc.rb',
|
16
17
|
'lib/ponder/callback.rb',
|
17
18
|
'lib/ponder/connection.rb',
|
@@ -27,7 +28,6 @@ Gem::Specification.new do |s|
|
|
27
28
|
'lib/ponder/logger/twoflogger18.rb',
|
28
29
|
'lib/ruby/1.8/string.rb',
|
29
30
|
'lib/ponder.rb',
|
30
|
-
'test/all_tests.rb',
|
31
31
|
'test/test_async_irc.rb',
|
32
32
|
'test/test_callback.rb',
|
33
33
|
'test/test_helper.rb',
|
data/test/test_callback.rb
CHANGED
@@ -17,7 +17,6 @@ class TestCallback < Test::Unit::TestCase
|
|
17
17
|
def test_perfect_case
|
18
18
|
callback = Ponder::Callback.new(:channel, /foo/, @empty_proc)
|
19
19
|
|
20
|
-
assert_equal(:channel, callback.event_type)
|
21
20
|
assert_equal(/foo/, callback.match)
|
22
21
|
assert_equal(@empty_proc, callback.proc)
|
23
22
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ponder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 29
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- "Tobias B\xC3\xBChlmann"
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-01-04 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 59
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
- 12
|
@@ -45,6 +43,7 @@ extra_rdoc_files: []
|
|
45
43
|
files:
|
46
44
|
- examples/echo.rb
|
47
45
|
- examples/github_blog.rb
|
46
|
+
- examples/redis_last_seen.rb
|
48
47
|
- lib/ponder/async_irc.rb
|
49
48
|
- lib/ponder/callback.rb
|
50
49
|
- lib/ponder/connection.rb
|
@@ -59,7 +58,6 @@ files:
|
|
59
58
|
- lib/ponder/logger/twoflogger18.rb
|
60
59
|
- lib/ruby/1.8/string.rb
|
61
60
|
- lib/ponder.rb
|
62
|
-
- test/all_tests.rb
|
63
61
|
- test/test_async_irc.rb
|
64
62
|
- test/test_callback.rb
|
65
63
|
- test/test_helper.rb
|
@@ -81,7 +79,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
79
|
requirements:
|
82
80
|
- - ">="
|
83
81
|
- !ruby/object:Gem::Version
|
84
|
-
hash: 59
|
85
82
|
segments:
|
86
83
|
- 1
|
87
84
|
- 8
|
@@ -92,7 +89,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
89
|
requirements:
|
93
90
|
- - ">="
|
94
91
|
- !ruby/object:Gem::Version
|
95
|
-
hash: 3
|
96
92
|
segments:
|
97
93
|
- 0
|
98
94
|
version: "0"
|