Permalink
Browse files

More events, cleanups.

  * Changed the user argument to be nick for almost all events.
  * Added events: topic changed, bot kicked, user kicked.
  • Loading branch information...
1 parent 949f642 commit da0012f55e053669f6205f5551ff7a8159866b94 @david committed Jun 7, 2008
Showing with 44 additions and 11 deletions.
  1. +24 −9 lib/minibot/events.rb
  2. +20 −2 spec/events_spec.rb
View
@@ -6,16 +6,16 @@ def message(channel, sender, message)
def private_message(sender, message)
end
- def user_joined(channel, user)
+ def user_joined(channel, nick)
end
- def user_parted(channel, user)
+ def user_parted(channel, nick)
end
- def user_action(channel, user, message)
+ def user_action(channel, nick, message)
end
- def invited(channel, user)
+ def invited(channel, nick)
end
def default(command_str)
@@ -24,23 +24,38 @@ def default(command_str)
def pinged
end
+ def topic_changed(channel, nick, topic)
+ end
+
+ def kicked(channel, nick, message)
+ end
+
+ def user_kicked(channel, kicker, kicked, message)
+ end
+
private
def dispatch(command)
- if match = (/^:(\w+)!.+ PRIVMSG (#\w+) :\001ACTION (.+)\001/.match command)
- send :user_action, match[2], match[1], match[3]
- elsif match = (/^:(\w+)!.+ PRIVMSG (#\w+) :(.+)/.match command)
+ if match = (/^:(\w+)!.+ PRIVMSG (#\w+) :([^\001].+)/.match command)
send :message, match[2], match[1], match[3]
elsif match = (/^:(\w+)!.+ JOIN :(#\w+)/.match command)
- send :user_joined, match[3], match[1]
+ send :user_joined, match[2], match[1]
elsif match = (/^:(\w+)!.+ PART :(#\w+)/.match command)
- send :user_parted, match[3], match[1]
+ send :user_parted, match[2], match[1]
+ elsif match = (/^:(\w+)!.+ PRIVMSG (#\w+) :\001ACTION (.+)\001/.match command)
+ send :user_action, match[2], match[1], match[3]
elsif match = (/^:(\w+)!.+ PRIVMSG #{@nick} :(.+)/.match command)
send :private_message, match[1], match[2]
elsif match = (/^:(\w+)!.+ INVITE \w+ :(#\w+)/.match command)
send :invited, match[2], match[1]
elsif match = (/^PING/.match command)
send :pinged
+ elsif match = (/^:(\w+)!.+ TOPIC (#\w+) :(.+)/.match command)
+ send :topic_changed, match[2], match[1], match[3]
+ elsif match = (/^:(\w+)!.+ KICK (#\w+) #{@nick} :(.+)/.match command)
+ send :kicked, match[2], match[1], match[3]
+ elsif match = (/^:(\w+)!.+ KICK (#\w+) (\w+) :(.+)/.match command)
+ send :user_kicked, match[2], match[1], match[3], match[4]
else
send :default, command
end
View
@@ -48,14 +48,32 @@ def initialize
it "should dispatch joins" do
d = EventBot.new
- d.should_receive(:user_joined)
+ d.should_receive(:user_joined).with('#ior3k', 'ior3k')
d.send :dispatch, ":ior3k!n=ior3k@213.63.55.41 JOIN :#ior3k"
end
it "should dispatch parts" do
d = EventBot.new
- d.should_receive(:user_parted)
+ d.should_receive(:user_parted).with('#ior3k', 'ior3k')
d.send :dispatch, ":ior3k!n=ior3k@213.63.55.41 PART :#ior3k"
end
+
+ it "should dispatch topic changes" do
+ d = EventBot.new
+ d.should_receive(:topic_changed).with('#ior3k', 'ior3k', 'd00dz!')
+ d.send :dispatch, ":ior3k!n=david@89.152.220.123 TOPIC #ior3k :d00dz!"
+ end
+
+ it "should dispatch when bot is kicked" do
+ d = EventBot.new
+ d.should_receive(:kicked).with('#ior3k', 'ior3k', 'd00dz!')
+ d.send :dispatch, ":ior3k!n=david@89.152.220.123 KICK #ior3k enick :d00dz!"
+ end
+
+ it "should dispatch when user is kicked" do
+ d = EventBot.new
+ d.should_receive(:user_kicked).with('#ior3k', 'ior3k', 'victim', 'd00dz!')
+ d.send :dispatch, ":ior3k!n=david@89.152.220.123 KICK #ior3k victim :d00dz!"
+ end
end
end

0 comments on commit da0012f

Please sign in to comment.