コード例 #1
0
ファイル: bot.py プロジェクト: jimcarreer/Frisky
 def parse_message_string(self, message: str) -> Tuple[str, Tuple[str]]:
     if message is None or len(message) == 0:
         return '', tuple()
     if message.startswith(self.prefix):
         message = message[len(self.prefix):]
     elif message.startswith(f'@{self.name}'):
         message = message[len(self.name) + 1:]
     else:
         return '', tuple()
     message = message.strip()
     tokens = quotesplit(message)
     command = tokens[0]
     args = tuple(tokens[1:])
     return command, args
コード例 #2
0
ファイル: pipe.py プロジェクト: jordanbray/Frisky
    def handle_message(self, message: MessageEvent) -> Optional[str]:
        """
        example usage: `?pipe votes thing | learn thing | ping`
        :param message:
        :return:
        """
        if message.command not in ('pipe', '|'):
            return
        built_args = []
        for arg in message.args:
            arg = arg.strip()
            if ' ' in arg:
                built_args.append(f'"{arg}"')
            else:
                built_args.append(arg)
        raw_text = ' '.join(built_args)
        split_commands = raw_text.split('|')

        previous_result: Optional[str] = None
        for item in split_commands:
            item = item.strip(' ')
            if previous_result:
                item = ' '.join([item, f'"{previous_result}"'])
            split_item = quotesplit(item.strip(' '))
            command: str = split_item[0]
            args: List[str] = split_item[1:]
            plugin = self.get_plugin_for_command(command)

            event = MessageEvent(username=message.username,
                                 channel_name=message.channel_name,
                                 text=item,
                                 command=command,
                                 args=args)
            if plugin is None:
                plugin = self.get_generic_handler()
                if plugin is None:
                    return
                event = self.convert_message_to_generic(event)
            previous_result = plugin.handle_message(event)
        return previous_result
コード例 #3
0
ファイル: tests.py プロジェクト: jordanbray/Frisky
 def test_quotesplit_errors_with_dupe_chars(self):
     with self.assertRaises(ValueError):
         quotesplit("", separators=('a', 'b'), groupers=('b', 'c'))
コード例 #4
0
ファイル: tests.py プロジェクト: jordanbray/Frisky
 def test_quotesplit_nested(self):
     result = quotesplit('foo "bar \'blah\'"')
     expected = ['foo', "bar 'blah'"]
     self.assertEqual(result, expected)
コード例 #5
0
ファイル: tests.py プロジェクト: jordanbray/Frisky
 def test_quotesplit_empty(self):
     result = quotesplit('foo ""')
     expected = ['foo', '']
     self.assertEqual(result, expected)
コード例 #6
0
ファイル: tests.py プロジェクト: jordanbray/Frisky
 def test_quotesplit_with_quotes(self):
     result = quotesplit('foo bar "foo bar"')
     expected = ['foo', 'bar', 'foo bar']
     self.assertEqual(result, expected)
コード例 #7
0
ファイル: tests.py プロジェクト: jordanbray/Frisky
 def test_basic_quotesplit(self):
     result = quotesplit('foo bar')
     expected = ['foo', 'bar']
     self.assertEqual(result, expected)