コード例 #1
0
ファイル: roll.py プロジェクト: evilchili/telisar
    def run(self, message):
        (cmd, args) = message_parts(message)

        # roll, if the request is sane.
        try:
            (count, sides) = args[0].split('d', 1)
            if int(count) > 100 or int(sides) > 100:
                results = None
            else:
                results = dice.roll(args[0])
        except (ValueError, dice.exceptions.DiceFatalException,
                dice.exceptions.DiceException):
            results = None

        if not results:
            return ":game_die: {message.author}: Invalid expression."

        # dice.roll() returns either an Integer or a List, because dice.roll() DGAF
        try:
            total = sum(results)
        except TypeError:
            return f":game_die: {message.author}: {results}"

        # Add the modifier, if there is one
        try:
            modifier = ''.join(args[1:])
            total += int(modifier)
        except (IndexError, TypeError, ValueError):
            modifier = ''

        return f":game_die: {message.author}: {results} {modifier} = {total}"
コード例 #2
0
 def run(self, message):
     (_, parts) = message_parts(message)
     if not parts:
         return self.cmd_npc(*parts)
     elif parts[0] == 'names':
         return self.cmd_names(*parts[1:])
     else:
         return self.cmd_npc(*parts)
コード例 #3
0
    def run(self, message):
        (cmd, args) = message_parts(message)

        if len(args) > 1 and self.is_digits.match(args[0]):
            count = args[0]
            args = args[1:]
        else:
            count = 3

        return self.searcher.search(search_terms=args,
                                    count=count,
                                    formatter=self.embed_formatter)
コード例 #4
0
ファイル: date.py プロジェクト: evilchili/telisar
    def run(self, message):
        (_, parts) = message_parts(message)

        if not parts:
            cmd = 'today'
        else:
            cmd = parts[0]

        attr = getattr(self.calendar, cmd)
        try:
            return getattr(attr, parts[1])
        except AttributeError:
            try:
                return attr(parts[1:])
            except TypeError:
                return repr(attr)
コード例 #5
0
    def run(self, message):
        (_, parts) = message_parts(message)

        self.logger.debug(_)
        self.logger.debug(parts)

        if _.lower() == 'what':
            if parts[0].lower() == 'is':
                parts = parts[1:]
            return self.cmd_recall(' '.join(parts))

        msg = f"{_} {' '.join(parts)}".strip()
        if msg[-1] == '?':
            return self.cmd_recall(msg[:-1])

        if '=' in parts:
            (term, definition) = ' '.join(parts).split('=', 1)
            return self.cmd_remember(message.author, term, definition)
コード例 #6
0
ファイル: hoarding.py プロジェクト: evilchili/telisar
    def run(self, message):
        """
        Message routing for commands.
        """
        args = message_parts(message)[1]
        response = None

        # .hoard n
        try:
            count = int(args[0])
        except (IndexError, TypeError):
            pass
        else:
            response = self.cmd_hoard_n(count)

        # .hoard
        if not response:
            response = self.cmd_hoard()

        return response