Okay, next try! I added 'on' and 'off' as arguments for the base channel command in channelhandler which allows you to unmute or mute the channel respectively, and added the mute and unmute methods to ChannelDB. distribute_message now checks for a subscriber being muted before passing along the message. Reverted the changes to the channel cmdset. Added the 'all' switch to delcom to allow for the deletion of aliases, otherwise it keeps the aliases intact for when they next join the channel.

This commit is contained in:
Tehom 2016-10-18 19:13:40 -04:00 committed by Griatch
parent 441b081e55
commit 951cd60a6d
3 changed files with 74 additions and 8 deletions

View file

@ -112,7 +112,10 @@ class CmdAddCom(COMMAND_DEFAULT_CLASS):
else: else:
string += "You now listen to the channel %s. " % channel.key string += "You now listen to the channel %s. " % channel.key
else: else:
string += "You are already connected to channel %s." % channel.key if channel.unmute(player):
string += "You unmute channel %s." % channel.key
else:
string += "You are already connected to channel %s." % channel.key
if alias: if alias:
# create a nick and add it to the caller. # create a nick and add it to the caller.
@ -130,10 +133,12 @@ class CmdDelCom(COMMAND_DEFAULT_CLASS):
Usage: Usage:
delcom <alias or channel> delcom <alias or channel>
delcom/all <channel>
If the full channel name is given, unsubscribe from the If the full channel name is given, unsubscribe from the
channel. If an alias is given, remove the alias but don't channel. If an alias is given, remove the alias but don't
unsubscribe. unsubscribe. If the 'all' switch is used, remove all aliases
for that channel.
""" """
key = "delcom" key = "delcom"
@ -162,13 +167,16 @@ class CmdDelCom(COMMAND_DEFAULT_CLASS):
self.msg("You are not listening to that channel.") self.msg("You are not listening to that channel.")
return return
chkey = channel.key.lower() chkey = channel.key.lower()
delnicks = "all" in self.switches
# find all nicks linked to this channel and delete them # find all nicks linked to this channel and delete them
for nick in [nick for nick in make_iter(caller.nicks.get(category="channel", return_obj=True)) if delnicks:
if nick and nick.pk and nick.value[3].lower() == chkey]: for nick in [nick for nick in make_iter(caller.nicks.get(category="channel", return_obj=True))
nick.delete() if nick and nick.pk and nick.value[3].lower() == chkey]:
nick.delete()
disconnect = channel.disconnect(player) disconnect = channel.disconnect(player)
if disconnect: if disconnect:
self.msg("You stop listening to channel '%s'. Eventual aliases were removed." % channel.key) wipednicks = " Eventual aliases were removed." if delnicks else ""
self.msg("You stop listening to channel '%s'.%s" % channel.key)
return return
else: else:
# we are removing a channel nick # we are removing a channel nick

View file

