vetinari 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/examples/echo_bot.rb +3 -3
- data/lib/vetinari/bot.rb +15 -6
- data/lib/vetinari/callback.rb +9 -5
- data/lib/vetinari/callback_container.rb +3 -3
- data/lib/vetinari/channel.rb +4 -0
- data/lib/vetinari/message_parser.rb +1 -1
- data/lib/vetinari/user.rb +9 -1
- data/lib/vetinari/version.rb +1 -1
- data/spec/channel_spec.rb +10 -0
- data/spec/default_callbacks_spec.rb +23 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/user_spec.rb +10 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8caa318b353a259ce354a4f33ac6512929a70ddc
|
4
|
+
data.tar.gz: 6b0c114d8756323c6c93c7945e44b5c1392ee852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edd9ea43bb5a3636a2a4dec5246c205c40d18c310d24782e4d43cfce515fa89558c83ae2f261b823053d45456265f38aca52e0d9d7a2ade0969894ba1f3a601d
|
7
|
+
data.tar.gz: ce1804db1898b39dfc6869dac32f98b3c2b1a9846e02a8ef8881c504e7b48bcaa71101b3ddad80a3d72009be0f106bcf14e1de00336cce6f9e223f5852d3d7d8
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Vetinari
|
1
|
+
# Vetinari [![Gem Version](https://badge.fury.io/rb/vetinari.png)](http://badge.fury.io/rb/vetinari)
|
2
2
|
Vetinari is a Domain Specific Language for writing IRC Bots using the [Celluloid::IO](https://github.com/celluloid/celluloid-io "Celluloid::IO") library.
|
3
3
|
|
4
4
|
## Requirements
|
@@ -29,7 +29,7 @@ bot.on(:connect) do
|
|
29
29
|
bot.join '#vetinari'
|
30
30
|
end
|
31
31
|
|
32
|
-
bot.on(:channel, /foo/) do |env|
|
32
|
+
bot.on(:channel, :pattern => /foo/) do |env|
|
33
33
|
env[:channel].message('bar')
|
34
34
|
end
|
35
35
|
|
data/examples/echo_bot.rb
CHANGED
@@ -10,14 +10,14 @@ echo_bot = Vetinari::Bot.new do |config|
|
|
10
10
|
end
|
11
11
|
|
12
12
|
echo_bot.on :connect do
|
13
|
-
echo_bot.join
|
13
|
+
echo_bot.join('#vetinari')
|
14
14
|
end
|
15
15
|
|
16
|
-
echo_bot.on
|
16
|
+
echo_bot.on(:channel, :pattern => /\Aquit!\z/) do |env|
|
17
17
|
echo_bot.quit
|
18
18
|
end
|
19
19
|
|
20
|
-
echo_bot.on
|
20
|
+
echo_bot.on(:channel, :pattern => //) do |env|
|
21
21
|
env[:channel].message(env[:message])
|
22
22
|
end
|
23
23
|
|
data/lib/vetinari/bot.rb
CHANGED
@@ -19,8 +19,8 @@ module Vetinari
|
|
19
19
|
setup_dcc
|
20
20
|
end
|
21
21
|
|
22
|
-
def on(event,
|
23
|
-
@callbacks.add(event,
|
22
|
+
def on(event, options = {}, &block)
|
23
|
+
@callbacks.add(event, options, block)
|
24
24
|
end
|
25
25
|
|
26
26
|
exclusive :on
|
@@ -111,16 +111,16 @@ module Vetinari
|
|
111
111
|
end
|
112
112
|
|
113
113
|
# User ping request.
|
114
|
-
on :query, /^\001PING \d+\001$/ do |env|
|
114
|
+
on :query, :pattern => /^\001PING \d+\001$/ do |env|
|
115
115
|
time = env[:message].scan(/\d+/)[0]
|
116
116
|
env[:user].notice("\001PING #{time}\001")
|
117
117
|
end
|
118
118
|
|
119
|
-
on :query, /^\001VERSION\001$/ do |env|
|
119
|
+
on :query, :pattern => /^\001VERSION\001$/ do |env|
|
120
120
|
env[:user].notice("\001VERSION Vetinari #{Vetinari::VERSION} (https://github.com/tbuehlmann/vetinari)")
|
121
121
|
end
|
122
122
|
|
123
|
-
on :query, /^\001TIME\001$/ do |env|
|
123
|
+
on :query, :pattern => /^\001TIME\001$/ do |env|
|
124
124
|
env[:user].notice("\001TIME #{Time.now.strftime('%a %b %d %H:%M:%S %Y')}\001")
|
125
125
|
end
|
126
126
|
end
|
@@ -306,7 +306,7 @@ module Vetinari
|
|
306
306
|
env[:user] = @users[nick] || User.new(nick, @actor)
|
307
307
|
end
|
308
308
|
|
309
|
-
on :query, /\A\001DCC SEND \"?\S+\"? \d+ \d+ \d+\001\z/ do |env|
|
309
|
+
on :query, :pattern => /\A\001DCC SEND \"?\S+\"? \d+ \d+ \d+\001\z/ do |env|
|
310
310
|
results = env[:message].scan(/\A\001DCC SEND \"?(\S+)\"? (\d+) (\d+) (\d+)\001\z/)
|
311
311
|
filename, ip, port, filesize = results.first
|
312
312
|
filename = filename.delete("/\\")
|
@@ -337,6 +337,15 @@ module Vetinari
|
|
337
337
|
end
|
338
338
|
end
|
339
339
|
|
340
|
+
on :nick_change do |env|
|
341
|
+
# TODO: Update existing users with user/host information.
|
342
|
+
env.delete(:user)
|
343
|
+
env.delete(:host)
|
344
|
+
env[:old_nick] = env.delete(:nick)
|
345
|
+
env[:user] = @users[env[:old_nick]]
|
346
|
+
env[:user].renamed_to(env.delete(:new_nick))
|
347
|
+
end
|
348
|
+
|
340
349
|
# Response to MODE command, giving back the channel modes.
|
341
350
|
on 324 do |env|
|
342
351
|
split = env[:params].split(/ /)
|
data/lib/vetinari/callback.rb
CHANGED
@@ -5,9 +5,9 @@ module Vetinari
|
|
5
5
|
attr_reader :event
|
6
6
|
attr_writer :container
|
7
7
|
|
8
|
-
def initialize(event,
|
8
|
+
def initialize(event, options, proc, container, uuid)
|
9
9
|
@event = event
|
10
|
-
@
|
10
|
+
@options = options
|
11
11
|
@proc = proc
|
12
12
|
@container = container
|
13
13
|
@uuid = uuid
|
@@ -29,9 +29,9 @@ module Vetinari
|
|
29
29
|
|
30
30
|
def inspect
|
31
31
|
event = @event.inspect
|
32
|
-
|
32
|
+
options = @options.inspect
|
33
33
|
uuid = @uuid.inspect
|
34
|
-
"#<Callback event=#{event}
|
34
|
+
"#<Callback event=#{event} options=#{options} uuid=#{uuid}>"
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
@@ -39,7 +39,11 @@ module Vetinari
|
|
39
39
|
def matching?(env)
|
40
40
|
case @event
|
41
41
|
when :channel, :query
|
42
|
-
|
42
|
+
if @options[:pattern]
|
43
|
+
env[:message] =~ @options[:pattern] ? true : false
|
44
|
+
else
|
45
|
+
true
|
46
|
+
end
|
43
47
|
else
|
44
48
|
true
|
45
49
|
end
|
@@ -8,10 +8,10 @@ module Vetinari
|
|
8
8
|
@mutex = Mutex.new
|
9
9
|
end
|
10
10
|
|
11
|
-
def add(event,
|
11
|
+
def add(event, options, proc)
|
12
|
+
worker = Integer(options.delete(:worker) || 0)
|
12
13
|
uuid = Celluloid.uuid
|
13
|
-
args = [event,
|
14
|
-
worker = Integer(worker)
|
14
|
+
args = [event, options, proc, self, uuid]
|
15
15
|
|
16
16
|
case
|
17
17
|
when worker == 1
|
data/lib/vetinari/channel.rb
CHANGED
@@ -21,7 +21,7 @@ module Vetinari
|
|
21
21
|
when /^:(\S+)!(\S+)@(\S+) MODE ((?:#{chantypes})\S+) ([+-]\S+)/
|
22
22
|
{:type => :channel_mode, :nick => $1, :user => $2, :host => $3, :channel => $4, :modes => $5, :params => $'.lstrip}
|
23
23
|
when /^:(\S+)!(\S+)@(\S+) NICK :/
|
24
|
-
{:type => :
|
24
|
+
{:type => :nick_change, :nick => $1, :user => $2, :host => $3, :new_nick => $'}
|
25
25
|
when /^:(\S+)!(\S+)@(\S+) KICK (\S+) (\S+) :/
|
26
26
|
{:type => :kick, :nick => $1, :user => $2, :host => $3, :channel => $4, :kickee => $5, :message => $'}
|
27
27
|
when /^:(\S+)!(\S+)@(\S+) TOPIC (\S+) :/
|
data/lib/vetinari/user.rb
CHANGED
@@ -4,8 +4,8 @@ module Vetinari
|
|
4
4
|
attr_reader :nick, :user, :host, :online, :observed
|
5
5
|
|
6
6
|
def initialize(nick, bot)
|
7
|
+
# TODO
|
7
8
|
@bot = bot
|
8
|
-
|
9
9
|
@nick = nick
|
10
10
|
@user = nil
|
11
11
|
@host = nil
|
@@ -97,8 +97,16 @@ module Vetinari
|
|
97
97
|
@bot.raw "NOTICE #{@nick} :#{message}"
|
98
98
|
end
|
99
99
|
|
100
|
+
def renamed_to(nick)
|
101
|
+
@nick = nick
|
102
|
+
end
|
103
|
+
|
100
104
|
def inspect
|
101
105
|
"#<User nick=#{@nick}>"
|
102
106
|
end
|
107
|
+
|
108
|
+
def to_s
|
109
|
+
@nick
|
110
|
+
end
|
103
111
|
end
|
104
112
|
end
|
data/lib/vetinari/version.rb
CHANGED
@@ -50,4 +50,27 @@ describe Vetinari::Bot do
|
|
50
50
|
subject.parse(':TheLibrarian!foo@bar KICK #mended_drum Vetinari :foo')
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
describe 'on :nick_change' do
|
55
|
+
before(:each) do
|
56
|
+
subject.parse(':Vetinari!foo@bar JOIN #mended_drum')
|
57
|
+
subject.parse(':Ridcully!foo@bar JOIN #mended_drum')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'works' do
|
61
|
+
user = subject.users['Ridcully']
|
62
|
+
subject.parse(':Ridcully!foo@bar NICK :Twoflower')
|
63
|
+
expect(user.nick).to eq('Twoflower')
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'sets the old nick properly' do
|
67
|
+
subject.on :nick_change do |env|
|
68
|
+
expect(env[:old_nick]).to eq('Ridcully')
|
69
|
+
@called = true
|
70
|
+
end
|
71
|
+
|
72
|
+
subject.parse(':Ridcully!foo@bar NICK :Twoflower')
|
73
|
+
expect(@called).to be_true
|
74
|
+
end
|
75
|
+
end
|
53
76
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/user_spec.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vetinari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Bühlmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid-io
|
@@ -116,10 +116,12 @@ files:
|
|
116
116
|
- lib/vetinari/version.rb
|
117
117
|
- spec/callback_spec.rb
|
118
118
|
- spec/channel_management_spec.rb
|
119
|
+
- spec/channel_spec.rb
|
119
120
|
- spec/default_callbacks_spec.rb
|
120
121
|
- spec/isupport_spec.rb
|
121
122
|
- spec/spec_helper.rb
|
122
123
|
- spec/user_management_spec.rb
|
124
|
+
- spec/user_spec.rb
|
123
125
|
- vetinari.gemspec
|
124
126
|
homepage: https://github.com/tbuehlmann/vetinari
|
125
127
|
licenses:
|
@@ -148,7 +150,9 @@ summary: Multithreaded IRC Bot Framework.
|
|
148
150
|
test_files:
|
149
151
|
- spec/callback_spec.rb
|
150
152
|
- spec/channel_management_spec.rb
|
153
|
+
- spec/channel_spec.rb
|
151
154
|
- spec/default_callbacks_spec.rb
|
152
155
|
- spec/isupport_spec.rb
|
153
156
|
- spec/spec_helper.rb
|
154
157
|
- spec/user_management_spec.rb
|
158
|
+
- spec/user_spec.rb
|