async def set_cmd(self, ctx, channel_id: int): channel = self.client.get_channel(channel_id) e = success_embed(self.client) e.description = f"{channel.mention} is now the command channel" await ctx.send(embed=e) await self.client.cache.states[ctx.guild.id].update_channel("cmd", channel_id) edit_settings_cmd.delay(ctx.guild.id, channel_id)
async def set_stdout(self, ctx, channel_id: int): channelstdout = self.client.get_channel(channel_id) e = success_embed(self.client) e.description = f"{channelstdout.mention} is now the standard out channel" await ctx.send(embed=e) await self.client.cache.states[ctx.guild.id].update_channel("stdout", channel_id) edit_settings_stdout.delay(ctx.guild.id, channel_id)
async def on_message(self, message): if message.guild is None: return if message.content is None: return if not await _enabled(self.client, message.guild.id): return if message.author.id == self.client.user.id: return channel_id = self.client.cache.states[message.guild.id].get_channel( "lvl") print(channel_id) if channel_id is None or channel_id == 0: channel = message.guild.system_channel else: channel = self.client.get_channel(channel_id) xp_before = await self.client.sql.get_text_xp(message.guild.id, message.author.id) xp_after = await update_data(message, xp_before) e = success_embed(self.client) lvl_start = await self.client.sql.get_lvl_text(message.guild.id, message.author.id) lvl_end = int(float(int(xp_after)**(1 / 4))) if lvl_start < lvl_end: e.title = "LEEVEEL UP" e.description = f"{message.author.mention} reached level {lvl_end} and has now {xp_after}XP" await channel.send(embed=e) update_text_lvl.delay(message.guild.id, message.author.id, lvl_end) update_xp_text.delay(message.guild.id, message.author.id, xp_after)
async def roleinfo(self, ctx, role: discord.Role = None): counter = 0 for members in self.client.get_all_members(): for i in members.roles: if role == i: counter += 1 e = success_embed(self.client) e.description = f"Here are some important info's about {role.mention}" e.add_field(name="Members", value=f"Has {counter} members", inline=True) e.add_field(name="Created at", value=f"Was created at \n{role.created_at}", inline=True) e.add_field(name="Color", value=f"Has this {role.color} color", inline=True) e.add_field(name="Permissions", value=f"Shown as integers \n{role.permissions}", inline=True) e.add_field(name="Shown on the right", value=f"{role.hoist}", inline=True) e.add_field(name="Is mentionable", value=f"{role.mentionable}", inline=True) await ctx.send(embed=e)
async def prefix(self, ctx, arg: str): e = success_embed(self.client) await self.client.cache.states[ctx.guild.id].set_prefix(arg) prefix = self.client.cache.states[ctx.guild.id].get_prefix e.description = f"{prefix} is now the bot prefix" await ctx.send(embed=e) set_prefix.delay(ctx.guild.id, arg)
async def set_warns(self, ctx, channel_id: int): channelwarn = self.client.get_channel(channel_id) e = success_embed(self.client) e.description = f"{channelwarn.mention} is now the warn channel" await ctx.send(embed=e) await self.client.cache.states[ctx.guild.id].update_channel("warn", channel_id) edit_settings_warn.delay(ctx.guild.id, channel_id)
async def roles_in_db(self, ctx): for i in ctx.guild.roles: roles_to_db.delay(ctx.guild.id, i.name, i.id) e = success_embed(self.client) e.title = "Hey" e.description = f"I'm done {ctx.author.mention} <3" await ctx.send(embed=e) return e
async def unmute(self, ctx, member: discord.Member = None): e = success_embed(self.client) try: e.description = f"{member.mention} has been unmuted " await member.remove_roles(discord.utils.get(ctx.guild.roles, name="Muted")) await ctx.send(embed=e) except discord.DiscordException: e.description = f"{member.mention} already unmuted or {member.mention} was never muted" await ctx.send(embed=e) return e
async def levelsystemtoggle(self, ctx): e = success_embed(self.client) if self.client.cache.states[ctx.guild.id].get_levelsystem == 1: edit_settings_levelsystem.delay(ctx.guild.id, 0) e.description = "The levelsystem is now disabled" else: edit_settings_levelsystem.delay(ctx.guild.id, 1) e.description = "The levelsystem is now enabled" await self.client.cache.states[ctx.guild.id].set_lvltoggle() await ctx.send(embed=e)
async def load(self, ctx, module: str): cog = "base_folder.bot.modules." + module try: self.client.load_extension(cog) except Exception as ex: e = error_embed(self.client) e.description = f"{cog} could not be loaded, here is the error:{ex}" await ctx.send(embed=e) e = success_embed(self.client) e.description = f"{cog} loaded" await ctx.send(embed=e)
async def tempmute(self, ctx, member: discord.Member = None, reason="you made a mistake", time: int = 0): muteduntil = ctx.message.created_at + datetime.timedelta(hours=time) role = discord.utils.get(ctx.guild.roles, name="Muted") e = success_embed(self.client) e.description = f"{member.mention} was successfully muted for {reason} until {muteduntil}" await member.add_roles(role) await ctx.send(embed=e) edit_muted_at.delay(ctx.guild.id, member.id, ctx.message.created_at) muted_until.delay(ctx.guild.id, member.id, muteduntil) self.client.scheduler.add_job(self.unmute, "date", run_date=muteduntil, args=[ctx, member]) return e
async def builddb(self, ctx): """ Currently broken but in theory it should build the database if it somehow wasn't on guild join :param ctx: :return: """ initialize_guild.delay(ctx.guild.id) async for user in ctx.guild.fetch_members(): print(user) is_user_indb.delay(user.name, user.id, ctx.guild.id) e = success_embed(self.client) e.title = "Hey" e.description = f"I'm done my master {ctx.author.mention} <3" await ctx.send(embed=e)
async def kick(self, ctx, member: discord.Member = None, reason: str = "Because you were bad. We kicked you."): e = success_embed(self.client) if member is not None: e.description = f"{member.mention} has been successfully kicked for {reason}" await ctx.send(embed=e) e.description = f"You have been banned from {ctx.guild.name} for {reason}."\ f"If you think this is wrong then message an admin but shit happens"\ f" when you don't have the name." await ctx.guild.kick(member, reason=reason) await member.send(embed=e) else: e.title = "Error!" e.description = f"You need to specify a member via mention" await ctx.send(embed=e) return e
async def slowmode(self, ctx, seconds: int = 0): e = success_embed(self.client) if seconds > 120: e.description = ":no_entry: Amount can't be over 120 seconds" await ctx.send(embed=e) if seconds == 0: e.description = f"{ctx.author.mention} tuned slow mode off for the channel {ctx.channel.mention}" await ctx.channel.edit(slowmode_delay=seconds) await ctx.send(embed=e) else: e.description = f"{ctx.author.mention} set the {ctx.channel.mention} channel's slow mode delay " \ f"to `{seconds}`" \ f"\nTo turn this off, do prefixslowmode" await ctx.channel.edit(slowmode_delay=seconds) await ctx.send(embed=e) return e
async def unban(self, ctx, member: str = "", reason: str = "You have been unbanned. Time is over. Please behave"): e = success_embed(self.client) if member == "": e.title = "Error!" e.description = f"No member specified! Specify a user by writing his name without #tag" await ctx.send(embed=e) bans = await ctx.guild.bans() for b in bans: if b.user.name == member: e.description = f"{b.user.name} has been successfully unbanned!" await ctx.guild.unban(b.user, reason=reason) await ctx.sende(embed=e) e.description = f"{member} wasn't found in the ban list so either you wrote the name " \ f"wrong or {member} was never banned!" await ctx.send(embed=e) return e
async def tempban(self, ctx, member: discord.Member = None, time: int = 2): reason = "Tempban" e = success_embed(self.client) if member is not None: banneduntil = ctx.message.created_at + datetime.timedelta( hours=time) e.description = f"{member.mention} was successfully banned for {reason}, until {banneduntil}" await ctx.send(embed=e) e.title = "Banned" e.description = f"You have been banned from {ctx.guild.name} for {reason}" \ f"If you think this is wrong then message an admin but shit happens" \ f"when you don't have the name." await member.send(embed=e) edit_banned_at.delay(ctx.guild.id, member.id, ctx.message.created_at) banned_until.delay(ctx.guild.id, member.id, banneduntil) return e
async def warn(self, ctx, member: discord.Member = None, *, reason="you made a mistake"): warnings = await self.client.sql.get_warns(ctx.guild.id, member.id) e = success_embed(self.client) if warnings == 0: warnings += 1 edit_warns.delay(ctx.guild.id, member.id, warnings) e.description = f"{member.mention} you have been warned this is your " \ f"first infraction keep it at this, reason {reason}" await member.send(embed=e) await ctx.send(embed=e) else: warnings += 1 e.description = f"{member.mention} you have been warned, you have now {warnings} warning(s)" edit_warns.delay(ctx.guild.id, member.id, warnings) await member.send(embed=e) await ctx.send(embed=e) return e
async def ban(self, ctx, member: discord.Member = None, reason: str = "Because you are naughty. We banned you."): e = success_embed(self.client) if member is not None: e.description = f"You have been banned from {ctx.guild.name} for {reason}."\ f"If you think this is wrong then message an admin but shit happens"\ f" when you don't have the name." await member.send(embed=e) await ctx.guild.ban(member, reason=reason) e.description = f"{member.mention} has been successfully banned for {reason}." await ctx.send(embed=e) edit_banned_at.delay(ctx.message.created_at) else: e.description = f"You need to specify an member" await ctx.send(embed=e) return e
async def mute(self, ctx, member: discord.Member = None, reason="you made a mistake"): role = discord.utils.get(ctx.guild.roles, name="Muted") # retrieves muted role returns none if there isn't e = success_embed(self.client) e.description = f"{member.mention} was successfully muted for {reason}" if not role: # checks if there is muted role try: # creates muted role muted = await ctx.guild.create_role(name="Muted", reason="To use for muting") for channel in ctx.guild.channels: # removes permission to view and send in the channels await channel.set_permissions(muted, send_messages=False, read_message_history=False, read_messages=False) except discord.Forbidden: e = error_embed(self.client) e.description = f"Master please give me admin rights" return await ctx.send(embed=e) # self-explainatory await member.add_roles(muted) # adds newly created muted role await ctx.send(embed=e) else: await member.add_roles(role) # adds already existing muted role await ctx.send(embed=e) return e
async def give_role(self, ctx, member: discord.Member, role: discord.Role): e = success_embed(self.client) e.description = f"Giving the role {role.mention} to {member.mention}" await ctx.send(embed=e) await member.add_roles(role) return e
async def set_mod(self, ctx, role: discord.Role = None): e = success_embed(self.client) e.description = f"{role} is now the mod role" await ctx.send(embed=e) await self.client.cache.states[ctx.guild.id].update_permission_role("mod", role.id) edit_settings_role.delay(ctx.guild.id, role.id, "mod_role_id")
async def infractions(self, ctx, member: discord.Member = None): e = success_embed(self.client) warnings = await self.client.sql.get_warns(ctx.guild.id, member.id) e.description = f"{member.mention} Has {warnings} infraction(s)!" await ctx.send(embed=e) return e
async def delete(self, ctx, limit: int): await ctx.channel.purge(limit=limit+1) e = success_embed(self.client) e.description = f"cleared: {limit} messages!" await ctx.send(embed=e) return e