<commit_before>"""
Comsys command module.
"""
import time
from django.conf import settings
import src.comsys
from src import defines_global
from src import ansi
from src.util import functions_general
from src.cmdtable import GLOBAL_CMD_TABLE
from src.imc2.models import IMC2ChannelMapping
from src.imc2.packets import IMC2PacketIceMsgBroadcasted

def cmd_addcom(command):
    """
    addcom

    Adds an alias for a channel.
    addcom foo=Bar
    """
    source_object = command.source_object

    if not command.command_argument:
        source_object.emit_to("You need to specify a channel alias and name.")
        return
    
    eq_args = command.command_argument.split('=', 1)
           
    chan_alias = eq_args[0]
    chan_name = eq_args[1]
    
    if len(eq_args) < 2 or len(chan_name) == 0:
        source_object.emit_to("You need to specify a channel name.")
        return

    if chan_alias in command.session.channels_subscribed:
        source_object.emit_to("You are already on that channel.")
        return

    name_matches = src.comsys.cname_search(chan_name, exact=True)

    if name_matches:
        chan_name_parsed = name_matches[0].get_name()
        source_object.emit_to("You join %s, with an alias of %s." % \
            (chan_name_parsed, chan_alias))
        src.comsys.plr_set_channel(command.session, chan_alias, 
                                   chan_name_parsed, True)

        # Announce the user's joining.
        join_msg = "[%s] %s has joined the channel." % \
            (chan_name_parsed, source_object.get_name(show_dbref=False))
        src.comsys.send_cmessage(chan_name_parsed, join_msg)
    else:
        source_object.emit_to("Could not find channel %s." % (chan_name,))
GLOBAL_CMD_TABLE.add_command("addcom", cmd_addcom),

def cmd_delcom(command):
    """
    delcom

    Removes the specified alias to a channel. If this is the last alias,
    the user is effectively removed from the channel.
    """
    source_object = command.source_object

    if not command.command_argument:
        source_object.emit_to("You must specify a channel alias.")
        return

    if command.command_argument not in command.session.channels_subscribed:
        source_object.emit_to("You are not on that channel.")
        return

    chan_name = command.session.channels_subscribed[command.command_argument][0]
    source_object.emit_to("You have left %s." % (chan_name,))
    src.comsys.plr_del_channel(command.session, command.command_argument)

    # Announce the user's leaving.
    leave_msg = "[%s] %s has left the channel." % \
        (chan_name, source_object.get_name(show_dbref=False))
    src.comsys.send_cmessage(chan_name, leave_msg)
GLOBAL_CMD_TABLE.add_command("delcom", cmd_delcom),

def cmd_comlist(command):
    """
    Lists the channels a user is subscribed to.
    """
    source_object = command.source_object 
    session = command.session

    source_object.emit_to("Alias     Channel             Status")
    for chan in session.channels_subscribed:
        if session.channels_subscribed[chan][1]:
            chan_on = "On"
        else:
            chan_on = "Off"
            
        source_object.emit_to("%-9.9s %-19.19s %s" %
            (chan, session.channels_subscribed[chan][0], chan_on))
    source_object.emit_to("-- End of comlist --")
GLOBAL_CMD_TABLE.add_command("comlist", cmd_comlist),
    
def cmd_allcom(command):
    """
    allcom

    Allows the user to universally turn off or on all channels they are on,
    as well as perform a "who" for all channels they are on.
    """
    # TODO: Implement cmd_allcom
    pass

def cmd_clearcom(command):
    """
    clearcom

    Effectively runs delcom on all channels the user is on.  It will remove their aliases,
    remove them from the channel, and clear any titles they have set.
    """
    # TODO: Implement cmd_clearcom
    pass

def cmd_clist(command):
    """
    @clist

    Lists all available channels on the game.
    """
    session = command.session
    source_object = command.source_object
    
    source_object.emit_to("** Channel       Owner         Description")
    for chan in src.comsys.get_all_channels():
        source_object.emit_to("%s%s %-14.13s%-22.15s%s" %
            ('-', 
             '-', 
             chan.get_name(), 
             chan.get_owner().get_name(show_dbref=False), 
             'No Description'))<commit_msg>Make @clist actually show channel descriptions instead of 'No description' all the time.<commit_after>"""
Comsys command module.
"""
import time
from django.conf import settings
import src.comsys
from src import defines_global
from src import ansi
from src.util import functions_general
from src.cmdtable import GLOBAL_CMD_TABLE
from src.imc2.models import IMC2ChannelMapping
from src.imc2.packets import IMC2PacketIceMsgBroadcasted

