Exemplo n.º 1
0
    def setUp(self):
        self.now = datetime(2000, 1, 1)
        self.tags = IrcMessageTags()
        self.channel = Mock(spec=Channel)
        self.channel.channel = 'botgotsthis'
        self.data = Mock(spec=CacheStore)
        self.data.hasFeature.return_value = False
        self.database = Mock(spec=DatabaseMain)
        self.database.hasFeature.return_value = False
        self.permissions = MagicMock(spec=ChatPermissionSet)
        self.command = CustomCommand('Kappa KappaRoss KappaPride', '#global',
                                     '')
        self.args = ChatCommandArgs(self.data,
                                    self.channel, self.tags, 'botgotsthis',
                                    Message('Kappa'), self.permissions,
                                    self.now)

        patcher = patch(library.__name__ + '.split_message', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_split = patcher.start()

        patcher = patch(library.__name__ + '.convert_field')
        self.addCleanup(patcher.stop)
        self.mock_convert = patcher.start()
        self.mock_convert.side_effect = lambda args: args.default

        patcher = patch(library.__name__ + '.format', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_format = patcher.start()
        self.mock_format.side_effect = lambda string, format, has: string

        patcher = patch('lib.items.custom', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_list = patcher.start()
        self.mock_list.postProcess.return_value = []
Exemplo n.º 2
0
 async def test_multiple_permissions_with_channel(self):
     self.permissions['turbo'] = True
     self.permissions['subscriber'] = True
     self.permissions['moderator'] = True
     self.permissions['broadcaster'] = True
     self.data.getChatCommands.return_value = {
         'botgotsthis': {
             '': 'Kappa',
             'turbo': 'KappaClaus',
             'subscriber': 'KappaRoss',
             'moderator': 'KappaPride',
             'broadcaster': 'KappaHD',
         },
         '#global': {
             '': ':(',
             'turbo': ':s',
             'subscriber': ':o',
             'moderator': 'R)',
             'broadcaster': ':)',
         }
     }
     self.assertEqual(
         await library.get_command(self.data, '!kappa', 'botgotsthis',
                                   self.permissions),
         CustomCommand('KappaHD', 'botgotsthis', 'broadcaster'))
     self.data.getChatCommands.assert_called_once_with(
         'botgotsthis', '!kappa')
Exemplo n.º 3
0
 async def test_public_command(self):
     self.data.getChatCommands.return_value = {
         'botgotsthis': {
             '': 'Kappa'
         },
         '#global': {}
     }
     self.assertEqual(
         await library.get_command(self.data, '!kappa', 'botgotsthis',
                                   self.permissions),
         CustomCommand('Kappa', 'botgotsthis', ''))
     self.data.getChatCommands.assert_called_once_with(
         'botgotsthis', '!kappa')
Exemplo n.º 4
0
async def get_command(
        data: CacheStore, command: str, channel: str,
        permissions: ChatPermissionSet) -> Optional[CustomCommand]:
    commands: Dict[str, Dict[str, str]]
    commands = await data.getChatCommands(channel, command)
    permission: str
    broadcaster: str
    message: str
    for permission in reversed(permissionsOrder):
        if not permission or permissions[permission]:
            for broadcaster in [channel, '#global']:
                if permission in commands[broadcaster]:
                    message = commands[broadcaster][permission]
                    return CustomCommand(message, broadcaster, permission)
    return None
Exemplo n.º 5
0
    def setUp(self):
        super().setUp()
        self.args = self.args._replace(message=Message('Kappa'))
        self.permissions.moderator = True
        self.permissions.chatModerator = False
        self.command = CustomCommand('Kappa', '#global', '')

        patcher = patch('bot.config', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_config = patcher.start()
        self.mock_config.customMessageCooldown = 5
        self.mock_config.customMessageUserCooldown = 30

        patcher = patch('lib.helper.chat.inCooldown', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_channel_cooldown = patcher.start()
        self.mock_channel_cooldown.return_value = False

        patcher = patch('lib.helper.chat.in_user_cooldown', autospec=True)
        self.addCleanup(patcher.stop)
        self.mock_user_cooldown = patcher.start()
        self.mock_user_cooldown.return_value = False

        patcher = patch('lib.helper.timeout.record_timeout')
        self.addCleanup(patcher.stop)
        self.mock_timeout = patcher.start()

        patcher = patch(library.__name__ + '.get_command')
        self.addCleanup(patcher.stop)
        self.mock_command = patcher.start()
        self.mock_command.return_value = self.command

        patcher = patch(library.__name__ + '.create_messages')
        self.addCleanup(patcher.stop)
        self.mock_messages = patcher.start()
        self.mock_messages.return_value = []