Example #1
0
 async def test_command_property_false(self):
     input = CommandActionTokens('', self.broadcaster, '', 'Kappa', '')
     self.assertIs(await channel.command_property(self.args, input), False)
     self.permissionSet['broadcaster'] = True
     self.assertIs(await channel.command_property(self.args, input), False)
     self.assertFalse(self.data.processCustomCommandProperty.called)
     self.assertFalse(self.channel.send.called)
Example #2
0
 def test_level_blank(self):
     for level in ['', 'any', 'ANY', 'all', 'public']:
         message = Message('!command add level=%s Kappa' % level)
         self.assertEqual(
             library.parse_action_message(message, 'botgotsthis'),
             CommandActionTokens('add', 'botgotsthis', '', 'Kappa', ''),
             level)
Example #3
0
 def test_level_global_moderator(self):
     for level in ['globalmod', 'globalMod', 'global_mod', 'gmod']:
         message = Message('!command add level=%s Kappa' % level)
         self.assertEqual(
             library.parse_action_message(message, 'botgotsthis'),
             CommandActionTokens('add', 'botgotsthis', 'globalMod', 'Kappa',
                                 ''), level)
Example #4
0
 def test_level_admin(self):
     for level in ['admin', 'twitchadmin']:
         message = Message('!command add level=%s Kappa' % level)
         self.assertEqual(
             library.parse_action_message(message, 'botgotsthis'),
             CommandActionTokens('add', 'botgotsthis', 'admin', 'Kappa',
                                 ''), level)
Example #5
0
 async def test_no_action(self):
     self.mock_input.return_value = CommandActionTokens(
         'test', self.broadcaster, '', 'Kappa', '')
     self.assertIs(
         await channel.process_command(self.args, self.broadcaster), False)
     self.mock_input.assert_called_once_with(self.message, self.broadcaster)
     self.assertFalse(self.channel.send.called)
Example #6
0
 def test_level_owner(self):
     for level in ['owner', 'self', 'bot']:
         message = Message('!command add level=%s Kappa' % level)
         self.assertEqual(
             library.parse_action_message(message, 'botgotsthis'),
             CommandActionTokens('add', 'botgotsthis', 'owner', 'Kappa',
                                 ''), level)
Example #7
0
 async def test_level_permission_wrong(self):
     self.mock_input.return_value = CommandActionTokens(
         'test', self.broadcaster, 'Kappa', 'Kappa', '')
     self.assertIs(
         await channel.process_command(self.args, self.broadcaster), True)
     self.mock_input.assert_called_once_with(self.message, self.broadcaster)
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Invalid level'))
Example #8
0
 async def test_rename(self, mock_rename):
     mock_rename.return_value = True
     input = CommandActionTokens('rename', self.broadcaster, '', '', '')
     self.mock_input.return_value = input
     self.assertIs(
         await channel.process_command(self.args, self.broadcaster), True)
     self.mock_input.assert_called_once_with(self.message, self.broadcaster)
     mock_rename.assert_called_once_with(self.args, input)
     self.assertFalse(self.channel.send.called)
Example #9
0
 async def test_level_command_dberror(self):
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'moderator')
     self.data.levelCustomCommand.return_value = False
     self.assertIs(await channel.level_command(self.args, input), True)
     self.data.levelCustomCommand.assert_called_once_with(
         self.broadcaster, '', 'Kappa', 'botgotsthis', 'moderator')
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Kappa', 'change', 'not', 'success'))
Example #10
0
 async def test_delete_command_dberror(self):
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'PogChamp')
     self.data.deleteCustomCommand.return_value = False
     self.assertIs(await channel.delete_command(self.args, input), True)
     self.data.deleteCustomCommand.assert_called_once_with(
         self.broadcaster, '', 'Kappa', 'botgotsthis')
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Kappa', 'remove', 'not', 'success'))
Example #11
0
 async def test_append_command(self):
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'PogChamp')
     self.data.appendCustomCommand.return_value = True
     self.assertIs(await channel.append_command(self.args, input), True)
     self.data.appendCustomCommand.assert_called_once_with(
         self.broadcaster, '', 'Kappa', 'PogChamp', 'botgotsthis')
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Kappa', 'append', 'success'))
Example #12
0
 async def test_level_command_unknown_level(self):
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'PogChamp DansGame')
     self.data.levelCustomCommand.return_value = True
     self.assertIs(await channel.level_command(self.args, input), True)
     self.assertFalse(self.data.levelCustomCommand.called)
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'PogChamp DansGame', 'invalid',
                     'permission'))
