Exemplo n.º 1
0
    def alias(self, *args):
        try:
            name, alias = args[0], args[1]
        except IndexError:
            return 'Indicate a name and an alias: `%s alias foo bar`, ' \
                'where `foo` is the original name and `alias` is an ' \
                'additional name.'

        emoticon = db.get_emoticon(name)
        if not emoticon:
            return 'Emoticon `%s` not found. Enter `%s help` ' \
                'for a list of available ASCII emoticons'

        if db.get_emoticon(alias):
            return '`%s` is already taken' % name

        if db.create_alias(emoticon['id'], alias):
            return 'Aliased `%s` -> `%s`' % (alias, name)
Exemplo n.º 2
0
    def get(self, name):
        emoticon = db.get_emoticon(name)
        if not emoticon:
            return

        if '\n' in emoticon['content']:
            # Displaying multiline emoticons/ascii art improves readability
            emoticon['content'] = '```%s```' % emoticon['content']

        return emoticon['content']
Exemplo n.º 3
0
    def create(self, *args):
        try:
            name, content = args[0], ' '.join(args[1:])
            name = name.lower()
        except IndexError:
            content = None
        if not content:
            return 'Please specify a name and the emoticon ' \
                'text. Example: `%s add foo (o_o)`' % self._command_name

        existing = db.get_emoticon(name)
        if existing is not None:
            return '`%s` is already assigned to an emoticon.' % name

        try:
            content = content.encode('utf-8')
        except UnicodeEncodeError:
            pass
        if db.create_emoticon(name, content):
            return 'Emoticon `%s` added' % name