Ejemplo n.º 1
0
def change_user_name(user, command):
    from lib.users import users
    import re

    pattern = re.compile('^(?P<nick>[a-z0-9\-_]+)$')

    result = pattern.match(command)

    try:

        nick = result.group('nick')

        if len(nick) > 12:
            raise Exception()

        if nick in users.list.keys():
            return user.send_text(lang.create_clause('wrong_nick_being_used'))

        del users.list[user.nick]

        users.list[nick] = user
        user.nick = nick

        user.send_text(lang.create_clause('new_user_name', nick))
    except:
        return user.send_text(lang.create_clause('wrong_nick_change'))
Ejemplo n.º 2
0
    def generate_random_nick(self):

        self._last_id += 1
        last_id = self._last_id
        user_name = lang.create_clause('random_user_name', last_id)

        while user_name in self.list:
            self._last_id += 1
            last_id = self._last_id
            user_name = lang.create_clause('random_user_name', last_id)

        return user_name
Ejemplo n.º 3
0
def help_(user, command):
    from commands.manager import command_manager

    if command == "":
        return user.send_text(help_.__doc__)

    if command_manager.is_command(command) is True:
        command_function = command_manager.commands[command]

        if getattr(command_function, '__doc__') is not None:
            user.send_text(lang.create_clause('help_command_doc', command, command_function.__doc__))
        else:
            user.send_text(lang.create_clause('help_command_doc_not_set', command))
    else:
        user.send_text(lang.create_clause('wrong_command_name', command))
Ejemplo n.º 4
0
def broadcast(user, command, ignore=None, send_user=False):
    from lib.users import users

    if ignore is None:
        ignore = []

    if send_user is False:
        ignore.append(user.nick)

    for _nick in users.list:
        if not _nick in ignore:
            users.list[_nick].send_text(lang.create_clause('broadcast', user.nick, command))
Ejemplo n.º 5
0
    def send_error(user, template, *args, **kwargs):
        """
        :type template: str
        :type user: UserThread
        """

        error_clause = lang.create_clause(template, *args)

        if 'log' in kwargs:
            if kwargs['log'] is True:
                logger.warning(error_clause)

        user.send_text(error_clause)
Ejemplo n.º 6
0
def command_list(user, command):
    from commands.manager import command_manager
    user.send_text(lang.create_clause('command_list', '\n'.join(command_manager.commands)))