Example #13
0
 async def test_command_property_empty(self, mock_list):
     mock_list.properties.return_value = []
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'someproperty PogChamp')
     self.permissionSet['broadcaster'] = True
     self.assertIs(await channel.command_property(self.args, input), True)
     self.assertFalse(self.data.processCustomCommandProperty.called)
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'someproperty', 'property', 'not',
                     'exist'))
Example #14
0
 async def test_raw_command_not_exist(self, mock_whisper, mock_config):
     mock_config.messageLimit = 100
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'PogChamp')
     self.data.getCustomCommand.return_value = None
     self.assertIs(await channel.raw_command(self.args, input), True)
     self.data.getCustomCommand.assert_called_once_with(
         self.broadcaster, '', 'Kappa')
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Kappa', 'not', 'exist'))
     self.assertFalse(mock_whisper.called)
Example #15
0
 async def test_command_property_no_value(self, mock_list):
     mock_list.properties.return_value = ['someproperty']
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'someproperty')
     self.data.processCustomCommandProperty.return_value = True
     self.permissionSet['broadcaster'] = True
     self.assertIs(await channel.command_property(self.args, input), True)
     self.data.processCustomCommandProperty.assert_called_once_with(
         self.broadcaster, '', 'Kappa', 'someproperty', None)
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'Kappa', 'someproperty', 'unset'))
Example #16
0
 async def test_raw_command(self, mock_whisper, mock_config):
     mock_config.messageLimit = 100
     input = CommandActionTokens('', self.broadcaster, '',
                                 'Kappa', 'PogChamp')
     self.data.getCustomCommand.return_value = 'KappaRoss KappaPride'
     self.assertIs(await channel.raw_command(self.args, input), True)
     self.data.getCustomCommand.assert_called_once_with(
         self.broadcaster, '', 'Kappa')
     mock_whisper.assert_called_once_with(
         'botgotsthis',
         IterableMatch('KappaRoss KappaPride'))
     self.assertFalse(self.channel.send.called)
Example #17
0
def parse_action_message(message: Message,
                         broadcaster: str) -> Optional[CommandActionTokens]:
    try:
        action = message.lower[1]
        i = 2
        level: Optional[str] = None
        if message[2].startswith('level='):
            i = 3
            level = message.lower[2][len('level='):]
        if level in permissions:
            level = permissions[level]
        else:
            level = None
        command = message[i]
        text = message[i + 1:]

        return CommandActionTokens(action, broadcaster, level, command, text)
    except Exception:
        return None
Example #18
0
 def test_level_unknown(self):
     message = Message('!command add level=abc Kappa')
     self.assertEqual(
         library.parse_action_message(message, 'botgotsthis'),
         CommandActionTokens('add', 'botgotsthis', None, 'Kappa', ''))
Example #19
0
 def test_level_5_args(self):
     message = Message('!command add level=owner Kappa PogChamp  KreyGasm')
     self.assertEqual(
         library.parse_action_message(message, 'botgotsthis'),
         CommandActionTokens('add', 'botgotsthis', 'owner', 'Kappa',
                             'PogChamp  KreyGasm'))
Example #20
0
 def test_wrong_level_2_args(self):
     message = Message('!command level=owner add')
     self.assertEqual(
         library.parse_action_message(message, 'botgotsthis'),
         CommandActionTokens('level=owner', 'botgotsthis', '', 'add', ''))
Example #21
0
 def test_4_args(self):
     message = Message('!command add Kappa PogChamp')
     self.assertEqual(
         library.parse_action_message(message, 'botgotsthis'),
         CommandActionTokens('add', 'botgotsthis', '', 'Kappa', 'PogChamp'))
Example #22
0
 async def test_rename_command_blank(self):
     input = CommandActionTokens('', self.broadcaster, '', 'Kappa', '')
     self.assertIs(await channel.rename_command(self.args, input), True)
     self.assertFalse(self.data.renameCustomCommand.called)
     self.channel.send.assert_called_once_with(
         StrContains(self.args.nick, 'specify', 'command', 'rename'))