async def cmd_help(message: Message, cmd_name: str) -> None: """ Sends help to a command :param message: Message that executed the command :param cmd_name: Name of the command """ # Initialize varaibles guild: Guild = message.guild channel: TextChannel = message.channel prefix = appearance.get_prefix(guild.id) # Call different help messages depending on permission is_suggestion, similar_cmd = description.get_similar_command(cmd_name) # Get name with first letter in upper name = similar_cmd.name[0].upper() + similar_cmd.name[1:] if not is_suggestion: embed = Embed(title=f'Help - {name}', description=f'`{prefix}{similar_cmd.syntax}`\n' f'{similar_cmd.get_complete_description()}', colour=appearance.get_color(guild.id)) else: embed = Embed(title=f'Help - {name}', description=f'**Did you mean {similar_cmd.name}?**\n\n' f'`{prefix}{similar_cmd.syntax}`\n' f'{similar_cmd.get_complete_description()}', colour=appearance.get_color(guild.id)) embed.set_footer(text='Created by frysel | <> Required | () Optional', icon_url=message.author.avatar_url) await channel.send(embed=embed) # Delete message await util.delete_message(message)
async def color_page(channel: TextChannel, guild: Guild) -> None: """ Sends a page with all information about the setup of the color. :param guild: Guild of call :param channel: TextChannel to send the message to """ # Initialize important values prefix = appearance.get_prefix(guild.id) # Setup appearance of the embed embed: Embed = Embed(title=f'{appearance.bot_name} Setup - Color', description='Setup your custom color!') embed.colour = appearance.get_color(guild.id) # Fetch colorand format to hex color code color = hex(appearance.get_color(guild.id)) color = '#' + str(color)[2:] # Setup the fields embed.add_field(name='Current Color', value=f'`{color}`', inline=False) embed.add_field( name='Set Color', value=f'`{prefix}{description.get_command("color").syntax}`', inline=False) embed.add_field(name='Valid Color', value='HEX color code', inline=False) embed.add_field(name='Set To Default', value='React with 🟧️', inline=False) # Send embed and add reactions message = await channel.send(embed=embed) await message.add_reaction(emoji='🟧')
async def _admin_help(message: Message, channel: TextChannel) -> None: """ Sends help message for admins via dm. """ # Initialize attributes of message guild: Guild = message.guild member: Member = message.author prefix = appearance.get_prefix(guild.id) # Setup embed content embed: Embed = Embed() embed.title = 'Admin Commands' # Add fields for commands for cmd in description.commands: if cmd.admin_only and cmd.in_help(guild): embed.add_field(name='`' + prefix + cmd.syntax + '`', value=cmd.description, inline=False) # Setup embed style embed.colour = appearance.get_color(guild.id) embed.set_footer( text= f'{prefix}help <command> for detailed information | <> Required | () Optional', icon_url=member.avatar_url) # Send direct message or in channel if dm is forbidden try: await member.send(embed=embed) except Forbidden: await channel.send(embed=embed)
async def welcome_message(member: Member) -> None: """ Sends welcome message for member :param member: Member joined """ guild: Guild = member.guild if not select.welcome_messages(guild.id): # Only send welcome messages when they are enabled on guild return # Get welcome channel welcome_channel: TextChannel = guild.get_channel( select.welcome_channel_id(guild.id)) welcome_messages = [ '{} joined. You must construct additional pylons.', 'Never gonna give {} up. Never let {} down!', 'Hey! Listen! {} has joined!', 'Ha! {} has joined! You activated my trap card!', "We've been expecting you, {}.", "It's dangerous to go alone, take {}!", 'Swoooosh. {} just landed.', 'Brace yourselves. {} just joined the Server.', 'A wild {} appeared.' ] # Setup embed embed: Embed = Embed() embed.description = random.choice(welcome_messages).replace( '{}', member.mention) # Setup embed style embed.colour = appearance.get_color(guild.id) # Send embed to welcome_channel await welcome_channel.send(embed=embed)
async def leave_message(member: Member) -> None: """ Sends leave message for member :param member: Member left """ guild: Guild = member.guild if not select.leave_messages(guild.id): # Only send leave messages when they are enabled on guild return # Get welcome channel welcome_channel: TextChannel = guild.get_channel( select.welcome_channel_id(guild.id)) welcome_messages = ["{} left, the party's over."] # Setup embed embed: Embed = Embed() embed.description = random.choice(welcome_messages).replace( '{}', member.mention) # Setup embed style embed.colour = appearance.get_color(guild.id) # Send embed to welcome_channel await welcome_channel.send(embed=embed)
async def prefix_page(channel: TextChannel, guild: Guild) -> None: """ Sends a page with all information about the setup of the prefix. :param guild: Guild of call :param channel: TextChannel to send the message to """ # Initialize important values prefix = appearance.get_prefix(guild.id) # Setup appearance of the embed embed: Embed = Embed(title=f'{appearance.bot_name} Setup - Prefix', description='Setup your custom prefix!') embed.colour = appearance.get_color(guild.id) # Setup the fields embed.add_field(name='Current Prefix', value=f'`{prefix}`', inline=False) embed.add_field( name='Set Prefix', value=f'`{prefix}{description.get_command("prefix").syntax}`', inline=False) embed.add_field(name='Valid Prefix', value='A single character.', inline=False) embed.add_field(name='Set To Default', value='React with ❗️', inline=False) # Send embed and add reactions message = await channel.send(embed=embed) await message.add_reaction(emoji='❗')
async def setup_page(channel: TextChannel, guild: Guild) -> None: """ Sends a page with all information about the setup of the bot. :param guild: Guild of call :param channel: TextChannel to send the message to """ # Initialize important values guild_prefix = appearance.get_prefix(guild.id) # Setup appearance of the embed embed: Embed = Embed(title=f'{appearance.bot_name} - Setup', description='Use the following commands or react.') embed.colour = appearance.get_color(guild.id) # Setup the command descriptions embed.add_field(name='Prefix ❗', value=f'`{guild_prefix}setup prefix`', inline=True) embed.add_field(name='Color 🟧', value=f'`{guild_prefix}setup color`', inline=True) embed.add_field(name='Roles 👥', value=f'`{guild_prefix}setup roles`', inline=True) embed.add_field(name='Welcome 👋', value=f'`{guild_prefix}setup welcome`', inline=True) embed.add_field(name='Moderation 👮🏽♂️', value=f'`{guild_prefix}setup moderation`', inline=True) embed.add_field(name='Private Rooms 🔉', value=f'`{guild_prefix}setup private rooms`', inline=True) # Send embed and add reactions message = await channel.send(embed=embed) await message.add_reaction(emoji='❗') await message.add_reaction(emoji='🟧') await message.add_reaction(emoji='👥') await message.add_reaction(emoji='👋') await message.add_reaction(emoji='👮🏽♂️') await message.add_reaction(emoji='🔉')
async def invite_command(message: Message) -> None: """ Sends server invite messages. :param message: Message that executed the command :return: None """ # Initialize attributes of message channel: TextChannel = message.channel guild: Guild = message.guild member: Member = message.author prefix = appearance.get_prefix(guild.id) # Fetch invite or create new one server_invite: Invite = await channel.create_invite( reason='Server invite by fryselBot', unique=False) # Setup embed content embed: Embed = Embed() embed.title = 'Invite - ' + guild.name embed.description = server_invite.url # Setup embed style embed.colour = appearance.get_color(guild.id) embed.set_thumbnail(url=guild.icon_url) embed.set_footer(text=prefix + 'invite', icon_url=member.avatar_url) # Send embed & delete message await channel.send(embed=embed) await message.delete()
async def information_message(guild: Guild, private_room: PrivateRoom) -> None: """ Send direct message to the owner about the current settings of the private room :param guild: Guild of private room :param private_room: Private room to send settings of """ owner: Member = guild.get_member(private_room.owner_id) embed: Embed = Embed(title='Your Private Room Settings', timestamp=datetime.utcnow(), colour=appearance.get_color(guild.id)) # Add information about game activity if private_room.game_activity: embed.add_field(name='Game Activity', value='Game activity will be shown 🎮', inline=False) else: embed.add_field(name='Game Activity', value='Game activity will not be shown', inline=False) # Add information about privacy status if private_room.locked: embed.add_field( name='Privacy', value='Currently locked 🔒', inline=False) else: embed.add_field( name='Privacy', value='Currently unlocked 🔓', inline=False) # Add information about limit if private_room.user_limit == 0: embed.add_field( name='Limit', value='There is no limit 🔄', inline=False) else: embed.add_field( name='Limit', value=f'The limit is set to `{private_room.user_limit}`', inline=False) # Add information about visibiltiy status if private_room.hidden: embed.add_field( name='Visibility', value='The room is hidden at the moment 🚫', inline=False) else: embed.add_field( name='Visibility', value='The room is visible at the moment 👀', inline=False) # Set footer embed.set_footer(text='Private Room', icon_url=owner.avatar_url) # Try to send embed try: await owner.send(embed=embed) except Forbidden: pass
async def roles_page(channel: TextChannel, guild: Guild) -> None: """ Sends a page with all information about the setup of roles. :param guild: Guild of call :param channel: TextChannel to send the message to """ # Initialize important values prefix = appearance.get_prefix(guild.id) # Setup appearance of the embed embed: Embed = Embed(title=f'{appearance.bot_name} Setup - Roles', description='Setup the roles!', colour=appearance.get_color(guild.id)) # Get existing roles admin_roles = '\n'.join( map(lambda r: r.mention, roles.get_admin_roles(guild))) moderator_roles = '\n'.join( map(lambda r: r.mention, roles.get_moderator_roles(guild))) # support_roles = '\n'.join(map(lambda r: r.mention, roles.get_support_roles(guild))) auto_roles = '\n'.join( map(lambda r: r.mention, roles.get_auto_roles(guild))) # Add information about the roles already existing to embed if admin_roles: embed.add_field(name='Admin Roles', value=admin_roles, inline=True) if moderator_roles: embed.add_field(name='Moderator Roles', value=moderator_roles, inline=True) # if support_roles: # embed.add_field(name='Support Roles', value=support_roles, inline=True) if auto_roles: embed.add_field(name='Autoroles', value=auto_roles, inline=True) embed.add_field(name='\u200b', value='\u200b', inline=False) # Add information about the commands embed.add_field( name='Add Roles', value=f'`{prefix}{description.get_command("roles add").syntax}`' f'\nThe type is either *admin*, *moderator* or *autorole*.', inline=False) embed.add_field( name='Remove Roles', value=f'`{prefix}{description.get_command("roles remove").syntax}`' f'\nThe type is either *admin*, *moderator* or *autorole*.', inline=False) await channel.send(embed=embed)
async def remove_role(guild: Guild, role: Role, type_: str, channel: TextChannel, message: Message) -> None: """ Remove a role from the server :param guild: Guild of the role :param role: Role :param type_: Type of the role :param channel: Channel of message :param message: Message of the command call """ # Dele # Delete message of member await util.delete_message(message) # Check for type and remove the role type_ = type_.lower() if type_ == 'admin': roles.remove_admin_role(role) elif type_ == 'moderator': roles.remove_moderator_role(role) # elif type_ == 'supporter': # roles.remove_support_role(role) elif type_ == 'autorole': roles.remove_auto_role(role) else: raise Exception('Invalid type') # Send message if type_ == 'autorole': embed: Embed = Embed( description=f'Removed {role.mention} from **{type_}s**', colour=appearance.get_color(guild.id)) else: embed: Embed = Embed( description=f'Removed {role.mention} from **{type_} roles**', colour=appearance.get_color(guild.id)) await channel.send(embed=embed)
async def setup_moderation_log(channel: TextChannel, guild: Guild, message: Message, mod_log: TextChannel = None) -> None: """ Set up th moderation log channel for the server :param channel: Channel of message :param guild: Guild for moderation log :param message: Message of the command call :param mod_log: The channel set as moderation log """ if mod_log: # Delete message of member await util.delete_message(message) # Throw exception if the mod_log isn't a channel of the guild if mod_log not in guild.channels: raise util.InvalidInputError( mod_log, 'The moderation log has to be a text-channel of the server.') # Set moderation log mod.set_mod_log(guild, mod_log.id) # Send response to command await channel.send(embed=Embed( description=f'The **moderation log** was set to {mod_log.mention}', colour=appearance.get_color(guild.id))) else: # Deactivate moderation log mod.set_mod_log(guild, None) # Send response to command await channel.send( embed=Embed(description='The **moderation log** was deactivated', colour=appearance.get_color(guild.id)))
async def _member_help(message: Message) -> None: """ Sends help message for members in the text channel. :param message: Message that executed the command """ # Initialize attributes of message channel: TextChannel = message.channel guild: Guild = message.guild member: Member = message.author prefix = appearance.get_prefix(guild.id) # Setup embed content embed: Embed = Embed() embed.title = 'Commands - ' + appearance.bot_name # Add fields for commands for cmd in description.commands: if cmd.member_cmd() and cmd.in_help(guild): embed.add_field(name='`' + prefix + cmd.syntax + '`', value=cmd.description, inline=False) # Add fields for other bot functions cpr_channel: VoiceChannel = private_rooms.get_cpr_channel(guild) if cpr_channel: settings_channel: TextChannel = private_rooms.get_settings_channel( guild) embed.add_field(name='\u200b', value='\u200b', inline=False) embed.add_field( name='Private Rooms', value=f'• Join `{cpr_channel.name}` to create a private Room\n' f'• Adjust the settings in {settings_channel.mention}', inline=False) # Setup embed style embed.colour = appearance.get_color(guild.id) embed.set_thumbnail(url=guild.get_member(secret.bot_id).avatar_url) embed.set_footer( text= f'{prefix}help <command> for detailed information | <> Required | () Optional', icon_url=member.avatar_url) # Send message await channel.send(embed=embed)
async def setup_welcome_dm_text(channel: TextChannel, guild: Guild, message: Message, text: str) -> None: """ Sets up the welcome dm text for the server. :param channel: Channel of message :param guild: Guild of welcome channel :param message: Message of the command call :param text: The text for the welcome messages via dm """ # Delete message of member await util.delete_message(message) welcome_sys.set_welcome_dm(guild, text) # Send response to command await channel.send(embed=Embed( description=f"The text for **welcome DMs** was set to:\n*'{text}'*", colour=appearance.get_color(guild.id)))
async def setup_welcome_channel(channel: TextChannel, guild: Guild, message: Message, welcome_channel: TextChannel) -> None: """ Sets up the welcome channel for the server. :param channel: Channel of message :param guild: Guild of welcome channel :param message: Message of the command call :param welcome_channel: The channel, welcome channel will be set to """ # Delete message of member await util.delete_message(message) welcome_sys.set_welcome_channel(guild, welcome_channel.id) # Send response to command await channel.send(embed=Embed( description= f"The **welcome channel** was set to {welcome_channel.mention}", colour=appearance.get_color(guild.id)))
async def setup_color(channel: TextChannel, guild: Guild, message: Message = None, color: str = None) -> None: """ Command for setting prefix on guild. :param guild: Guild of call :param channel: TextChannel to send the message to :param message: Message that called the command :param color: The given primary color hex-code :raises InvalidInputError: When the given primary_color isn't 'default', hex-color code or integer """ # Delete message of member await util.delete_message(message) # Set color to valid integer if color: try: if color.startswith("#"): color = int("0x" + color[1:], 16) elif color.startswith("0x"): color = int(color, 16) else: color = int("0x" + color, 16) # Set primary color of the server appearance.set_color(guild_id=guild.id, color=color) except TypeError: raise util.InvalidInputError( color, "color has to be an hex-code or integer") else: # Set color to default appearance.set_color(guild.id) # Send response to command await channel.send(embed=Embed(description="The **color** was updated", colour=appearance.get_color(guild.id)))
async def setup_prefix(channel: TextChannel, guild: Guild, message: Message = None, prefix: str = None) -> None: """ Command for setting prefix on guild. :param guild: Guild of call :param channel: TextChannel to send the message to :param message: Message that called the command :param prefix: The given prefix :raises InvalidInputError: When the given prefix isn't 'default' or a single character """ # Delete message of member await util.delete_message(message) appearance.set_prefix(guild_id=guild.id, prefix=prefix) # Send response to command await channel.send(embed=Embed( description= f"The **prefix** was set to `{appearance.get_prefix(guild.id)}`", colour=appearance.get_color(guild.id)))
async def welcome_dm(member: Member, channel: TextChannel = None, force: bool = False): """ Welcome members to the server via DM :param member: Member to welcome :param channel: Channel of call :param force: Force the dm without checking whether they are enabled """ guild: Guild = member.guild if not select.welcome_dms(guild.id) and not force: # Only send welcome dms when they are enabled on guild return # Set welcome text text: str = select.welcome_dm(guild.id) # Replace <member> with the name of the member text = text.replace('<member>', member.display_name) # Setup embed embed: Embed = Embed(title=f'Welcome to {guild.name}!', description=text, color=appearance.get_color(guild.id)) embed.set_thumbnail(url=guild.icon_url) embed.set_footer( text=f'Use {appearance.get_prefix(guild.id)}help on {guild.name}', icon_url=guild.get_member(secret.bot_id).avatar_url) # Send direct message or in channel if dm is forbidden try: await member.send(embed=embed) except Forbidden: if channel and force: await channel.send(embed=embed)
async def welcome_page(channel: TextChannel, guild: Guild) -> None: """ Sends a page with all information about the setup of the welcome system. :param guild: Guild of call :param channel: TextChannel to send the message to """ # Initialize important values prefix = appearance.get_prefix(guild.id) # Setup appearance of the embed embed: Embed = Embed(title=f'{appearance.bot_name} Setup - Welcome', description='Setup the welcome system!') embed.colour = appearance.get_color(guild.id) # Emojis whether welcome/leave is setup welcome_dm_emoji = '✅' if select.welcome_dms(guild.id) else '❌' welcome_emoji = '✅' if select.welcome_messages(guild.id) else '❌' leave_emoji = '✅' if select.leave_messages(guild.id) else '❌' welcome_channel: TextChannel = guild.get_channel( select.welcome_channel_id(guild.id)) welcome_dm = select.welcome_dm(guild.id) # Setup the fields embed.add_field(name='Welcome Messages Set Up?', value=welcome_emoji, inline=True) embed.add_field(name='Toggle Welcome Messages', value='React with 👋', inline=True) embed.add_field(name='\u200b', value='\u200b', inline=True) embed.add_field(name='Leave Message Set Up?', value=leave_emoji, inline=True) embed.add_field(name='Toggle Leave Messages', value='React with 🚶♂️', inline=True) embed.add_field(name='\u200b', value='\u200b', inline=True) embed.add_field(name='Welcome DMs Set Up?', value=welcome_dm_emoji, inline=True) embed.add_field(name='Toggle Welcome DMs', value='React with 📩', inline=True) embed.add_field(name='\u200b', value='\u200b', inline=True) embed.add_field(name='\u200b', value='\u200b', inline=False) if welcome_channel: embed.add_field(name='Welcome Channel', value=welcome_channel.mention, inline=True) embed.add_field( name='Set Welcome Channel', value=f'`{prefix}{description.get_command("welcome channel").syntax}`', inline=False) embed.add_field(name='\u200b', value='\u200b', inline=False) if welcome_dm: embed.add_field(name='Preview Welcome DM', value='React with 📄', inline=False) embed.add_field( name='Set Welcome DM Text', value=f'`{prefix}{description.get_command("welcome dm").syntax}`' f"\n'<member>' will be replaced by the name" f"\nof the member.", inline=False) # Send embed and add reactions message = await channel.send(embed=embed) await message.add_reaction(emoji='👋') await message.add_reaction(emoji='🚶♂️') await message.add_reaction(emoji='📩') if welcome_dm: await message.add_reaction(emoji='📄')
async def moderation_page(channel: TextChannel, guild: Guild): """ Sends a page with all information about the setup of moderation. :param guild: Guild of call :param channel: TextChannel to send the message to """ # Initialize important values prefix = appearance.get_prefix(guild.id) # Setup appearance of the embed embed: Embed = Embed(title=f'{appearance.bot_name} Setup - Moderation', description='Setup the moderation system!', colour=appearance.get_color(guild.id)) # Add information about moderation roles embed.add_field(name='Set Moderation Roles', value=f'React with 👥', inline=False) mod_log: TextChannel = mod.get_mod_log(guild) # Add information about the current moderation log embed.add_field(name='\u200b', value='\u200b', inline=False) embed.add_field(name='Moderation Log', value='• Get notified of mod operations\n' '• Unlock reports', inline=False) if mod_log: embed.add_field(name='Current Channel', value=mod_log.mention, inline=False) # Add information about the commands embed.add_field( name='Set Moderation Log', value=f'`{prefix}{description.get_command("moderation log").syntax}`', inline=False) # How to deactivate moderation log if mod_log: embed.add_field(name='Deactivate Moderation Log', value='React with 📪', inline=False) # Add information about the warn system embed.add_field(name='\u200b', value='\u200b', inline=False) embed.add_field(name='Warn Punishment', value=f'• **1 warn:** 20 min mute\n' f'• **3 warns within two weeks:** 2h mute\n' f'• **4 warns within one month:** 24h mute & kick') # Add information about mute mute_role: Role = await mute.get_mute_role(guild) embed.add_field(name='\u200b', value='\u200b', inline=False) embed.add_field( name='Problems With Mute?', value=f'Make sure the position of {mute_role.mention} is high enough.') # Send embed msg = await channel.send(embed=embed) # Add reactions await msg.add_reaction('👥') if mod_log: await msg.add_reaction('📪')
async def setup_settings(guild: Guild) -> None: """ Setup setting messages for the guild :param guild: Guild to set up setting messages """ old_channel: TextChannel = private_rooms.get_settings_channel(guild) await asyncio.sleep(0.2) category: CategoryChannel = private_rooms.get_category(guild) # Create settings channel, set permissions and add to database settings_overwrites = { guild.default_role: PermissionOverwrite(view_channel=False, send_messages=False), } settings_channel: TextChannel = await guild.create_text_channel('settings', category=category, overwrites=settings_overwrites, reason='Setup private rooms') update.pr_settings_id(argument=guild.id, value=settings_channel.id) await asyncio.sleep(0.2) if old_channel: try: await old_channel.delete() except NotFound: pass try: # Send settings embed and add emoji settings_emebd: Embed = Embed(title='Private Room Settings', description='Here you can adjust your private room', colour=appearance.get_color(guild.id)) settings_emebd.add_field(name='Current Settings', value='React with ℹ️ to get the current settings of your room ' 'via dm') settings_msg: Message = await settings_channel.send(embed=settings_emebd) await settings_msg.add_reaction(emoji='ℹ️') if select.pr_change_name(guild.id): # Send lock embed and add emoji lock_embed: Embed = Embed(title='Name', description='Set the name of your private room', colour=appearance.get_color(guild.id)) lock_embed.add_field(name='Set Name', value='React with 🪧 to change the name of your private room\n' 'You have 10 seconds time to write the new name in this text channel' ' (20 characters maximum)') lock_embed.add_field(name='Toggle Game Activity', value='React with 🎮 to toggle whether the main game activity of ' 'your room is shown in the name', inline=False) lock_msg: Message = await settings_channel.send(embed=lock_embed) await lock_msg.add_reaction(emoji='🪧') await lock_msg.add_reaction(emoji='🎮') if select.pr_change_privacy(guild.id): # Send lock embed and add emoji lock_embed: Embed = Embed(title='Privacy', description='Decide whether members can join your private room or ' 'have to be moved', colour=appearance.get_color(guild.id)) lock_embed.add_field( name='Toggle Privacy', value='React with 🔒 to lock or unlock your private room') lock_msg: Message = await settings_channel.send(embed=lock_embed) await lock_msg.add_reaction(emoji='🔒') if select.pr_change_limit(guild.id): # Send limit embed and add emojis limit_embed: Embed = Embed(title='Limit', description='Set how many users can join your channel', colour=appearance.get_color(guild.id)) limit_embed.add_field( name='No Limit', value='React with 🔄 to set no user limit', inline=False) limit_embed.add_field(name='Limit', value='React with 🔢 to set the user limit to a specific number\n' 'You have 10 seconds time to write the new limit in this text channel', inline=False) limit_msg: Message = await settings_channel.send(embed=limit_embed) await limit_msg.add_reaction(emoji='🔄') await limit_msg.add_reaction(emoji='🔢') if select.pr_change_visibility(guild.id): # Send hide embed and add emoji hide_embed: Embed = Embed(title='Visibility', description='Adjust whether your channel can be seen or not', colour=appearance.get_color(guild.id)) hide_embed.add_field( name='Toggle Visibility', value='React with 👀 to lock or unlock your private room') hide_msg: Message = await settings_channel.send(embed=hide_embed) await hide_msg.add_reaction(emoji='👀') except NotFound: return