async def rob(self, ctx, user: discord.User = None): if Cooldowns.on_cooldown(ctx, "rob"): return await ctx.send(embed=Cooldowns.cooldown_text(ctx, "rob")) elif not user: return await ctx.send( embed=Tools.error("Please specify somebody to rob.")) user = await Tools.getClosestUser(ctx, user) if user.id == ctx.author.id: return await ctx.send( embed=Tools.error("Stop trying to rob yourself.")) elif user.id == self.bot.user.id: return await ctx.send(embed=Tools.error("Stop trying to rob me.")) 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.")) elif db[str(user.id)]["balance"] < 500: return await ctx.send( embed=Tools.error(f"Bruh, {user.name} is poor.")) elif db[str(ctx.author.id)]["balance"] < 300: return await ctx.send(embed=Tools.error( "You need at least 300 coins to rob someone.")) elif Tools.has_flag(db, user, "protected"): return await ctx.send( embed=Tools.error(f"{user.name} has a bank lock active.")) elif randint(0, 1): # user wins earn = randint(250, round(db[str(user.id)]["balance"] / 2)) db[str(user.id)]["balance"] -= earn db[str(ctx.author.id)]["balance"] += earn if len(str(earn)) > 15: earn = "∞" embed = discord.Embed( title="Nice :ok_hand:", description= f"You just robbed {user.name} and earned `{earn}` coins.", color=0x126bf1) else: # caught fee = randint(300, round(db[str(ctx.author.id)]["balance"] / 2)) db[str(ctx.author.id)]["balance"] -= fee embed = discord.Embed( title="L O L", description= f"You failed miserably at robbing {user.name} and got caught!!!111\nYou paid `{fee}` coins as a fee.", color=0xFF0000) embed.set_author(name=" | Rob", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) open("db/users", "w").write(dumps(db, indent=4)) await ctx.send(embed=embed) return await Cooldowns.set_cooldown(ctx, "rob", 3600)
async def fight(self, ctx, user: discord.User = None): if not user: return await ctx.send( embed=Tools.error("You need to specify someone to fight.")) elif user.id == self.bot.user.id: return await ctx.send( embed=Tools.error("You cannot fight me; I am over 9000.")) elif user.id == ctx.author.id: return await ctx.send( embed=Tools.error("You cannot fight yourself.")) db = json.loads(open("db/users", "r").read()) if not str(user.id) in db or not db[str(user.id)]["pet"]["name"]: return await ctx.send(embed=Tools.error( f"{user.name} doesn't have a pet for you to fight.")) elif not db[str(ctx.author.id)]["pet"]["name"]: return await ctx.send( embed=Tools.error(f"You don't have a pet to fight with.")) embed = discord.Embed( description= f":clock1: \t **Now waiting for {user.name} to say accept.**", color=0x126bf1) await ctx.send(embed=embed) def usercheck(m): return m.author == user and m.channel == ctx.channel while True: try: message = await self.bot.wait_for("message", check=usercheck, timeout=30) except: return await ctx.send(embed=Tools.error( f"{user.name} never accepted your request.")) if message.content.lower() in [ "accept", "yes", "yea", "si", "ye", "ya" ]: break elif message.content.lower() in ["deny", "cancel", "no", "stop"]: return await ctx.send( embed=Tools.error(f"{user.name} denied your request.")) def make_embed(text): return discord.Embed(title=text, color=0x126bf1) user_db = db[str(user.id)] user_health = 120 * user_db["pet"]["level"] author_db = db[str(ctx.author.id)] author_health = 120 * author_db["pet"]["level"] if random.randint(1, 4) != 1: damage = random.randint(15 * user_db["pet"]["level"], 30 * user_db["pet"]["level"]) author_health -= damage m = await ctx.send(embed=make_embed( f"{user_db['pet']['name']} just attacked {author_db['pet']['name']} and dealt {damage} damage." )) await sleep(3) else: m = await ctx.send(embed=make_embed( f"{user_db['pet']['name']} tried to attack but missed!")) await sleep(3) while True: try: if user_health <= 0: rep = random.randint(9, 20) author_db["data"]["levels"]["rep"] += rep open("db/users", "w").write(json.dumps(db, indent=4)) embed = discord.Embed( title= f"Congrats, {ctx.author.name}; you won the battle and gained {rep} reputation.", color=0x126bf1) return await m.edit(embed=embed) elif author_health <= 0: rep = random.randint(9, 20) user_db["data"]["levels"]["rep"] += rep open("db/users", "w").write(json.dumps(db, indent=4)) embed = discord.Embed( title= f"Congrats, {user.name}; you won the battle and gained {rep} reputation.", color=0x126bf1) return await m.edit(embed=embed) elif len(str(author_db["pet"]["level"])) > 50: rep = random.randint(20, 40) author_db["data"]["levels"]["rep"] += rep open("db/users", "w").write(json.dumps(db, indent=4)) embed = discord.Embed( title= f"Congrats, {ctx.author.name}; you just one shot {user_db['pet']['name']} and gained {rep} reputation.", color=0x126bf1) return await m.edit(embed=embed) elif len(str(user_db["pet"]["level"])) > 50: rep = random.randint(20, 40) user_db["data"]["levels"]["rep"] += rep open("db/users", "w").write(json.dumps(db, indent=4)) embed = discord.Embed( title= f"Congrats, {ctx.author.name}; you just one shot {user_db['pet']['name']} and gained {rep} reputation.", color=0x126bf1) return await m.edit(embed=embed) elif random.randint(1, 4) != 1: damage = random.randint(15 * user_db["pet"]["level"], 30 * user_db["pet"]["level"]) author_health -= damage await m.edit(embed=make_embed( f"{user_db['pet']['name']} just attacked {author_db['pet']['name']} and dealt {damage} damage." )) await sleep(3) else: await m.edit(embed=make_embed( f"{user_db['pet']['name']} tried to attack but missed!" )) await sleep(3) if random.randint(1, 4) != 1: damage = random.randint(15 * author_db["pet"]["level"], 30 * author_db["pet"]["level"]) user_health -= damage await m.edit(embed=make_embed( f"{author_db['pet']['name']} just attacked {user_db['pet']['name']} and dealt {damage} damage." )) await sleep(3) else: await m.edit(embed=make_embed( f"{author_db['pet']['name']} tried to attack but missed!" )) await sleep(3) except Exception as e: await ctx.send(e) return await ctx.send( embed=Tools.error("It seems someone deleted my message."))
async def emojify(self, ctx, *, text=None): if not text: return await ctx.send(embed=Tools.error("No text specified.")) message = "" for character in text: if character.lower() in Constants.alphabet: message = f"{message}:regional_indicator_{character.lower()}: " else: if character == " ": message = f"{message} " elif character == "#": message = f"{message}:hash: " elif character == "$": message = f"{message}:heavy_dollar_sign: " elif character == "1": message = f"{message}:one: " elif character == "2": message = f"{message}:two: " elif character == "3": message = f"{message}:three: " elif character == "4": message = f"{message}:four: " elif character == "5": message = f"{message}:five: " elif character == "6": message = f"{message}:six: " elif character == "7": message = f"{message}:seven: " elif character == "8": message = f"{message}:eight: " elif character == "9": message = f"{message}:nine: " elif character == "0": message = f"{message}:zero: " elif character == "!": message = f"{message}:grey_exclamation: " elif character == "?": message = f"{message}:grey_question: " elif character == ".": message = f"{message}:white_circle: " else: message = f"{message}{character}" try: return await ctx.send(message) except: return await ctx.send("Sorry, your text is too long to emojify.")
async def settings(self, ctx, key: str = None, value=None): db = loads(open("db/guilds", "r").read()) _db = db[str(ctx.guild.id)] if not key: prefix = _db["prefix"] nsfw = True if "nsfw-enabled" in _db["tags"] else False levels = True if "levels-enabled" in _db["tags"] else False joinleave = self.bot.get_channel( _db["data"]["joinleave_channel"] ).name if _db["data"]["joinleave_channel"] else "Not setup" if _db["data"]["autorole"]: autorole = discord.utils.get(ctx.guild.roles, id=_db["data"]["autorole"]) if not autorole: autorole = "Not setup" _db["data"]["autorole"] = None open("db/guilds", "w").write(dumps(db, indent=4)) else: autorole = "@" + autorole.name else: autorole = "Not setup" embed = Embed( title="Server Settings", description=f"Last updated: {_db['data']['last_updated']}", color=0x126bf1) embed.add_field( name="Settings", value= f"Prefix: {prefix}\nNSFW Enabled: {nsfw}\nLevels Enabled: {levels}\nJoin/Leave Channel: #{joinleave}\nAutorole: {autorole}", inline=False) embed.add_field( name="How to change these", value= f"To change a setting, use ``{prefix}settings [setting] [value]``.\nFor example: ``{prefix}settings nsfw off``.", inline=False) embed.set_author(name=" | Settings", 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) elif key and not value: return await ctx.send(embed=Tools.error("No value specified.")) key = key.lower() if not key in ["prefix", "nsfw", "levels", "joinleave", "autorole"]: return await ctx.send( embed=Tools.error("That isn't a valid setting.")) elif not isinstance(value, str) and not isinstance(value, bool): return await ctx.send( embed=Tools.error("That isn't a valid value.")) elif value.lower() in ["on", "enable", "true", "yes"]: value = True elif value.lower() in ["off", "disable", "false", "no"]: value = False else: if key != "prefix" and not isinstance( value, str) and not isinstance(value, bool): return await ctx.send( embed=Tools.error("That isn't a valid value.")) if key == "prefix": for char in ["`", "\\"]: if char in value: return await ctx.send(embed=Tools.error( "Prefix contains unsupported characters.")) if len(value) > 10: return await ctx.send(embed=Tools.error( "Prefixes cannot be longer than 10 characters.")) _db["prefix"] = value text = f"The prefix in this server has been set to ``{value}``." elif key == "nsfw": if value: if not "nsfw-enabled" in _db["tags"]: _db["tags"].append("nsfw-enabled") else: if "nsfw-enabled" in _db["tags"]: _db["tags"].remove("nsfw-enabled") text = f"NSFW has been set to ``{value}``." elif key == "levels": if value: if not "levels-enabled" in _db["tags"]: _db["tags"].append("levels-enabled") else: if "levels-enabled" in _db["tags"]: _db["tags"].remove("levels-enabled") text = f"Leveling has been set to ``{value}``." elif key == "joinleave": if not isinstance(value, str): return await ctx.send( embed=Tools.error("That isn't a valid value.")) try: id = int(value) except: try: id = int(value.split("<#")[1].split(">")[0]) except: return await ctx.send( embed=Tools.error("That isn't a valid value.")) channel = self.bot.get_channel(id) if not channel: return await ctx.send( embed=Tools.error("That isn't a valid channel ID.")) _db["data"]["joinleave_channel"] = channel.id text = f"The join/leave channel has been set to #{channel.name}" elif key == "autorole": if value.lower() in ["remove", "reset"]: _db["data"]["autorole"] = None text = "The autorole for this server has been reset." else: if value.startswith("<@&") and value.endswith(">"): value = value.replace("<", "").replace(">", "").replace( "@", "").replace("&", "") else: if value.startswith("@"): value = value[1:] role = discord.utils.get(ctx.guild.roles, name=value) if not role: return await ctx.send(embed=Tools.error( "Couldn't find that role; check your capitalization. You can't use IDs here." )) value = role.id role = discord.utils.get(ctx.guild.roles, id=int(value)) _db["data"]["autorole"] = role.id text = "This server's autorole has been set to @" + role.name _db["data"]["last_updated"] = str(date.today()) open("db/guilds", "w").write(dumps(db, indent=4)) embed = Embed(title=text, color=0x126bf1) embed.set_author(name=" | Settings", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Set by {ctx.author}.", icon_url=ctx.author.avatar_url) return await ctx.send(embed=embed)
async def bet(self, ctx, amount=None): if not amount: return await ctx.send( embed=Tools.error("No amount specified to bet.")) db = loads(open("db/users", "r").read()) try: amount = int(amount) if amount < 1: return await ctx.send( embed=Tools.error("Please enter a valid integer.")) except: if amount.lower() != "all": return await ctx.send(embed=Tools.error("That isn't a number.") ) amount = db[str(ctx.author.id)]["balance"] if len(str(amount)) > 50 and amount != db[str( ctx.author.id)]["balance"]: return await ctx.send( embed=Tools.error("That's way too much money.")) elif Cooldowns.on_cooldown(ctx, "bet"): return await ctx.send(embed=Cooldowns.cooldown_text(ctx, "bet")) elif db[str(ctx.author.id)]["balance"] < amount: return await ctx.send(embed=Tools.error( f"You don't have {amount} coins in your account.")) elif randint(1, 2) == 1: db[str(ctx.author.id)]["balance"] += amount if len(str(amount)) > 50: amount = "∞" embed = discord.Embed(title=f"Darn, you win {amount} coins.", color=0x126bf1) embed.set_author(name=" | Bet", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) else: db[str(ctx.author.id)]["balance"] -= amount if len(str(amount)) > 50: amount = "∞" embed = discord.Embed(title=f"Ha, you lose {amount} coins.", color=0x126bf1) embed.set_author(name=" | Bet", icon_url=self.bot.user.avatar_url) embed.set_footer(text=f" | Requested by {ctx.author}.", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) open("db/users", "w").write(dumps(db, indent=4)) return await Cooldowns.set_cooldown(ctx, "bet", 60)
async def dictionary(self, ctx, *, word = None): #return await ctx.send("Sorry, but this command is temporarily disabled.\nDetails: ``API not responding well``") 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.")) elif not ctx.channel.nsfw: return await ctx.send(embed = Tools.error("This channel doesn't allow NSFW.")) elif not word: return await ctx.send(embed = Tools.error("No word/phrase specified.")) elif word.startswith("<@!"): word = Tools.getClosestUser(word).name elif len(word) > 50: return await ctx.send(embed = Tools.error("That word/phrase is too long.")) elif word.lower() == "commuter": embed = discord.Embed(title = word, description = f"[Commuter] is a person that likes to play [beamng.drive]. His catchphrase is [idiot] although he has multiple other [phrases] that he says often. He likes playing around with [Prism] and talking about corn. He plays Roblox games and stuff, he is [super duper insanely] smart when it comes to learning Python.", color = 0x126bf1) embed.set_author(name = " | Dictionary", 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) request = get(f"https://api.urbandictionary.com/v0/define?term={word.lower()}", headers = {"content-type": "application/json"}).text if not request: return await ctx.send(embed = Tools.error("Couldn't connect to the urban dictionary.")) data = loads(request) if len(data["list"]) == 0: return await ctx.send(embed = Tools.error(f"No dictionary results found for: ``{word}``.")) embed = discord.Embed(title = word, description = data["list"][0]["definition"], color = 0x126bf1) embed.set_author(name = " | Dictionary", 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("That description is too long to send."))
async def work(self, ctx): if Cooldowns.on_cooldown(ctx, "work"): return await ctx.send(embed = Cooldowns.cooldown_text(ctx, "work")) n1 = randint(1, 20) n2 = randint(1, 20) answer = n1 + n2 bot_msg = await ctx.send(f"You are now working; solve the equation: `{n1} + {n2}`.") db = loads(open("db/users", "r").read()) def check(m): return m.author == ctx.author and m.channel == ctx.channel try: message = await self.bot.wait_for("message", check = check, timeout = 5) except: earnings = randint(20, 100) db[str(ctx.author.id)]["balance"] += earnings open("db/users", "w").write(dumps(db, indent = 4)) return await ctx.send(embed = Tools.error(f"You didn't respond fast enough; but you still earned {earnings} coins.")) try: await bot_msg.delete() except: pass if not message.content.lower() == str(answer): earnings = randint(20, 100) db[str(ctx.author.id)]["balance"] += earnings open("db/users", "w").write(dumps(db, indent = 4)) await ctx.send(embed = Tools.error(f"You messed up at work; but you still earned {earnings} coins.")) return await Cooldowns.set_cooldown(ctx, "work", 600) reward = randint(200, 450) db[str(ctx.author.id)]["balance"] += reward open("db/users", "w").write(dumps(db, indent = 4)) embed = discord.Embed(title = f"Good job, you went to work and earned {reward} coins.", color = 0x126bf1) embed.set_author(name = " | Work", icon_url = self.bot.user.avatar_url) embed.set_footer(text = f" | Requested by {ctx.author}.", icon_url = ctx.author.avatar_url) await ctx.send(embed = embed) return await Cooldowns.set_cooldown(ctx, "work", 600)
async def math(self, ctx, *, equation: str = None): if not equation: return await ctx.send(embed=Tools.error("No equation specified.")) equation = equation.replace("9 + 10", "21") equation = equation.replace("9+10", "21") equation = equation.replace("^", "**") equation = equation.replace("%", " / 100") for expr in self.not_allowed: if expr in equation: return await ctx.send( embed=Tools.error("Specified expression is invalid.")) if equation.count("^") > 3 or equation.count("999") > 2: return await ctx.send( embed=Tools.error("Specified expression is too long.")) try: fn_name = "_eval_expr" equation = equation.strip("`") equation = "\n".join(f" {i}" for i in equation.splitlines()) body = f"async def {fn_name}():\n{equation}" parsed = ast.parse(body) body = parsed.body[0].body self.insert_returns(body) exec(compile(parsed, filename="math", mode="exec")) result = (await eval(f"{fn_name}()")) except: return await ctx.send( embed=Tools.error("Specified expression is invalid.")) embed = discord.Embed(title=str(result), color=0x126bf1) embed.set_author(name=" | Math", 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("Specified expression is too long."))
async def vote(self, ctx): if Cooldowns.on_cooldown(ctx, "vote"): return await ctx.send(embed=Cooldowns.cooldown_text(ctx, "vote")) bot_data = loads( requests.get("https://top.gg/api/bots/685550504276787200", headers={ "Authorization": self.token }).text) base_upvotes = bot_data["points"] embed = discord.Embed( title="Click here to vote for Prism!", description="When your done, send a message in this channel.", url="https://top.gg/bot/685550504276787200/vote", color=0x126bf1) await ctx.send(embed=embed) def check(m): return m.author == ctx.author and m.channel == ctx.channel await self.bot.wait_for("message", check=check) embed = discord.Embed( title="This might take a few minutes.", description= "Since the top.gg API doesn't update instantly,\nit might take a minute to verify your vote.", color=0x126bf1) embed.set_author(name=" | Waiting for change", 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) failed_attempts = 0 while failed_attempts < 16: bot_data = loads( requests.get("https://top.gg/api/bots/685550504276787200", headers={ "Authorization": self.token }).text) current_upvotes = bot_data["points"] if current_upvotes > base_upvotes: db = loads(open("db/users", "r").read()) db[str(ctx.author.id)]["balance"] = db[str( ctx.author.id)]["balance"] + 2750 open("db/users", "w").write(json.dumps(db, indent=4)) embed = discord.Embed( title="Thanks for voting!", description="Since you voted, you get a free $2,750.", color=0x0ee323) embed.set_author(name=" | Successful Vote", icon_url=self.bot.user.avatar_url) embed.set_footer(text=" | You can vote every 12 hours.", icon_url=ctx.author.avatar_url) try: await ctx.author.send(embed=embed) except: await ctx.send(embed=embed) try: await message.delete() except: pass if Tools.has_flag(db, ctx.author, "premium"): await Cooldowns.set_cooldown(ctx, "vote", 86400) break await Cooldowns.set_cooldown(ctx, "vote", 43200) break await sleep(15) failed_attempts += 1
async def leaderboard(self, ctx, page_number: int = 1): db = loads(open("db/users", "r").read()) pages = {"1": {"count": 0, "members": {}}} current_page = 1 for user in ctx.guild.members: if str(user.id) in db: page = pages[str(current_page)] if not page["count"] == 5: page["count"] += 1 page["members"][str(user.id)] = db[str( user.id)]["data"]["levels"]["level"] else: current_page += 1 pages[str(current_page)] = { "count": 1, "members": { str(user.id): db[str(user.id)]["data"]["levels"]["level"] } } if not str(page_number) in pages: return await ctx.send(embed=Tools.error("That page doesn't exist.") ) _sorted = sorted(pages[str(page_number)]["members"].items(), key=lambda x: x[1], reverse=True) users, c = "", 1 for i in _sorted: user = self.bot.get_user(int(i[0])) bal = db[str(user.id)]["balance"] if len(str(bal)) > 10: bal = "∞" line = f"{user.name} - Level {i[1]} ({bal} coins)" medal = "" if c < 4 and page_number == 1: medal = f":{self.ToWord(c)}_place: " users += f"{medal}{line}\n" c += 1 embed = discord.Embed( description= f"This is page {page_number} / {len(pages)}.\n\n{users}", color=0x126bf1) embed.set_author(name=" | Leaderboard", 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 trigger(self, ctx, option: str = None, *, trigger: str = None): db = loads(open("db/guilds", "r").read()) triggers = db[str(ctx.guild.id)]["data"]["triggers"] if not option: triggerlist, index = "", 1 for trigger in triggers: triggerlist += f"(#{index}) `{trigger}`: {triggers[trigger]} \n" index += 1 if not triggerlist: triggerlist = "No triggers to display." embed = discord.Embed(title="Server Triggers", description=triggerlist, color=0x126bf1) elif not trigger: return await ctx.send( embed=Tools.error("No trigger data specified.")) elif "`" in trigger: return await ctx.send( embed=Tools.error("Triggers cannot contain the ` character.")) else: if option in ["add", "create", "make"]: if not "|" in trigger or trigger.count("|") > 1: return await ctx.send(embed=Tools.error( "Invalid trigger specified, example: `hello|world`.")) elif len(trigger) > 90: return await ctx.send(embed=Tools.error( "Triggers have a maximum length of 90 characters.")) elif len(triggers) == 20: return await ctx.send(embed=Tools.error( "You can have a maximum of 20 triggers.")) raw = trigger.split("|") name = raw[0] data = raw[1] if name in triggers: return await ctx.send( embed=Tools.error("That trigger already exists.")) elif name.startswith(" ") or name.endswith(" "): return await ctx.send(embed=Tools.error( "Trigger names cannot start or end with a space.")) triggers[name] = data embed = discord.Embed( title=f"Trigger #{len(triggers)} created.", color=0x126bf1) elif option in ["remove", "delete"]: if trigger not in triggers: return await ctx.send( embed=Tools.error("No such trigger exists.")) triggers.pop(trigger) embed = discord.Embed(title="Trigged deleted.", color=0x126bf1) else: return await ctx.send( embed=Tools.error("Invalid (or unknown) option specified.") ) open("db/guilds", "w").write(dumps(db, indent=4)) embed.set_author(name=" | Triggers", 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)