async def remove(self, ctx, user: discord.User = None, table: str = None): if user and table: if table == "admins" or table == "owners": if self.owner_check( ctx.author.id) or ctx.author.id == 439327545557778433: if self.has_access(user): if self.remove_access(user, table): await ctx.send(embed=func.Editable( f"Removed {user.name} from {table}", "", "Access"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E( "Something went wrong. Please try again", "", "Access"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E( "That user has no access rights", "", "Access"), delete_after=config.deltimer) else: await ctx.send(embed=func.NoPerm()) else: await ctx.send(embed=func.Editable_E( f"Please type 'admins' or 'owners'", "", "Access"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E( f"Mention a user & access rank", "", "Access"), delete_after=config.deltimer)
async def load(self, ctx, cog: str = None): if cog: try: self.bot.load_extension(f"modules.cogs.{cog}") await ctx.send(embed=func.Editable("Done", f"{cog} was successfully loaded.", "Cogs"), delete_after=config.deltimer) except Exception as error: await ctx.send(embed=func.Editable_E(f"An unexpected error occurred", f"{cog} failed to load", "Error"), delete_after=config.deltimer) func.log(error) else: await ctx.send(embed=func.Editable_E("You missed something", "Please name a cog to load", "Error"), delete_after=config.deltimer)
async def set(self, ctx, flag = None): GID = str(ctx.guild.id) if flag: if flag == "-s": self.logs[GID]["Server_Logs"]["Enabled"] = True self.logs[GID]["Server_Logs"]["Channel"] = ctx.channel.id with open("./data/settings/logs.json", "w") as f: json.dump(self.logs, f, indent=4) await ctx.send(embed=func.Editable_S(f"Server Logs Enabled and set to **{ctx.channel.name}**", "", "Logs"), delete_after=config.deltimer) elif flag == "-e": self.logs[GID]["Edit_Logs"]["Enabled"] = True self.logs[GID]["Edit_Logs"]["Channel"] = ctx.channel.id with open("./data/settings/logs.json", "w") as f: json.dump(self.logs, f, indent=4) await ctx.send(embed=func.Editable_S(f"Message Edit Logs Enabled and set to **{ctx.channel.name}**", "", "Logs"), delete_after=config.deltimer) elif flag == "-d": self.logs[GID]["Delete_Logs"]["Enabled"] = True self.logs[GID]["Delete_Logs"]["Channel"] = ctx.channel.id with open("./data/settings/logs.json", "w") as f: json.dump(self.logs, f, indent=4) await ctx.send(embed=func.Editable_S(f"Delete logs Enabled and set to **{ctx.channel.name}**", "", "Logs"), delete_after=config.deltimer) elif flag == "-c": self.logs[GID]["Channel_Logs"]["Enabled"] = True self.logs[GID]["Channel_Logs"]["Channel"] = ctx.channel.id with open("./data/settings/logs.json", "w") as f: json.dump(self.logs, f, indent=4) await ctx.send(embed=func.Editable_S(f"Channel Edit logs Enabled and set to **{ctx.channel.name}**", "", "Logs"), delete_after=config.deltimer) elif flag == "-r": self.logs[GID]["Role_Logs"]["Enabled"] = True self.logs[GID]["Role_Logs"]["Channel"] = ctx.channel.id with open("./data/settings/logs.json", "w") as f: json.dump(self.logs, f, indent=4) await ctx.send(embed=func.Editable_S(f"Channel Edit logs Enabled and set to **{ctx.channel.name}**", "", "Logs"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E("Invalid Arguments", f"{ctx.prefix}logs set flag - Sets the logging channel for the flag\n**-s** - Server Edit Logs\n**-e** - Message Edit logs\n**-d** - Message delete logs\n**-c** - Channel Logs\n**-r** - Role logs", "Logs"), delete_after=config.deltimer)
async def on_command_error(self, ctx, error): ignored = (commands.CommandNotFound, commands.NoPrivateMessage, commands.DisabledCommand, discord.NotFound) error = getattr(error, "original", error) if isinstance(error, ignored): return elif isinstance(error, commands.MissingPermissions): try: return await ctx.send(embed=func.Editable_E( "Error!", "Uh oh.. I seem to be missing some permissions!", "Error")) except discord.Forbidden: return elif isinstance(error, commands.CommandOnCooldown): return await ctx.send(embed=func.Editable_E( "Error!", f"Woah woah {ctx.author.mention} calm down, that command is currently cooling down!", "Error")) elif isinstance(error, commands.CheckFailure): return elif isinstance(error, discord.Forbidden): try: return await ctx.send(embed=func.Editable_E( "Error!", "Uh oh.. I seem to be missing some permissions! Use `!help permissions` to see what I require!", "Error")) except discord.Forbidden: return elif isinstance(error, discord.HTTPException): return await ctx.send(embed=func.Editable_E( "Error!", f"There was an error with your command! Here it is: {error}", "Error")) file = open("./utils/logs/Error.log", "a") file.write("[{}]: Command Error Logged {}\n".format( datetime.datetime.utcnow().strftime( "%d/%m/%Y at %H:%M:%S (System Time)"), error)) file.close() print("An error has been logged")
async def logs(self, ctx): GID = str(ctx.guild.id) if GID in self.logs: await ctx.send(embed=func.Editable_E("Invalid Arguments", f"{ctx.prefix}logs set flag\n{ctx.prefix}logs toggle", "Logs"), delete_after=config.deltimer) else: self.logs[GID] = logs_settings with open("./data/settings/logs.json", "w") as f: json.dump(self.logs, f, indent=4) await ctx.reinvoke()
async def pm(self, ctx, user: discord.User = None, *args): message = ' '.join(args) if message != "" and user: try: embed = discord.Embed( title=f"You've recieved a message from {ctx.author}", colour=0x9bf442, ) embed.set_author(name=f"Message from {ctx.author}", icon_url=f"{ctx.author.avatar_url}") embed.add_field(name="Message:", value=message, inline=True) embed.set_footer(text=f"UserID: {ctx.author.id}") await user.send(embed=embed) except Exception as error: await ctx.send( embed=func.Editable_E("An unexpected error occurred", "Message failed to send.", "Error"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E("You forgot something", "Please @someone and message to DM", "Error"), delete_after=config.deltimer)
async def add(self, ctx, roleid: int = None): if roleid: role = discord.utils.get(ctx.guild.roles, id=roleid) if role: if self.add_support_role(roleid): await ctx.send(embed=func.Editable( f"Added {roleid} to the Database", "", "Colour Roles"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E( "That role is not in the database", "", "Colour Roles"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E( "I couldnt find that role", "", "Colour Roles"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E( f"Please provide me with a role name", "", "Colour Roles"), delete_after=config.deltimer)
async def remove(self, ctx, roleid: int = None): if roleid: role = discord.utils.get(ctx.guild.roles, id=roleid) if role: if self.remove_support_role(roleid): await ctx.send(embed=func.Editable( f"Removed {roleid} from the Database", "", "Colour Roles"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E( "That user already has access rights", "", "Colour Roles"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E( "I couldnt find that role", "", "Colour Roles"), delete_after=config.deltimer) else: await ctx.send(embed=func.Editable_E( f"Please provide me with a role name", "", "Colour Roles"), delete_after=config.deltimer)
async def lockdown(self, ctx, flag: str = None): if not flag: await ctx.send(embed=func.Editable_E("Lockdown Help Page", f"{ctx.prefix}lockdown - Locks all channels down from users with no roles\n\n**__Flags__** (Optional)\n**-s** - Starts the lockdown\n**-u** - Stops the lockdown", "Lockdown"), delete_after=15) elif flag == '-s': for channels in ctx.guild.channels: role = discord.utils.get(ctx.guild.roles, name="@everyone") overwrite = discord.PermissionOverwrite() overwrite.send_messages = False await channels.set_permissions(role, overwrite=overwrite) await ctx.send("Locked down all channels", delete_after=30) elif flag == '-u': for channels in ctx.guild.channels: role = discord.utils.get(ctx.guild.roles, name="@everyone") overwrite = discord.PermissionOverwrite() overwrite.send_messages = None await channels.set_permissions(role, overwrite=overwrite) await ctx.send("Lock Down Removed", delete_after=30)
async def access(self, ctx): await ctx.send(embed=func.Editable_E("Available Options", "Usage:\n\naccess add @user {access}\naccess remove @user {access}\n\n Access Types: admins & owners", "Access"), delete_after=config.deltimer)
async def apply(self, ctx): emojis = ["✖️", "✔️"] UID = str(ctx.author.id) category_emojis = [] if ctx.message.guild.id == 540784184470274069 and ctx.channel.id == 660474909339680788: if not self.has_applied(UID): user = ctx.message.author guild = ctx.guild await ctx.message.delete() double_check = await user.send(embed=func.ENoFooter("Hey!", "Just to double check, you wish to apply for Helper in **My Anime Land**?")) await double_check.add_reaction(emojis[0]) await double_check.add_reaction(emojis[1]) def EmojisCheck(reaction, user): return ctx.author == user and str(reaction.emoji) == emojis[0] or ctx.author == user and str(reaction.emoji) == emojis[1] try: reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=EmojisCheck) except asyncio.TimeoutError: await start.delete() await ctx.author.send(embed=timeoutEmbed, delete_after=60) else: if str(reaction.emoji) == emojis[0]: await double_check.delete() await user.send(embed=func.Editable_E("Application Cancelled", "Thanks for your participation", "Cancelled")) elif str(reaction.emoji) == emojis[1]: await double_check.delete() await user.send("Ok perfect, you should get a notification about your application shortly.") overwrites = {ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False), ctx.author: discord.PermissionOverwrite(read_messages=True)} channel = await guild.create_text_channel(name=f"application-{user.id}", overwrites=overwrites) mention = await channel.send(user.mention) await mention.delete() main = await channel.send(embed=func.ENoFooter("Alright Cool. Lets begin with some questions", f"{user.mention} How old are you?")) try: age = await self.bot.wait_for("message", timeout=300, check=lambda message: message.author == user) await age.delete() except asyncio.TimeoutError: await msg.edit(embed=timeoutEmbed, delete_after=60) await channel.delete() else: if age.content.isdigit() and int(age.content) > 12: pass else: await main.edit(embed=discord.Embed(title="Invalid Age", color=0xff0000, description="Age must be a number, and above 12.")) await main.edit(embed=func.ENoFooter("Which timezone are you in?", "This question is optional. Type 'N/A' if you do not wish to answer")) try: timezone = await self.bot.wait_for("message", timeout=500, check=lambda message: message.author == user) await timezone.delete() except asyncio.TimeoutError: await msg.edit(embed=timeoutEmbed, delete_after=60) await channel.delete() else: await main.edit(embed=func.ENoFooter("Why do you want to become Helper?", "Please give detail in your answer. You'll have a better chance, I promise.")) try: reason = await self.bot.wait_for("message", timeout=300, check=lambda message: message.author == user) await reason.delete() except asyncio.TimeoutError: await msg.edit(embed=timeoutEmbed, delete_after=60) await channel.delete() else: await main.edit(embed=func.ENoFooter("Can you work as a team?", "You may be required to cover for another helper during their downtime.\n\nGive us a few reasons behind your answer")) try: teamwork = await self.bot.wait_for("message", timeout=300, check=lambda message: message.author == user) await teamwork.delete() except asyncio.TimeoutError: await msg.edit(embed=timeoutEmbed, delete_after=60) await channel.delete() else: await main.edit(embed=func.ENoFooter("Activity", "We take activity seriously. How active can you be throughout the week on average?")) try: activity = await self.bot.wait_for("message", timeout=300, check=lambda message: message.author == user) await activity.delete() except asyncio.TimeoutError: await msg.edit(embed=timeoutEmbed, delete_after=60) await channel.delete() else: await main.edit(embed=func.ENoFooter("Your Tasks", "Helpers main task is to keep the activity, revive channels and to clean them. Are you capable of that?")) await main.add_reaction(emojis[0]) await main.add_reaction(emojis[1]) try: reaction, user = await self.bot.wait_for('reaction_add', timeout=60.0, check=EmojisCheck) except asyncio.TimeoutError: await start.delete() await ctx.author.send(embed=timeoutEmbed, delete_after=60) else: if str(reaction.emoji) == emojis[0]: await channel.delete() await user.send(embed=func.Editable_E("Application Cancelled", "Thanks for your participation", "Cancelled")) elif str(reaction.emoji) == emojis[1]: capable = "Yes" await main.clear_reactions() final = discord.Embed( title=f"{user.name}'s Helper Application ({age.content})", colour=0xf7d17, ) final.add_field(name="Your Timezone", value=timezone.content, inline=True) final.add_field(name="Activity", value=activity.content, inline=True) final.add_field(name="Manage Tasks", value=capable, inline=True) final.add_field(name="Reasoning", value=reason.content, inline=False) final.add_field(name="Teamwork", value=teamwork.content, inline=False) await main.edit(embed=final) await channel.send(f"Congratulations {user.mention} you're one step closer to becoming a helper here at **My Anime Land**\n\nPlease leave us upto 7 days to review your application, please refrain from pinging staff.\n\nThis channel will be deleted in 60 seconds") self.add_id(user) await asyncio.sleep(60) await channel.delete() applog = self.bot.get_channel(657965850057506827) await applog.send(embed=final) else: await ctx.message.delete() user = ctx.author await user.send(embed=func.ENoFooter("Hey!", "You've already created an application in **My Anime Land**, so you cannot create another until that one has been completed."))