Beispiel #1
0
 def test_in_cooldown_existing(self):
     sessionData = {'': self.now - timedelta(hours=1)}
     self.channel.sessionData = sessionData
     self.assertIs(chat.inCooldown(self.args, timedelta(hours=1), ''),
                   False)
     self.assertIn('', sessionData)
     self.assertEqual(sessionData[''], self.now)
Beispiel #2
0
 def test_in_cooldown_level_override(self):
     sessionData = {'': self.now - timedelta(seconds=1)}
     self.channel.sessionData = sessionData
     self.permissions.__getitem__.return_value = True
     self.assertIs(chat.inCooldown(self.args, timedelta(hours=1), '', ''),
                   False)
     self.assertIn('', sessionData)
     self.assertEqual(sessionData[''], self.now)
Beispiel #3
0
async def process_wall(args: ChatCommandArgs, repetition: str,
                       rows: int) -> bool:
    if not args.permissions.broadcaster:
        rows = min(rows, 10)

        cooldown: timedelta
        cooldown = timedelta(seconds=bot.config.spamModeratorCooldown)
        if chat.inCooldown(args, cooldown, 'modWall'):
            return False
    elif not args.permissions.globalModerator:
        rows = min(rows, 500)
    spacer: str = '' if args.permissions.chatModerator else ' \ufeff'
    messages: Iterator[str] = (repetition + ('' if i % 2 == 0 else spacer)
                               for i in range(rows))
    args.chat.send(messages, -1)
    if args.permissions.chatModerator:
        await timeout.record_timeout(args.chat, args.nick, repetition,
                                     str(args.message), 'wall')
    return True
Beispiel #4
0
async def customCommands(args: ChatCommandArgs) -> bool:
    command: Optional[CustomCommand]
    command = await library.get_command(args.data, args.message.command,
                                        args.chat.channel, args.permissions)
    if command is not None:
        cooldown: timedelta
        cooldown = timedelta(seconds=bot.config.customMessageCooldown)
        if chat.inCooldown(args, cooldown, 'customCommand', 'moderator'):
            return False

        cooldown = timedelta(seconds=bot.config.customMessageUserCooldown)
        if chat.in_user_cooldown(args, cooldown, 'customUserCommand',
                                 'moderator'):
            return False

        msgs: List[str] = await library.create_messages(command, args)
        args.chat.send(msgs)
        if args.permissions.chatModerator:
            await timeout.record_timeout(args.chat, args.nick, msgs,
                                         str(args.message), 'custom')
        return True
    return False
Beispiel #5
0
async def process_pyramid(args: ChatCommandArgs,
                          repetition: str,
                          count: int) -> bool:
    count = min(count, (bot.config.messageLimit + 1) // (len(repetition) + 1))
    if not args.permissions.broadcaster:
        count = min(count, 5)

        cooldown: timedelta
        cooldown = timedelta(seconds=bot.config.spamModeratorCooldown)
        if chat.inCooldown(args, cooldown, 'modPyramid'):
            return False
    elif not args.permissions.globalModerator:
        count = min(count, 20)
    messages: Iterator[str] = itertools.chain(
        (' '.join((repetition,) * i) for i in range(1, count)),
        (' '.join((repetition,) * i) for i in range(count, 0, -1))
        )
    if args.permissions.chatModerator:
        await timeout.record_timeout(
            args.chat, args.nick, ' '.join((repetition,) * count),
            str(args.message), 'pyramid')
    args.chat.send(messages, -1)
    return True
Beispiel #6
0
async def commandRandomPyramid(args: ChatCommandArgs) -> bool:
    emoteSets: Optional[Set[int]] = await args.data.twitch_get_bot_emote_set()
    if emoteSets is None:
        return False
    if not await args.data.twitch_load_emotes(emoteSets):
        return False
    emotes: Optional[Dict[int, str]] = await args.data.twitch_get_emotes()
    if emotes is None:
        return False
    count: int = 5 if args.permissions.broadcaster else 3
    # If below generate a ValueError or IndexError,
    # only the above line gets used
    with suppress(ValueError, IndexError):
        count = int(args.message[1])
    rep = []
    if not args.permissions.broadcaster:
        count = min(count, 5)

        cooldown: timedelta
        cooldown = timedelta(seconds=bot.config.spamModeratorCooldown)
        if chat.inCooldown(args, cooldown, 'modPyramid'):
            return False
    elif not args.permissions.globalModerator:
        count = min(count, 20)
    emoteIds: List[int] = list(emotes.keys())
    _i: int
    for _i in range(count):
        rep.append(emotes[random.choice(emoteIds)])
        if len(' '.join(rep)) > bot.config.messageLimit:
            del rep[-1]
            count = len(rep)
            break
    messages: Iterator[str] = itertools.chain(
        (' '.join(rep[0:i]) for i in range(1, count)),
        (' '.join(rep[0:i]) for i in range(count, 0, -1)))
    args.chat.send(messages, -1)
    return True
Beispiel #7
0
 def test_in_cooldown_recent(self):
     sessionData = {'': self.now - timedelta(seconds=1)}
     self.channel.sessionData = sessionData
     self.assertIs(chat.inCooldown(self.args, timedelta(hours=1), ''), True)
     self.assertIn('', sessionData)
     self.assertEqual(sessionData[''], self.now - timedelta(seconds=1))