X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Frbot%2Fcore%2Fcore.rb;h=8217895ef6eb061acc6be3b57d3bb5639c14d245;hb=7685163bcfd21c678d7faecac62415e8235ad4fe;hp=c9210d5944c4855308b4d4e3e56ecdb2e7a70d6d;hpb=fdc64bd6634ae0aa3b9ecc4973648114f4a83ef5;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/core.rb b/lib/rbot/core/core.rb index c9210d59..8217895e 100644 --- a/lib/rbot/core/core.rb +++ b/lib/rbot/core/core.rb @@ -2,118 +2,95 @@ #++ -class Core < CoreBotModule +class BasicsModule < CoreBotModule - # TODO cleanup - # handle incoming IRC PRIVMSG +m+ def listen(m) - return unless m.class <= PrivMessage + return unless m.kind_of?(PrivMessage) if(m.private? && m.message =~ /^\001PING\s+(.+)\001/) @bot.notice m.sourcenick, "\001PING #$1\001" @bot.irclog "@ #{m.sourcenick} pinged me" return end + end + + def bot_join(m, param) + if param[:pass] + @bot.join param[:chan], param[:pass] + else + @bot.join param[:chan] + end + end + + def bot_part(m, param) + if param[:chan] + @bot.part param[:chan] + else + @bot.part m.target if m.public? + end + end + + def bot_quit(m, param) + @bot.quit(param[:msg] ? param[:msg].join(" ") : nil) + end + + def bot_restart(m, param) + @bot.restart(param[:msg] ? param[:msg].join(" ") : nil) + end + + def bot_hide(m, param) + @bot.join 0 + end + + def bot_say(m, param) + @bot.say param[:where], param[:what].join(" ") + end + + def bot_action(m, param) + @bot.action param[:where], param[:what].join(" ") + end + + def bot_mode(m, param) + @bot.mode param[:where], param[:what], param[:who].join(" ") + end + + def bot_ping(m, param) + m.reply "pong" + end + + def bot_quiet(m, param) + if param.has_key?(:where) + @bot.set_quiet param[:where].sub(/^here$/, m.target) + else + @bot.set_quiet + end + end - if(m.address?) - case m.message - when (/^join\s+(\S+)\s+(\S+)$/i) - @bot.join $1, $2 if(@bot.auth.allow?("join", m.source, m.replyto)) - when (/^join\s+(\S+)$/i) - @bot.join $1 if(@bot.auth.allow?("join", m.source, m.replyto)) - when (/^part$/i) - @bot.part m.target if(m.public? && @bot.auth.allow?("join", m.source, m.replyto)) - when (/^part\s+(\S+)$/i) - @bot.part $1 if(@bot.auth.allow?("join", m.source, m.replyto)) - when (/^quit(?:\s+(.*))?$/i) - @bot.quit $1 if(@bot.auth.allow?("quit", m.source, m.replyto)) - when (/^restart(?:\s+(.*))?$/i) - @bot.restart $1 if(@bot.auth.allow?("quit", m.source, m.replyto)) - when (/^hide$/i) - @bot.join 0 if(@bot.auth.allow?("join", m.source, m.replyto)) - when (/^save$/i) - if(@bot.auth.allow?("config", m.source, m.replyto)) - @bot.save - m.okay - end - when (/^nick\s+(\S+)$/i) - @bot.nickchg($1) if(@bot.auth.allow?("nick", m.source, m.replyto)) - when (/^say\s+(\S+)\s+(.*)$/i) - @bot.say $1, $2 if(@bot.auth.allow?("say", m.source, m.replyto)) - when (/^action\s+(\S+)\s+(.*)$/i) - @bot.action $1, $2 if(@bot.auth.allow?("say", m.source, m.replyto)) - # when (/^topic\s+(\S+)\s+(.*)$/i) - # topic $1, $2 if(@bot.auth.allow?("topic", m.source, m.replyto)) - when (/^mode\s+(\S+)\s+(\S+)\s+(.*)$/i) - @bot.mode $1, $2, $3 if(@bot.auth.allow?("mode", m.source, m.replyto)) - when (/^ping$/i) - @bot.say m.replyto, "pong" - when (/^rescan$/i) - if(@bot.auth.allow?("config", m.source, m.replyto)) - m.reply "saving ..." - @bot.save - m.reply "rescanning ..." - @bot.rescan - m.reply "done. #{@plugins.status(true)}" - end - when (/^quiet$/i) - if(@bot.auth.allow?("talk", m.source, m.replyto)) - m.okay - @bot.set_quiet - end - when (/^quiet in (\S+)$/i) - where = $1 - if(@bot.auth.allow?("talk", m.source, m.replyto)) - m.okay - where.gsub!(/^here$/, m.target) if m.public? - @bot.set_quiet(where) - end - when (/^talk$/i) - if(@bot.auth.allow?("talk", m.source, m.replyto)) - @bot.reset_quiet - m.okay - end - when (/^talk in (\S+)$/i) - where = $1 - if(@bot.auth.allow?("talk", m.source, m.replyto)) - where.gsub!(/^here$/, m.target) if m.public? - @bot.reset_quiet(where) - m.okay - end - when (/^status\??$/i) - m.reply status if @bot.auth.allow?("status", m.source, m.replyto) - when (/^registry stats$/i) - if @bot.auth.allow?("config", m.source, m.replyto) - m.reply @registry.stat.inspect - end - when (/^(help\s+)?config(\s+|$)/) - @config.privmsg(m) - when (/^(version)|(introduce yourself)$/i) - @bot.say m.replyto, "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/" - when (/^help(?:\s+(.*))?$/i) - @bot.say m.replyto, help($1) - #TODO move these to a "chatback" plugin - when (/^(botsnack|ciggie)$/i) - @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?) - @bot.say m.replyto, @lang.get("thanks") if(m.private?) - when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/i) - @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?) - @bot.say m.replyto, @lang.get("hello") if(m.private?) - end + def bot_talk(m, param) + if param.has_key?(:where) + @bot.reset_quiet param[:where].sub(/^here$/, m.target) else - # stuff to handle when not addressed - case m.message - when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi|yo(\W|$))[\s,-.]+#{Regexp.escape(@bot.nick)}$/i) - @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick - when (/^#{Regexp.escape(@bot.nick)}!*$/) - @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick - else - # @keywords.privmsg(m) - end + @bot.reset_quiet end end + def bot_help(m, param) + m.reply @bot.help(param[:topic].join(" ")) + end + + #TODO move these to a "chatback" plugin + # when (/^(botsnack|ciggie)$/i) + # @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?) + # @bot.say m.replyto, @lang.get("thanks") if(m.private?) + # when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/i) + # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?) + # @bot.say m.replyto, @lang.get("hello") if(m.private?) + # when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi|yo(\W|$))[\s,-.]+#{Regexp.escape(@bot.nick)}$/i) + # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick + # when (/^#{Regexp.escape(@bot.nick)}!*$/) + # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick + # handle help requests for "core" topics - def help(topic="") + def help(plugin, topic="") case topic when "quit" return "quit [] => quit IRC with message " @@ -141,15 +118,69 @@ class Core < CoreBotModule return "talk [in here|] => with no arguments, resume speaking in all channels, if \"in here\", resume speaking in this channel, or resume speaking in " when "version" return "version => describes software version" - when "botsnack" - return "botsnack => reward #{myself} for being good" - when "hello" - return "hello|hi|hey|yo [#{myself}] => greet the bot" + # when "botsnack" + # return "botsnack => reward #{myself} for being good" + # when "hello" + # return "hello|hi|hey|yo [#{myself}] => greet the bot" else - return "Core help topics: quit, restart, config, join, part, hide, save, rescan, nick, say, action, topic, quiet, talk, version, botsnack, hello" + return "#{name}: quit, restart, join, part, hide, save, rescan, nick, say, action, topic, quiet, talk, version"#, botsnack, hello" end end end -core = Core.new +basics = BasicsModule.new + +basics.map "quit *msg", + :action => 'bot_quit', + :defaults => { :msg => nil }, + :auth_path => 'quit' +basics.map "restart *msg", + :action => 'bot_restart', + :defaults => { :msg => nil }, + :auth_path => 'quit' + +basics.map "quiet", + :action => 'bot_quiet', + :auth_path => 'talk::set' +basics.map "quiet in :chan", + :action => 'bot_quiet', + :auth_path => 'talk::set' +basics.map "talk", + :action => 'bot_talk', + :auth_path => 'talk::set' +basics.map "quiet in :chan", + :action => 'bot_quiet', + :auth_path => 'talk::set' + +basics.map "say :where *what", + :action => 'bot_say', + :auth_path => 'talk::do' +basics.map "action :where *what", + :action => 'bot_action', + :auth_path => 'talk::do' +basics.map "mode :where :what *who", + :action => 'bot_mode', + :auth_path => 'talk::do' + +basics.map "join :chan :pass", + :action => 'bot_join', + :defaults => {:pass => nil}, + :auth_path => 'move' +basics.map "part :chan", + :action => 'bot_part', + :defaults => {:chan => nil}, + :auth_path => 'move' +basics.map "hide", + :action => 'bot_hide', + :auth_path => 'move' + +basics.map "ping", + :action => 'bot_ping', + :auth_path => '!ping!' +basics.map "help *topic", + :action => 'bot_help', + :default => { :topic => [""] }, + :auth_path => '!help!' + +basics.default_auth('*', false)