Example #1
0
 async def whatis(self, ctx, prefix=None, image: bool = False):
     """Send a canned response."""
     if prefix:
         try:
             name, response, image_link = google.connector.whatis.get(
                 prefix.lower())
         except TypeError:
             if ctx.guild and ctx.guild.id == 726963775927746650:
                 await ctx.send(self.invalid_whatis(prefix))
             else:
                 await ctx.send(embed=utils.Embed(
                     title="Error: **Invalid Whatis**",
                     description=
                     f"To view all the options, type `{ctx.prefix}whatis`.")
                                )
         except google.HollowSheet as e:
             await ctx.send(e)
         else:
             embed = utils.Embed(title=f"What Is... {name.capitalize()}?",
                                 description=response)
             if image:
                 embed.set_image(url=image_link)
             await ctx.send(embed=embed)
     else:
         try:
             embed = utils.Embed(title="What Is...")
             embed.add_field(name="Options:",
                             value=utils.Embed.list(
                                 google.connector.whatis.options()))
         except google.HollowSheet as e:
             await ctx.send(e)
         else:
             await ctx.send(embed=embed)
Example #2
0
    async def rules(self, ctx, prefix=None, image: bool = False):
        """Send an embedded rules section."""
        if prefix:
            try:
                name, response, image_link = google.connector.rules.get(
                    prefix.lower())
                embed = utils.Embed(title=f"{name.capitalize()} Rules",
                                    description=response)
                if image:
                    embed.set_image(image_link)
                await ctx.send(embed=embed)
            except TypeError:
                await ctx.send(
                    "Section could not be found, try a different prefix.")
            except google.HollowSheet as e:
                await ctx.send(e)

        else:
            try:
                embed = utils.Embed(title="Rules")
                embed.add_field(name="Options:",
                                value=utils.Embed.list(
                                    google.connector.rules.options()))
            except google.HollowSheet as e:
                await ctx.send(e)
            else:
                await ctx.send(embed=embed)
Example #3
0
    async def _set_checkin(self, ctx: commands.Context, checkin_status: bool, team_name: str = None):
        """
        Set checkin status
        :param ctx:
        :param checkin_status:
        :param team_name:
        :return:
        """

        async def checkin_set():
            """
            Check in team
            :return: None
            """
            if team.bracket <= 0:  # Team isn't in a bracket
                fun_embed = utils.Embed(title=f"❌ Checking Disabled for: `{team.name}`",
                                        thumbnail=team.logo_icon)
                return await ctx.send(embed=fun_embed)
            if await team.set_check_in(checkin_status):
                fun_embed = utils.Embed(title=f"Checked {'in' if checkin_status else 'out'} `{team.name}` ✅")
                if team.logo_icon:
                    fun_embed.set_thumbnail(url=team.logo_icon)
                return await ctx.send(embed=fun_embed)
            else:  # We got an error somewhere checking in
                fun_embed = utils.Embed(title=f"Error Checking in: `{team.name}` ⛔",
                                        description=f"Internal Error trying to check {checkin_status}!"
                                                    f" Go to Helpdesk for help.",
                                        thumbnail=team.logo_icon)
                return await ctx.send(embed=fun_embed)

        # Someone check in/out with name that's not staff
        if team_name and not discord.utils.get(ctx.author.roles, name="Staff"):
            raise commands.MissingRole
        if team_name:  # if a team name was given by staff member
            team = await self.database.get_team(team_name, self._battlefy_id)
            if team:
                await checkin_set()
            else:
                embed = utils.Embed(title=f"No Team Found under: `{team_name}` ❌")
                return await ctx.send(embed=embed)
        else:  # If no team name given
            team = await self.database.get_discord_team(
                [f"{ctx.author.name}#{ctx.author.discriminator}", str(ctx.author.id)],  # Forms list of field to find by
                self._battlefy_id)
            if team:
                await checkin_set()
            else:
                embed = utils.Embed(title=f"No Team Found for `{ctx.author.name}`❗",
                                    description=f"{ctx.author.mention}, head to Helpdesk if you need help!")
                return await ctx.send(embed=embed)
