Class BasicsModule
In: lib/rbot/core/basics.rb
Parent: CoreBotModule
BasicsModule CoreBotModule dot/f_16.png
Author:Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>

Methods

Public Instance methods

[Source]

     # File lib/rbot/core/basics.rb, line 106
106:   def bot_action(m, param)
107:     @bot.action param[:where], param[:what].to_s
108:   end

[Source]

    # File lib/rbot/core/basics.rb, line 72
72:   def bot_channel_list(m, param)
73:     ret = _('I am in: ')
74:     # sort the channels by the base name and then map with prefixes for the
75:     # mode and display.
76:     ret << @bot.channels.compact.sort { |a,b|
77:         a.name.downcase <=> b.name.downcase
78:     }.map { |c|
79:         c.modes_of(@bot.myself).map{ |mo|
80:           m.server.prefix_for_mode(mo)
81:         }.to_s + c.name
82:     }.join(', ')
83:     m.reply ret
84:   end

[Source]

     # File lib/rbot/core/basics.rb, line 140
140:   def bot_help(m, param)
141:     m.reply @bot.help(param[:topic].join(" "))
142:   end

[Source]

     # File lib/rbot/core/basics.rb, line 98
 98:   def bot_hide(m, param)
 99:     @bot.join 0
100:   end

[Source]

    # File lib/rbot/core/basics.rb, line 50
50:   def bot_join(m, param)
51:     if param[:pass]
52:       @bot.join param[:chan], param[:pass]
53:     else
54:       @bot.join param[:chan]
55:     end
56:   end

[Source]

     # File lib/rbot/core/basics.rb, line 110
110:   def bot_mode(m, param)
111:     @bot.mode param[:where], param[:what], param[:who].join(" ")
112:   end

[Source]

    # File lib/rbot/core/basics.rb, line 64
64:   def bot_part(m, param)
65:     if param[:chan]
66:       @bot.part param[:chan]
67:     else
68:       @bot.part m.target if m.public?
69:     end
70:   end

[Source]

     # File lib/rbot/core/basics.rb, line 114
114:   def bot_ping(m, param)
115:     m.reply "pong"
116:   end

[Source]

     # File lib/rbot/core/basics.rb, line 118
118:   def bot_quiet(m, param)
119:     if param.has_key?(:where)
120:       @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)
121:     else
122:       @bot.set_quiet
123:     end
124:     # Make sense when the commmand is given in private or in a non-quieted
125:     # channel
126:     m.okay
127:   end

[Source]

    # File lib/rbot/core/basics.rb, line 86
86:   def bot_quit(m, param)
87:     @bot.quit param[:msg].to_s
88:   end

[Source]

    # File lib/rbot/core/basics.rb, line 94
94:   def bot_reconnect(m, param)
95:     @bot.reconnect param[:msg].to_s
96:   end

[Source]

    # File lib/rbot/core/basics.rb, line 90
90:   def bot_restart(m, param)
91:     @bot.restart param[:msg].to_s
92:   end

[Source]

     # File lib/rbot/core/basics.rb, line 102
102:   def bot_say(m, param)
103:     @bot.say param[:where], param[:what].to_s
104:   end

[Source]

     # File lib/rbot/core/basics.rb, line 129
129:   def bot_talk(m, param)
130:     if param.has_key?(:where)
131:       @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)
132:     else
133:       @bot.reset_quiet
134:     end
135:     # Make sense when the commmand is given in private or in a non-quieted
136:     # channel
137:     m.okay
138:   end

on connect, we join the default channels unless we have to wait for identification. Observe that this means the bot may not connect any channels until the ‘identified’ method gets delegated

[Source]

    # File lib/rbot/core/basics.rb, line 32
32:   def connect
33:     if @bot.config['irc.join_after_identify']
34:       log "waiting for identififcation before JOINing default channels"
35:     else
36:       join_channels
37:     end
38:   end

[Source]

    # File lib/rbot/core/basics.rb, line 40
40:   def ctcp_listen(m)
41:     who = m.private? ? "me" : m.target
42:     case m.ctcp.intern
43:     when :PING
44:       m.ctcp_reply m.message
45:     when :TIME
46:       m.ctcp_reply Time.now.to_s
47:     end
48:   end

handle help requests for "core" topics

[Source]

     # File lib/rbot/core/basics.rb, line 152
152:   def help(cmd, topic="")
153:     case cmd
154:     when "quit"
155:       _("quit [<message>] => quit IRC with message <message>")
156:     when "restart"
157:       _("restart => completely stop and restart the bot (including reconnect)")
158:     when "reconnect"
159:       _("reconnect => ask the bot to disconnect and then connect again")
160:     when "join"
161:       _("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")
162:     when "part"
163:       _("part <channel> => part channel <channel>")
164:     when "hide"
165:       _("hide => part all channels")
166:     when "say"
167:       _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
168:     when "action"
169:       _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
170:     when "quiet"
171:       _("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>")
172:     when "talk"
173:       _("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>")
174:     when "ping"
175:       _("ping => replies with a pong")
176:     when "mode"
177:       _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
178:     #     when "botsnack"
179:     #       return "botsnack => reward #{@bot.myself} for being good"
180:     #     when "hello"
181:     #       return "hello|hi|hey|yo [#{@bot.myself}] => greet the bot"
182:     else
183:       _("%{name}: quit, restart, join, part, hide, save, say, action, topic, quiet, talk, ping, mode") % {:name=>name}
184:       #, botsnack, hello
185:     end
186:   end

[Source]

    # File lib/rbot/core/basics.rb, line 25
25:   def identified
26:     join_channels
27:   end

[Source]

    # File lib/rbot/core/basics.rb, line 58
58:   def invite(m)
59:     if @bot.auth.allow?("basics::move::join""basics::move::join", m.source, m.source)
60:       @bot.join m.channel
61:     end
62:   end

[Source]

    # File lib/rbot/core/basics.rb, line 14
14:   def join_channels
15:     @bot.config['irc.join_channels'].each { |c|
16:       debug "autojoining channel #{c}"
17:       if(c =~ /^(\S+)\s+(\S+)$/i)
18:         @bot.join $1, $2
19:       else
20:         @bot.join c if(c)
21:       end
22:     }
23:   end

[Validate]