X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fcore%2Fbasics.rb;h=0473028aceff3899813b029ea60bbd2370367e30;hb=a2eeb15faadf94c879d749e211d160cb86b659c6;hp=2db2bcd84e71bd482a81685aeab54f4b6ae66e80;hpb=445b4b7f144edb862f7744eae4eeddb5f4b27038;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/basics.rb b/lib/rbot/core/basics.rb index 2db2bcd8..0473028a 100644 --- a/lib/rbot/core/basics.rb +++ b/lib/rbot/core/basics.rb @@ -4,20 +4,46 @@ # :title: rbot basic management from IRC # # Author:: Giuseppe "Oblomov" Bilotta -# Copyright:: (C) 2006,2007 Giuseppe Bilotta -# License:: GPL v2 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 + if @bot.config['irc.join_after_identify'] + log "waiting for identififcation before JOINing default channels" + else + join_channels + end + end + def ctcp_listen(m) who = m.private? ? "me" : m.target case m.ctcp.intern when :PING m.ctcp_reply m.message - @bot.irclog "@ #{m.source} pinged #{who}" when :TIME m.ctcp_reply Time.now.to_s - @bot.irclog "@ #{m.source} asked #{who} what time it is" end end @@ -43,6 +69,20 @@ class BasicsModule < CoreBotModule end end + def bot_channel_list(m, param) + ret = _('I am in: ') + # sort the channels by the base name and then map with prefixes for the + # mode and display. + ret << @bot.channels.compact.sort { |a,b| + a.name.downcase <=> b.name.downcase + }.map { |c| + c.modes_of(@bot.myself).map{ |mo| + m.server.prefix_for_mode(mo) + }.to_s + c.name + }.join(', ') + m.reply ret + end + def bot_quit(m, param) @bot.quit param[:msg].to_s end @@ -51,6 +91,10 @@ class BasicsModule < CoreBotModule @bot.restart param[:msg].to_s end + def bot_reconnect(m, param) + @bot.reconnect param[:msg].to_s + end + def bot_hide(m, param) @bot.join 0 end @@ -59,6 +103,10 @@ class BasicsModule < CoreBotModule @bot.say param[:where], param[:what].to_s end + def bot_notify(m, param) + @bot.notice param[:where], param[:what].to_s + end + def bot_action(m, param) @bot.action param[:where], param[:what].to_s end @@ -111,14 +159,14 @@ class BasicsModule < CoreBotModule _("quit [] => quit IRC with message ") when "restart" _("restart => completely stop and restart the bot (including reconnect)") + when "reconnect" + _("reconnect => ask the bot to disconnect and then connect again") when "join" _("join [] => join channel with secret key if specified. #{@bot.myself} also responds to invites if you have the required access level") when "part" _("part => part channel ") when "hide" _("hide => part all channels") - when "nick" - _("nick => attempt to change nick to ") when "say" _("say | => say to or in private message to ") when "action" @@ -136,7 +184,7 @@ class BasicsModule < CoreBotModule # when "hello" # return "hello|hi|hey|yo [#{@bot.myself}] => greet the bot" else - _("%{name}: quit, restart, join, part, hide, save, nick, say, action, topic, quiet, talk, ping, mode") % {:name=>name} + _("%{name}: quit, restart, join, part, hide, save, say, action, topic, quiet, talk, ping, mode") % {:name=>name} #, botsnack, hello end end @@ -152,6 +200,10 @@ basics.map "restart *msg", :action => 'bot_restart', :defaults => { :msg => nil }, :auth_path => 'quit' +basics.map "reconnect *msg", + :action => 'bot_reconnect', + :defaults => { :msg => nil }, + :auth_path => 'quit' basics.map "quiet [in] [:where]", :action => 'bot_quiet', @@ -163,6 +215,9 @@ basics.map "talk [in] [:where]", basics.map "say :where *what", :action => 'bot_say', :auth_path => 'talk::do' +basics.map "notify :where *what", + :action => 'bot_notify', + :auth_path => 'talk::do' basics.map "action :where *what", :action => 'bot_action', :auth_path => 'talk::do' @@ -170,7 +225,7 @@ basics.map "mode :where :what *who", :action => 'bot_mode', :auth_path => 'talk::do' -basics.map "join :chan :pass", +basics.map "join :chan :pass", :action => 'bot_join', :defaults => {:pass => nil}, :auth_path => 'move' @@ -178,6 +233,9 @@ basics.map "part :chan", :action => 'bot_part', :defaults => {:chan => nil}, :auth_path => 'move' +basics.map "channels", + :action => 'bot_channel_list', + :auth_path => 'move' basics.map "hide", :action => 'bot_hide', :auth_path => 'move'