async def refresh_commentators(self, ctx): """ Force refresh the commentator in a the live voice channel """ guild_info = await self.database.get_guild_info( str(ctx.message.guild.id)) if guild_info: voice_channel = ctx.guild.get_channel(int( guild_info.vc_channel_id)) comms_list = [] for member in voice_channel.members: member_comms_info = await self.database.get_comms_info( str(member.id)) if member_comms_info and (not member_comms_info.no_show): comms_list.append(member_comms_info) elif member_comms_info and member_comms_info.no_show and ( not member_comms_info.no_alert): # Alert member they are not being shown embed = utils.Embed( title="Commentator Warning", description= f"{member.mention} you're not shown as a commentator") await ctx.send(embed=embed) elif not member_comms_info: # Alert member they don't have a profile setup embed = utils.Embed( title="Commentator Error", description= f"{member.mention} you don't have a commentator profile!\n" f"use `{ctx.prefix}help commentators set_profile` to get started" ) await ctx.send(embed=embed) await self.database.set_server_comms(str(ctx.message.guild.id), comms_list) await ctx.message.add_reaction("👍")
async def set_no_show(self, ctx, no_show: str): """ Set the no show, to avoid showing on commentators details """ if no_show.upper() in ["TRUE", "YES"]: response = await self.database.set_comms_no_show( str(ctx.message.author.id), True) try: if response: embed = utils.Embed(title="Commentator No Show", description=f"Set your no show state") embed.add_field(name="No Show", value=f"True") await ctx.send(embed=embed) return except Exception as err: await ctx.send(embed=utils.Embed( title="Error", description=f"```\n{err}\n```")) elif no_show.upper() in ["FALSE", "NO"]: response = await self.database.set_comms_no_show( str(ctx.message.author.id), False) try: if response: embed = utils.Embed(title="Commentator No Show", description=f"Set your no show state") embed.add_field(name="No Show", value=f"False") await ctx.send(embed=embed) return except Exception as err: await ctx.send(embed=utils.Embed( title="Error", description=f"```\n{err}\n```")) pass
async def profile(self, ctx, profile=None): """ View profile for yourself or a server member """ if profile: if re.match(r"<@!(\d+)>", profile): query = await self.database.get_comms_info(profile[3:-1]) description = f"Commentator profile for {profile}" else: query = await self.database.get_comms_info(profile) description = f"Commentator profile for <@!{profile}>" else: query = await self.database.get_comms_info( str(ctx.message.author.id)) description = f"Your Commentator profile" if query: embed = utils.Embed(title="Commentator Profile", description=f"{description}") embed.add_field(name="Name", value=f"{query.name}", inline=False) embed.add_field(name="Twitter", value=f"@{query.twitter}", inline=False) embed.add_field(name="Pronouns", value=f"{query.pronouns}", inline=False) embed.add_field(name="No Show", value=f"{query.no_show}") embed.add_field(name="No Alert", value=f"{query.no_alert}") await ctx.send(embed=embed) return else: await ctx.send(embed=utils.Embed( title="No Profile Found", description="Query has no commentator profile")) return
async def set_profile(self, ctx, name: str, twitter: str, pronouns: str): """ Set your commentator profile for stream """ try: if twitter[0] == "@": # If the user add @, remove it from string twitter = twitter[1:] elif "https://twitter.com/" in twitter: # if they gave the full link, remove the link portion twitter = twitter.replace("https://twitter.com/home", "") elif re.search(discord_mention, twitter): await ctx.send(embed=utils.Embed( title="Set Commentator Twitter Handle Error!", description= f"You Twitter handle contains a Discord mention!\n" f"Try the command again without the `@` in your " f"Twitter handle")) return response = await self.database.set_comms_info( str(ctx.message.author.id), name, twitter, pronouns) if response: embed = utils.Embed(title=f"Set Commentator Profile", description="We've set your profile") embed.add_field(name="Name", value=f"{name}", inline=False) embed.add_field(name="Twitter", value=f"@{twitter}", inline=False) embed.add_field(name="Pronouns", value=f"{pronouns}", inline=False) await ctx.send(embed=embed) except Exception as err: await ctx.send(embed=utils.Embed(title="Error", description=f"```\n{err}\n```")) pass
async def remove_command(self, ctx, command_name: str): """ Remove custom command for server's Twitch Channel """ try: if await self.database.remove_custom_command( str(ctx.message.guild.id), command_name): embed = utils.Embed( title="Removed Twitch Command", description=f"Removed command `{command_name}`") await ctx.send(embed=embed) return except Exception as err: await ctx.send(embed=utils.Embed(title="Error", description=f"```\n{err}\n```")) pass
async def new(self, ctx, name: str, delete: bool = False): """Create new roles for a new season. `season` - The season name, if it's the name of an actual season (such as "winter"), it will be converted to an emoji. Otherwise, the name will be used directly. `delete` - Whether the old season roles should be deleted, defaults to `no`. """ if delete: await ctx.invoke(self.end) async with ctx.typing(): verified = await self.get_verified_role(ctx) rank_roles = [] for rank, color in self.rank_roles.items(): season_name = { "spring": "🌱", "summer": "🌻", "fall": "🍂", "autumn": "🍂", "winter": "❄️", }.get(name.lower(), name) role_name = f"{rank} ({season_name} '{str(datetime.now().year)[2:]})" rank_roles.append(await ctx.guild.create_role( name=role_name, color=color, reason="Creating new season roles")) await ctx.guild.edit_role_positions( {role: verified.position for role in rank_roles}) await ctx.send(embed=utils.Embed( title="✅ Created new season roles!", description=utils.Embed.list([role.mention for role in rank_roles])))
async def roles(self, ctx): """List all of the current verification season roles.""" rank_roles = await self.get_rank_roles(ctx) await ctx.send(embed=utils.Embed(title="Current season roles:", description=utils.Embed.list( role.mention for role in rank_roles)))
async def pet(self, ctx, num: int = None): """Get a picture of a pet.""" embed = utils.Embed(title="Pets!") embed.set_image( url= f"https://cdn.vlee.me.uk/TurnipBot/pets/{num if num else randint(0, 140)}.png" ) await ctx.send(embed=embed)
async def end(self, ctx): """Delete the old season roles.""" async with ctx.typing(): rank_roles = await self.get_rank_roles(ctx) for role in rank_roles: await role.delete(reason="Deleting old season roles") await ctx.send(embed=utils.Embed( title="🗑️ Deleted old season roles!", description=utils.Embed.list([role.name for role in rank_roles])))
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)
async def list_commands(self, ctx): """ View custom commands for server's Twitch channel. """ guild_info = await self.database.get_guild_info( str(ctx.message.guild.id)) if guild_info: embed = utils.Embed( title=f"Custom Commands for {guild_info.twitch_channel}") for com in guild_info.get_all_commands(): embed.add_field(name=com.name, value=com.message, inline=False) await ctx.send(embed=embed)
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.") else: embed = utils.Embed(title="Rules") embed.add_field(name="Options:", value=utils.Embed.list( google.connector.rules.options())) await ctx.send(embed=embed)
async def add_command(self, ctx, command_name: str, command_message: str): """ Add custom command for server's Twitch Channel """ if command_name in predefined_commands: # Check if command is not already defined await ctx.send(embed=utils.Embed( title="Added Twitch Command Error", description=f"Can not override a pre-existing command")) return try: if await self.database.add_custom_command( str(ctx.message.guild.id), command_name, command_message): embed = utils.Embed(title="Added Twitch Command") embed.add_field(name=command_name, value=command_message, inline=False) await ctx.send(embed=embed) return except Exception as err: await ctx.send(embed=utils.Embed(title="Error", description=f"```\n{err}\n```")) pass
async def on_command_error(self, ctx, error): if isinstance(error, commands.MissingRequiredArgument): await ctx.send(embed=utils.Embed( title= f"Error: **Missing Required Argument: '{error.param.name}'**", description= f"You can use `{ctx.prefix}help {ctx.command.full_parent_name} {ctx.command.name}` for help." )) elif isinstance(error, (commands.CommandNotFound, commands.MissingRole)): return else: logging.error(error) raise error
async def info_compiler(self, ctx): guild_info = await self.database.get_guild_info( str(ctx.message.guild.id)) if guild_info: embed = utils.Embed(title="Current Information") embed.add_field(name="Tournament", value=f"{guild_info.tournament_name}", inline=False) embed.add_field(name="Bracket Link(s)", value=f"{guild_info.bracket_link}", inline=False) for n in range(len(guild_info.current_comms)): x = guild_info.current_comms[n] embed.add_field(name=f"Comm {n + 1}", value=f"```\nName: {x['name']}\n" f"Twitter: {x['twitter']}\n" f"Pronouns: {x['pronouns']}\n```", inline=False) await ctx.send(embed=embed) else: await ctx.send( embed=utils.Embed(title="Display Info Error", description=f"Guild has no data stored"))
async def on_voice_state_update(self, member, before, after): guild_info = await self.database.get_guild_info(str(member.guild.id)) if guild_info: # If guild exists # If user joins the vc used for live comms data if after.channel and ((not before.channel) or (before.channel.id != after.channel.id)) and \ (str(after.channel.id) == guild_info.vc_channel_id): member_comms_info = await self.database.get_comms_info( str(member.id)) if member_comms_info and (not member_comms_info.no_show): await self.database.upsert_server_comm( str(member.guild.id), member_comms_info) elif member_comms_info and member_comms_info.no_show and ( not member_comms_info.no_alert): # Alert member they are not being shown alert_channel = self.bot.get_channel( int(guild_info.alert_channel_id)) embed = utils.Embed( title="Commentator Warning", description= f"{member.mention} you're not shown as a commentator") await alert_channel.send(embed=embed) elif not member_comms_info: # Alert member they don't have a profile setup alert_channel = self.bot.get_channel( int(guild_info.alert_channel_id)) embed = utils.Embed( title="Commentator Error", description= f"{member.mention} you don't have a commentator profile!\n" f"use `!help commentators set_profile` to get started") await alert_channel.send(embed=embed) # Member leave voice channel used for live comms data elif before.channel and ((after.channel is None) or (after.channel.id != before.channel.id)) and \ (str(before.channel.id) == guild_info.vc_channel_id): # Remove them from the guild current live comms list await self.database.remove_server_comm(str(member.guild.id), str(member.id))
async def verifications(self, ctx): """Temporary command to verify members.""" number = 0 msg = await ctx.send(embed=await self.create_embed(number, "None")) verified = await self.get_verified_role(ctx) for member in ctx.guild.members: if any(role.name.endswith("'21)") for role in member.roles): await member.add_roles(verified) number += 1 await msg.edit( embed=await self.create_embed(number, member.mention)) await msg.edit(embed=utils.Embed( title="✅ Verified!", description=f"Total Members: `{number}`", ))
async def prune(self, ctx): """Prune the Verified role members. This will remove the Verified role from anyone who doesn't currently have a rank role. """ async with ctx.typing(): pruned = 0 verified = await self.get_verified_role(ctx) rank_roles = await self.get_rank_roles(ctx) for member in verified.members: if not any(role in member.roles for role in rank_roles): await member.remove_roles( verified, reason="Pruning the Verified role members.") pruned += 1 await ctx.send( embed=utils.Embed(title="✂️ Pruned the Verified role members!", description=f"Pruned Members: `{str(pruned)}`"))
async def create_embed(num, mention): return utils.Embed(title="⚙️ Verifying...", description="\n".join([ f"Latest verified: {mention}", f"Verified so far: `{num}`", ]))