]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
basics: option to join channel after identification is confirmed
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 6 Aug 2008 19:36:41 +0000 (21:36 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 6 Aug 2008 20:06:10 +0000 (22:06 +0200)
Sometimes it is necessary to wait for identification to be confirmed
before certain channels may be joined. In this case the option
irc.join_after_identify can be set to true, and the bot will wait for
nickserv to confirm the identification before joining any channels.

This solution is actually a rather ugly hack, but I can't think of a
better way to approach the problem without rewriting the whole
framework.

lib/rbot/core/basics.rb
lib/rbot/ircbot.rb

index fd7a085f755191304c4a15cbccef83f632523f9b..3fc794bc6656d701617970a5db04fea4647f32f9 100644 (file)
@@ -7,6 +7,32 @@
 
 class BasicsModule < CoreBotModule
 
+  Config.register Config::BooleanValue.new('irc.join_after_identify',
+    :default => false, :wizard => true, :requires_restart => true,
+    :desc => "Should the bot wait until its identification is confirmed before joining any channels?")
+
+  def join_channels
+    @bot.config['irc.join_channels'].each { |c|
+      debug "autojoining channel #{c}"
+      if(c =~ /^(\S+)\s+(\S+)$/i)
+        @bot.join $1, $2
+      else
+        @bot.join c if(c)
+      end
+    }
+  end
+
+  def identified
+    join_channels
+  end
+
+  # on connect, we join the default channels unless we have to wait for
+  # identification. Observe that this means the bot may not connect any channels
+  # until the 'identified' method gets delegated
+  def connect
+    join_channels unless @bot.config['irc.join_after_identify']
+  end
+
   def ctcp_listen(m)
     who = m.private? ? "me" : m.target
     case m.ctcp.intern
index 01dbb12b4e6c1111bde3ad073a54fea7a770615a..0d934e33f0621430fc36e5ee09cedb7344bc43ec 100644 (file)
@@ -609,15 +609,6 @@ class Bot
 
       @plugins.delegate("welcome", m)
       @plugins.delegate("connect")
-
-      @config['irc.join_channels'].each { |c|
-        debug "autojoining channel #{c}"
-        if(c =~ /^(\S+)\s+(\S+)$/i)
-          join $1, $2
-        else
-          join c if(c)
-        end
-      }
     }
 
     # TODO the next two @client should go into rfc2812.rb, probably