Exemplo n.º 1
0
    async def handleEvent(self, twitchChannel: Channel, twitchUser: User,
                          tags: Dict[str, Any]) -> bool:
        if twitchChannel is None:
            raise ValueError(
                f'twitchChannel argument is malformed: \"{twitchChannel}\"')
        elif twitchUser is None:
            raise ValueError(
                f'twitchUser argument is malformed: \"{twitchUser}\"')
        elif tags is None:
            raise ValueError(f'tags argument is malformed: \"{tags}\"')

        if not twitchUser.isChatLoggingEnabled():
            return False

        raidedByName = tags.get('msg-param-displayName')
        if not utils.isValidStr(raidedByName):
            raidedByName = tags.get('display-name')
        if not utils.isValidStr(raidedByName):
            raidedByName = tags.get('login')

        if not utils.isValidStr(raidedByName):
            self.__timber.log(
                'RaidLogEvent',
                f'{twitchUser.getHandle()} was raided, but the tags dictionary seems to have strange values: {tags}'
            )
            return False

        raidSize = utils.getIntFromDict(tags, 'msg-param-viewerCount', 0)

        self.__chatLogger.logRaid(raidSize=raidSize,
                                  fromWho=raidedByName,
                                  twitchChannel=twitchChannel)

        return True
Exemplo n.º 2
0
    async def handleMessage(self, twitchUser: User, message: Message) -> bool:
        if twitchUser is None:
            raise ValueError(
                f'twitchUser argument is malformed: \"{twitchUser}\"')
        elif message is None:
            raise ValueError(f'message argument is malformed: \"{message}\"')

        if not twitchUser.isChatLoggingEnabled():
            return False

        self.__chatLogger.logMessage(twitchChannel=twitchUser.getHandle(),
                                     userId=str(message.author.id),
                                     userName=message.author.name,
                                     msg=utils.cleanStr(message.content))

        return True