def get_raidteam(self, guild_id: int, team_name: str) -> RaidTeam:
        teams_resource = RaidTeamsResource()
        raid_team = teams_resource.get_raidteam(guild_id=guild_id,
                                                team_name=team_name)

        if raid_team is None:
            raise InternalBotException(
                f'Could not find team {guild_id}/{team_name}')
        return raid_team
class RaidTeamSelectionInteraction(OptionInteraction):
    def __init__(self, ctx: DokBotContext, *args, **kwargs):
        self.raid_team_resource = RaidTeamsResource()
        self.raid_teams = self.raid_team_resource.list_raidteams(ctx.guild_id)
        options = [raid_team.name for raid_team in self.raid_teams] + [ADD_RAID_TEAM]
        message = "Please choose the raidteam you want to manage or add a new one?"
        super().__init__(ctx=ctx, options=options, content=message, *args, **kwargs)

    async def get_response(self) -> RaidTeam:
        response = await super(RaidTeamSelectionInteraction, self).get_response()

        players_resource = PlayersResource()
        player = players_resource.get_player_by_id(self.ctx.author.id)
        if not player:
            player, _ = await register(self.ctx)

        if response == ADD_RAID_TEAM:
            return await create_raidteam(ctx=self.ctx, first=len(self.raid_teams) == 0)
        for raid_team in self.raid_teams:
            if response == raid_team.name:
                if player.get_selected_raid_team_name(guild_id=self.ctx.guild_id) != raid_team.name:
                    player.set_selected_raid_team_name(guild_id=self.ctx.guild_id, team_name=raid_team.name)
                    players_resource.update_player(player)
                return raid_team
        raise InvalidInputException(f'Please choose on of: {self.options}')
예제 #3
0
 async def dokbot(self, ctx: Context):
     """
     Organize and manage your raids for raiding team.
     """
     ctx = DokBotContext.from_context(ctx)
     raid_team = RaidTeamsResource().get_selected_raidteam(
         guild_id=ctx.guild_id, discord_id=ctx.author.id)
     await RaidTeamMessage.reply_in_channel(ctx, raid_team=raid_team)
예제 #4
0
async def remove_raider(ctx: RaidTeamContext):
    member = await FindMemberInteraction.interact(ctx)
    if member.id not in ctx.raid_team.raider_ids:
        await ctx.reply(f"{member} is not yet in the raid team.")
        return
    ctx.raid_team.raider_ids.remove(member.id)
    RaidTeamsResource().update_raidteam(ctx.raid_team)
    await ctx.reply(f"Removed {member} from raid team.")
    await member.send(f'You have been removed from {ctx.raid_team}')
예제 #5
0
async def add_raider(ctx: RaidTeamContext):
    member = await FindMemberInteraction.interact(ctx)
    if member.id in ctx.raid_team.raider_ids:
        await ctx.reply(f"{member} is already in the raid team.")
        return
    ctx.raid_team.raider_ids.append(member.id)
    RaidTeamsResource().update_raidteam(ctx.raid_team)
    await member.send(f'You have been added to {ctx.raid_team}')
    await ctx.reply(f"Added {member} to raid team.")
async def add_raid_leader(ctx: RaidTeamContext):
    member = await FindMemberInteraction.interact(ctx)
    if member.id in ctx.raid_team.manager_ids:
        await ctx.reply(f"{member} is already manager of the raid team.")
        return
    ctx.raid_team.manager_ids.append(member.id)
    RaidTeamsResource().update_raidteam(ctx.raid_team)
    await ctx.reply(f"Added {member} as manager for the raid team.")
    await member.send(
        f'You are now a raid leader for {ctx.raid_team}.\n'
        f'You can start managing the raidteam and its raids by typing !dokbot in the channel #{await ctx.get_managers_channel()}'
    )
