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