Example #4
0
    async def check(self, ctx, index: int = 0, _invalid_captains=None):
        """Show the current status of captains."""
        await ctx.trigger_typing()

        # Get the tournament teams
        tourney = utils.agenda.tourney_at(index)
        if not tourney:
            return await ctx.send("⛔ **No event found**")
        teams = await battlefy.connector.get_teams(tourney.battlefy)

        # Create list of invalid captains
        if not _invalid_captains:
            invalid_captains = [
                f"`{team.captain.discord}` | `{team.name}`" for team in teams
                if not await team.captain.get_discord(ctx)
            ]
        else:
            invalid_captains = [f"`{team.captain.discord}` | `{team.name}`" for team in _invalid_captains]

        # Send status check embed
        embed = utils.Embed(
            title=f"🗒️ Captain status check for `{tourney.event.name}`",
            description=f"Invalid Captains / Total Teams: `{len(invalid_captains)}/{len(teams)}`")
        embed.add_field(
            name="List of invalid captains:",
            value=utils.Embed.list(invalid_captains) if invalid_captains else "> ✨ **~ No invalid captains! ~**")
        await ctx.send(embed=embed)
Example #5
0
 async def on_command_error(self, ctx, error):
     if isinstance(error, commands.MissingRequiredArgument):
         await ctx.send(embed=utils.Embed(
             title="Error: **Missing Required Argument**",
             description=f"You can use `{ctx.prefix}help` for help."))
     elif isinstance(error, discord.errors.Forbidden):
         await ctx.send(embed=utils.Embed(
             title="Error: **Missing Permissions**",
             description=
             f"This is probably a mistake, please notify staff about this.")
                        )
     elif isinstance(error,
                     (commands.CommandNotFound, commands.MissingRole)):
         return
     else:
         logging.error(error)
         raise error
Example #6
0
 async def prev(self, ctx):
     tourney = utils.agenda.prev_tourney()
     if not tourney:
         return await ctx.send("⛔ **No event found**")
     await ctx.send(embed=utils.Embed(
         title=f"📆 Event Name: `{tourney.event.name}`",
         description=self.tourney_desc(ctx, tourney),
     ))
Example #7
0
 async def agenda(self, ctx, index: int = None):
     """View the agenda."""
     if index is None:
         # Send an embedded list of all of the agenda events
         await ctx.send(embed=utils.Embed(
             title="🗓️ Agenda",
             description=utils.Embed.list(
                 [item.event.name for item in utils.agenda], ordered=True)))
     else:
         # Send an embed of the event at index, send an error if it fails
         tourney = utils.agenda.tourney_at(index)
         if not tourney:
             await ctx.send("⛔ **No event found**")
         else:
             await ctx.send(embed=utils.Embed(
                 title=f"📅 Event Name: `{tourney.event.name}`",
                 description=self.tourney_desc(ctx, tourney)))
Example #8
0
 async def pet(self, ctx, num: int = None):
     """Get a picture of a pet."""
     embed = utils.Embed(title="Pets!", description="Picture of pets")
     embed.set_image(
         url=
         f"https://cdn.vlee.me.uk/TurnipBot/pets/{num if num != None else randint(0, 140)}.png"
     )
     await ctx.send(embed=embed)
Example #9
0
 async def whatis(self, ctx, prefix=None, image: bool = False):
     """Send a canned response."""
     if prefix:
         try:
             name, response, image_link = google.connector.whatis.get(prefix.lower())
         except TypeError:
             await ctx.send(self.invalid_whatis(prefix))
         else:
             embed = utils.Embed(title=f"What Is... {name.capitalize()}?", description=response)
             if image:
                 embed.set_image(url=image_link)
             await ctx.send(embed=embed)
     else:
         embed = utils.Embed(title="What Is...")
         embed.add_field(
             name="Options:",
             value=utils.Embed.list(google.connector.whatis.options()))
         await ctx.send(embed=embed)
Example #10
0
 async def on_command_error(self, ctx, error):
     if isinstance(error, commands.MissingRequiredArgument):
         await ctx.send(embed=utils.Embed(
             title="Error: **Missing Required Argument**",
             description=f"You can use `{ctx.prefix}help` for help."))
     elif isinstance(error,
                     (commands.CommandNotFound, commands.MissingRole)):
         return
     else:
         logging.error(error)
         raise error