@ -43,6 +43,8 @@ class ChannelCommand(command.Command):
Usage: Usage:
{lower_channelkey} <message> {lower_channelkey} <message>
{lower_channelkey}/history [start] {lower_channelkey}/history [start]
{lower_channelkey} off - mutes the channel
{lower_channelkey} on - unmutes the channel
Switch: Switch:
history: View 20 previous messages, either from the end or history: View 20 previous messages, either from the end or
@ -107,6 +109,22 @@ class ChannelCommand(command.Command):
string = _("You are not permitted to send to channel '%s'.") string = _("You are not permitted to send to channel '%s'.")
self.msg(string % channelkey) self.msg(string % channelkey)
return return
if msg == "on":
caller = caller if not hasattr(caller, 'player') else caller.player
unmuted = channel.unmute(caller)
if unmuted:
self.msg("You start listening to %s." % channel)
return
self.msg("You were already listening to %s." % channel)
return
if msg == "off":
caller = caller if not hasattr(caller, 'player') else caller.player
muted = channel.mute(caller)
if muted:
self.msg("You stop listening to %s." % channel)
return
self.msg("You were already not listening to %s." % channel)
return
if self.history_start is not None: if self.history_start is not None:
# Try to view history # Try to view history
log_file = channel.attributes.get("log_file", default="channel_%s.log" % channel.key) log_file = channel.attributes.get("log_file", default="channel_%s.log" % channel.key)
@ -114,6 +132,10 @@ class ChannelCommand(command.Command):
if "[-]" in line else line for line in lines)) if "[-]" in line else line for line in lines))
tail_log_file(log_file, self.history_start, 20, callback=send_msg) tail_log_file(log_file, self.history_start, 20, callback=send_msg)
else: else:
caller = caller if not hasattr(caller, 'player') else caller.player
if caller in channel.mutelist:
self.msg("You currently have %s muted." % channel)
return
channel.msg(msg, senders=self.caller, online=True) channel.msg(msg, senders=self.caller, online=True)
def get_extra_info(self, caller, **kwargs): def get_extra_info(self, caller, **kwargs):
@ -234,12 +256,13 @@ class ChannelHandler(object):
# create a new cmdset holding all viable channels # create a new cmdset holding all viable channels
chan_cmdset = None chan_cmdset = None
chan_cmds = [channelcmd for channel, channelcmd in self.cached_channel_cmds.iteritems() chan_cmds = [channelcmd for channel, channelcmd in self.cached_channel_cmds.iteritems()
if channelcmd.access(source_object, 'send')] if channel.subscriptions.has(source_object) and
channelcmd.access(source_object, 'send')]
if chan_cmds: if chan_cmds:
chan_cmdset = cmdset.CmdSet() chan_cmdset = cmdset.CmdSet()
chan_cmdset.key = 'ChannelCmdSet' chan_cmdset.key = 'ChannelCmdSet'
chan_cmdset.priority = 101 chan_cmdset.priority = 101
chan_cmdset.duplicates = False chan_cmdset.duplicates = True
for cmd in chan_cmds: for cmd in chan_cmds:
chan_cmdset.add(cmd) chan_cmdset.add(cmd)
self.cached_cmdsets[source_object] = chan_cmdset self.cached_cmdsets[source_object] = chan_cmdset

View file

@ -79,6 +79,34 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
has_sub = self.subscriptions.has(subscriber.player) has_sub = self.subscriptions.has(subscriber.player)
return has_sub return has_sub
@property
def mutelist(self):
return self.db.mute_list or []
def mute(self, subscriber):
"""
Adds an entity to the list of muted subscribers.
A muted subscriber will no longer see channel messages,
but may use channel commands.
"""
mutelist = self.mutelist
if subscriber not in mutelist:
mutelist.append(subscriber)
self.db.mute_list = mutelist
return True
def unmute(self, subscriber):
"""
Removes an entity to the list of muted subscribers.
A muted subscriber will no longer see channel messages,
but may use channel commands.
"""
mutelist = self.mutelist
if subscriber in mutelist:
mutelist.remove(subscriber)
self.db.mute_list = mutelist
return True
def connect(self, subscriber): def connect(self, subscriber):
""" """
@ -102,6 +130,8 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
return False return False
# subscribe # subscribe
self.subscriptions.add(subscriber) self.subscriptions.add(subscriber)
# unmute
self.unmute(subscriber)
# post-join hook # post-join hook
self.post_join_channel(subscriber) self.post_join_channel(subscriber)
return True return True
@ -125,6 +155,8 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
return False return False
# disconnect # disconnect
self.subscriptions.remove(subscriber) self.subscriptions.remove(subscriber)
# unmute
self.unmute(subscriber)
# post-disconnect hook # post-disconnect hook
self.post_leave_channel(subscriber) self.post_leave_channel(subscriber)
return True return True
@ -197,6 +229,9 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
""" """
# get all players connected to this channel and send to them # get all players connected to this channel and send to them
for entity in self.subscriptions.all(): for entity in self.subscriptions.all():
# if the entity is muted, we don't send them a message
if entity in self.mutelist:
continue
try: try:
# note our addition of the from_channel keyword here. This could be checked # note our addition of the from_channel keyword here. This could be checked
# by a custom player.msg() to treat channel-receives differently. # by a custom player.msg() to treat channel-receives differently.