Skip to content

Commit

Permalink
remove pve only stats from pvp. closes #188
Browse files Browse the repository at this point in the history
  • Loading branch information
Kigstn committed Sep 4, 2022
1 parent 159094a commit de5f8b5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
43 changes: 21 additions & 22 deletions ElevatorBot/backgroundEvents/clanRoleAssigment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
16 changes: 13 additions & 3 deletions ElevatorBot/commandHelpers/optionTemplates.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -103,20 +104,29 @@ def wrapper(func):
return wrapper


def default_stat_option() -> Any:
def default_stat_option(pvp: bool = False) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_stat_option()`
"""

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
Expand Down
2 changes: 1 addition & 1 deletion ElevatorBot/commands/a_destiny/stat/pvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions ElevatorBot/discordEvents/memberEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de5f8b5

Please sign in to comment.