Пример #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}\"')

        generalSettings = await self.__generalSettingsRepository.getAllAsync()
        authSnapshot = await self.__authRepository.getAllAsync()

        if not generalSettings.isSubGiftThankingEnabled():
            return False
        elif not twitchUser.isSubGiftThankingEnabled():
            return False

        giftedByName: str = tags.get('display-name')
        if not utils.isValidStr(giftedByName):
            giftedByName = tags.get('login')

        giftedToName: str = tags.get('msg-param-recipient-display-name')
        if not utils.isValidStr(giftedToName):
            giftedToName = tags.get('msg-param-recipient-user-name')

        if giftedToName.lower() != authSnapshot.requireNick().lower():
            return False
        elif not utils.isValidStr(giftedByName):
            return False
        elif giftedToName.lower() == giftedByName.lower():
            return False

        self.__eventLoop.create_task(
            twitchUtils.waitThenSend(
                messageable=twitchChannel,
                delaySeconds=5,
                message=
                f'😻 Thank you for the gifted sub @{giftedByName}! ✨'))

        self.__timber.log(
            'SubGiftThankingEvent',
            f'{authSnapshot.requireNick()} received sub gift to {twitchUser.getHandle()} from {giftedByName}!'
        )
        return True