From 9b28df160e736561547440f985c35056d044276e Mon Sep 17 00:00:00 2001 From: Alex Legler Date: Wed, 11 Nov 2009 22:37:07 +0100 Subject: ircbot: Delegate ERR_NOSUCHNICK and ERR_NOSUCHCHANNEL events to plugins --- lib/rbot/ircbot.rb | 4 ++++ lib/rbot/message.rb | 12 ++++++++++++ lib/rbot/rfc2812.rb | 14 ++++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 6f7bed7d..1e1106de 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -757,6 +757,10 @@ class Bot m.users = data[:users] @plugins.delegate "names", m } + @client[:nosuchtarget] = proc { |data| + m = NoSuchTargetMessage.new(self, server, server, data[:target], data[:message]) + @plugins.delegate "nosuchtarget", m + } @client[:error] = proc { |data| raise ServerError, data[:message] } diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb index 64c4b6bb..e0cb753c 100644 --- a/lib/rbot/message.rb +++ b/lib/rbot/message.rb @@ -661,6 +661,18 @@ module Irc class PartMessage < JoinMessage end + # class to handle ERR_NOSUCHNICK and ERR_NOSUCHCHANNEL + class NoSuchTargetMessage < BasicUserMessage + # the channel or nick that was not found + attr_reader :target + + def initialize(bot, server, source, target, message='') + super(bot, server, source, target, message) + + @target = target + end + end + class UnknownMessage < BasicUserMessage end end diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb index ee0d08d6..0b7e0786 100644 --- a/lib/rbot/rfc2812.rb +++ b/lib/rbot/rfc2812.rb @@ -1344,17 +1344,19 @@ module Irc data[:channel].url=data[:url].dup handle(:channel_url, data) when ERR_NOSUCHNICK - data[:nick] = argv[1] - if user = @server.get_user(data[:nick]) + data[:target] = argv[1] + data[:message] = argv[2] + handle(:nosuchtarget, data) + if user = @server.get_user(data[:target]) @server.delete_user(user) end - handle(:nosuchnick, data) when ERR_NOSUCHCHANNEL - data[:channel] = argv[1] - if channel = @server.get_channel(data[:channel]) + data[:target] = argv[1] + data[:message] = argv[2] + handle(:nosuchtarget, data) + if channel = @server.get_channel(data[:target]) @server.delete_channel(channel) end - handle(:nosuchchannel, data) else warning "Unknown message #{serverstring.inspect}" handle(:unknown, data) -- cgit v1.2.3