Example #11
0
 async def checkin_set():
     """
     Check in team
     :return: None
     """
     if team.bracket <= 0:  # Team isn't in a bracket
         fun_embed = utils.Embed(title=f"❌ Checking Disabled for: `{team.name}`",
                                 thumbnail=team.logo_icon)
         return await ctx.send(embed=fun_embed)
     if await team.set_check_in(checkin_status):
         fun_embed = utils.Embed(title=f"Checked {'in' if checkin_status else 'out'} `{team.name}` ✅")
         if team.logo_icon:
             fun_embed.set_thumbnail(url=team.logo_icon)
         return await ctx.send(embed=fun_embed)
     else:  # We got an error somewhere checking in
         fun_embed = utils.Embed(title=f"Error Checking in: `{team.name}` ⛔",
                                 description=f"Internal Error trying to check {checkin_status}!"
                                             f" Go to Helpdesk for help.",
                                 thumbnail=team.logo_icon)
         return await ctx.send(embed=fun_embed)
Example #12
0
 async def clear(self, ctx):
     """Remove all of the bracket roles."""
     async with ctx.typing():
         counter = 0
         for bracket in id_to_bracket.values():
             role = discord.utils.get(ctx.guild.roles, name=f"{bracket}")
             for member in role.members:
                 await member.remove_roles(role)
                 counter += 1
     embed = utils.Embed(
         title=f"✅ **Success:** bracket roles cleared from all members",
         description=f"Cleared `{str(counter)}` roles.")
     await ctx.send(embed=embed)
Example #13
0
    async def on_message(self, message):
        """
        Send an unreciprocated error when someone confesses their love for radia.

        This is mainly because of Skye (radia's mine)
        """
        if any(msg in message.content
               for msg in ["love", "ily"]) and (self.bot.user
                                                in message.mentions
                                                or "radia" in message.content):
            if message.author.id == 571494333090496514:
                await message.add_reaction("<:radia_uwu:748176810059104358>")
            else:
                await message.channel.send(embed=utils.Embed(
                    title="Error: Unreciprocated"))
Example #14
0
    async def add(self, ctx):
        """Add the Champion role to members."""
        with ctx.typing():
            # Create list of applicable champion roles
            roles = self.get_roles(ctx, "Past Low Ink Winner",
                                   "Low Ink Current Champions")
            # Add champion roles from every member mentioned
            for member in ctx.message.mentions:
                await member.add_roles(*roles)

        # Log all members the champion roles were added to
        embed = utils.Embed(title="Added champion roles to:",
                            description=utils.Embed.list([
                                member.mention
                                for member in ctx.message.mentions
                            ]))
        await ctx.send(embed=embed)
Example #15
0
    async def remove(self, ctx, index: int = 0, nick: bool = True):
        """Remove captain role from members."""
        tourney = utils.agenda.tourney_at(index)
        if not tourney:
            return await ctx.send("⛔ **No event found**")
        removed_from = len(tourney.get_role(ctx).members)

        async with ctx.typing():
            # Loop over members with the captain_role
            for member in tourney.get_role(ctx).members:
                await member.remove_roles(tourney.get_role(ctx))
                if nick:
                    await member.edit(nick=None)

        # Display embed
        embed = utils.Embed(
            title=f"❎ **Success:** roles removed for `{tourney.event.name}`",
            description=f"{tourney.get_role(ctx).mention} removed from `{removed_from}` members.")
        await ctx.send(embed=embed)
Example #16
0
    async def load(self, ctx, tourney: int = 0):
        """Load battlefy teams data."""
        async with ctx.typing():
            tourney = utils.agenda.tourney_at(tourney)
        if not tourney:
            return await ctx.send("⛔ **No event found**")

        battlefy_teams = await battlefy.connector.get_teams(tourney.battlefy)

        try:
            await self.database.load_teams(battlefy_teams, tourney.battlefy)
            self._battlefy_id = tourney.battlefy
            embed = utils.Embed(
                title=f"✅ **Success:** teams loaded for `{tourney.event.name}` checkin",
                description=f"Loaded `{len(battlefy_teams)}` teams.")
            await ctx.send(embed=embed)
        except Exception as error:
            await ctx.send(f"Error\n ```\n{error}\n```")
            pass
