|
# File rbot/ircbot.rb, line 492
def onprivmsg(m)
# log it first
if(m.action?)
if(m.private?)
log "* [#{m.sourcenick}(#{m.sourceaddress})] #$1", m.sourcenick
else
log "* #{m.sourcenick} #$1", m.target
end
else
if(m.public?)
log "<#{m.sourcenick}> #{m.message}", m.target
else
log "[#{m.sourcenick}(#{m.sourceaddress})] #{m.message}", m.sourcenick
end
end
# pass it off to plugins that want to hear everything
@plugins.delegate "listen", m
if(m.private? && m.message =~ /^\001PING\s+(.+)\001/)
notice m.sourcenick, "\001PING #$1\001"
log "@ #{m.sourcenick} pinged me"
return
end
if(m.address?)
case m.message
when (/^join\s+(\S+)\s+(\S+)$/)
join $1, $2 if(@auth.allow?("join", m.source, m.replyto))
when (/^join\s+(\S+)$/)
join $1 if(@auth.allow?("join", m.source, m.replyto))
when (/^part$/)
part m.target if(m.public? && @auth.allow?("join", m.source, m.replyto))
when (/^part\s+(\S+)$/)
part $1 if(@auth.allow?("join", m.source, m.replyto))
when (/^quit(?:\s+(.*))?$/)
quit $1 if(@auth.allow?("quit", m.source, m.replyto))
when (/^hide$/)
join 0 if(@auth.allow?("join", m.source, m.replyto))
when (/^save$/)
if(@auth.allow?("config", m.source, m.replyto))
okay m.replyto
save
end
when (/^nick\s+(\S+)$/)
nickchg($1) if(@auth.allow?("nick", m.source, m.replyto))
when (/^say\s+(\S+)\s+(.*)$/)
say $1, $2 if(@auth.allow?("say", m.source, m.replyto))
when (/^action\s+(\S+)\s+(.*)$/)
action $1, $2 if(@auth.allow?("say", m.source, m.replyto))
when (/^topic\s+(\S+)\s+(.*)$/)
topic $1, $2 if(@auth.allow?("topic", m.source, m.replyto))
when (/^ping$/)
say m.replyto, "pong"
when (/^rescan$/)
if(@auth.allow?("config", m.source, m.replyto))
okay m.replyto
rescan
end
when (/^quiet$/)
if(auth.allow?("talk", m.source, m.replyto))
say m.replyto, @lang.get("okay")
@channels.each_value {|c| c.quiet = true }
end
when (/^quiet in (\S+)$/)
where = $1
if(auth.allow?("talk", m.source, m.replyto))
say m.replyto, @lang.get("okay")
where.gsub!(/^here$/, m.target) if m.public?
@channels[where].quiet = true if(@channels.has_key?(where))
end
when (/^talk$/)
if(auth.allow?("talk", m.source, m.replyto))
@channels.each_value {|c| c.quiet = false }
okay m.replyto
end
when (/^talk in (\S+)$/)
where = $1
if(auth.allow?("talk", m.source, m.replyto))
where.gsub!(/^here$/, m.target) if m.public?
@channels[where].quiet = false if(@channels.has_key?(where))
okay m.replyto
end
# TODO break this out into an options module
when (/^options get sendq_delay$/)
if auth.allow?("config", m.source, m.replyto)
m.reply "options->sendq_delay = #{@socket.get_sendq}"
end
when (/^options get sendq_burst$/)
if auth.allow?("config", m.source, m.replyto)
m.reply "options->sendq_burst = #{@socket.get_maxburst}"
end
when (/^options set sendq_burst (.*)$/)
num = $1.to_i
if auth.allow?("config", m.source, m.replyto)
@socket.set_maxburst(num)
@config["SENDQ_BURST"] = num
okay m.replyto
end
when (/^options set sendq_delay (.*)$/)
freq = $1.to_f
if auth.allow?("config", m.source, m.replyto)
@socket.set_sendq(freq)
@config["SENDQ_DELAY"] = freq
okay m.replyto
end
when (/^status$/)
m.reply status if auth.allow?("status", m.source, m.replyto)
when (/^registry stats$/)
if auth.allow?("config", m.source, m.replyto)
m.reply @registry.stat.inspect
end
when (/^(version)|(introduce yourself)$/)
say m.replyto, "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/"
when (/^help(?:\s+(.*))?$/)
say m.replyto, help $1
when (/^(botsnack|ciggie)$/)
say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
say m.replyto, @lang.get("thanks") if(m.private?)
when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/)
say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?)
say m.replyto, @lang.get("hello") if(m.private?)
else
delegate_privmsg(m)
end
else
# stuff to handle when not addressed
case m.message
when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$))\s+#{@nick}$/)
say m.replyto, @lang.get("hello_X") % m.sourcenick
when (/^#{@nick}!*$/)
say m.replyto, @lang.get("hello_X") % m.sourcenick
else
@keywords.privmsg(m)
end
end
end
|