Class: BasicsModule

Inherits:
CoreBotModule
  • Object
show all
Defined in:
lib/rbot/core/basics.rb

Overview

– vim:sw=2:et ++

:title: rbot basic management from IRC

Author

Giuseppe “Oblomov” Bilotta <[email protected]>

Instance Method Summary collapse

Instance Method Details

#bot_action(m, param) ⇒ Object



84
85
86
# File 'lib/rbot/core/basics.rb', line 84

def bot_action(m, param)
  @bot.action param[:where], param[:what].to_s
end

#bot_help(m, param) ⇒ Object



118
119
120
# File 'lib/rbot/core/basics.rb', line 118

def bot_help(m, param)
  m.reply @bot.help(param[:topic].join(" "))
end

#bot_hide(m, param) ⇒ Object



76
77
78
# File 'lib/rbot/core/basics.rb', line 76

def bot_hide(m, param)
  @bot.join 0
end

#bot_join(m, param) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/rbot/core/basics.rb', line 46

def bot_join(m, param)
  if param[:pass]
    @bot.join param[:chan], param[:pass]
  else
    @bot.join param[:chan]
  end
end

#bot_mode(m, param) ⇒ Object



88
89
90
# File 'lib/rbot/core/basics.rb', line 88

def bot_mode(m, param)
  @bot.mode param[:where], param[:what], param[:who].join(" ")
end

#bot_part(m, param) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/rbot/core/basics.rb', line 60

def bot_part(m, param)
  if param[:chan]
    @bot.part param[:chan]
  else
    @bot.part m.target if m.public?
  end
end

#bot_ping(m, param) ⇒ Object



92
93
94
# File 'lib/rbot/core/basics.rb', line 92

def bot_ping(m, param)
  m.reply "pong"
end

#bot_quiet(m, param) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/rbot/core/basics.rb', line 96

def bot_quiet(m, param)
  if param.has_key?(:where)
    @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)
  else
    @bot.set_quiet
  end
  # Make sense when the commmand is given in private or in a non-quieted
  # channel
  m.okay
end

#bot_quit(m, param) ⇒ Object



68
69
70
# File 'lib/rbot/core/basics.rb', line 68

def bot_quit(m, param)
  @bot.quit param[:msg].to_s
end

#bot_restart(m, param) ⇒ Object



72
73
74
# File 'lib/rbot/core/basics.rb', line 72

def bot_restart(m, param)
  @bot.restart param[:msg].to_s
end

#bot_say(m, param) ⇒ Object



80
81
82
# File 'lib/rbot/core/basics.rb', line 80

def bot_say(m, param)
  @bot.say param[:where], param[:what].to_s
end

#bot_talk(m, param) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/rbot/core/basics.rb', line 107

def bot_talk(m, param)
  if param.has_key?(:where)
    @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)
  else
    @bot.reset_quiet
  end
  # Make sense when the commmand is given in private or in a non-quieted
  # channel
  m.okay
end

#connectObject

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



32
33
34
# File 'lib/rbot/core/basics.rb', line 32

def connect
  join_channels unless @bot.config['irc.join_after_identify']
end

#ctcp_listen(m) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/rbot/core/basics.rb', line 36

def ctcp_listen(m)
  who = m.private? ? "me" : m.target
  case m.ctcp.intern
  when :PING
    m.ctcp_reply m.message
  when :TIME
    m.ctcp_reply Time.now.to_s
  end
end

#help(cmd, topic = "") ⇒ Object

handle help requests for “core” topics



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/rbot/core/basics.rb', line 130

def help(cmd, topic="")
  case cmd
  when "quit"
    _("quit [<message>] => quit IRC with message <message>")
  when "restart"
    _("restart => completely stop and restart the bot (including reconnect)")
  when "join"
    _("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")
  when "part"
    _("part <channel> => part channel <channel>")
  when "hide"
    _("hide => part all channels")
  when "say"
    _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
  when "action"
    _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
  when "quiet"
    _("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>")
  when "talk"
    _("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>")
  when "ping"
    _("ping => replies with a pong")
  when "mode"
    _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
  #     when "botsnack"
  #       return "botsnack => reward #{@bot.myself} for being good"
  #     when "hello"
  #       return "hello|hi|hey|yo [#{@bot.myself}] => greet the bot"
  else
    _("%{name}: quit, restart, join, part, hide, save, say, action, topic, quiet, talk, ping, mode") % {:name=>name}
    #, botsnack, hello
  end
end

#identifiedObject



25
26
27
# File 'lib/rbot/core/basics.rb', line 25

def identified
  join_channels
end

#invite(m) ⇒ Object



54
55
56
57
58
# File 'lib/rbot/core/basics.rb', line 54

def invite(m)
  if @bot.auth.allow?(:"basics::move::join", m.source, m.source)
    @bot.join m.channel
  end
end

#join_channelsObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/rbot/core/basics.rb', line 14

def join_channels
  @bot.config['irc.join_channels'].each { |c|
    debug "autojoining channel #{c}"
    if(c =~ /^(\S+)\s+(\S+)$/i)
      @bot.join $1, $2
    else
      @bot.join c if(c)
    end
  }
end