def cmd_addcom(command):
    """
    addcom

    Adds an alias for a channel.
    addcom foo=Bar
    """
    source_object = command.source_object

    if not command.command_argument:
        source_object.emit_to("You need to specify a channel alias and name.")
        return
    
    eq_args = command.command_argument.split('=', 1)
           
    chan_alias = eq_args[0]
    chan_name = eq_args[1]
    
    if len(eq_args) < 2 or len(chan_name) == 0:
        source_object.emit_to("You need to specify a channel name.")
        return

    if chan_alias in command.session.channels_subscribed:
        source_object.emit_to("You are already on that channel.")
        return

    name_matches = src.comsys.cname_search(chan_name, exact=True)

    if name_matches:
        chan_name_parsed = name_matches[0].get_name()
        source_object.emit_to("You join %s, with an alias of %s." % \
            (chan_name_parsed, chan_alias))
        src.comsys.plr_set_channel(command.session, chan_alias, 
                                   chan_name_parsed, True)

        # Announce the user's joining.
        join_msg = "[%s] %s has joined the channel." % \
            (chan_name_parsed, source_object.get_name(show_dbref=False))
        src.comsys.send_cmessage(chan_name_parsed, join_msg)
    else:
        source_object.emit_to("Could not find channel %s." % (chan_name,))
GLOBAL_CMD_TABLE.add_command("addcom", cmd_addcom),

def cmd_delcom(command):
    """
    delcom

    Removes the specified alias to a channel. If this is the last alias,
    the user is effectively removed from the channel.
    """
    source_object = command.source_object

    if not command.command_argument:
        source_object.emit_to("You must specify a channel alias.")
        return

    if command.command_argument not in command.session.channels_subscribed:
        source_object.emit_to("You are not on that channel.")
        return

    chan_name = command.session.channels_subscribed[command.command_argument][0]
    source_object.emit_to("You have left %s." % (chan_name,))
    src.comsys.plr_del_channel(command.session, command.command_argument)

    # Announce the user's leaving.
    leave_msg = "[%s] %s has left the channel." % \
        (chan_name, source_object.get_name(show_dbref=False))
    src.comsys.send_cmessage(chan_name, leave_msg)
GLOBAL_CMD_TABLE.add_command("delcom", cmd_delcom),

def cmd_comlist(command):
    """
    Lists the channels a user is subscribed to.
    """
    source_object = command.source_object 
    session = command.session

    source_object.emit_to("Alias     Channel             Status")
    for chan in session.channels_subscribed:
        if session.channels_subscribed[chan][1]:
            chan_on = "On"
        else:
            chan_on = "Off"
            
        source_object.emit_to("%-9.9s %-19.19s %s" %
            (chan, session.channels_subscribed[chan][0], chan_on))
    source_object.emit_to("-- End of comlist --")
GLOBAL_CMD_TABLE.add_command("comlist", cmd_comlist),
    
def cmd_allcom(command):
    """
    allcom

    Allows the user to universally turn off or on all channels they are on,
    as well as perform a "who" for all channels they are on.
    """
    # TODO: Implement cmd_allcom
    pass

def cmd_clearcom(command):
    """
    clearcom

    Effectively runs delcom on all channels the user is on.  It will remove their aliases,
    remove them from the channel, and clear any titles they have set.
    """
    # TODO: Implement cmd_clearcom
    pass

def cmd_clist(command):
    """
    @clist

    Lists all available channels on the game.
    """
    session = command.session
    source_object = command.source_object
    
    source_object.emit_to("** Channel       Owner         Description")
    for chan in src.comsys.get_all_channels():
        source_object.emit_to("%s%s %-14.13s%-22.15s%s" %
            ('-', 
             '-', 
             chan.get_name(), 
             chan.get_owner().get_name(show_dbref=False), 
             chan.description))
{'fraction_non_alphanumeric': 0.09385915492957747, 'fraction_numerical': 0.006084507042253521, 'mean_word_length': 2.7642069550466495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4475233', 'n_tokens_mistral': 2782, 'n_tokens_neox': 2694, 'n_words': 706}