Example #17
0
    async def remove(self, ctx):
        """Remove the champion roles from members who currently have it."""
        with ctx.typing():
            # Create list of applicable champion roles
            roles = self.get_roles(ctx, "Low Ink Current Champions",
                                   "Beta Bracket Champions",
                                   "Gamma Bracket Champions")
            # Create a set of all members with any champion role
            all_champions = set()
            for role in roles:
                all_champions += role.members
            # Remove champion roles from each of those members
            for member in all_champions:
                await member.remove_roles(*roles)

        # Log all members the champion roles were removed from
        embed = utils.Embed(title="Removed champion roles from:",
                            description=utils.Embed.list(
                                [member.mention for member in all_champions]))
        await ctx.send(embed=embed)
Example #18
0
                    if (member := await team.captain.get_discord(ctx)) is None:
                        raise discord.DiscordException
                    await member.add_roles(tourney.get_role(ctx))
                    assigned_to += 1
                # Adding role failed, append team to the list of invalid captains
                except discord.DiscordException:
                    invalid_captains.append(team)
                # Adding captain role was successful, optionally edit captain nickname
                else:
                    if nick:
                        await member.edit(nick=team.name[:32])

        # Send Report Embed
        embed = utils.Embed(
            title=f"✅ **Success:** roles assigned for `{tourney.event.name}`",
            description=
            f"{tourney.get_role(ctx).mention} assigned to `{assigned_to}` members."
        )
        await ctx.send(embed=embed)
        await ctx.invoke(self.check, index,
                         invalid_captains)  # Run 'captain check' command

    @captain.command()
    async def remove(self, ctx, index: int = 0, nick: bool = False):
        """Remove captain role from members."""
        tourney = utils.agenda.tourney_at(index)
        if not tourney:
            return await ctx.send("⛔ **No event found**")
        removed_from = len(tourney.get_role(ctx).members)

        async with ctx.typing():
Example #19
0
                            "raw": player.raw,
                            "created_at": str(player.created_at),
                        } for player in team.players]
                    } for team in battlefy_tourney.teams
                ]
            }
            print(exported_data)
            # Create a file in memory and dump the dictionary into it
            file = StringIO()
            json.dump(exported_data, file)
            file.seek(0)

        # Send the file with an embed
        await ctx.send(
            embed=utils.Embed(
                title=f"📥 **Success:** Exported data for `{tourney.event.name}`",
                description="Froze and exported a compiled report of the tournament data!"),
            file=discord.File(file, filename="export.json"))

    @staticmethod
    def tourney_desc(ctx, tourney):
        """ Format tournament description.

        :param utils.Event tourney: the tournament event object
        """
        format_str = 'MMM DD, YYYY h:mm A UTC'
        return "\n".join([
            f"Event Begin Time: `{tourney.event.begin.format(format_str)}`",
            f"Event End Time: `{tourney.event.end.format(format_str)}`",
            f"Battlefy Tournament ID: `{tourney.battlefy}`",
            f"Captain Role: {tourney.get_role(ctx).mention}",
Example #20
0
                description=f"Loaded `{len(battlefy_teams)}` teams.")
            await ctx.send(embed=embed)
        except Exception as error:
            await ctx.send(f"Error\n ```\n{error}\n```")
            pass

    @commands.has_role("Staff")
    @checkin.command(aliases=["setid"])
    async def setID(self, ctx, tourney: int = 0):
        """Set tournament ID to use."""
        async with ctx.typing():
            if not (tourney := utils.agenda.tourney_at(tourney)):
                return await ctx.send("⛔ **No event found**")
            else:
                self._battlefy_id = tourney.battlefy
                embed = utils.Embed(
                    title=f"✅ **Success:** ID set for `{tourney.event.name}`")
                await ctx.send(embed=embed)

    @commands.has_role("Staff")
    @checkin.command(aliases=["a"])
    async def assign(self, ctx, bracket: str, team_name: str, captain: discord.Member = None):
        """
        Assign bracket role to team based on team name.

        You can optionally specify a captain in case the battlefy one is incorrect.
        """
        if team := await self.database.get_team(team_name, self._battlefy_id):
            if captain:
                # if provided a captain we attempt to assign it to the team first
                if not await team.set_captain_discord(str(captain.id)):
                    return await ctx.send(f"⛔ **Failed to override set captain**")