]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
+ WelcomeMessage class
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 12 Apr 2008 21:43:37 +0000 (23:43 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 12 Apr 2008 21:43:37 +0000 (23:43 +0200)
lib/rbot/core/auth.rb
lib/rbot/ircbot.rb
lib/rbot/message.rb
lib/rbot/plugins.rb
lib/rbot/rfc2812.rb

index 32e6f7337267ea6e718c32ee6b4bf7e690c01e0d..c37c9273ecc89d71dfa8059be54e4aab8f6ce944 100644 (file)
@@ -293,8 +293,8 @@ class AuthModule < CoreBotModule
     get_botuser_for(user).username
   end
 
-  def welcome(user)
-    _("welcome, %{user}") % {:user => get_botusername_for(user)}
+  def say_welcome(m)
+    m.reply _("welcome, %{user}") % {:user => get_botusername_for(m.source)}
   end
 
   def auth_auth(m, params)
@@ -306,7 +306,7 @@ class AuthModule < CoreBotModule
     begin
       case @bot.auth.login(m.source, params[:botuser], params[:password])
       when true
-        m.reply welcome(m.source)
+        say_welcome(m)
         @bot.auth.set_changed
       else
         m.reply _("sorry, can't do")
@@ -322,7 +322,7 @@ class AuthModule < CoreBotModule
     if u.default?
       m.reply _("I couldn't find anything to let you login automatically")
     else
-      m.reply welcome(m.source)
+      say_welcome(m)
     end
   end
 
index 9afdc46cf17a581be9a70b1dfd5aaacfa744b765..29c0a116990dcbbc36b2ad60ec77309fd3d3090f 100644 (file)
@@ -528,8 +528,11 @@ class Bot
     @quiet = []
 
     @client[:welcome] = proc {|data|
+      m = WelcomeMessage.new(self, server, data[:source], data[:target], data[:message])
+
       irclog "joined server #{@client.server} as #{myself}", "server"
 
+      @plugins.delegate("welcome", m)
       @plugins.delegate("connect")
 
       @config['irc.join_channels'].each { |c|
index 918425d9ea65b41730646d22224a2da541d51cf2..d923fd8efd6aed61478426cb8a9e3a1ef1234a49 100644 (file)
@@ -215,6 +215,10 @@ module Irc
 
   end
 
+  # class for handling welcome messages from the server
+  class WelcomeMessage < BasicUserMessage
+  end
+
   # class for handling IRC user messages. Includes some utilities for handling
   # the message, for example in plugins.
   # The +message+ member will have any bot addressing "^bot: " removed
index 8c077beadd652254f0a8a37df1ac573af11e7067..d714fcf3ca1c2ce598bb2c552a48a57f87af4e5e 100644 (file)
@@ -118,6 +118,10 @@ module Plugins
                          Called when a user (or the bot) changes a channel
                          topic
 
+  welcome(WelcomeMessage)::
+                         Called when the welcome message is received on
+                         joining a server succesfully.
+
   connect::              Called when a server is joined successfully, but
                          before autojoin channels are joined (no params)
 
index b5203648fa56d14c9565056fc7cd058b8a5149fc..f3dabf30ef5bb9d8b02fd8a9e818ddb6d1ac0922 100644 (file)
@@ -1069,13 +1069,14 @@ module Irc
         num=command.to_i
         case num
         when RPL_WELCOME
+          data[:message] = argv[1]
           # "Welcome to the Internet Relay Network
           # <nick>!<user>@<host>"
           if not_us
             warning "Server thinks client (#{@user.inspect}) has a different nick"
             @user.nick = data[:target]
           end
-          if argv[1] =~ /([^@!\s]+)(?:!([^@!\s]+?))?@(\S+)/
+          if data[:message] =~ /([^@!\s]+)(?:!([^@!\s]+?))?@(\S+)/
             nick = $1
             user = $2
             host = $3