diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2010-01-25 22:05:21 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2010-01-25 22:05:21 +0100 |
commit | f244e66650f76559232cbbdc2a336c546f87e7ab (patch) | |
tree | 22aa14764bb621423f1150879017c78da92e7833 | |
parent | 1a864cb7b90cc237e5af8f7fb8298d2efd46ee37 (diff) |
Message 'prefixed?' method
This is used to tell apart colloquial messages to the bot ("botname,
do this") from classic bot-style interface ("!do this").
-rw-r--r-- | lib/rbot/message.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb index ef2e14fe..8fc96490 100644 --- a/lib/rbot/message.rb +++ b/lib/rbot/message.rb @@ -159,7 +159,11 @@ module Irc ret << ' plainmessage=' << plainmessage.inspect ret << fields if fields ret << ' (identified)' if identified? - ret << ' (addressed to me)' if address? + if address? + ret << ' (addressed to me' + ret << ', with prefix' if prefixed? + ret << ')' + end ret << ' (replied)' if replied? ret << ' (ignored)' if ignored? ret << ' (in thread)' if in_thread? @@ -179,6 +183,7 @@ module Irc @bot = bot @source = source @address = false + @prefixed = false @target = target @message = message || "" @replied = false @@ -237,6 +242,12 @@ module Irc return @address end + # returns true if the messaged was addressed to the bot via the address + # prefix. This can be used to tell appart "!do this" from "botname, do this" + def prefixed? + return @prefixed + end + # strip mIRC colour escapes from a string def BasicUserMessage.stripcolour(string) return "" unless string @@ -342,6 +353,7 @@ module Irc bot.config['core.address_prefix'].each {|mprefix| if @message.gsub!(/^#{Regexp.escape(mprefix)}\s*/, "") @address = true + @prefixed = true break end } |