async def icon_cmd(ctx: Message, *args: str): channel, guild, user, msg = utils.unpack(ctx) # type: TextChannel, Guild, User, Message if not args: url = str(user.avatar_url) embed = Embed(color=user.color) embed.set_image(url=url) embed.set_author(name=f"{user}'s icon") embed.set_footer(text=f'Executed by {user}') await channel.send(embed=embed) return mentioned = args[0] if not utils.is_match_usermention(mentioned): await channel.send("That's not a user mention!") return target = guild.get_member(utils.parse_user_mention(mentioned)) if not target: await channel.send(f'Cannot find user with the ID of `{utils.parse_user_mention(mentioned)}`!') return embed = Embed(color=target.color) embed.set_image(url=str(target.avatar_url)) embed.set_author(name=f"{target}'s icon") embed.set_footer(text=f'Executed by {user}') await channel.send(embed=embed)
async def prefix_cmd(ctx: Context, *args: str): """handles the prefix command, get or set here""" channel, guild, user, msg = utils.unpack( ctx) # type: TextChannel, Guild, User, Message member: Member = guild.get_member(user.id) current_prefix = await bot.get_prefix(msg) if not len(args): await channel.send(f'The command prefix is `{current_prefix}`') return if not member.guild_permissions.administrator: await channel.send('No permission!') return new_prefix = args[0] server = utils.server_manager.find_server(guild) server.set_prefix(new_prefix) utils.server_manager.save_servers() await channel.send( f'The bot command prefix for this server has changed to `{new_prefix}`!' )
async def clear_cmd(ctx: Context, *args: str): """Clears the messages within the channel that was sent to""" channel, guild, user, msg = utils.unpack( ctx) # type: TextChannel, Guild, User, Message member: Member = guild.get_member(user.id) if not member.guild_permissions.administrator: await channel.send('No permission!') return if not args: await channel.send(f'Usage: {bot.command_prefix}clear <amount>') return if not utils.isnum(args[0]): await channel.send("wtf? that ain't a number you stupid head!") return amount = int(args[0]) if amount < 1: await channel.send('What are you trying to delete with those numbers?') return if amount > 100: await channel.send( 'The discord limit to delete multiple messages is 100!') return deleted_messages = await channel.purge(limit=amount) response = await channel.send( f'{len(deleted_messages)} messages are purged!') await response.delete(delay=5)
async def help_cmd(ctx: Context, *args: str): channel, guild, user, msg = utils.unpack( ctx) # type: TextChannel, Guild, User, Message commands_list: Set[Command] = bot.commands if not args: embed = discord.Embed(title='Command List', color=0x79FF00) embed.set_thumbnail(url=bot.user.avatar_url) name_list = [] for cmd in commands_list: name_list.append(cmd.name) embed.description = f'**Unknown commands**\n`{", ".join(name_list)}`' await channel.send(embed=embed) else: cmd: Command = bot.get_command(args[0]) if not cmd: await channel.send(f'Cannot find any command called {args[0]}!') return embed = discord.Embed(title='Command Info', color=0x79FF00) embed.set_thumbnail(url=bot.user.avatar_url) embed.description = f''' Information for command named {args[0].lower()} **Name**: {cmd.name} **Aliases**: [{', '.join(cmd.aliases)}] **Description**: {'-' if not cmd.description else cmd.description} ''' await channel.send(embed=embed)
async def info_cmd(ctx: Context, *args: str): channel, guild, user, msg = utils.unpack( ctx) # type: TextChannel, Guild, User, Message embed = discord.Embed(title='Information', description=''' Just a bot that is made for fun! Actually... to learn python :P [You can go to my GitHub profile here](https://github.com/Alviannn) ''', color=Colour.blue()) try: embed.set_thumbnail(url=bot.user.avatar_url) embed.set_footer(text='Made by Alvian#1341') embed.add_field(name='Python', value=sys.version.split(' ')[0]) embed.add_field(name='discord.py', value=discord.__version__) # first time learning elapsed and string formatting elapsed = utils.current_millis() - utils.start_time elapsed_format = utils.from_elapsed_millis(elapsed) embed.add_field(name='Online Time', value=elapsed_format, inline=False) embed.add_field(name='Source Code', value='This bot is open-source, you can view it ' '[here](https://github.com/Alviannn/KiritodBot/)', inline=False) headers = {'user-agent': 'Mozilla/5.0'} with requests.get('https://github.com/Alviannn/KiritodBot', headers=headers) as res: version = html5lib.__version__ soup = BeautifulSoup(res.text, 'html5lib') if soup: grabbed_list = soup.find_all('span', attrs={'class': 'd-none d-sm-inline'}) repo_info = grabbed_list[1] if len( grabbed_list) == 2 else grabbed_list[0] total_commits = int(repo_info.strong.text) embed.add_field(name='Total Commits', value=f'**{total_commits}** commits') await channel.send(embed=embed) except Exception as error: print(error)
async def eval_cmd(ctx: Context, *args: str): """Evaluates a given python code""" channel, guild, user, msg = utils.unpack( ctx) # type: TextChannel, Guild, User, Message member: Member = guild.get_member(user.id) if not member.guild_permissions.administrator: await channel.send('No permission!') return if not len(args): await channel.send('Cannot evaluate an empty string!') return raw_input = ' '.join(args) await utils.super_eval(raw=raw_input, msg=ctx.message)
async def on_message(msg: discord.Message): channel, guild, user = utils.unpack(msg) # type: TextChannel, Guild, User content = str(msg.content) if content.startswith('```py') or content.startswith('```python') and content.endswith('```'): await utils.super_eval(content, msg) return try: match = re.compile(r'^<@!?[0-9]{18}>$') if user.bot or not match.match(content) or msg.mentions[0] != bot.user: return prefix = await bot.get_prefix(message=msg) await channel.send(f"Hello {user.mention}! My command prefix is `{prefix}`!") except Exception as error: print(error)
async def show_perm(ctx: Context, *args: str): """shows the permission of a discord user""" channel, guild, user, msg = utils.unpack( ctx) # type: TextChannel, Guild, User, Message member: Member = guild.get_member(user.id) if not member.guild_permissions.administrator: await channel.send('No permission!') return target_member: Member if not args: target_member = member else: if len(msg.mentions) == 0: await channel.send('Mention someone to view their permissions!') return mentioned_user: User = msg.mentions[0] target_member = guild.get_member(mentioned_user.id) if not target_member: await channel.send('Who are you trying to call?') return embed = discord.Embed(title=f'{target_member} permisions', color=0xFF0000) count = 0 indexes = [] perms = [] statuses = [] for perm, status in target_member.guild_permissions: count += 1 indexes.append(str(count)) perms.append(f'**{perm}**') statuses.append(str(status).lower()) embed.add_field(name='Indexes', value='\n'.join(indexes), inline=True) embed.add_field(name='Permissions', value='\n'.join(perms), inline=True) embed.add_field(name='Statuses', value='\n'.join(statuses), inline=True) await channel.send(embed=embed)
async def varied_cmd(ctx: Context, *args: str): channel, guild, user, msg = utils.unpack(ctx) # type: TextChannel, Guild, User, Message target_msg = ' '.join(args) if not args: await channel.send('Try filling up a random word!') return def rand(): return random.randint(0, 1) == 1 builder = [] for char in target_msg: if rand(): builder.append(char.upper()) continue builder.append(char) await channel.send(f"Oi {user.mention}! Here's your varied words: `{''.join(builder)}`")
async def reboot_cmd(ctx: Context, *args: str): """Reboots the discord bot""" channel, guild, user, msg = utils.unpack( ctx) # type: TextChannel, Guild, User, Message member: Member = guild.get_member(user.id) if not member.guild_permissions.administrator: await channel.send('No permission!') return await channel.send('Rebooting the bot....') with open('reboot.json', 'w') as file: data = {'guild': guild.id, 'channel': channel.id} file.write(json.dumps(data)) file.flush() utils.shutdown(closeall=False, restart=True)