Пример #1
0
    async def invited(self, ctx):
        """Show a list of invited members (Admin only, requires registration)"""
        manager = MessageManager(ctx)

        admin_db = await self.bot.database.get_member_by_discord_id(
            ctx.author.id)
        clan_db = await self.get_admin_group(ctx)

        members = await execute_pydest_auth(
            self.bot.ext_conns,
            self.bot.destiny.api.get_group_invited_members,
            admin_db,
            manager,
            group_id=clan_db.clan_id,
            access_token=admin_db.bungie_access_token,
            return_type=DestinyGroupPendingMembersResponse)

        embed = discord.Embed(colour=constants.BLUE,
                              title=f"Invited Clan Members in {clan_db.name}")

        if len(members.response.results) == 0:
            embed.description = "None"
        else:
            for member in members.response.results:
                bungie_name = member.destiny_user_info.display_name
                bungie_member_id = member.destiny_user_info.membership_id
                bungie_member_type = member.destiny_user_info.membership_type
                date_invited = date_as_string(member.creation_date,
                                              with_tz=True)
                bungie_url = f"https://www.bungie.net/en/Profile/{bungie_member_type}/{bungie_member_id}"
                member_info = f"Date Invited: {date_invited}\nProfile: {bungie_url}"
                embed.add_field(name=bungie_name, value=member_info)

        await manager.send_embed(embed)
Пример #2
0
    async def info(self, ctx, *args):
        """Show member information"""
        manager = MessageManager(ctx)
        member_name = " ".join(args)
        requestor_db = await get_requestor(ctx, include_clan=True)

        if not member_name:
            clanmember_db = requestor_db
            member_name = ctx.author.nick
            member_discord = ctx.message.author
            discord_username = str(ctx.message.author)
        else:
            try:
                member_discord = await commands.MemberConverter().convert(
                    ctx, str(member_name))
            except BadArgument:
                discord_username = None
            else:
                discord_username = str(member_discord)

            clanmember_db = await self.bot.database.get_member_by_naive_username(
                member_name)
            if not clanmember_db:
                return await manager.send_and_clean(
                    f"Could not find username `{member_name}` in any connected clans"
                )

        member_db = clanmember_db.member

        the100_link = None
        if member_db.the100_username:
            the100_url = (
                f"https://www.the100.io/users/{quote(member_db.the100_username)}"
            )
            the100_link = f"[{member_db.the100_username}]({the100_url})"

        bungie_link = None
        if member_db.bungie_id:
            bungie_info = await execute_pydest(
                self.bot.destiny.api.get_membership_data_by_id,
                member_db.bungie_id,
                return_type=DestinyMembershipResponse,
            )
            if not bungie_info.response:
                bungie_link = member_db.bungie_username
            else:
                bungie_member_data = DestinyUser(bungie_info.response)
                bungie_member_id = bungie_member_data.memberships.bungie.id
                bungie_member_type = constants.PLATFORM_BUNGIE
                bungie_member_name = bungie_member_data.memberships.bungie.username
                bungie_url = f"https://www.bungie.net/en/Profile/{bungie_member_type}/{bungie_member_id}"
                bungie_link = f"[{bungie_member_name}]({bungie_url})"

        timezone = None
        if member_db.timezone:
            tz = datetime.now(pytz.timezone(member_db.timezone))
            timezone = f"{tz.strftime('UTC%z')} ({tz.tzname()})"

        if member_db.discord_id:
            member_discord = await commands.MemberConverter().convert(
                ctx, str(member_db.discord_id))
            discord_username = str(member_discord)

        requestor_is_admin = False
        if requestor_db and requestor_db.member_type >= constants.CLAN_MEMBER_ADMIN:
            requestor_is_admin = True

        member_is_admin = False
        if clanmember_db.member_type >= constants.CLAN_MEMBER_ADMIN:
            member_is_admin = True

        embed = discord.Embed(colour=constants.BLUE,
                              title=f"Member Info for {member_name}")
        embed.add_field(
            name="Clan",
            value=f"{clanmember_db.clan.name} [{clanmember_db.clan.callsign}]",
        )
        embed.add_field(name="Join Date",
                        value=date_as_string(clanmember_db.join_date))

        if requestor_is_admin:
            embed.add_field(name="Last Active Date",
                            value=date_as_string(clanmember_db.last_active))

        embed.add_field(name="Time Zone", value=timezone)
        embed.add_field(name="Xbox Gamertag", value=member_db.xbox_username)
        embed.add_field(name="PSN Username", value=member_db.psn_username)
        embed.add_field(name="Steam Username", value=member_db.steam_username)
        embed.add_field(name="Stadia Username",
                        value=member_db.stadia_username)
        embed.add_field(name="Discord Username", value=discord_username)
        embed.add_field(name="Destiny Username", value=bungie_link)
        embed.add_field(name="The100 Username", value=the100_link)
        embed.add_field(
            name="Is Sherpa",
            value=constants.EMOJI_CHECKMARK
            if clanmember_db.is_sherpa else constants.EMOJI_CROSSMARK,
        )
        embed.add_field(
            name="Is Admin",
            value=constants.EMOJI_CHECKMARK
            if member_is_admin else constants.EMOJI_CROSSMARK,
        )
        embed.set_footer(text="All times shown in UTC")
        await manager.send_embed(embed)
