]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/core/core.rb
New modular framework is in place. Nothing works until core/auth.rb is done, though
[user/henk/code/ruby/rbot.git] / lib / rbot / core / core.rb
1 #-- vim:sw=2:et\r
2 #++\r
3 \r
4 \r
5 class Core < CoreBotModule\r
6 \r
7   # TODO cleanup\r
8   # handle incoming IRC PRIVMSG +m+\r
9   def listen(m)\r
10     return unless m.class <= PrivMessage\r
11     if(m.private? && m.message =~ /^\001PING\s+(.+)\001/)\r
12       @bot.notice m.sourcenick, "\001PING #$1\001"\r
13       @bot.irclog "@ #{m.sourcenick} pinged me"\r
14       return\r
15     end\r
16 \r
17     if(m.address?)\r
18       case m.message\r
19       when (/^join\s+(\S+)\s+(\S+)$/i)\r
20         @bot.join $1, $2 if(@bot.auth.allow?("join", m.source, m.replyto))\r
21       when (/^join\s+(\S+)$/i)\r
22         @bot.join $1 if(@bot.auth.allow?("join", m.source, m.replyto))\r
23       when (/^part$/i)\r
24         @bot.part m.target if(m.public? && @bot.auth.allow?("join", m.source, m.replyto))\r
25       when (/^part\s+(\S+)$/i)\r
26         @bot.part $1 if(@bot.auth.allow?("join", m.source, m.replyto))\r
27       when (/^quit(?:\s+(.*))?$/i)\r
28         @bot.quit $1 if(@bot.auth.allow?("quit", m.source, m.replyto))\r
29       when (/^restart(?:\s+(.*))?$/i)\r
30         @bot.restart $1 if(@bot.auth.allow?("quit", m.source, m.replyto))\r
31       when (/^hide$/i)\r
32         @bot.join 0 if(@bot.auth.allow?("join", m.source, m.replyto))\r
33       when (/^save$/i)\r
34         if(@bot.auth.allow?("config", m.source, m.replyto))\r
35           @bot.save\r
36           m.okay\r
37         end\r
38       when (/^nick\s+(\S+)$/i)\r
39         @bot.nickchg($1) if(@bot.auth.allow?("nick", m.source, m.replyto))\r
40       when (/^say\s+(\S+)\s+(.*)$/i)\r
41         @bot.say $1, $2 if(@bot.auth.allow?("say", m.source, m.replyto))\r
42       when (/^action\s+(\S+)\s+(.*)$/i)\r
43         @bot.action $1, $2 if(@bot.auth.allow?("say", m.source, m.replyto))\r
44         # when (/^topic\s+(\S+)\s+(.*)$/i)\r
45         #   topic $1, $2 if(@bot.auth.allow?("topic", m.source, m.replyto))\r
46       when (/^mode\s+(\S+)\s+(\S+)\s+(.*)$/i)\r
47         @bot.mode $1, $2, $3 if(@bot.auth.allow?("mode", m.source, m.replyto))\r
48       when (/^ping$/i)\r
49         @bot.say m.replyto, "pong"\r
50       when (/^rescan$/i)\r
51         if(@bot.auth.allow?("config", m.source, m.replyto))\r
52           m.reply "saving ..."\r
53           @bot.save\r
54           m.reply "rescanning ..."\r
55           @bot.rescan\r
56           m.reply "done. #{@plugins.status(true)}"\r
57         end\r
58       when (/^quiet$/i)\r
59         if(@bot.auth.allow?("talk", m.source, m.replyto))\r
60           m.okay\r
61           @bot.set_quiet\r
62         end\r
63       when (/^quiet in (\S+)$/i)\r
64         where = $1\r
65         if(@bot.auth.allow?("talk", m.source, m.replyto))\r
66           m.okay\r
67           where.gsub!(/^here$/, m.target) if m.public?\r
68           @bot.set_quiet(where)\r
69         end\r
70       when (/^talk$/i)\r
71         if(@bot.auth.allow?("talk", m.source, m.replyto))\r
72           @bot.reset_quiet\r
73           m.okay\r
74         end\r
75       when (/^talk in (\S+)$/i)\r
76         where = $1\r
77         if(@bot.auth.allow?("talk", m.source, m.replyto))\r
78           where.gsub!(/^here$/, m.target) if m.public?\r
79           @bot.reset_quiet(where)\r
80           m.okay\r
81         end\r
82       when (/^status\??$/i)\r
83         m.reply status if @bot.auth.allow?("status", m.source, m.replyto)\r
84       when (/^registry stats$/i)\r
85         if @bot.auth.allow?("config", m.source, m.replyto)\r
86           m.reply @registry.stat.inspect\r
87         end\r
88       when (/^(help\s+)?config(\s+|$)/)\r
89         @config.privmsg(m)\r
90       when (/^(version)|(introduce yourself)$/i)\r
91         @bot.say m.replyto, "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/"\r
92       when (/^help(?:\s+(.*))?$/i)\r
93         @bot.say m.replyto, help($1)\r
94         #TODO move these to a "chatback" plugin\r
95       when (/^(botsnack|ciggie)$/i)\r
96         @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)\r
97         @bot.say m.replyto, @lang.get("thanks") if(m.private?)\r
98       when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/i)\r
99         @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?)\r
100         @bot.say m.replyto, @lang.get("hello") if(m.private?)\r
101       end\r
102     else\r
103       # stuff to handle when not addressed\r
104       case m.message\r
105       when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi|yo(\W|$))[\s,-.]+#{Regexp.escape(@bot.nick)}$/i)\r
106         @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick\r
107       when (/^#{Regexp.escape(@bot.nick)}!*$/)\r
108         @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick\r
109       else\r
110         # @keywords.privmsg(m)\r
111       end\r
112     end\r
113   end\r
114 \r
115   # handle help requests for "core" topics\r
116   def help(topic="")\r
117     case topic\r
118     when "quit"\r
119       return "quit [<message>] => quit IRC with message <message>"\r
120     when "restart"\r
121       return "restart => completely stop and restart the bot (including reconnect)"\r
122     when "join"\r
123       return "join <channel> [<key>] => join channel <channel> with secret key <key> if specified. #{myself} also responds to invites if you have the required access level"\r
124     when "part"\r
125       return "part <channel> => part channel <channel>"\r
126     when "hide"\r
127       return "hide => part all channels"\r
128     when "save"\r
129       return "save => save current dynamic data and configuration"\r
130     when "rescan"\r
131       return "rescan => reload modules and static facts"\r
132     when "nick"\r
133       return "nick <nick> => attempt to change nick to <nick>"\r
134     when "say"\r
135       return "say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>"\r
136     when "action"\r
137       return "action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>"\r
138     when "quiet"\r
139       return "quiet [in here|<channel>] => with no arguments, stop speaking in all channels, if \"in here\", stop speaking in this channel, or stop speaking in <channel>"\r
140     when "talk"\r
141       return "talk [in here|<channel>] => with no arguments, resume speaking in all channels, if \"in here\", resume speaking in this channel, or resume speaking in <channel>"\r
142     when "version"\r
143       return "version => describes software version"\r
144     when "botsnack"\r
145       return "botsnack => reward #{myself} for being good"\r
146     when "hello"\r
147       return "hello|hi|hey|yo [#{myself}] => greet the bot"\r
148     else\r
149       return "Core help topics: quit, restart, config, join, part, hide, save, rescan, nick, say, action, topic, quiet, talk, version, botsnack, hello"\r
150     end\r
151   end\r
152 end\r
153 \r
154 core = Core.new\r
155 \r