Beispiel #1
0
    async def destination_channel(self):
        """
        Returns the destination channel for this event.

        :rtype: discord.Channel
        """
        if self._destination_channel is not _sentinel:
            return self._destination_channel

        if self.event.message_scope == 'gameId':
            self._destination_channel = self.channel
            return self.channel
        elif self.event.message_scope == 'userId':
            if self.event.user_id == self.event.message_target:  # optimization: we already got this user (probably)
                discord_user = await self.get_discord_user()
            else:
                discord_user = await ddb_id_to_discord_user(
                    self, self.event.message_target, self.guild)

            if discord_user is None:  # we did our best to find the user, but oh well
                raise IgnoreEvent(
                    f"could not find discord user associated with userId: {self.event.message_target!r}"
                )

            # try to find an existing dmchannel with the user
            existing_dmchannel = discord_user.dm_channel
            if existing_dmchannel is not None:
                self._destination_channel = existing_dmchannel
                return existing_dmchannel

            # otherwise we have to create a dmchannel :(
            self._destination_channel = await discord_user.create_dm()
            return self._destination_channel
        else:
            raise ValueError("message scope must be gameId or userId")
Beispiel #2
0
 async def wrapped(self, gctx: GameLogEventContext, *args, **kwargs):
     # to avoid having to load the entire ddb user (slow!) we just check the user id in launchdarkly
     # the user must have connected their account to get here, so we don't have to worry about populating
     # custom attributes/username/etc
     # note: this means that feature flag targeting can only be controlled by global or individual user id
     # but still, better than nothing
     user_id = gctx.event.user_id
     flag_on = await gctx.bot.ldclient.variation(
         flag_name, {"key": user_id}, default)
     if not flag_on:
         raise IgnoreEvent(
             f"Feature flag {flag_name!r} is disabled for user {user_id}"
         )
     return await inner(self, gctx, *args, **kwargs)
Beispiel #3
0
    async def character_update_fulfilled(
            self, gctx: GameLogEventContext,
            data: ddb.character.scds_types.SCDSMessageBrokerData):
        char = await gctx.get_character()
        if char is None:
            raise IgnoreEvent("Character is not imported")

        character_id = data.character_id
        ddb_user = await self.bot.ddb.get_ddb_user(gctx, gctx.discord_user_id)
        resp = await self.bot.ddb.scds.get_characters(ddb_user, [character_id])
        if not resp.found_characters:
            return
        scds_char = resp.found_characters[0]

        hp_result = self.sync_hp(char, scds_char.hit_point_info)
        death_save_result = self.sync_death_saves(char,
                                                  scds_char.death_save_info)

        if any((hp_result.changed, death_save_result.changed)):
            await self.send_sync_result(gctx, char, hp_result,
                                        death_save_result)
            await char.commit(gctx, do_live_integrations=False)
Beispiel #4
0
    async def destination_channel(self):
        """
        Returns the destination channel for this event.

        :rtype: discord.Channel
        """
        if self.event.message_scope == 'gameId':
            return self.channel
        elif self.event.message_scope == 'userId':
            if self.event.user_id == self.event.message_target:  # optimization: we already got this user (probably)
                destination = await self.get_discord_user()
            else:
                destination = await ddb_id_to_discord_user(
                    self, self.event.message_target, self.guild)

            if destination is None:  # we did our best to find the user, but oh well
                raise IgnoreEvent(
                    f"could not find discord user associated with userId: {self.event.message_target!r}"
                )
            # noinspection PyProtectedMember
            # :(
            return await destination._get_channel()
        else:
            raise ValueError("message scope must be gameId or userId")