예제 #7
0
 async def make(cls, ctx: DokBotContext, **kwargs):
     if kwargs.get("name"):
         team_name = kwargs["name"]
         raid_team = RaidTeamsResource().get_raidteam(guild_id=ctx.guild.id, team_name=team_name)
         if not raid_team:
             await ctx.reply(f'{team_name} does not exist.')
             return None
     elif kwargs.get("raid_team"):
         raid_team = kwargs["raid_team"]
     else:
         raid_team = await RaidTeamSelectionInteraction.interact(ctx=ctx)
     embed = await cls.get_embed(ctx, raid_team=raid_team)
     return RaidTeamMessage(ctx=ctx, embed=embed)
예제 #8
0
async def add_raiders(ctx: RaidTeamContext):
    roles = await ctx.guild.fetch_roles()
    content = "Please select a role. All of the people who have this role get added to the raid team"
    options = [role.name for role in roles]
    role_name = await OptionInteraction.interact(ctx=ctx, options=options, content=content)
    role = [role for role in roles if role.name == role_name]
    if len(role) != 1:
        await ctx.reply(f"{role_name} is not a valid role.")
        return
    role = role[0]
    members = await ctx.guild.fetch_members(limit=None).flatten()
    new_raider_ids = [member.id for member in members if member.id not in ctx.raid_team.raider_ids and role in member.roles]
    for member in members:
        if member.id not in ctx.raid_team.raider_ids and role in member.roles:
            ctx.raid_team.raider_ids.append(member.id)
            await member.send(f'You have been added to {ctx.raid_team}')
    RaidTeamsResource().update_raidteam(ctx.raid_team)
    await ctx.reply(f"Added {len(new_raider_ids)} raider(s) to the to raid team.")
예제 #9
0
async def create_raidteam(ctx: DokBotContext,
                          first: bool) -> RaidTeam:
    if first:
        await ctx.channel.send(INTRODUCTORY_MESSAGE)
    msg = "Please fill in the name for your raid team."
    team_name = await TextInteractionMessage.interact(ctx=ctx, content=msg)
    msg = "Please fill in the realm of your team."
    realm = await TextInteractionMessage.interact(ctx=ctx, content=msg)
    msg = "Please fill in the region of your team."
    options = ["EU"]
    region = await OptionInteraction.interact(ctx=ctx, content=msg, options=options)
    msg = "Please choose a channel where I can show raids to your raiders"
    events_channel = await DiscordChannelInteraction.interact(ctx=ctx, content=msg)
    msg = "Please select a channel where you want to manage this raiding team and its raids"
    manager_channel = await DiscordChannelInteraction.interact(ctx=ctx, content=msg)
    msg = "Please select a channel where we can send all signup activity"
    signup_history_channel = await DiscordChannelInteraction.interact(ctx=ctx, content=msg)
    raid_team = RaidTeam(guild_id=ctx.guild_id, team_name=team_name, raider_ids=[], realm=realm,
                         region=region, manager_ids=[ctx.author.id], events_channel=events_channel.id,
                         manager_channel=manager_channel.id, signup_history_channel=signup_history_channel.id)
    RaidTeamsResource().create_raidteam(raid_team)
    await ctx.reply(f"Your raid team {raid_team} has successfully been created!")
    return raid_team
 def __init__(self, ctx: DokBotContext, *args, **kwargs):
     self.raid_team_resource = RaidTeamsResource()
     self.raid_teams = self.raid_team_resource.list_raidteams(ctx.guild_id)
     options = [raid_team.name for raid_team in self.raid_teams] + [ADD_RAID_TEAM]
     message = "Please choose the raidteam you want to manage or add a new one?"
     super().__init__(ctx=ctx, options=options, content=message, *args, **kwargs)
 def __getattr__(self, item):
     if item == 'raid_team':
         self.raid_team = RaidTeamsResource().get_raidteam(
             guild_id=self.guild_id, team_name=self.team_name)
         return self.raid_team