summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-07 10:35:28 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-07 10:35:28 +0000
commit2590963515e99f6735981fd5fc0fc9ef042b22b2 (patch)
treef24a74770d9866758f8c20d6addc83312b0da528
parentbf8325c9a59667474940566065590b8da3dec85d (diff)
Fix rbot quieting
-rw-r--r--lib/rbot/core/basics.rb20
-rw-r--r--lib/rbot/ircbot.rb36
2 files changed, 28 insertions, 28 deletions
diff --git a/lib/rbot/core/basics.rb b/lib/rbot/core/basics.rb
index 4c18037e..38c96b23 100644
--- a/lib/rbot/core/basics.rb
+++ b/lib/rbot/core/basics.rb
@@ -59,18 +59,24 @@ class BasicsModule < CoreBotModule
def bot_quiet(m, param)
if param.has_key?(:where)
- @bot.set_quiet param[:where].sub(/^here$/, m.target)
+ @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
def bot_talk(m, param)
if param.has_key?(:where)
- @bot.reset_quiet param[:where].sub(/^here$/, m.target)
+ @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
def bot_help(m, param)
@@ -141,18 +147,12 @@ basics.map "restart *msg",
:defaults => { :msg => nil },
:auth_path => 'quit'
-basics.map "quiet",
+basics.map "quiet [in] [:where]",
:action => 'bot_quiet',
:auth_path => 'talk::set'
-basics.map "quiet in :chan",
- :action => 'bot_quiet',
- :auth_path => 'talk::set'
-basics.map "talk",
+basics.map "talk [in] [:where]",
:action => 'bot_talk',
:auth_path => 'talk::set'
-basics.map "quiet in :chan",
- :action => 'bot_quiet',
- :auth_path => 'talk::set'
basics.map "say :where *what",
:action => 'bot_say',
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 0fed5493..a54fd7cd 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -441,9 +441,10 @@ class IrcBot
myself.nick = @config['irc.nick']
# Channels where we are quiet
- # It's nil when we are not quiet, an empty list when we are quiet
- # in all channels, a list of channels otherwise
- @quiet = nil
+ # Array of channels names where the bot should be quiet
+ # '*' means all channels
+ #
+ @quiet = []
@client[:welcome] = proc {|data|
irclog "joined server #{@client.server} as #{myself}", "server"
@@ -632,24 +633,24 @@ class IrcBot
# checks if we should be quiet on a channel
def quiet_on?(channel)
- return false unless @quiet
- return true if @quiet.empty?
- return @quiet.include?(channel.to_s)
+ return @quiet.include?('*') || @quiet.include?(channel.downcase)
end
- def set_quiet(channel=nil)
+ def set_quiet(channel)
if channel
- @quiet << channel.to_s unless @quiet.include?(channel.to_s)
+ ch = channel.downcase.dup
+ @quiet << ch unless @quiet.include?(ch)
else
- @quiet = []
+ @quiet.clear
+ @quiet << '*'
end
end
- def reset_quiet(channel=nil)
+ def reset_quiet(channel)
if channel
- @quiet.delete_if { |x| x == channel.to_s }
+ @quiet.delete channel.downcase
else
- @quiet = nil
+ @quiet.clear
end
end
@@ -884,20 +885,19 @@ class IrcBot
# send a notice message to channel/nick +where+
def notice(where, message, options={})
- unless quiet_on?(where)
- sendmsg "NOTICE", where, message, options
- end
+ return if where.kind_of?(Channel) and quiet_on?(where)
+ sendmsg "NOTICE", where, message, options
end
# say something (PRIVMSG) to channel/nick +where+
def say(where, message, options={})
- unless quiet_on?(where)
- sendmsg "PRIVMSG", where, message, options
- end
+ return if where.kind_of?(Channel) and quiet_on?(where)
+ sendmsg "PRIVMSG", where, message, options
end
# perform a CTCP action with message +message+ to channel/nick +where+
def action(where, message, options={})
+ return if where.kind_of?(Channel) and quiet_on?(where)
mchan = options.fetch(:queue_channel, nil)
mring = options.fetch(:queue_ring, nil)
if mchan