From de5f8b548d23eeca64b0b93379cf2fac95db858f Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 4 Sep 2022 11:20:37 +0200 Subject: [PATCH] remove pve only stats from pvp. closes #188 --- .../backgroundEvents/clanRoleAssigment.py | 43 +++++++++---------- ElevatorBot/commandHelpers/optionTemplates.py | 16 +++++-- ElevatorBot/commands/a_destiny/stat/pvp.py | 2 +- ElevatorBot/discordEvents/memberEvents.py | 1 + 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/ElevatorBot/backgroundEvents/clanRoleAssigment.py b/ElevatorBot/backgroundEvents/clanRoleAssigment.py index 841e9a20..b2203712 100644 --- a/ElevatorBot/backgroundEvents/clanRoleAssigment.py +++ b/ElevatorBot/backgroundEvents/clanRoleAssigment.py @@ -23,25 +23,24 @@ async def run(self, client: ElevatorClient): persistent_messages = PersistentMessages(ctx=None, guild=guild, message_name="clan_role") result = await persistent_messages.get() - if not result: - continue - clan_role = await guild.fetch_role(result.channel_id) - if not clan_role: - continue - - # get clan members - destiny_clan = DestinyClan(ctx=None, discord_guild=guild) - clan_members = await destiny_clan.get_clan_members() - clan_members_discord_ids = [member.discord_id for member in clan_members.members if member.discord_id] - - # check all members - member: Member - for member in guild.humans: - if member.id not in clan_members_discord_ids: - if member.has_role(clan_role): - await member.remove_role(role=clan_role, reason="Destiny2 Clan Membership Update") - logger.info(f"Removed clan role from {member}") - else: - if not member.has_role(clan_role): - await member.add_role(role=clan_role, reason="Destiny2 Clan Membership Update") - logger.info(f"Added clan role to {member}") + persistent_messages = PersistentMessages(ctx=None, guild=guild, message_name="clan_role") + if result := await persistent_messages.get(): + if clan_role := await guild.fetch_role(result.channel_id): + # get clan members + destiny_clan = DestinyClan(ctx=None, discord_guild=guild) + clan_members = await destiny_clan.get_clan_members() + clan_members_discord_ids = [ + member.discord_id for member in clan_members.members if member.discord_id + ] + + # check all members + member: Member + for member in guild.humans: + if member.id not in clan_members_discord_ids: + if member.has_role(clan_role): + await member.remove_role(role=clan_role, reason="Destiny2 Clan Membership Update") + logger.info(f"Removed clan role from {member}") + else: + if not member.has_role(clan_role): + await member.add_role(role=clan_role, reason="Destiny2 Clan Membership Update") + logger.info(f"Added clan role to {member}") diff --git a/ElevatorBot/commandHelpers/optionTemplates.py b/ElevatorBot/commandHelpers/optionTemplates.py index 8bdf9e23..18024106 100644 --- a/ElevatorBot/commandHelpers/optionTemplates.py +++ b/ElevatorBot/commandHelpers/optionTemplates.py @@ -1,9 +1,10 @@ +import copy from typing import Any from bungio.models import DamageType from naff import OptionTypes, SlashCommandChoice, slash_option -from ElevatorBot.core.destiny.stat import stat_translation +import ElevatorBot.core.destiny.stat as stats from ElevatorBot.misc.formatting import capitalize_string from ElevatorBot.static.destinyDates import expansion_dates, season_and_expansion_dates from ElevatorBot.static.timezones import timezones_dict @@ -103,7 +104,7 @@ def wrapper(func): return wrapper -def default_stat_option() -> Any: +def default_stat_option(pvp: bool = False) -> Any: """ Decorator that replaces @slash_option() @@ -111,12 +112,21 @@ def default_stat_option() -> Any: """ def wrapper(func): + if pvp: + options = copy.deepcopy(stats.stat_translation) + options.pop("Activities Cleared") + options.pop("Public Events Completed") + options.pop("Heroic Public Events Completed") + + else: + options = stats.stat_translation + return slash_option( name="name", description="The name of the leaderboard you want to see", opt_type=OptionTypes.STRING, required=True, - choices=[SlashCommandChoice(name=name, value=name) for name in stat_translation], + choices=[SlashCommandChoice(name=name, value=name) for name in options], )(func) return wrapper diff --git a/ElevatorBot/commands/a_destiny/stat/pvp.py b/ElevatorBot/commands/a_destiny/stat/pvp.py index 975bd832..9747506c 100644 --- a/ElevatorBot/commands/a_destiny/stat/pvp.py +++ b/ElevatorBot/commands/a_destiny/stat/pvp.py @@ -15,7 +15,7 @@ class StatPvP(BaseModule): sub_cmd_description="Displays the specified stat for all PvP activities", dm_permission=False, ) - @default_stat_option() + @default_stat_option(pvp=True) @default_class_option() @default_user_option() async def pvp(self, ctx: ElevatorInteractionContext, name: str, destiny_class: str = None, user: Member = None): diff --git a/ElevatorBot/discordEvents/memberEvents.py b/ElevatorBot/discordEvents/memberEvents.py index 8ea83a89..cd8b91b0 100644 --- a/ElevatorBot/discordEvents/memberEvents.py +++ b/ElevatorBot/discordEvents/memberEvents.py @@ -6,6 +6,7 @@ from ElevatorBot.core.destiny.lfg.lfgSystem import LfgMessage from ElevatorBot.core.destiny.roles import Roles +from ElevatorBot.core.misc.persistentMessages import PersistentMessages from ElevatorBot.misc.discordShortcutFunctions import assign_roles_to_member from ElevatorBot.misc.formatting import embed_message from ElevatorBot.networking.destiny.clan import DestinyClan