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