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