async def reboot(self, ctx, *args): if "--no-embed" not in args: await ctx.send(embed=embed("Rebooting...", "This may take a while.")) else: await ctx.send("`Rebooting...\nThis may take a while.`") await self.bot.log(embed=embed("Status", "Offline"), cause="Close", log=self.bot.logs.status) # might vary for other people os.execl(sys.executable, sys.executable, self.bot.file)
async def reload(self, ctx, *cog_names): title = (", ").join(map(str.title, cog_names)) desc = "Successfully restarted!" for i, cog_name in enumerate(cog_names): if cog_name == "all": cog_name = "cogs" try: self.bot.setup() except Exception as e: desc = (f"Restarting failed\n\n" f"{type(e).__name__}: {e}") break else: break else: cog_name = cog_name == "info" and "information" or cog_name cog = f"bot.cogs.{cog_name}" try: self.bot.unload_extension(cog) self.bot.load_extension(cog) except Exception as e: desc = (f"Restarting failed\n\n" f"{type(e).__name__}: {e}") break await ctx.send(embed=embed(title, desc))
async def answer(self, ctx, id: int, *, answer): """ Set the answer to the question's ID. If you do not know how to get a question's ID, do `>help ask` """ title = "Answer has been added" desc = None entry = Ask.get_entry(id=str(id)) # entry does not exist if entry is None: title = "Question with ID does not exist" desc = ("Try using `>ask` then your question to get a valid entry " "for a question.") # entry exists, answer exists elif entry.get("answer") is not None: entry = Ask.get_entry(answer=answer) id = entry.get("id") title = f"Answer already exists with ID `{id}`" desc = "You cannot overwrite an answer." # entry exists, answer does not, add answer to entry elif Ask.add_answer_to(entry, answer) is False: title = "Failed to add answer" await ctx.send(embed=embed(title, desc))
async def help(self, ctx, name=None): """ Displays information for a particular command, such as parameters, instructions, alternate names """ command = self.command_exists(name) title = "" desc = "" args = None # list all commands if name is None: data = {} message = "" for command in self.bot.commands: if command.hidden: continue name = command.name cog_name = command.cog_name or "Uncategorised" cog = data.get(cog_name) if data.get(cog_name) is None: data[cog_name] = [] if name not in cog: cog.append(name) for cog, commands_list in data.items(): message += f"{cog}:\n" for name in sorted(commands_list): message += " " * 2 + f"{name}\n" for block in wrap(message, type=""): await ctx.send(block) return elif command is None or command.hidden: title = "That command does not exist!" desc = "How about trying one that does?" else: title = command.name.capitalize() desc = command.help args = { "Category": command.cog_name, "Parameters": (", ").join(command.clean_params.keys()), "Usage": f"`{command.usage}`", "Aliases": command.aliases or "None" } embed_ = embed(title, desc) if args is not None: for name, value in args.items(): embed_.add_field(name=name, value=value, inline=False) await ctx.send(embed=embed_)
async def whois(self, ctx, member: discord.Member = None): member = member or ctx.author roles = (", ").join(map(str, member.roles)) embed_ = embed(str(member), member.mention) embed_.add_field(name="Status", value=str(member.status).title()) embed_.add_field(name="Joined", value=str(member.joined_at)) embed_.add_field(name="Registered", value=str(member.created_at)) embed_.add_field(name="Roles", value=roles)
async def _import(self, ctx, module_name): title = module_name.title() desc = "Successfully imported!" try: globals()[module_name] = importlib.import_module(module_name) except Exception as e: desc = (f"Importing failed\n\n" f"{type(e).__name__} - {e}") await ctx.send(embed=embed(title, desc))
async def on_ready(self): Logs = namedtuple("Logs", ["default", "status", "error"]) self.init_time = int(time.time()) self.guild = self.get_guild(464446709146320897) self.logs = Logs(default=self.get_channel(530005984891109386), status=self.get_channel(464446775135174656), error=self.get_channel(530001923399483413)) # setup loops self.loop.create_task(self.on_minute()) # visuals clear_screen("windows", post_message=f"{self.user.name}\n") await self.log(embed=embed("Status", "Online"), log=self.logs.status)
async def unload(self, ctx, *cog_names): title = (", ").join(map(str.title, cog_names)) desc = "Successfully unloaded" for cog_name in cog_names: cog = f"bot.cogs.{cog_name}" try: self.bot.unload_extension(cog) except Exception as e: desc = (f"Loading failed\n\n" f"{type(e).__name__}: {e}") break await ctx.send(embed=embed(title, desc))
async def roll(self, ctx, dice_sides: int = 6): critted = "" unlucky = "" if dice_sides <= 1: dice_sides = 6 rolled = random.randint(1, dice_sides) if rolled == dice_sides: critted = "**Critical Strike!**" elif rolled == 1: unlucky = "Yikes..." title = f"You rolled a {dice_sides}-sided dice." desc = f"{critted} A {rolled} was rolled! {unlucky}" await ctx.send(embed=embed(title, desc))
async def ask(self, ctx, *, question): """ Ask a question and either get an answer if it has been answered before or get the question ID you can use to supply an answer. """ question = question.lower() title = "Question" desc = f"\"{question}\"" answer_given = False entry = Ask.get_entry(question=question) # not a question, explain question pre-requisites if not question.endswith("?"): title = "Invalid Question" desc = ("You either did not ask a question or forgot to add " "`?` to the end of your question.") # is a question, given no data elif entry is None: entry = Ask.create_entry(ctx, question) id = entry.get("id") title = "Question not asked before" desc = (f"You can add your own answer by using `>add {id}` " f"with your answer at the end of it.") # is a question, given entry elif entry.get("answer") is None: id = entry.get("id") title = "No answer for question" desc = (f"The question has been asked but there is no answer. " f"Use `>add {id}` with your answer at the end to " f"add one.") # given question, answer found else: answer_given = entry.get("answer") embed_ = embed(title, desc) if answer_given is not False: answer = entry.get("answer") embed_.add_field(name="Answer", value=f"\"{answer}\"") await ctx.send(embed=embed_)
async def slowmode(self, ctx, delay=15): title = "Slowmode has been disabled" desc = "You can now type freely." if ctx.channel.slowmode_delay == delay: title = f"The slowmode delay is at {delay}s." desc = "There is no need to change it!" elif delay < 0 or delay > 120: scale = delay < 0 and "low" or "high" title = f"The delay is too {scale}!" desc = "It must be from 0 - 120" elif delay == 0: title = "Slowmode has been delayed." desc = "You may now type freely" else: title = "The slowmode delay has been set." desc = f"You can type a new message every `{delay}` seconds!" await ctx.channel.edit(slowmode_delay=delay) await ctx.send(embed=embed(title, desc))
async def hug(self, ctx, member: discord.Member): file = random.choice(List.hugs) embed_ = embed(desc=f":hugging: {ctx.author.mention} hugged " f"{member.mention}!", image=file) await ctx.send(embed=embed_, file=file)
async def close(self, ctx): await ctx.send(embed=embed(title=None, desc="Shutting down...")) await self.bot.log(embed=embed("Status", "Offline"), cause="Close", log=self.bot.logs.status) await self.bot.logout()
async def avatar(self, ctx, member: discord.Member = None): member = member or ctx.author await ctx.send(embed=embed().set_image(url=member.avatar_url))