Пример #3
0
    async def info(self, ctx, *args):
        """Show information for all connected clans"""
        redis_cache = self.bot.ext_conns["redis_cache"]
        manager = MessageManager(ctx)

        clan_dbs = await self.bot.database.get_clans_by_guild(ctx.guild.id)

        if not clan_dbs:
            return await manager.send_and_clean(
                "No connected clans found", mention=False
            )

        embeds = []
        clan_redis_key = f"{ctx.guild.id}-clan-info"
        clan_info_redis = await redis_cache.get(clan_redis_key)
        if clan_info_redis and "-nocache" not in args:
            log.debug(f"{clan_redis_key} {clan_info_redis}")
            await redis_cache.expire(clan_redis_key, constants.TIME_HOUR_SECONDS)
            embeds = [
                discord.Embed.from_dict(embed)
                for embed in deserializer(clan_info_redis)
            ]
        else:
            for clan_db in clan_dbs:
                group = await execute_pydest(
                    self.bot.destiny.api.get_group,
                    clan_db.clan_id,
                    return_type=DestinyGroupResponse,
                )
                if not group.response:
                    log.error(
                        f"Could not get details for clan {clan_db.name} ({clan_db.clan_id}) - "
                        f"{group.error_status} {group.error_description}"
                    )
                    return await manager.send_and_clean(
                        f"Clan {clan_db.name} not found", mention=False
                    )
                else:
                    group = group.response

                embed = discord.Embed(
                    colour=constants.BLUE,
                    title=group.detail.motto,
                    description=group.detail.about,
                )
                embed.set_author(
                    name=f"{group.detail.name} [{group.detail.clan_info.clan_callsign}]",
                    url=f"https://www.bungie.net/en/ClanV2?groupid={clan_db.clan_id}",
                )
                embed.add_field(
                    name="Members", value=group.detail.member_count, inline=True
                )
                embed.add_field(
                    name="Founder",
                    value=group.founder.bungie_net_user_info.display_name,
                    inline=True,
                )
                embed.add_field(
                    name="Founded",
                    value=date_as_string(group.detail.creation_date),
                    inline=True,
                )
                embeds.append(embed)
            await redis_cache.set(
                clan_redis_key,
                serializer([embed.to_dict() for embed in embeds]),
                expire=constants.TIME_HOUR_SECONDS,
            )

        if len(embeds) > 1:
            paginator = EmbedPages(ctx, embeds)
            await paginator.paginate()
        else:
            await manager.send_embed(embeds[0])
Пример #4
0
    async def create_application_embed(self, ctx, requestor_db, guild_db):
        redis_cache = self.bot.ext_conns["redis_cache"]

        if requestor_db.bungie_username:
            membership_name = requestor_db.bungie_username

        platform_id, membership_id, _ = get_primary_membership(requestor_db)

        group_id = None
        group_name = None
        groups_info = await execute_pydest(
            self.bot.destiny.api.get_groups_for_member,
            platform_id,
            membership_id,
            return_type=DestinyMemberGroupResponse,
        )
        if len(groups_info.response.results) > 0:
            for group in groups_info.response.results:
                if group.member.destiny_user_info.membership_id == membership_id:
                    group_id = group.group.group_id
                    group_name = group.group.name

        if group_id and group_name:
            group_url = f"https://www.bungie.net/en/ClanV2/Index?groupId={group_id}"
            group_link = f"[{group_name}]({group_url})"
        else:
            group_link = "None"

        last_active = await get_last_active(
            self.bot.ext_conns, platform_id=platform_id, member_id=membership_id
        )

        embed = discord.Embed(
            colour=constants.BLUE,
            title=f"Clan Application for {ctx.author.display_name}",
        )

        bungie_url = f"https://www.bungie.net/en/Profile/{platform_id}/{membership_id}"
        bungie_link = f"[{membership_name}]({bungie_url})"

        if requestor_db.discord_id:
            member_discord = await commands.MemberConverter().convert(
                ctx, str(requestor_db.discord_id)
            )
            discord_username = str(member_discord)

        embed.add_field(name="Last Active Date", value=date_as_string(last_active))
        embed.add_field(name="Bungie Username", value=bungie_link)
        embed.add_field(name="Current Clan", value=group_link)
        embed.add_field(name="Xbox Gamertag", value=requestor_db.xbox_username)
        embed.add_field(name="PSN Username", value=requestor_db.psn_username)
        embed.add_field(name="Steam Username", value=requestor_db.steam_username)
        embed.add_field(name="Stadia Username", value=requestor_db.stadia_username)
        embed.add_field(name="Discord Username", value=discord_username)
        embed.set_footer(text="All times shown in UTC")
        embed.set_thumbnail(url=str(ctx.author.avatar_url))

        await redis_cache.set(
            f"{ctx.guild.id}-clan-application-{requestor_db.id}", serializer(embed)
        )
        return embed