]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/core/basics.rb
basics: respond to public pings too (i.e. to /ping lib/rbot/rfc2812.rbchannel)
[user/henk/code/ruby/rbot.git] / lib / rbot / core / basics.rb
1 #-- vim:sw=2:et\r
2 #++\r
3 \r
4 \r
5 class BasicsModule < CoreBotModule\r
6 \r
7   def listen(m)\r
8     return unless m.kind_of?(PrivMessage)\r
9     if m.message =~ /^\001PING\s+(.+)\001/\r
10       ping_id = $1\r
11       if m.private?\r
12         @bot.notice m.source, "\001PING #{ping_id}\001"\r
13         @bot.irclog "@ #{m.source} pinged me"\r
14       else\r
15         @bot.notice m.source, "\001PING #{ping_id}\001"\r
16         @bot.irclog "@ #{m.source} pinged #{m.target}"\r
17       end\r
18     end\r
19   end\r
20 \r
21   def bot_join(m, param)\r
22     if param[:pass]\r
23       @bot.join param[:chan], param[:pass]\r
24     else\r
25       @bot.join param[:chan]\r
26     end\r
27   end\r
28 \r
29   def bot_part(m, param)\r
30     if param[:chan]\r
31       @bot.part param[:chan]\r
32     else\r
33       @bot.part m.target if m.public?\r
34     end\r
35   end\r
36 \r
37   def bot_quit(m, param)\r
38     @bot.quit(param[:msg] ? param[:msg].join(" ") : nil)\r
39   end\r
40 \r
41   def bot_restart(m, param)\r
42     @bot.restart(param[:msg] ? param[:msg].join(" ") : nil)\r
43   end\r
44 \r
45   def bot_hide(m, param)\r
46     @bot.join 0\r
47   end\r
48 \r
49   def bot_say(m, param)\r
50     @bot.say param[:where], param[:what].join(" ")\r
51   end\r
52 \r
53   def bot_action(m, param)\r
54     @bot.action param[:where], param[:what].join(" ")\r
55   end\r
56 \r
57   def bot_mode(m, param)\r
58     @bot.mode param[:where], param[:what], param[:who].join(" ")\r
59   end\r
60 \r
61   def bot_ping(m, param)\r
62     m.reply "pong"\r
63   end\r
64 \r
65   def bot_quiet(m, param)\r
66     if param.has_key?(:where)\r
67       @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)\r
68     else\r
69       @bot.set_quiet\r
70     end\r
71     # Make sense when the commmand is given in private or in a non-quieted\r
72     # channel\r
73     m.okay\r
74   end\r
75 \r
76   def bot_talk(m, param)\r
77     if param.has_key?(:where)\r
78       @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)\r
79     else\r
80       @bot.reset_quiet\r
81     end\r
82     # Make sense when the commmand is given in private or in a non-quieted\r
83     # channel\r
84     m.okay\r
85   end\r
86 \r
87   def bot_help(m, param)\r
88     m.reply @bot.help(param[:topic].join(" "))\r
89   end\r
90 \r
91   #TODO move these to a "chatback" plugin\r
92   # when (/^(botsnack|ciggie)$/i)\r
93   #   @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)\r
94   #   @bot.say m.replyto, @lang.get("thanks") if(m.private?)\r
95   # when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/i)\r
96   #   @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?)\r
97   #   @bot.say m.replyto, @lang.get("hello") if(m.private?)\r
98   # when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi|yo(\W|$))[\s,-.]+#{Regexp.escape(@bot.nick)}$/i)\r
99   #   @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick\r
100   # when (/^#{Regexp.escape(@bot.nick)}!*$/)\r
101   #   @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick\r
102 \r
103   # handle help requests for "core" topics\r
104   def help(cmd, topic="")\r
105     case cmd\r
106     when "quit"\r
107       return "quit [<message>] => quit IRC with message <message>"\r
108     when "restart"\r
109       return "restart => completely stop and restart the bot (including reconnect)"\r
110     when "join"\r
111       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
112     when "part"\r
113       return "part <channel> => part channel <channel>"\r
114     when "hide"\r
115       return "hide => part all channels"\r
116     when "save"\r
117       return "save => save current dynamic data and configuration"\r
118     when "rescan"\r
119       return "rescan => reload modules and static facts"\r
120     when "nick"\r
121       return "nick <nick> => attempt to change nick to <nick>"\r
122     when "say"\r
123       return "say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>"\r
124     when "action"\r
125       return "action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>"\r
126     when "quiet"\r
127       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
128     when "talk"\r
129       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
130     when "version"\r
131       return "version => describes software version"\r
132     when "ping"\r
133       return "ping => replies with a pong"\r
134     #     when "botsnack"\r
135     #       return "botsnack => reward #{myself} for being good"\r
136     #     when "hello"\r
137     #       return "hello|hi|hey|yo [#{myself}] => greet the bot"\r
138     else\r
139       return "#{name}: quit, restart, join, part, hide, save, rescan, nick, say, action, topic, quiet, talk, version, ping"#, botsnack, hello"\r
140     end\r
141   end\r
142 end\r
143 \r
144 basics = BasicsModule.new\r
145 \r
146 basics.map "quit *msg",\r
147   :action => 'bot_quit',\r
148   :defaults => { :msg => nil },\r
149   :auth_path => 'quit'\r
150 basics.map "restart *msg",\r
151   :action => 'bot_restart',\r
152   :defaults => { :msg => nil },\r
153   :auth_path => 'quit'\r
154 \r
155 basics.map "quiet [in] [:where]",\r
156   :action => 'bot_quiet',\r
157   :auth_path => 'talk::set'\r
158 basics.map "talk [in] [:where]",\r
159   :action => 'bot_talk',\r
160   :auth_path => 'talk::set'\r
161 \r
162 basics.map "say :where *what",\r
163   :action => 'bot_say',\r
164   :auth_path => 'talk::do'\r
165 basics.map "action :where *what",\r
166   :action => 'bot_action',\r
167   :auth_path => 'talk::do'\r
168 basics.map "mode :where :what *who",\r
169   :action => 'bot_mode',\r
170   :auth_path => 'talk::do'\r
171 \r
172 basics.map "join :chan :pass", \r
173   :action => 'bot_join',\r
174   :defaults => {:pass => nil},\r
175   :auth_path => 'move'\r
176 basics.map "part :chan",\r
177   :action => 'bot_part',\r
178   :defaults => {:chan => nil},\r
179   :auth_path => 'move'\r
180 basics.map "hide",\r
181   :action => 'bot_hide',\r
182   :auth_path => 'move'\r
183 \r
184 basics.map "ping",\r
185   :action => 'bot_ping',\r
186   :auth_path => '!ping!'\r
187 basics.map "help *topic",\r
188   :action => 'bot_help',\r
189   :defaults => { :topic => [""] },\r
190   :auth_path => '!help!'\r
191 \r
192 basics.default_auth('*', false)\r
193 \r