async def _list(self, ctx, all_events=None): """**Usage**: `!event list/li/l ['all']` Lists only the active event by default, will list all events if 'all' is included.""" result = (EventTable.select( EventTable.id, EventTable.eventname, EventTable.active, EventTable.role).join( GuildTable, on=(EventTable.guild_id == GuildTable.snowflake)).where( GuildTable.snowflake == ctx.guild.id)) if all_events is None or all_events.lower() != "all": result = result.where(EventTable.active) active_str = "Active" else: active_str = "All" if len(result) == 0: await ctx.message.add_reaction(self.failed_react) return await ctx.send(f"No {active_str} events found.") event_embed = embed = discord.Embed( colour=discord.Colour.purple(), description=f"{active_str} Events.") for event in result: try: event_role = ctx.guild.get_role(event.role) except: event_role = None if event_role: value = f"**{event_role.name}** will be assigned to all trainers who check-in to this event." else: value = "No role associated with this event." name = f"(*#{event.id}*) **{event.eventname}**" if event.active: name += " - *Active*" embed.add_field(name=name, value=value, inline=False) await ctx.message.add_reaction(self.success_react) return await ctx.send(embed=event_embed)
async def _checkin(self, ctx, member: discord.Member): result = (EventTable.select(EventTable.eventname, EventTable.role) .where((EventTable.active == True) & (EventTable.guild_id == member.guild.id))) roles = [r.role for r in result] events = [r.eventname for r in result] if len(roles) < 1: await ctx.message.add_reaction(self.failed_react) self.bot.help_logger(f"User: {ctx.author.name}, channel: {ctx.channel}, error: No active event.") return await ctx.send("There is no active event.", delete_after=10) if len(roles) > 1: await ctx.message.add_reaction(self.failed_react) self.bot.help_logger(f"User: {ctx.author.name}, channel: {ctx.channel}, error: Too many active events.") return await ctx.send("There are too many active events, please contact an admin.", delete_after=10) try: role = await self._validate_or_create_role(ctx, roles[0], eventname=events[0], checkin=True) if role is None: return await member.add_roles(*[role]) await asyncio.sleep(0.1) if role not in member.roles: await ctx.message.add_reaction(self.failed_react) self.bot.help_logger(f"User: {ctx.author.name}, channel: {ctx.channel}, error: Failed to give event badge {events[0]} to {member.display_name}.") return await ctx.send(f"Failed to give event role to {member.display_name}.", delete_after=10) except discord.Forbidden: await ctx.message.add_reaction(self.failed_react) self.bot.help_logger(f"User: {ctx.author.name}, channel: {ctx.channel}, error: Failed to give event badge {events[0]} to {member.display_name} due to permissions.") return await ctx.send(f"Failed to give event role to to {member.display_name} because you do not have permission", delete_after=10) message = f"Checked in **{member.display_name}** for the **{events[0]}** event!" await ctx.send(embed=discord.Embed(colour=discord.Colour.green(), description=message), delete_after=10) await ctx.message.add_reaction(self.success_react)