async def name(self, ctx, *, name: str = None): if not name: return await ctx.send( embed=Tools.error("You need to specify a new pet name.")) elif len(name) > 250 or "\n" in name: return await ctx.send(embed=Tools.error("Your name is too long.")) elif "<@" in name: name = self.bot.get_user(int( name.split("<@!")[1].split(">")[0])).name db = loads(open("db/users", "r").read()) if not db[str(ctx.author.id)]["pet"]["level"]: return await ctx.send(embed=Tools.error("You don't own a pet.")) db[str(ctx.author.id)]["pet"]["name"] = name open("db/users", "w").write(dumps(db, indent=4)) embed = discord.Embed(title=f"Your pet has been renamed to {name}.", color=0x126bf1) return await ctx.send(embed=embed)
async def whitelist(self, ctx, user: discord.User = None): if not user: return await ctx.send( embed=Tools.error("Please specify somebody to whitelist.")) db = loads(open("db/users", "r").read()) if not str(user.id) in db or not Tools.has_flag( db, user, "blacklisted"): return await ctx.send( embed=Tools.error(f"{user} isn't blacklisted.")) db[str(user.id)]["data"]["tags"].remove("blacklisted") open("db/users", "w").write(dumps(db, indent=4)) embed = discord.Embed(title=f"{user} has been whitelisted.", color=0x126bf1) embed.set_author(name=" | Whitelist", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Whitelisted by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def gif(self, ctx, *, query: str = None): if not query: return await ctx.send(embed=Tools.error("No query specified.")) elif not ctx.channel.nsfw: return await ctx.send(embed=Tools.error( "Due to no limitations, this channel has to be NSFW.")) data = loads( get(self.api_url, { "api_key": self.api_key, "q": query, "lang": "en" }).text)["data"] if not data: return await ctx.send(embed=Tools.error("No results found.")) embed = discord.Embed(color=0x126bf1) embed.set_image(url=choice(data)["images"]["downsized_large"]["url"]) embed.set_author(name=" | GIF", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def decrypt(self, ctx, *, text: str = None): if not text: return await ctx.send( embed=Tools.error("No text specified to decrypt.")) try: encrypted = base64.b64decode(text.encode("ascii")).decode("ascii") except ValueError: return await ctx.send( embed=Tools.error("Sorry, your text couldn't be decrypted.")) # Embed construction embed = discord.Embed(title="Decryption Results", description=f"```\n{encrypted}\n```", color=0x126bf1) embed.set_author(name=" | Decrypt", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) # Handle sending try: return await ctx.send(embed=embed) except Exception: return await ctx.send( embed=Tools.error("Failed to send the embed, check your text.") )
async def bban(self, ctx, user: discord.Member = None, *, reason: str = None): if not user: return await ctx.send( embed=Tools.error("Please specify a user to ban.")) elif user.id == ctx.author.id: return await ctx.send( embed=Tools.error("Stop trying to ban yourself lmao")) if reason: if len(reason) > 512: return await ctx.send(embed=Tools.error( "You can't have a reason over 512 characters.")) embed = discord.Embed( title=f"{ctx.author.name} just banned {user.name} from the server.", description=reason, color=0x126bf1) embed.set_author(name=" | Ban", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Banned by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def biography(self, ctx, *, bio: str = None): if not bio: return await ctx.send( embed=Tools.error("Please specify a biography.")) elif len(bio) > 40: return await ctx.send(embed=Tools.error( "You're biography is way too long (40 characters max).")) db = json.loads(open("db/users", "r").read()) db[str(ctx.author.id)]["data"]["bio"] = bio open("db/users", "w").write(json.dumps(db, indent=4)) embed = discord.Embed(title="Your biography has been set.", description=bio, color=0x126bf1) embed.set_author(name=" | Biography", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def tempban(self, ctx, user: discord.Member = None, seconds: int = 60, *, reason: str = None): if not user: return await ctx.send(embed = Tools.error("No user specified to ban.")) elif user.id == ctx.author.id: return await ctx.send(embed = Tools.error("You can't ban youself.")) elif user.id == self.bot.user.id: await ctx.send("If that's what you really want, then aight.") return await ctx.guild.leave() if reason and len(reason) > 512: return await ctx.send(embed = Tools.error("That reason is too long (max is 512 characters).")) await user.ban(reason = reason) embed = discord.Embed(title = f"{ctx.author} just tempbanned {user} for {seconds} seconds.", description = reason, color = 0x126bf1) embed.set_author(name = " | Ban", icon_url = self.bot.user.avatar_url) embed.set_footer(text = f" | Banned by {ctx.author}.", icon_url = ctx.author.avatar_url) await ctx.send(embed = embed) await sleep(seconds) return await user.unban(reason = "Ban has ended.")
async def update(self, ctx, branch: str = ""): await ctx.send(embed=discord.Embed(title="Fetching commits...", color=0x126bf1), delete_after=0) # Branch identifier if branch != "": branch = "/" + branch # Make request try: r = requests.get(self.url + branch, timeout=2) # Check if branch was not found if r.status_code == 404: return await ctx.send( embed=Tools.error("Specified branch does not exist.")) # Convert to JSON r = r.json() except requests.exceptions.ConnectionError: return await ctx.send(embed=Tools.error( "Sorry, something went wrong while fetching updates.")) # Load data try: commit = r[0] except KeyError: commit = r # Branches with only one commit _commit = commit["commit"] verification = ":white_check_mark:" if _commit["verification"][ "verified"] else ":x:" # Embed construction embed = discord.Embed( title=f"Running Prism {self.config['release']}", description= f"Latest github push: {_commit['message']}\nClick [here](https://github.com/ii-Python/Prism/commits) to view previous updates.", url="https://github.com/ii-Python/Prism/commit/" + _commit["url"].split("/")[-1], color=0x126bf1) embed.add_field(name="Pushed by", value=commit["author"]["login"]) embed.add_field(name="Push verified", value=verification) embed.add_field(name="Pushed on", value=_commit["committer"]["date"].split("T")[0]) embed.add_field(name="Push signature", value=commit["sha"][:-(len(commit["sha"]) - 7)]) embed.add_field(name="Branch", value=branch[1:] if branch else "stable") embed.set_author(name=" | Update", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def purge(self, ctx, amount: int = 5): if amount > 100: return await ctx.send(embed=Tools.error( "You cannot delete more than 100 messages at a time.")) try: await ctx.channel.purge(limit=amount + 1) except: return await ctx.send( embed=Tools.error("Something went wrong while deleting those.") ) embed = discord.Embed( title= f"{amount} messages have been deleted from #{ctx.channel.name}.", color=0x126bf1) embed.set_author(name=" | Purge", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) message = await ctx.send(embed=embed, delete_after=3)
async def use(self, ctx, item: str = None): if not item: return await ctx.send( embed=Tools.error("No item specified to use.")) return await ctx.send( embed=Tools.error("This command is coming in `v1.4`."))
async def buy(self, ctx, id: int = None, amount: int = 1): if not id: return await ctx.send( embed=Tools.error("You need to specify an item ID.")) elif amount < 0: return await ctx.send( embed=Tools.error("Invalid amount specified.")) return await self.purchase(ctx, id, amount)
async def tts(self, ctx, *, sentence: str = None): if not sentence: return await ctx.send(embed = Tools.error("No text specified.")) try: return await ctx.send(sentence, tts = True) except: return await ctx.send(embed = Tools.error("Missing permissions to send TTS messages."))
async def hack(self, ctx, *, somebody: str = None): if not somebody: return await ctx.send( embed=Tools.error("You forgot to specify who to hack. >_>")) message = await ctx.send(f"Now hacking {somebody}... :O") await sleep(2) await message.edit(content="[▝] Targeting remote host (127.0.0.1)") await sleep(2) await message.edit(content="[▗] Cracking Facebook password") await sleep(2) await message.edit(content="[▖] Checking memes") await sleep(2) await message.edit( content=f"[▘] Hacking into bank ({self.random_ip()})") await sleep(2) await message.edit(content="[▝] Calculating circumference") await sleep(2) await message.edit(content="[▗] Doing some math") await sleep(2) await message.edit( content=f"[▖] Shutting off cameras @ {self.random_ip()}") await sleep(2) try: return await ctx.send( f"{ctx.author.mention}, {somebody} has been hacked.") except: return await ctx.send( embed=Tools.error("What the actual heck are you typing???"))
async def clap(self, ctx, *, sentence: str = None): if not sentence: return await ctx.send( embed=Tools.error("No text specified to clap")) clapped_text = sentence.replace(" ", " :clap: ") try: return await ctx.send(clapped_text) except Exception: return await ctx.send( embed=Tools.error("That's too much text to clap."))
async def question(self, ctx, *, question: str = None): if not question: return await ctx.send(embed=Tools.error("No question provided.")) for user in ctx.message.mentions: question = question.replace(f"<@!{user.id}>", user.name) db = loads(open("db/guilds", "r").read())[str(ctx.guild.id)]["tags"] if not ctx.channel.nsfw and not "nsfw-enabled" in db: return await ctx.send(embed=Tools.error( "This command can only be used in NSFW channels.")) m = await ctx.send(embed=discord.Embed( title="Searching.. this might take a minute.", color=0x126bf1)) res = self.client.query(question) try: await m.delete() except: pass try: embed = discord.Embed(color=0x126bf1) embed.add_field(name="Results:", value=next(res.results).text, inline=False) embed.set_author(name=" | Question", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed) except: return await ctx.send(embed=Tools.error("No results found."))
async def deleted(self, ctx): db = json.loads(open("db/guilds", "r").read()) msgs = db[str(ctx.guild.id)]["data"]["deleted_messages"] if not msgs: return await ctx.send(embed=Tools.error( "This server doesn't have any deleted messages.")) embed = discord.Embed( title="Last 10 deleted messages", description= "This does not list embeds or messages longer than 100 characters.", color=0x126bf1) embed.set_author(name=" | Deleted Messages", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) for msg in msgs: embed.add_field(name=f"{msg['author']} ({msg['date']}):", value=msg['content'], inline=False) return await ctx.send(embed=embed)
async def balance(self, ctx, user: discord.User = None): # Just some references db = loads(open("db/users", "r").read()) user = await Tools.getClosestUser(ctx, user if user else ctx.author) # Check the user exists if str(user.id) not in db: return await ctx.send( embed=Tools.error(f"{user.name} doesn't have a Prism account.") ) _user = db[str(user.id)] _bal = _user["balance"] # Wow, rich kid UwU if len(str(_bal)) > 50: _bal = "∞" # Better references balance = f"<:coin:733723405118865479>\t{_bal} coins" name = user.name + "'s" if user.id == ctx.author.id: name = "Your" # Embed construction embed = discord.Embed(title=f"{name} Balance", description=balance, color=0x126bf1) embed.set_author(name=" | Balance", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def rembal(self, ctx, user: discord.User = None, amount: int = 1000): if not user: user = ctx.author db = loads(open("db/users", "r").read()) if not str(user.id) in db: return await ctx.send( embed=Tools.error(f"{user} is not in the database.")) db[str(user.id)]["balance"] -= amount open("db/users", "w").write(dumps(db, indent=4)) embed = discord.Embed( title=f"{user} has had ${amount} removed from their balance.", color=0x126bf1) embed.set_author(name=" | Balance Update", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Balance remove from by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def pp(self, ctx, user: discord.User = None): db = loads(open("db/guilds", "r").read()) if not "nsfw-enabled" in db[str(ctx.guild.id)]["tags"]: return await ctx.send(embed = Tools.error("NSFW is not enabled in this server.")) user = await Tools.getClosestUser(ctx, user if user else ctx.author) pp = "8" size = randint(4, 10) counter = 0 while counter < size: pp += "=" counter += 1 pp = f"{pp}D" message = f"Here is your PP:\n{pp}" if user.id != ctx.author.id: message = f"Here is {user.name}'s PP:\n{pp}" embed = discord.Embed(title = message, color = 0x126bf1) embed.set_author(name = " | PP", icon_url = self.bot.user.avatar_url) embed.set_footer(text = f" | Requested by {ctx.author}.", icon_url = ctx.author.avatar_url) return await ctx.send(embed = embed)
async def profile(self, ctx, user = None): db = loads(open("db/users", "r").read()) user = await Tools.getClosestUser(ctx, user if user else ctx.author) if not str(user.id) in db: return await ctx.send(embed = Tools.error(f"{user.name} does not have a Prism account.")) data = db[str(user.id)] pet_string = "" if data["pet"]["name"]: pet_level = data["pet"]["level"] if len(str(pet_level)) > 50: pet_level = "∞" pet_string = f"""Pet: [{Tools.uppercase(data["pet"]["type"])}] {data["pet"]["name"]} - Level {pet_level}""" if data["pet"]["holding"]: pet_string = f"{pet_string} (Holding a {data['pet']['holding']})" pet_string = f"{pet_string}\n" favorite_command = sorted(data["data"]["commands"]["used"].items(), key = lambda x: x[1], reverse = True)[0] favorite_command = f"{Tools.uppercase(favorite_command[0])} ({favorite_command[1]} times)" balance = str(data["balance"]) if len(balance) > 50: balance = "∞" profile = f""" Balance: <:coin:733723405118865479> {balance} coins Level: {data["data"]["levels"]["level"]} ({data["data"]["levels"]["xp"]} / {data["data"]["levels"]["level"] * 1000}) Reputation: {data["data"]["levels"]["rep"]} {pet_string}Inventory Size: {len(data["data"]["inventory"])} items Commands Used: {data["data"]["commands"]["sent"]} Favorite Command: {favorite_command} """ premium = ":medal: | " if "premium" in data["data"]["tags"] else "" embed = discord.Embed(title = premium + user.name + "#" + user.discriminator, description = data["data"]["bio"], color = 0x126bf1) embed.add_field(name = "Details:", value = profile, inline = False) embed.set_author(name = f" | Profile", icon_url = user.avatar_url) embed.set_footer(text = f" | Requested by {ctx.author}.", icon_url = ctx.author.avatar_url) return await ctx.send(embed = embed)
async def wipe(self, ctx, user: discord.User = None): if not user: user = ctx.author db = loads(open("db/users", "r").read()) if not str(user.id) in db: return await ctx.send( embed=Tools.error(f"{user} isn't in the database.")) db.pop(str(user.id)) open("db/users", "w").write(dumps(db, indent=4)) embed = discord.Embed(title=f"{user} has had their account wiped.", color=0x126bf1) embed.set_author(name=" | Account Removal", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Account removed by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def covid(self, ctx): try: r = get(self.url, timeout = 10).json() except: return await ctx.send(embed = Tools.error("API is currently down, try again later.")) embed = discord.Embed(title = "Coronavirus Pandemic", description = ":mask: Make sure you wear a mask!", color = 0x126bf1) embed.add_field(name = "Active", value = f"`{r['activeCases']}`") embed.add_field(name = "Recovered", value = f"`{r['recovered']}`") embed.add_field(name = "Closed", value = f"`{r['closedCases']}`") embed.add_field(name = "Deaths", value = f"`{r['deaths']}`") embed.add_field(name = "Total", value = f"`{r['totalCases']}`") embed.set_author(name = " | Covid-19", icon_url = self.bot.user.avatar_url) embed.set_footer(text = f" | Requested by {ctx.author}. | Last updated on {r['lastUpdate']}", icon_url = ctx.author.avatar_url) return await ctx.send(embed = embed)
async def shorten(self, ctx, *, url: str = None): if not url: return await ctx.send( embed=Tools.error("No URL specified to shorten.")) resp = post(self.url, data={"url": url, "trackIP": False}) shorturl = loads(resp.text)["shorturl"] embed = discord.Embed(title="Click here to visit your website.", description="Shortened URL: " + shorturl, url=shorturl, color=0x126bf1) embed.add_field(name="Please note:", value="This link **will** expire in ~24 hours.", inline=False) embed.set_author(name=" | URL Shortened", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def inventory(self, ctx, user: discord.User = None): user = await Tools.getClosestUser(ctx, user if user else ctx.author) db = loads(open("db/users", "r").read()) if not str(user.id) in db: return await ctx.send( embed=Tools.error(f"{user.name} doesn't have an account.")) inventory = "" for item in db[str(user.id)]["data"]["inventory"]: inventory = f"{inventory}{item} (x{db[str(user.id)]['data']['inventory'][item]['count']}), " if not inventory: inventory = "Nothing to display. " message = f"{user.name}'s Inventory" if ctx.author.id == user.id: message = "Your Inventory" embed = discord.Embed(title=message, description=inventory[:-2], color=0x126bf1) embed.set_author(name=" | Inventory", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) try: return await ctx.send(embed=embed) except: return await ctx.send( embed=Tools.error(f"{user.name} has way too many items."))
async def pet(self, ctx, user=None): db = loads(open("db/users", "r").read()) user = await Tools.getClosestUser(ctx, user if user else ctx.author) if not str(user.id) in db: return await ctx.send( embed=Tools.error(f"{user.name} doesn't have an account.")) elif not db[str(user.id)]["pet"]["level"]: if user.id == ctx.author.id: return await ctx.send( embed=Tools.error("You don't have a pet.")) else: return await ctx.send( embed=Tools.error(f"{user.name} doesn't have a pet.")) pet = db[str(user.id)]["pet"] level = pet["level"] if len(str(level)) > 50: level = "∞" embed = discord.Embed(title=pet["name"], color=0x126bf1) embed.add_field( name="Information", value= f"Name: {pet['name']}\nLevel: {level}\nType: {Tools.uppercase(pet['type'])}\nCurrently holding: {pet['holding']}\nAdopted on: {pet['adopted_on']}" ) embed.set_author(name=" | Pet", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f"Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def ranban(self, ctx, reason: str = None): if reason and len(reason) > 512: return await ctx.send(embed=Tools.error( "That reason is too long (max is 512 characters).")) c = 0 while True: user = random.choice(ctx.guild.members) try: if user == ctx.author: pass else: await user.ban(reason=reason) break except: if c >= 15: return await ctx.send( embed=Tools.error("Nobody here is able to be banned.")) c += 1 embed = discord.Embed(title=f"{user} has been banned from the server.", color=0x126bf1) embed.set_author(name=" | Random ban", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | banned by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def unload(self, ctx, module=None): if not module: return await ctx.send( embed=Tools.error("Please specify a module to unload.")) path = None for folder in listdir("commands"): for file in listdir(f"commands/{folder}"): if file == f"{module}.py": path = f"commands.{folder}.{module}" if not path: return await ctx.send( embed=Tools.error("The specified module does not exist.")) try: self.bot.unload_extension(path) except Exception as e: embed = discord.Embed(title=f"Module `{path}` failed to unload.", description=f"```\n{e}\n```", color=0xFF0000) return await ctx.send(embed=embed) embed = discord.Embed(title=f"The `{path}` module has been unloaded.", color=0x126bf1) embed.set_author(name=" | Module Unload", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Unloaded by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def hold(self, ctx, *, item: str = None): db = loads(open("db/users", "r").read()) if not item: return await ctx.send( embed=Tools.error("You need to specify an item.")) elif not db[str(ctx.author.id)]["pet"]["level"]: return await ctx.send(embed=Tools.error("You don't own a pet.")) elif db[str(ctx.author.id)]["pet"]["holding"]: return await ctx.send(embed=Tools.error( "Your pet is already holding an item; try the ``takeback`` command." )) for inv_item in db[str(ctx.author.id)]["data"]["inventory"]: if inv_item.lower() == item.lower(): item = inv_item if not item in db[str(ctx.author.id)]["data"]["inventory"]: return await ctx.send(embed=Tools.error( "You don't have that item in your inventory.")) db[str(ctx.author.id)]["data"]["inventory"][item]["count"] -= 1 if db[str(ctx.author.id)]["data"]["inventory"][item]["count"] == 0: db[str(ctx.author.id)]["data"]["inventory"].remove(item) db[str(ctx.author.id)]["pet"]["holding"] = item open("db/users", "w").write(dumps(db, indent=4)) embed = discord.Embed(title=f"Your pet is now holding a {item}.", color=0x126bf1) return await ctx.send(embed=embed)
async def spoiler(self, ctx, *, sentence = None): if not sentence: return await ctx.send(embed = Tools.error("No text specified.")) message = "" for char in sentence: message = f"{message}||{char}||" try: return await ctx.send(message) except: return await ctx.send(embed = Tools.error("Your sentence is too long."))
async def shelter(self, ctx): def check(m): return m.author == ctx.author and m.channel == ctx.channel db = loads(open("db/users", "r").read()) if not db[str(ctx.author.id)]["pet"]["level"]: return await ctx.send( embed=Tools.error("Sorry, but you don't own a pet.")) embed = discord.Embed( title= f"Are you sure you want to send {db[str(ctx.author.id)]['pet']['name']} back to the shelter?", color=0x126bf1) m = await ctx.send(embed=embed) message = await self.bot.wait_for("message", check=check) try: await m.delete() except: pass if not message.content.lower() in ["yes", "yea", "yup", "ye"]: embed = discord.Embed( title="You decided to look away from the shelter.", color=0x126bf1) return await ctx.send(embed=embed) name = db[str(ctx.author.id)]["pet"]["name"] db[str(ctx.author.id)]["pet"]["name"] = None db[str(ctx.author.id)]["pet"]["level"] = None db[str(ctx.author.id)]["pet"]["type"] = None db[str(ctx.author.id)]["pet"]["holding"] = None open("db/users", "w").write(dumps(db, indent=4)) embed = discord.Embed( title=f"You sent {name} back to the adoption shelter.", color=0x126bf1) return await ctx.send(embed=embed)