def func(self): "Implement the command" caller = self.caller if not self.args: self.msg("Usage @ccreate <channelname>[;alias;alias..] = description") return description = "" if self.rhs: description = self.rhs lhs = self.lhs channame = lhs aliases = None if ';' in lhs: channame, aliases = lhs.split(';', 1) aliases = [alias.strip().lower() for alias in aliases.split(';')] channel = ChannelDB.objects.channel_search(channame) if channel: self.msg("A channel with that name already exists.") return # Create and set the channel up lockstring = "send:all();listen:all();control:id(%s)" % caller.id new_chan = create.create_channel(channame.strip(), aliases, description, locks=lockstring) new_chan.connect(caller) CHANNELHANDLER.update() self.msg("Created channel %s and connected to it." % new_chan.key)
def func(self): """Implement the command""" caller = self.caller if not self.args: self.msg( "Usage ccreate <channelname>[;alias;alias..] = description") return description = "" if self.rhs: description = self.rhs lhs = self.lhs channame = lhs aliases = None if ";" in lhs: channame, aliases = lhs.split(";", 1) aliases = [alias.strip().lower() for alias in aliases.split(";")] channel = CHANNEL_DEFAULT_TYPECLASS.objects.channel_search(channame) if channel: self.msg("A channel with that name already exists.") return # Create and set the channel up lockstring = "send:all();listen:all();control:id(%s)" % caller.id new_chan = create.create_channel(channame.strip(), aliases, description, locks=lockstring) new_chan.connect(caller) CHANNELHANDLER.update() self.msg("Created channel %s and connected to it." % new_chan.key)
def func(self): """Destroy objects cleanly.""" caller = self.caller if not self.args: self.msg("Usage: cdestroy <channelname>") return channel = find_channel(caller, self.args) if not channel: self.msg("Could not find channel %s." % self.args) return if not channel.access(caller, "control"): self.msg("You are not allowed to do that.") return channel_key = channel.key message = "%s is being destroyed. Make sure to change your aliases." % channel_key msgobj = create.create_message(caller, message, channel) channel.msg(msgobj) channel.delete() CHANNELHANDLER.update() self.msg("Channel '%s' was destroyed." % channel_key) logger.log_sec( "Channel Deleted: %s (Caller: %s, IP: %s)." % (channel_key, caller, self.session.address) )
def delete(self): """ Deletes channel while also cleaning up channelhandler """ self.attributes.clear() self.aliases.clear() super(DefaultChannel, self).delete() from evennia.comms.channelhandler import CHANNELHANDLER CHANNELHANDLER.update()
def func(self): """implement the function""" if not self.args or not self.rhs: string = "Usage: cboot[/quiet] <channel> = <account> [:reason]" self.msg(string) return channel = find_channel(self.caller, self.lhs) if not channel: return reason = "" if ":" in self.rhs: accountname, reason = self.rhs.rsplit(":", 1) searchstring = accountname.lstrip("*") else: searchstring = self.rhs.lstrip("*") account = self.caller.search(searchstring, account=True) if not account: return if reason: reason = " (reason: %s)" % reason if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return if not channel.subscriptions.has(account): string = "Account %s is not connected to channel %s." % ( account.key, channel.key) self.msg(string) return if "quiet" not in self.switches: string = "%s boots %s from channel.%s" % (self.caller, account.key, reason) channel.msg(string) # find all account's nicks linked to this channel and delete them for nick in [ nick for nick in account.character.nicks.get( category="channel") or [] if nick.value[3].lower() == channel.key ]: nick.delete() # disconnect account channel.disconnect(account) CHANNELHANDLER.update() logger.log_sec( "Channel Boot: %s (Channel: %s, Reason: %s, Caller: %s, IP: %s)." % (account, channel, reason, self.caller, self.session.address))
def func(self): "implement the function" if not self.args or not self.rhs: string = "Usage: @cboot[/quiet] <channel> = <player> [:reason]" self.msg(string) return channel = find_channel(self.caller, self.lhs) if not channel: return reason = "" if ":" in self.rhs: playername, reason = self.rhs.rsplit(":", 1) searchstring = playername.lstrip('*') else: searchstring = self.rhs.lstrip('*') player = self.caller.search(searchstring, player=True) if not player: return if reason: reason = " (reason: %s)" % reason if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return if not player in channel.db_subscriptions.all(): string = "Player %s is not connected to channel %s." % ( player.key, channel.key) self.msg(string) return if not "quiet" in self.switches: string = "%s boots %s from channel.%s" % (self.caller, player.key, reason) channel.msg(string) # find all player's nicks linked to this channel and delete them for nick in [ nick for nick in player.character.nicks.get( category="channel") or [] if nick.db_real.lower() == channel.key ]: nick.delete() # disconnect player channel.disconnect(player) CHANNELHANDLER.update()
def func(self): "implement the function" if not self.args or not self.rhs: string = "Usage: @cboot[/quiet] <channel> = <player> [:reason]" self.msg(string) return channel = find_channel(self.caller, self.lhs) if not channel: return reason = "" if ":" in self.rhs: playername, reason = self.rhs.rsplit(":", 1) searchstring = playername.lstrip('*') else: searchstring = self.rhs.lstrip('*') player = self.caller.search(searchstring, player=True) if not player: return if reason: reason = " (reason: %s)" % reason if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return if not player in channel.db_subscriptions.all(): string = "Player %s is not connected to channel %s." % (player.key, channel.key) self.msg(string) return if not "quiet" in self.switches: string = "%s boots %s from channel.%s" % (self.caller, player.key, reason) channel.msg(string) # find all player's nicks linked to this channel and delete them for nick in [nick for nick in player.character.nicks.get(category="channel") or [] if nick.db_real.lower() == channel.key]: nick.delete() # disconnect player channel.disconnect(player) CHANNELHANDLER.update()
def func(self): """implement the function""" if not self.args or not self.rhs: string = "Usage: @cboot[/quiet] <channel> = <account> [:reason]" self.msg(string) return channel = find_channel(self.caller, self.lhs) if not channel: return reason = "" if ":" in self.rhs: accountname, reason = self.rhs.rsplit(":", 1) searchstring = accountname.lstrip('*') else: searchstring = self.rhs.lstrip('*') account = self.caller.search(searchstring, account=True) if not account: return if reason: reason = " (reason: %s)" % reason if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return if not channel.subscriptions.has(account): string = "Account %s is not connected to channel %s." % (account.key, channel.key) self.msg(string) return if "quiet" not in self.switches: string = "%s boots %s from channel.%s" % (self.caller, account.key, reason) channel.msg(string) # find all account's nicks linked to this channel and delete them for nick in [nick for nick in account.character.nicks.get(category="channel") or [] if nick.value[3].lower() == channel.key]: nick.delete() # disconnect account channel.disconnect(account) CHANNELHANDLER.update()
def func(self): "Destroy objects cleanly." caller = self.caller if not self.args: self.msg("Usage: @cdestroy <channelname>") return channel = find_channel(caller, self.args) if not channel: self.msg("Could not find channel %s." % self.args) return if not channel.access(caller, 'control'): self.msg("You are not allowed to do that.") return channel_key = channel.key message = "%s is being destroyed. Make sure to change your aliases." % channel_key msgobj = create.create_message(caller, message, channel) channel.msg(msgobj) channel.delete() CHANNELHANDLER.update() self.msg("Channel '%s' was destroyed." % channel_key)
def func(self): """Implement function""" caller = self.caller args = self.args # Of all channels, list only the ones with access to listen channels = [ chan for chan in ChannelDB.objects.get_all_channels() if chan.access(caller, 'listen') ] if not channels: self.msg("No channels available.") return subs = ChannelDB.objects.get_subscriptions( caller) # All channels already joined if 'list' in self.switches: # full listing (of channels caller is able to listen to) ✔ or ✘ com_table = evtable.EvTable("|wchannel|n", "|wdescription|n", "|wown sub send|n", "|wmy aliases|n", maxwidth=_DEFAULT_WIDTH) for chan in channels: c_lower = chan.key.lower() nicks = caller.nicks.get(category="channel", return_obj=True) nicks = nicks or [] control = '|gYes|n ' if chan.access(caller, 'control') else '|rNo|n ' send = '|gYes|n ' if chan.access(caller, 'send') else '|rNo|n ' sub = chan in subs and '|gYes|n ' or '|rNo|n ' com_table.add_row(*[ "%s%s" % (chan.key, chan.aliases.all() and "(%s)" % ",".join(chan.aliases.all()) or ''), chan.db.desc, control + sub + send, "%s" % ",".join(nick.db_key for nick in make_iter(nicks) if nick.strvalue.lower() == c_lower) ]) caller.msg( "|/|wAvailable channels|n:|/" + "%s|/(Use |w/list|n, |w/join|n and |w/part|n to manage received channels.)" % com_table) elif 'join' in self.switches or 'on' in self.switches: if not args: self.msg("Usage: %s/join [alias =] channel name." % self.cmdstring) return if self.rhs: # rhs holds the channel name channel_name = self.rhs alias = self.lhs else: channel_name = args alias = None channel = find_channel(caller, channel_name) if not channel: # custom search method handles errors. return # check permissions if not channel.access(caller, 'listen'): self.msg("%s: You are not able to receive this channel." % channel.key) return string = '' if not channel.has_connection(caller): # we want to connect as well. if not channel.connect(caller): # if this would have returned True, the account is connected self.msg("%s: You are not able to join this channel." % channel.key) return else: string += "You now listen to channel %s. " % channel.key else: string += "You already receive channel %s." % channel.key if alias: # create a nick and add it to the caller. caller.nicks.add(alias, channel.key, category="channel") string += " You can now refer to the channel %s with the alias '%s'." self.msg(string % (channel.key, alias)) else: string += " No alias added." self.msg(string) elif 'part' in self.switches or 'off' in self.switches: if not args: self.msg("Usage: %s/part <alias or channel>" % self.cmdstring) return o_string = self.args.lower() channel = find_channel(caller, o_string, silent=True, noaliases=True) if channel: # Given a channel name to part. if not channel.has_connection(caller): self.msg("You are not listening to that channel.") return ch_key = channel.key.lower() # 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 nick and nick.strvalue.lower() == ch_key ]: nick.delete() disconnect = channel.disconnect(caller) if disconnect: self.msg( "You stop receiving channel '%s'. Any aliases were removed." % channel.key) return else: # we are removing a channel nick chan_name = caller.nicks.get(key=o_string, category="channel") channel = find_channel(caller, chan_name, silent=True) if not channel: self.msg("No channel with alias '%s' was found." % o_string) else: if caller.nicks.get(o_string, category="channel"): caller.nicks.remove(o_string, category="channel") self.msg( "Your alias '%s' for channel %s was cleared." % (o_string, channel.key)) else: self.msg( "You had no such alias defined for this channel.") elif 'who' in self.switches: if not self.args: self.msg("Usage: %s/who <channel name or alias>" % self.cmdstring) return channel = find_channel(self.caller, self.lhs) if not channel: return if not channel.access(self.caller, "control"): string = "You do not control this channel." self.msg(string) return string = "\n|CChannel receivers|n" string += " of |w%s:|n " % channel.key subs = channel.db_subscriptions.all() if subs: string += ", ".join([account.key for account in subs]) else: string += "<None>" self.msg(string.strip()) elif 'lock' in self.switches: if not self.args: self.msg("Usage: %s/lock <alias or channel>" % self.cmdstring) return channel = find_channel(self.caller, self.lhs) if not channel: return if not self.rhs: # no =, so just view the current locks string = "Current locks on %s:" % channel.key string = "%s %s" % (string, channel.locks) self.msg(string) return # we want to add/change a lock. if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return channel.locks.add(self.rhs) # Try to add the lock string = "Lock(s) applied on %s:" % channel.key string = "%s %s" % (string, channel.locks) self.msg(string) elif 'emit' in self.switches or 'name' in self.switches: if not self.args or not self.rhs: switch = 'emit' if 'emit' in self.switches else 'name' string = "Usage: %s/%s <channel> = <message>" % ( self.cmdstring, switch) self.msg(string) return channel = find_channel(self.caller, self.lhs) if not channel: return if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return message = self.rhs if 'name' in self.switches: message = "%s: %s" % (self.caller.key, message) channel.msg(message) if 'quiet' not in self.switches: string = "Sent to channel %s: %s" % (channel.key, message) self.msg(string) elif 'desc' in self.switches: if not self.rhs: self.msg("Usage: %s/desc <channel> = <description>" % self.cmdstring) return channel = find_channel(caller, self.lhs) if not channel: self.msg("Channel '%s' not found." % self.lhs) return if not channel.access(caller, 'control'): # check permissions self.msg("You cannot describe this channel.") return channel.db.desc = self.rhs # set the description channel.save() self.msg("Description of channel '%s' set to '%s'." % (channel.key, self.rhs)) elif 'all' in self.switches: if not args: caller.execute_cmd("@channels") self.msg("Usage: %s/all on || off || who || clear" % self.cmdstring) return if args == "on": # get names of all channels available to listen to and activate them all channels = [ chan for chan in ChannelDB.objects.get_all_channels() if chan.access(caller, 'listen') ] for channel in channels: caller.execute_cmd("@command/join %s" % channel.key) elif args == 'off': # get names all subscribed channels and disconnect from them all channels = ChannelDB.objects.get_subscriptions(caller) for channel in channels: caller.execute_cmd("@command/part %s" % channel.key) elif args == 'who': # run a who, listing the subscribers on visible channels. string = "\n|CChannel subscriptions|n" channels = [ chan for chan in ChannelDB.objects.get_all_channels() if chan.access(caller, 'listen') ] if not channels: string += "No channels." for channel in channels: if not channel.access(self.caller, "control"): continue string += "\n|w%s:|n\n" % channel.key subs = channel.db_subscriptions.all() if subs: string += " " + ", ".join( [account.key for account in subs]) else: string += " <None>" self.msg(string.strip()) else: # wrong input self.msg("Usage: %s/all on | off | who | clear" % self.cmdstring) elif 'remove' in self.switches or 'quiet' in self.switches: if not self.args or not self.rhs: switch = 'remove' if 'remove' in self.switches else 'quiet' string = "Usage: %s/%s <channel> = <account> [:reason]" % ( self.cmdstring, switch) self.msg(string) return channel = find_channel(self.caller, self.lhs) if not channel: return reason = '' if ":" in self.rhs: account_name, reason = self.rhs.rsplit(":", 1) search_string = account_name.lstrip('*') else: search_string = self.rhs.lstrip('*') account = self.caller.search(search_string, account=True) if not account: return if reason: reason = " (reason: %s)" % reason if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return if account not in channel.db_subscriptions.all(): string = "Account %s is not connected to channel %s." % ( account.key, channel.key) self.msg(string) return if 'quiet' not in self.switches: string = "%s boots %s from channel.%s" % (self.caller, account.key, reason) channel.msg(string) # find all account's nicks linked to this channel and delete them for nick in [ nick for nick in account.character.nicks.get( category="channel") or [] if nick.db_real.lower() == channel.key ]: nick.delete() channel.disconnect(account) # disconnect account CHANNELHANDLER.update() else: # just display the subscribed channels with no extra info com_table = evtable.EvTable("|wchannel|n", "|wmy aliases|n", "|wdescription|n", align="l", maxwidth=_DEFAULT_WIDTH) for chan in subs: c_lower = chan.key.lower() nicks = caller.nicks.get(category="channel", return_obj=True) com_table.add_row(*[ "%s%s" % (chan.key, chan.aliases.all() and "(%s)" % ",".join(chan.aliases.all()) or ""), "%s" % ",".join(nick.db_key for nick in make_iter(nicks) if nick and nick.strvalue.lower() == c_lower), chan.db.desc ]) caller.msg( "\n|wChannel subscriptions|n (use |w@chan/list|n to list all, " + "|w/join|n |w/part|n to join or part):|n\n%s" % com_table)
def func(self): """Implement function""" caller = self.caller args = self.args # Of all channels, list only the ones with access to listen channels = [chan for chan in ChannelDB.objects.get_all_channels() if chan.access(caller, 'listen')] if not channels: self.msg("No channels available.") return subs = ChannelDB.objects.get_subscriptions(caller) # All channels already joined if 'list' in self.switches: # full listing (of channels caller is able to listen to) ✔ or ✘ com_table = evtable.EvTable("|wchannel|n", "|wdescription|n", "|wown sub send|n", "|wmy aliases|n", maxwidth=_DEFAULT_WIDTH) for chan in channels: c_lower = chan.key.lower() nicks = caller.nicks.get(category="channel", return_obj=True) nicks = nicks or [] control = '|gYes|n ' if chan.access(caller, 'control') else '|rNo|n ' send = '|gYes|n ' if chan.access(caller, 'send') else '|rNo|n ' sub = chan in subs and '|gYes|n ' or '|rNo|n ' com_table.add_row(*["%s%s" % (chan.key, chan.aliases.all() and "(%s)" % ",".join(chan.aliases.all()) or ''), chan.db.desc, control + sub + send, "%s" % ",".join(nick.db_key for nick in make_iter(nicks) if nick.strvalue.lower() == c_lower)]) caller.msg("|/|wAvailable channels|n:|/" + "%s|/(Use |w/list|n, |w/join|n and |w/part|n to manage received channels.)" % com_table) elif 'join' in self.switches or 'on' in self.switches: if not args: self.msg("Usage: %s/join [alias =] channel name." % self.cmdstring) return if self.rhs: # rhs holds the channel name channel_name = self.rhs alias = self.lhs else: channel_name = args alias = None channel = find_channel(caller, channel_name) if not channel: # custom search method handles errors. return # check permissions if not channel.access(caller, 'listen'): self.msg("%s: You are not able to receive this channel." % channel.key) return string = '' if not channel.has_connection(caller): # we want to connect as well. if not channel.connect(caller): # if this would have returned True, the account is connected self.msg("%s: You are not able to join this channel." % channel.key) return else: string += "You now listen to channel %s. " % channel.key else: string += "You already receive channel %s." % channel.key if alias: # create a nick and add it to the caller. caller.nicks.add(alias, channel.key, category="channel") string += " You can now refer to the channel %s with the alias '%s'." self.msg(string % (channel.key, alias)) else: string += " No alias added." self.msg(string) elif 'part' in self.switches or 'off' in self.switches: if not args: self.msg("Usage: %s/part <alias or channel>" % self.cmdstring) return o_string = self.args.lower() channel = find_channel(caller, o_string, silent=True, noaliases=True) if channel: # Given a channel name to part. if not channel.has_connection(caller): self.msg("You are not listening to that channel.") return ch_key = channel.key.lower() # 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 nick and nick.strvalue.lower() == ch_key]: nick.delete() disconnect = channel.disconnect(caller) if disconnect: self.msg("You stop receiving channel '%s'. Any aliases were removed." % channel.key) return else: # we are removing a channel nick chan_name = caller.nicks.get(key=o_string, category="channel") channel = find_channel(caller, chan_name, silent=True) if not channel: self.msg("No channel with alias '%s' was found." % o_string) else: if caller.nicks.get(o_string, category="channel"): caller.nicks.remove(o_string, category="channel") self.msg("Your alias '%s' for channel %s was cleared." % (o_string, channel.key)) else: self.msg("You had no such alias defined for this channel.") elif 'who' in self.switches: if not self.args: self.msg("Usage: %s/who <channel name or alias>" % self.cmdstring) return channel = find_channel(self.caller, self.lhs) if not channel: return if not channel.access(self.caller, "control"): string = "You do not control this channel." self.msg(string) return string = "\n|CChannel receivers|n" string += " of |w%s:|n " % channel.key subs = channel.db_subscriptions.all() if subs: string += ", ".join([account.key for account in subs]) else: string += "<None>" self.msg(string.strip()) elif 'lock' in self.switches: if not self.args: self.msg("Usage: %s/lock <alias or channel>" % self.cmdstring) return channel = find_channel(self.caller, self.lhs) if not channel: return if not self.rhs: # no =, so just view the current locks string = "Current locks on %s:" % channel.key string = "%s %s" % (string, channel.locks) self.msg(string) return # we want to add/change a lock. if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return channel.locks.add(self.rhs) # Try to add the lock string = "Lock(s) applied on %s:" % channel.key string = "%s %s" % (string, channel.locks) self.msg(string) elif 'emit' in self.switches or 'name' in self.switches: if not self.args or not self.rhs: switch = 'emit' if 'emit' in self.switches else 'name' string = "Usage: %s/%s <channel> = <message>" % (self.cmdstring, switch) self.msg(string) return channel = find_channel(self.caller, self.lhs) if not channel: return if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return message = self.rhs if 'name' in self.switches: message = "%s: %s" % (self.caller.key, message) channel.msg(message) if 'quiet' not in self.switches: string = "Sent to channel %s: %s" % (channel.key, message) self.msg(string) elif 'desc' in self.switches: if not self.rhs: self.msg("Usage: %s/desc <channel> = <description>" % self.cmdstring) return channel = find_channel(caller, self.lhs) if not channel: self.msg("Channel '%s' not found." % self.lhs) return if not channel.access(caller, 'control'): # check permissions self.msg("You cannot describe this channel.") return channel.db.desc = self.rhs # set the description channel.save() self.msg("Description of channel '%s' set to '%s'." % (channel.key, self.rhs)) elif 'all' in self.switches: if not args: caller.execute_cmd("@channels") self.msg("Usage: %s/all on || off || who || clear" % self.cmdstring) return if args == "on": # get names of all channels available to listen to and activate them all channels = [chan for chan in ChannelDB.objects.get_all_channels() if chan.access(caller, 'listen')] for channel in channels: caller.execute_cmd("@command/join %s" % channel.key) elif args == 'off': # get names all subscribed channels and disconnect from them all channels = ChannelDB.objects.get_subscriptions(caller) for channel in channels: caller.execute_cmd("@command/part %s" % channel.key) elif args == 'who': # run a who, listing the subscribers on visible channels. string = "\n|CChannel subscriptions|n" channels = [chan for chan in ChannelDB.objects.get_all_channels() if chan.access(caller, 'listen')] if not channels: string += "No channels." for channel in channels: if not channel.access(self.caller, "control"): continue string += "\n|w%s:|n\n" % channel.key subs = channel.db_subscriptions.all() if subs: string += " " + ", ".join([account.key for account in subs]) else: string += " <None>" self.msg(string.strip()) else: # wrong input self.msg("Usage: %s/all on | off | who | clear" % self.cmdstring) elif 'remove' in self.switches or 'quiet' in self.switches: if not self.args or not self.rhs: switch = 'remove' if 'remove' in self.switches else 'quiet' string = "Usage: %s/%s <channel> = <account> [:reason]" % (self.cmdstring, switch) self.msg(string) return channel = find_channel(self.caller, self.lhs) if not channel: return reason = '' if ":" in self.rhs: account_name, reason = self.rhs.rsplit(":", 1) search_string = account_name.lstrip('*') else: search_string = self.rhs.lstrip('*') account = self.caller.search(search_string, account=True) if not account: return if reason: reason = " (reason: %s)" % reason if not channel.access(self.caller, "control"): string = "You don't control this channel." self.msg(string) return if account not in channel.db_subscriptions.all(): string = "Account %s is not connected to channel %s." % (account.key, channel.key) self.msg(string) return if 'quiet' not in self.switches: string = "%s boots %s from channel.%s" % (self.caller, account.key, reason) channel.msg(string) # find all account's nicks linked to this channel and delete them for nick in [nick for nick in account.character.nicks.get(category="channel") or [] if nick.db_real.lower() == channel.key]: nick.delete() channel.disconnect(account) # disconnect account CHANNELHANDLER.update() else: # just display the subscribed channels with no extra info com_table = evtable.EvTable("|wchannel|n", "|wmy aliases|n", "|wdescription|n", align="l", maxwidth=_DEFAULT_WIDTH) for chan in subs: c_lower = chan.key.lower() nicks = caller.nicks.get(category="channel", return_obj=True) com_table.add_row(*["%s%s" % (chan.key, chan.aliases.all() and "(%s)" % ",".join(chan.aliases.all()) or ""), "%s" % ",".join(nick.db_key for nick in make_iter(nicks) if nick and nick.strvalue.lower() == c_lower), chan.db.desc]) caller.msg("\n|wChannel subscriptions|n (use |w@chan/list|n to list all, " + "|w/join|n |w/part|n to join or part):|n\n%s" % com_table)
def func(self): """ Create a new message and send it to channel, using the already formatted input. """ channelkey, msg = self.args caller = self.caller channel = ChannelDB.objects.get_channel(channelkey) admin_switches = ("destroy", "emit", "lock", "locks", "desc", "kick") # Check that the channel exist if not channel: self.msg(_("Channel '%s' not found.") % channelkey) return # Check that the caller is connected if not channel.has_connection(caller): string = _("You are not connected to channel '%s'.") self.msg(string % channelkey) return # Check that the caller has send access if not channel.access(caller, 'send'): string = _("You are not permitted to send to channel '%s'.") self.msg(string % channelkey) return # Get the list of connected to this channel puppets = [session.puppet for session in SESSION_HANDLER.values() \ if session.puppet] connected = [ obj for obj in channel.subscriptions.all() if obj in puppets ] # Handle the various switches if self.switch == "me": if not msg: self.msg("What do you want to do on this channel?") else: msg = "{} {}".format(caller.key, msg) channel.msg(msg, online=True) elif self.switch == "who": keys = [obj.key for obj in connected] keys.sort() string = "Connected to the {} channel:".format(channel.key) string += ", ".join(keys) if keys else "(no one)" string += "." self.msg(string) elif channel.access(caller, 'control') and self.switch in admin_switches: if self.switch == "destroy": confirm = yield ( "Are you sure you want to delete the channel {}? (Y?N)". format(channel.key)) if confirm.lower() in ("y", "yes"): channel.msg("Destroying the channel.") channel.delete() CHANNELHANDLER.update() self.msg("The channel was destroyed.") else: self.msg("Operation cancelled, do not destroy.") elif self.switch == "emit": if not msg: self.msg("What do you want to say on this channel?") else: channel.msg(msg, online=True) elif self.switch in ("lock", "locks"): if msg: try: channel.locks.add(msg) except LockException as err: self.msg(err) return else: self.msg("Channel permissions were edited.") string = "Current locks on {}:\n {}".format( channel.key, channel.locks) self.msg(string) elif self.switch == "desc": if msg: channel.db.desc = msg self.msg("Channel description was updated.") self.msg("Description of the {} channel: {}".format( channel.key, channel.db.desc)) elif self.switch == "kick": if not msg: self.msg("Who do you want to kick from this channel?") else: to_kick = caller.search(msg, candidates=connected) if to_kick is None: return channel.disconnect(to_kick) channel.msg("{} has been kicked from the channel.".format( to_kick.key)) to_kick.msg( "You have been kicked from the {} channel.".format( channel.key)) elif self.history_start is not None: # Try to view history log_file = channel.attributes.get("log_file", default="channel_%s.log" % channel.key) send_msg = lambda lines: self.msg("".join( line.split("[-]", 1)[1] if "[-]" in line else line for line in lines)) tail_log_file(log_file, self.history_start, 20, callback=send_msg) elif self.switch: self.msg("{}: Invalid switch {}.".format(channel.key, self.switch)) elif not msg: self.msg(_("Say what?")) return else: if caller in channel.mutelist: self.msg("You currently have %s muted." % channel) return channel.msg(msg, senders=self.caller, online=True)
def func(self): """ Create a new message and send it to channel, using the already formatted input. """ channelkey, msg = self.args caller = self.caller channel = ChannelDB.objects.get_channel(channelkey) admin_switches = ("destroy", "emit", "lock", "locks", "desc", "kick") # Check that the channel exist if not channel: self.msg(_("Channel '%s' not found.") % channelkey) return # Check that the caller is connected if not channel.has_connection(caller): string = _("You are not connected to channel '%s'.") self.msg(string % channelkey) return # Check that the caller has send access if not channel.access(caller, 'send'): string = _("You are not permitted to send to channel '%s'.") self.msg(string % channelkey) return # Get the list of connected to this channel connected = [ obj for obj in channel.subscriptions.all() if getattr(obj, "is_connected", False) ] # Handle the various switches if self.switch == "me": if not msg: self.msg("Quelle action voulez-vous faire dans ce canal ?") else: msg = "{} {}".format(caller.key, msg) channel.msg(msg, online=True) elif self.switch == "who": keys = [obj.username for obj in connected] keys.sort() string = "Connectés au canal {} : ".format(channel.key) string += ", ".join(keys) if keys else "(no one)" string += "." self.msg(string) elif channel.access(caller, 'control') and self.switch in admin_switches: if self.switch == "destroy": confirm = yield ( "Are you sure you want to delete the channel {}? (Y?N)". format(channel.key)) if confirm.lower() in ("y", "yes"): channel.msg("Destroying the channel.") channel.delete() CHANNELHANDLER.update() self.msg("The channel was destroyed.") else: self.msg("Operation cancelled, do not destroy.") elif self.switch == "emit": if not msg: self.msg("What do you want to say on this channel?") else: channel.msg(msg, online=True) elif self.switch in ("lock", "locks"): if msg: try: channel.locks.add(msg) except LockException, err: self.msg(err) return else: self.msg("Channel permissions were edited.") string = "Current locks on {}:\n {}".format( channel.key, channel.locks) self.msg(string) elif self.switch == "desc": if msg: channel.db.desc = msg self.msg("Channel description was updated.") self.msg("Description of the {} channel: {}".format( channel.key, channel.db.desc)) elif self.switch == "kick": if not msg: self.msg("Who do you want to kick from this channel?") else: to_kick = caller.search(msg, candidates=connected) if to_kick is None: return channel.disconnect(to_kick) channel.msg("{} has been kicked from the channel.".format( to_kick.key)) to_kick.msg( "You have been kicked from the {} channel.".format( channel.key))