2012-03-22 19:34:48 +01:00
|
|
|
from util import hook
|
|
|
|
|
|
|
|
muted = []
|
|
|
|
|
|
|
|
|
|
|
|
def mute_target(target):
|
2012-03-22 22:57:02 +01:00
|
|
|
""" mutes someone """
|
2012-03-22 22:53:35 +01:00
|
|
|
target = target.lower()
|
2012-03-22 19:34:48 +01:00
|
|
|
muted.append(target)
|
|
|
|
|
|
|
|
|
|
|
|
def unmute_target(target):
|
2012-03-22 22:57:02 +01:00
|
|
|
""" unmutes someone """
|
2012-03-22 22:53:35 +01:00
|
|
|
target = target.lower()
|
2012-03-22 19:34:48 +01:00
|
|
|
muted.remove(target)
|
|
|
|
|
|
|
|
|
|
|
|
def is_muted(target):
|
2012-03-22 22:57:02 +01:00
|
|
|
""" checks of someone is muted """
|
2012-03-22 22:53:35 +01:00
|
|
|
target = target.lower()
|
2012-03-22 19:34:48 +01:00
|
|
|
if target in muted:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@hook.sieve
|
|
|
|
def mutesieve(bot, input, func, type, args):
|
2012-03-22 22:57:02 +01:00
|
|
|
""" blocks input from muted channels/users """
|
|
|
|
# don't block input to event hooks
|
2012-03-22 19:54:57 +01:00
|
|
|
if type == "event":
|
2012-03-22 22:57:02 +01:00
|
|
|
return input
|
2012-03-22 19:34:48 +01:00
|
|
|
if is_muted(input.chan) or is_muted(input.nick):
|
|
|
|
if input.command == "PRIVMSG" and input.lastparam[1:] == "unmute":
|
|
|
|
return input
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
return input
|
|
|
|
|
|
|
|
|
|
|
|
@hook.command(autohelp=False)
|
|
|
|
def listmuted(inp, bot=None):
|
2012-03-22 22:53:35 +01:00
|
|
|
".listmuted -- Lists muted users/channels."
|
2012-03-22 19:54:57 +01:00
|
|
|
if muted:
|
|
|
|
return "Muted users/channels are: " + ", ".join(muted)
|
|
|
|
else:
|
|
|
|
return "No users are currently muted."
|
2012-03-22 19:34:48 +01:00
|
|
|
|
|
|
|
|
2012-03-22 19:36:00 +01:00
|
|
|
@hook.command(adminonly=True)
|
2012-03-22 19:34:48 +01:00
|
|
|
def mute(inp, input=None, db=None):
|
|
|
|
".mute <channel/user> -- Makes the bot ignore <channel/user>."
|
2012-03-22 19:36:00 +01:00
|
|
|
target = inp
|
2012-03-22 19:34:48 +01:00
|
|
|
|
|
|
|
if is_muted(target):
|
|
|
|
input.notice("%s is already muted." % target)
|
|
|
|
else:
|
|
|
|
mute_target(target)
|
|
|
|
input.notice("%s has been muted." % target)
|
|
|
|
|
|
|
|
|
2012-03-22 19:36:00 +01:00
|
|
|
@hook.command(adminonly=True)
|
2012-03-22 19:34:48 +01:00
|
|
|
def unmute(inp, input=None, db=None):
|
|
|
|
".unmute <channel/user> -- Makes the bot listen to <channel/user>."
|
2012-03-22 19:36:00 +01:00
|
|
|
target = inp
|
2012-03-23 01:00:22 +01:00
|
|
|
|
2012-03-22 19:34:48 +01:00
|
|
|
if is_muted(target):
|
|
|
|
unmute_target(target)
|
|
|
|
input.notice("%s has been unmuted." % target)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
input.notice("%s is not muted." % target)
|
|
|
|
return
|