Created
November 4, 2018 15:05
-
-
Save TAG-Epic/feb7979642f49d25586e75f0a128e44e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import discord | |
| from discord.ext.commands import Bot | |
| from discord.ext import commands | |
| import asyncio | |
| import json | |
| import log | |
| import PIL.Image | |
| import datetime | |
| from PIL import Image, ImageFilter, ImageDraw, ImageFont | |
| from io import * | |
| import requests | |
| import random | |
| import math | |
| import config | |
| from concurrent.futures import ProcessPoolExecutor | |
| import async_timeout | |
| #VARS | |
| queue = [] | |
| developers = [279714095480176642, 344404945359077377, 397745647723216898] | |
| verified = [] | |
| onlineShards = 0 | |
| server_offline = False | |
| arenas = {} | |
| def get_prefix(bot, message): | |
| with open("data/serverPrefixes.json") as f: | |
| try: | |
| j = json.loads(f.read()) | |
| prefixes = j[str(message.guild.id)] | |
| except: | |
| prefixes = ["t!"] | |
| return commands.when_mentioned_or(*prefixes)(bot, message) | |
| client = commands.AutoShardedBot(command_prefix = get_prefix, case_insensitive=False, shard_count=1) | |
| client.remove_command("help") | |
| ### COMMON FUNCTIONS (NO COMMANDS) #### | |
| async def game_manager(p1, p2): | |
| try: | |
| p1health = 100 | |
| p2health = 100 | |
| p1send = p1["msg"] | |
| p2send = p2["msg"] | |
| p1user = p1["user"] | |
| p2user = p2["user"] | |
| p1username = p1user.name | |
| p2username = p2user.name | |
| while True: | |
| print(p1health) | |
| print(p2health) | |
| # P1 | |
| await p1send.edit(embed=discord.Embed(title="MATCHMAKING",description=f"Your oponent is {p2username}",color=0x000)) | |
| await p2send.edit(embed=discord.Embed(title="MATCHMAKING",description=f"Your oponent is {p1username}",color=0x000)) | |
| p1msg = await p1send.channel.send(embed=discord.Embed(title="Your turn!",description="Choose from the reactions!",color=0x000)) | |
| p2msg = await p2send.channel.send(delete_after=5,embed=discord.Embed(title="Opponents turn.",description="Please wait",color=0x000)) | |
| await p1msg.add_reaction(client.get_emoji(493851797601910794)) | |
| await p1msg.add_reaction(client.get_emoji(493852002254585856)) | |
| await asyncio.sleep(1) | |
| def check(reaction, user): | |
| return user == p1user | |
| res,user = await client.wait_for('reaction_add',check=check) | |
| if int(res.emoji.id) == int(493852002254585856): | |
| r = random.choice([i for i in range(5)]) | |
| if r == 1: | |
| await p1send.edit(embed=discord.Embed(title="You won",description="Your worm took over their system!",color=0x000)) | |
| await p2send.edit(embed=discord.Embed(title="You lost",description="The enemys worm infected your systems.",color=0x000)) | |
| return | |
| else: | |
| await p1send.edit(embed=discord.Embed(title="You failed",description="Your worm didnt go throu their firewall.",color=0x000)) | |
| await p2send.channel.send(delete_after=10,embed=discord.Embed(title="WARNING",description="The enemy tryed to infect you with a worm. Luckily our firewall is better",color=0x000)) | |
| p2msg = await p2send.channel.send(delete_after=5,embed=discord.Embed(title="Opponents turn.",description="Please wait",color=0x000)) | |
| elif int(res.emoji.id) == int(493851797601910794): | |
| r = random.choice([i for i in range(5, 20)]) | |
| p1health -= r | |
| if p1health <= 0: | |
| await p1send.edit(embed=discord.Embed(title="You won",description="All the enemy systems got offline",color=0x000)) | |
| await p2send.edit(embed=discord.Embed(title="You lost",description="all your systems went offline",color=0x000)) | |
| else: | |
| await p1send.edit(embed=discord.Embed(title="DDoS",description=f"We managed to shut down {r} systems",color=0x000)) | |
| await p2send.edit(embed=discord.Embed(title="You got DDoSed",description=f"{p1health} systems left. ",color=0x000)) | |
| await asyncio.sleep(2) | |
| else: | |
| await p1send.edit(embed=discord.Embed(title="Invalid action. You lost your time",color=0x000)) | |
| # P2 | |
| await p2send.edit(embed=discord.Embed(title="MATCHMAKING",description=f"Your oponent is {p2username}",color=0x000)) | |
| await p1send.edit(embed=discord.Embed(title="MATCHMAKING",description=f"Your oponent is {p1username}",color=0x000)) | |
| p2msg = await p2send.channel.send(embed=discord.Embed(title="Your turn!",description="Choose from the reactions!",color=0x000)) | |
| p1msg = await p1send.channel.send(embed=discord.Embed(delete_after=5,title="Opponents turn.",description="Please wait",color=0x000)) | |
| await p2msg.add_reaction(client.get_emoji(493851797601910794)) | |
| await p2msg.add_reaction(client.get_emoji(493852002254585856)) | |
| await asyncio.sleep(1) | |
| def check(reaction, user): | |
| return user == p2user | |
| res,user = await client.wait_for('reaction_add',check=check) | |
| if int(res.emoji.id) == int(493852002254585856): | |
| r = random.choice([i for i in range(5)]) | |
| if r == 1: | |
| await p2send.edit(embed=discord.Embed(title="You won",description="Your worm took over their system!",color=0x000)) | |
| await p1send.edit(embed=discord.Embed(title="You lost",description="The enemys worm infected your systems.",color=0x000)) | |
| return | |
| else: | |
| await p2send.edit(embed=discord.Embed(title="You failed",description="Your worm didnt go throu their firewall.",color=0x000)) | |
| await p1send.channel.send(delete_after=10,embed=discord.Embed(title="WARNING",description="The enemy tryed to infect you with a worm. Luckily our firewall is better",color=0x000)) | |
| p1msg = await p1send.channel.send(embed=discord.Embed(title="Opponents turn.",description="Please wait",color=0x000)) | |
| elif int(res.emoji.id) == int(493851797601910794): | |
| r = random.choice([i for i in range(5, 20)]) | |
| p2health -= r | |
| if int(p2health) <= 0: | |
| await p1send.channel.send(embed=discord.Embed(title="You won",description="All the enemy systems got offline",color=0x000)) | |
| await p2send.channel.send(embed=discord.Embed(title="You lost",description="all your systems went offline",color=0x000)) | |
| return | |
| else: | |
| await p2send.edit(embed=discord.Embed(title="DDoS",description=f"We managed to shut down {r} systems",color=0x000)) | |
| await p1send.edit(embed=discord.Embed(title="You got DDoSed",description=f"{p1health} systems left. ",color=0x000)) | |
| await asyncio.sleep(2) | |
| else: | |
| await p2send.edit(embed=discord.Embed(title="Invalid action. You lost your time",color=0x000)) | |
| except Exception as e: | |
| return | |
| async def checkVotes(): | |
| await client.wait_until_ready() | |
| log.info("Check vote service on!") | |
| while True: | |
| if not server_offline: | |
| r = requests.get("https://itzepic.net/api/recentvotes",headers={"authorization":config.apitoken}) | |
| res = json.loads(r.text) | |
| #print(res) | |
| for i in res: | |
| try: | |
| if not i["weekend"] is True: | |
| await client.get_user(int(i["uid"])).send(embed=discord.Embed(title="VOTE",description="Thanks for voting! +5 hashes",color=0x000)) | |
| add_balance(int(i["uid"]), 5) | |
| else: | |
| add_balance(int(i["uid"]), 10) | |
| await client.get_user(int(i["uid"])).send(embed=discord.Embed(title="VOTE",description="Thanks for voting! +10 hashes (weekend bonus)",color=0x000)) | |
| except Exception as e:log.error(str(e)) | |
| await asyncio.sleep(10) | |
| async def send_stats(): | |
| await client.wait_until_ready() | |
| dbltoken = config.dbltoken | |
| url = "https://discordbots.org/api/bots/" + str(client.user.id) + "/stats" | |
| headers = {"Authorization" : dbltoken} | |
| while True: | |
| data = { | |
| "server_count":len(client.guilds), | |
| "shard_count":onlineShards, | |
| "shard_no":0 | |
| } | |
| try: | |
| requests.post(url,data=data,headers=headers) | |
| except: | |
| if not server_offline: | |
| requests.get("https://itzepic.net/api/error",json={"error":"DBL stat push failed"}) | |
| await asyncio.sleep(10) | |
| async def queue_running(): | |
| await client.wait_until_ready() | |
| while True: | |
| if len(queue) >= 2: | |
| last=queue[0] | |
| second=queue[1] | |
| queue.remove(last) | |
| queue.remove(second) | |
| client.loop.create_task(game_manager(last, second)) | |
| await asyncio.sleep(5) | |
| async def status(): | |
| # STATUSES: playing with x shards, playing Weekend bonus! Vote now for extra hashes! | |
| await client.wait_until_ready() | |
| while True: | |
| try: | |
| await client.change_presence(status=discord.Status.online, activity=discord.Game(f"in {len(client.guilds)} servers")) | |
| await asyncio.sleep(10) | |
| await client.change_presence(status=discord.Status.online,activity=discord.Game(f"with {int(onlineShards)} shards")) | |
| await asyncio.sleep(10) | |
| if int(datetime.datetime.utcnow().weekday()) >= 5: | |
| await client.change_presence(status=discord.Status.online,activity=discord.Game("Weekend bonus! Vote now for extra hashes")) | |
| await asyncio.sleep(10) | |
| else: | |
| await client.change_presence(status=discord.Status.online,activity=discord.Game("vote now for hashes")) | |
| await asyncio.sleep(10) | |
| await client.change_presence(status=discord.Status.online,activity=discord.Game("with love from discord.py rewrite")) | |
| await asyncio.sleep(10) | |
| except: | |
| pass | |
| def is_verifyed(userID:str): | |
| with open("data/verifyed.json") as f: | |
| j = json.loads(f.read()) | |
| try: | |
| return j[str(userID)] | |
| except: | |
| with open("data/verifyed.json", "w") as f: | |
| j[str(userID)] = False | |
| f.write(json.dumps(j)) | |
| return False | |
| def set_verifyed(userID:str, value:bool): | |
| with open("data/verifyed.json") as f: | |
| j = json.loads(f.read()) | |
| with open("data/verifyed.json","w") as f: | |
| j[str(userID)] = value | |
| f.write(json.dumps(j)) | |
| def set_balance(userID:str,value:int): | |
| with open("data/coins.json") as f: | |
| j = json.loads(f.read()) | |
| j[str(userID)] = value | |
| with open("data/coins.json", "w") as f: | |
| f.write(json.dumps(j)) | |
| def get_balance(userID:str): | |
| with open("data/coins.json") as f: | |
| j = json.loads(f.read()) | |
| try: | |
| return j[str(userID)] | |
| except: | |
| return 0 | |
| def add_balance(userID:str, value:int): | |
| set_balance(userID, get_balance(userID)+value) | |
| def remove_balance(userID:str, value:int): | |
| set_balance(userID, get_balance(userID)-value) | |
| def add_user(userID: str): | |
| with open("data/items.json") as f: | |
| j = json.loads(f.read()) | |
| try: | |
| fffff = j[str(userID)] | |
| return False | |
| except: | |
| j[userID] = {} | |
| with open("data/items.json", "w") as FW: | |
| FW.write(json.dumps(j)) | |
| def set_inventory(userID:str, inventory): | |
| f = open("data/items.json") | |
| j = json.loads(f.read()) | |
| f.close() | |
| j[str(userID)] = inventory | |
| with open("data/items.json", "w") as f: | |
| f.write(json.dumps(j)) | |
| def get_inventory(userID: str): | |
| with open("data/items.json") as f: | |
| add_user(userID) | |
| j = json.loads(f.read()) | |
| user = j[str(userID)] | |
| return user | |
| def add_item(userID:str, itemname, item): | |
| inv = get_inventory(userID) | |
| inv[itemname] = item | |
| set_inventory(userID, inv) | |
| #json | |
| # { | |
| # "ID": { | |
| # "Item":{ | |
| # "Health": 1, | |
| # "Damage": 1, | |
| # "Uses": 1, | |
| # }, | |
| # "Item2":{ | |
| # "Health": 1, | |
| # "Damage": 1, | |
| # "Uses": 1, | |
| # } | |
| # }, | |
| # | |
| # "ID2": { | |
| # "Item":{ | |
| # "Health": 1, | |
| # "Damage": 1, | |
| # "Uses": 1, | |
| # }, | |
| # "Item2":{ | |
| # "Health": 1, | |
| # "Damage": 1, | |
| # "Uses": 1, | |
| # } | |
| # }, | |
| # } | |
| #json file ^^^ | |
| #json.dumps(var) | |
| @client.event | |
| async def on_command_error(ctx, error): | |
| if isinstance(error, discord.ext.commands.errors.CommandNotFound):return | |
| if not server_offline: | |
| requests.get("https://itzepic.net/api/error",json={"error":str(error)}) | |
| else: | |
| raise(error) | |
| @client.group(hidden=True) | |
| async def dev(ctx): | |
| if not ctx.message.author.id in developers: | |
| return await ctx.send(embed=discord.Embed(title="Invalid perms. ",description="This is only for the devs",color=0x000)) | |
| if ctx.invoked_subcommand is None: | |
| await ctx.send(embed=discord.Embed(title="WRONG COMMAND",description="Please ask epic.",color=0x000)) | |
| @dev.command() | |
| async def set_inv(ctx, userID:str, *,inv): | |
| if not ctx.message.author.id in developers:return | |
| inv = json.loads(inv) | |
| set_inventory(userID, inv) | |
| await ctx.send(embed=discord.Embed(title="DEVELOPER",description="Action complete!",color=0x000)) | |
| @dev.command(name="set_verifyed") | |
| async def verify(ctx,userID:str, value:bool): | |
| if not ctx.message.author.id in developers:return | |
| set_verifyed(userID, value) | |
| @dev.command() | |
| async def error(ctx): | |
| if not ctx.message.author.id in developers:return | |
| raise(TypeError) | |
| @client.command() | |
| async def announce(ctx, channel:discord.TextChannel, *, text): | |
| if not ctx.message.author.guild_permissions.administrator:return await ctx.send(embed=discord.Embed(title="Error",description="You need admin to do this.",color=0x000)) | |
| await channel.send(embed=discord.Embed(title="Announcement",description=text,color=0x45a247)) | |
| @client.command(aliases=["support"]) | |
| async def vote(ctx): | |
| await ctx.send(embed=discord.Embed(title="VOTE",description="Votes help us a lot. [VOTE](https://discordbots.org/bot/493091956503740447/vote)")) | |
| @client.command() | |
| async def invite(ctx): | |
| await ctx.send(embed=discord.Embed(title="Invite",description="[LINK](https://discordbots.org/bot/493091956503740447)")) | |
| @client.command(aliases=["inv", "inven"]) | |
| async def inventory(ctx, user:discord.Member=None): | |
| if user == None:user = ctx.message.author | |
| inv = get_inventory(user.id) | |
| embed=discord.Embed(title="Inventory",color=0x000) | |
| for i in inv.keys(): | |
| name = i | |
| item = inv[i] | |
| if name.lower() == "computer": | |
| hph = item["hph"] | |
| embed.add_field(name="Computer",value=f"Produces {hph} hashes a hour.") | |
| else: | |
| desc = "" | |
| for x in item.keys(): | |
| tmp = f"{x}: {item[x]}" | |
| desc += tmp | |
| embed.add_field(name=name,value=desc) | |
| if len(embed.fields) == 0: | |
| embed.add_field(name="Nothing",value="Uh seems like i have forgotten something...") | |
| await ctx.send(embed=embed) | |
| @client.command(aliases=["hack","war"]) | |
| async def battle(ctx): | |
| if ctx.message.channel.id in [queue[i]["channelID"] for i in range(len(queue))]: return await ctx.send(embed=discord.Embed(title="Error",description="Battles cannot be in the same channel",color=0x000)) | |
| msg = await ctx.send(embed=discord.Embed(title="MATCHMAKING",description="<a:Creating:483181809555996682> Searching for match",color=0x000)) | |
| queue.append({"msg":msg,"user":ctx.message.author,"channelID":ctx.message.channel.id}) | |
| @client.event | |
| async def on_ready(): | |
| global onlineShards | |
| onlineShards += 1 | |
| log.info("Bot loaded!") | |
| #while True: | |
| # try:await status() | |
| # except:pass | |
| @client.command() | |
| async def prefix(ctx, newPrefix=None): | |
| if not ctx.message.author.guild_permissions.administrator and not ctx.message.author.id == 397745647723216898: | |
| return await ctx.send(embed=discord.Embed(title="No Perms",description="You dont have perms for this.",color=0x000)) | |
| if newPrefix == None: | |
| with open("data/serverPrefixes.json") as f: | |
| try: | |
| j = json.loads(f.read()) | |
| prefix = j[str(ctx.message.guild.id)] | |
| except: | |
| prefix = ["t!"] | |
| return await ctx.send(embed=discord.Embed(title="Prefix",description=f"This servers prefix is {prefix[0]}",color=0x000)) | |
| else: | |
| if len(newPrefix) != 1:return await ctx.send(embed=discord.Embed(title="Prefix",description="Customizable prefixes can only be 1 char long.",color=0x000)) | |
| file = open("data/serverPrefixes.json") | |
| fileRead = file.read() | |
| file.close() | |
| with open("data/serverPrefixes.json","w") as f: | |
| j = json.loads(fileRead) | |
| j[str(ctx.message.guild.id)] = newPrefix | |
| f.write(json.dumps(j)) | |
| await ctx.send(embed=discord.Embed(title="Prefix",description="The prefix has been set. ",color=0x000)) | |
| @client.command() | |
| async def help(ctx, cmd=None): | |
| all_commands = { | |
| "help": "Shows this message", | |
| "prefix": "Change or view the servers prefix.", | |
| "slowmode":"Sloooooows the chat down", | |
| "kick":"Kicks a user from ur server", | |
| "coder":"Makes your pfp a hacker", | |
| "battle":"Battle people from other servers and take them down!", | |
| "inventory":"Shows what you have in your inventory", | |
| "vote":"Show your support to the bot.", | |
| "birb":"BIRRRRRRRRRRRRRRB Shows you a birb", | |
| "meme":"This is the internet", | |
| "trivia":"Do a computer quiz", | |
| "info":"Gives you info about the bot.", | |
| "invite":"Gives you a invite link to add the bot.", | |
| "profile":"Shows you your profile", | |
| "announce":"Announces a message to a channel" | |
| } | |
| categorys = {"image":["meme","birb","coder"],"moderation":["slowmode","prefix","kick"]} | |
| if cmd == None: | |
| embed = discord.Embed(title="Help",color=0x000) | |
| for command in all_commands.keys(): | |
| embed.add_field(name=command, value=all_commands[command], inline=False) | |
| await ctx.send(embed=embed) | |
| elif cmd in categorys.keys(): | |
| for category in categorys.keys(): | |
| if cmd.lower() == category: | |
| categori = category | |
| break | |
| commandsInCategory = categorys[categori] | |
| embed = discord.Embed(title=categori[0].upper() + "".join(categori[1:]), colour=0x000) | |
| for command in commandsInCategory: | |
| for all_command in all_commands.keys(): | |
| if command == all_command: | |
| embed.add_field(name=command, value=all_commands[command], inline=False) | |
| await ctx.send(embed=embed) | |
| elif cmd in all_commands.keys(): | |
| embed=discord.Embed(title=cmd,description=all_commands[cmd],color=0x000) | |
| await ctx.send(embed=embed) | |
| else: | |
| await ctx.send(embed=discord.Embed(title="Invalid category/command",description=f"Try {ctx.prefix}help",color=0x000)) | |
| @client.command() | |
| async def arena(ctx,cmd="help", *,code=None): | |
| global arenas | |
| # { | |
| # [ | |
| # "title": "", | |
| # "description": "", | |
| # "difficulty": 1, | |
| # "tests": [ | |
| # { | |
| # "variables": {}, | |
| # "expected": None | |
| # } | |
| # ] | |
| # ] | |
| # } | |
| if code != None: | |
| code = code.replace("`","") | |
| cmd = cmd.lower() | |
| if cmd == "start": | |
| if ctx.message.channel not in arenas: | |
| with open("data/arenas.json") as f: | |
| j = json.loads(f.read()) | |
| f.close() | |
| arenas[ctx.message.channel] = random.choice(j["arenas"]) | |
| current_arena = arenas[ctx.message.channel] | |
| await ctx.send(embed=discord.Embed(title=current_arena["title"],description=current_arena["description"],color=0x000)) | |
| else: | |
| await ctx.send(embed=discord.Embed(title="Error",description="An arena is already running.",color=0x000)) | |
| elif cmd == "stop": | |
| if ctx.message.author.guild_permissions.administrator: | |
| if ctx.message.channel in arenas: | |
| await ctx.send(embed=discord.Embed(title="Stopped",description="The arena was stopped.",color=0x000)) | |
| j = {} | |
| for i in arenas.keys(): | |
| if not i == ctx.message.channel: | |
| j[i] = arenas[i] | |
| arenas = j | |
| else: | |
| await ctx.send(embed=discord.Embed(title="Error",description="No arena is running right now.",color=0x000)) | |
| else: | |
| await ctx.send(embed=discord.Embed(title="Perms",description="You need admin to stop an arena.",color=0x000)) | |
| elif cmd == "submit": | |
| if ctx.message.channel in arenas: | |
| if "while" in code.lower():return await ctx.send(embed=discord.Embed(title="Error",description="Please use for loops instead of while loops.",color=0x000)) | |
| try: | |
| async with async_timeout.timeout(2): | |
| res = test_code(code, arenas[ctx.message.channel]) | |
| except Exception as e: | |
| return await ctx.send(embed=discord.Embed(title="😭",description=f"Your application failed. Error: {str(e)}",color=0x000)) | |
| if res == True and type(res) == bool: | |
| await ctx.send(embed=discord.Embed(title="GG",description="You made it!",color=0x000)) | |
| j = {} | |
| for i in arenas.keys(): | |
| if not i == ctx.message.channel: | |
| j[i] = arenas[i] | |
| arenas = j | |
| else: | |
| arena = arenas[ctx.message.channel] | |
| await ctx.send(embed=discord.Embed(title="😭",description=f"You failed {res} tests out of {len(arena['tests'])}",color=0x000)) | |
| else: | |
| await ctx.send(embed=discord.Embed(title="Error",description="No arena is running right now.",color=0x000)) | |
| elif cmd == "help": | |
| embed = discord.Embed(title="Arena",description="Welcome to the coding arena! Here you can train your coding skills!\n\n***Commands***:\n{p}arena start - *start a new arena*\n{p}arena stop - *stops the current arena*\n{p}arena submit <code> - *submits some code to the current arena*\n\n\n*<> are required args*".format(p=ctx.prefix),color=0x000) | |
| await ctx.send(embed=embed) | |
| def test_code(code, arena): | |
| failed = 0 | |
| for test in arena["tests"]: | |
| result = better_exec(code, test["builtins"], args=test["variables"]) | |
| if bool(test["expected"]) == bool(result): | |
| pass | |
| else: | |
| failed += 1 | |
| if str(failed) == "0":return True | |
| return failed | |
| def better_exec(code, builtins,args={}): | |
| allowed_builtins = {} | |
| for builtin in builtins: | |
| allowed_builtins[builtin] = eval(builtin) | |
| global_vars = {"__builtins__": allowed_builtins} | |
| local_vars = {} | |
| for i in args.keys(): | |
| local_vars[i] = args[i] | |
| code_start_line = "\n " | |
| code_prfx = "def runpy():" + code_start_line | |
| code_lines_splitted = code.split("\n") | |
| code_lines = code_start_line.join(code_lines_splitted) | |
| code_run = code_prfx+code_lines | |
| # exec(code_run, {'__builtins__': {"min":min,"False":False,"True":True,"range":range,"type":type,"str":str,"int":int,"reversed":reversed,"bytes":bytes,"hex":hex, "sum":sum,"id":id,"round":round}}, variables) | |
| exec(code_run,global_vars,local_vars) | |
| result = local_vars["runpy"]() | |
| #print(result) | |
| return result | |
| @client.command() | |
| async def trivia(ctx): | |
| #await ctx.send(embed=discord.Embed(title="In-dev",description="This is currently in development, so this doesnt show anything.")) | |
| with open("data/trivia.json") as f: | |
| data = json.loads(f.read()) | |
| points = 0 | |
| def author_check(message): | |
| return message.author.id == ctx.message.author.id | |
| while True: | |
| all_questions = data.keys() | |
| question = random.choice(list(all_questions)) | |
| awnser = data[question] | |
| try: | |
| question_embed = discord.Embed(title="Trivia",description=f"{question}\n You have 30 seconds.",color=0x000) | |
| question_embed.set_footer(text="Answer with Y/N in the chat.") | |
| await ctx.send(embed=question_embed,delete_after=30) | |
| message = await client.wait_for('message', check=author_check, timeout=30) | |
| if message.content.upper() in ["Y", "YES", "YEAH", "YASSS", "T", "TRUE", "TRU"]: | |
| guess = True | |
| elif message.content.upper() in ["N", "NO", "NOPE", "NOOPE", "F", "FALSE", "FAKE"]: | |
| guess = False | |
| else: | |
| break | |
| if guess != bool(awnser): | |
| raise RuntimeError | |
| else: | |
| points += 1 | |
| await ctx.send(embed=discord.Embed(title="Correct",description=f"This is the correct awnser!\nYou now have {str(points)} correct awnsers!",color=0x000),delete_after=30) | |
| except asyncio.TimeoutError: | |
| break | |
| except RuntimeError: | |
| break | |
| await ctx.send(embed=discord.Embed(title="WRONG",description="Your answer doesnt seem to be right.",color=0x000),delete_after=30) | |
| coins = int(points // 2) | |
| add_balance(ctx.message.author.id, coins) | |
| await ctx.send(embed=discord.Embed(title="Reward",description=f"You got {coins} as a reward for answering {str(points)} right.",color=0x000),delete_after=60) | |
| @client.command() | |
| async def kick(ctx, user:discord.Member, reason=None): | |
| if not ctx.message.author.guild_permissions.administrator and not ctx.message.author.id == 397745647723216898: | |
| return await ctx.send(embed=discord.Embed(title="No Perms",description="You dont have perms for this.",color=0x000)) | |
| try: | |
| await user.kick(reason=reason) | |
| except: return await ctx.send(embed=discord.Embed(title="Failed",description="Seems like i dont have perms?",color=0x000)) | |
| await ctx.send(embed=discord.Embed(title="Kick",description="User has been kicked",color=0x000)) | |
| @client.command() | |
| async def info(ctx): | |
| embed=discord.Embed(title="TDev info",description=f"Bot started: 9/22/2018\nShards online: {str(onlineShards)}\nServer count: {str(len(client.guilds))}",color=0x000) | |
| await ctx.send(embed=embed) | |
| @client.command() | |
| async def slowmode(ctx, value:int,channel:discord.TextChannel=None): | |
| if not ctx.message.author.guild_permissions.administrator and not ctx.message.author.id == 397745647723216898: | |
| return await ctx.send(embed=discord.Embed(title="No Perms",description="You dont have perms for this.",color=0x000)) | |
| if channel == None: | |
| channel = ctx.message.channel | |
| if value < 0 or value > 120: | |
| return await ctx.send(embed=discord.Embed(title="Incorrect value",description="Value has to be between 0-120 (seconds)",color=0x000)) | |
| route = discord.http.Route('PATCH', f'/channels/{str(ctx.message.channel.id)}') | |
| try: | |
| await client.http.request(route, json={'rate_limit_per_user': value}) | |
| except: | |
| return await ctx.send(embed=discord.Embed(title="No perms",description="Seems like i am lacking perms. ",color=0x000)) | |
| if value == 0: return await ctx.send(embed=discord.Embed(title="Disabled",description="Slowmode has been disabled",color=0x000)) | |
| if value == 1: return await ctx.send(embed=discord.Embed(title="Slowmode",description="Slowmode is now at 1 second",color=0x000)) | |
| else:return await ctx.send(embed=discord.Embed(title="Slowmode",description=f"Slowmode is now at {value} seconds",color=0x000)) | |
| ########## IMAGES ########## | |
| @client.command(aliases=["hacker"]) | |
| async def coder(ctx, user:discord.Member=None): | |
| if user == None:user = ctx.message.author | |
| basewidth = 125 | |
| userprofile = requests.get(user.avatar_url) | |
| background = Image.open(BytesIO(userprofile.content)).convert("RGBA") | |
| foreground = Image.open("data/images/code.png").convert("RGBA") | |
| wpercent = (basewidth / float(background.size[0])) | |
| hsize = int((float(background.size[1]) * float(wpercent))) | |
| final = background.resize((basewidth, hsize), PIL.Image.ANTIALIAS) | |
| foreground.putalpha(160) | |
| final.paste(foreground, (0, 0), foreground) | |
| final.save("tmp.png") | |
| await ctx.send(file=discord.File("tmp.png")) | |
| @client.command() | |
| async def catify(ctx, user:discord.Member=None): | |
| if user == None:user = ctx.message.author | |
| request = requests.get('https://api.thecatapi.com/v1/images/search?') | |
| data = request.json()[0] | |
| link = data['url'] | |
| cat = requests.get(link) | |
| ##### IMAGING #### | |
| basewidth = 125 | |
| userprofile = requests.get(user.avatar_url) | |
| foreground = Image.open(BytesIO(cat.content)).convert("RGBA") | |
| background = Image.open(BytesIO(userprofile.content)).convert("RGBA") | |
| wpercent = (basewidth / float(background.size[0])) | |
| hsize = int((float(background.size[1]) * float(wpercent))) | |
| finalBG = background.resize((basewidth, hsize), PIL.Image.ANTIALIAS) | |
| finalFG = foreground.resize((basewidth, hsize), PIL.Image.ANTIALIAS) | |
| finalFG.putalpha(160) | |
| finalBG.paste(finalFG, (0, 0), finalFG) | |
| finalBG.save("tmp.png") | |
| await ctx.send(file=discord.File("tmp.png")) | |
| @client.command() | |
| async def meme(ctx): | |
| response = requests.get('https://some-random-api.ml/meme') | |
| data = response.json() | |
| embed = discord.Embed(title="Meme incomming!!!",color=0x000) | |
| embed.set_image(url=f"{data['url']}") | |
| await ctx.send(embed=embed) | |
| @client.command() | |
| async def birb(ctx): | |
| request = requests.get("https://random.birb.pw/tweet/random") | |
| background = Image.open(BytesIO(request.content)).convert("RGBA") | |
| background.save("tmp.png") | |
| await ctx.send(file=discord.File("tmp.png")) | |
| # pfp 51,69 | |
| # name 303,120 | |
| # hashes 304,212 | |
| # 91,57,19,3 COLOR | |
| # 50,215 BADGE | |
| @client.command() | |
| async def profile(ctx, user:discord.Member=None): | |
| if user == None: | |
| user = ctx.message.author | |
| if user.id in developers and not is_verifyed(user.id): | |
| basewidth = 125 | |
| response = requests.get(user.avatar_url) | |
| foreground = Image.open(BytesIO(response.content)).convert("RGBA") | |
| background = Image.open("data/images/profile.png").convert("RGBA") | |
| devbadge_raw = Image.open("data/images/badges/devbadge_big.png").convert("RGBA") | |
| devbadge = devbadge_raw.resize((40, 40), PIL.Image.ANTIALIAS) | |
| wpercent = (basewidth / float(foreground.size[0])) | |
| hsize = int((float(foreground.size[1]) * float(wpercent))) | |
| final = foreground.resize((basewidth, hsize), PIL.Image.ANTIALIAS) | |
| background.paste(final, (51,69), final) | |
| background.paste(devbadge, (50,215), devbadge) | |
| font_type = ImageFont.truetype('font.ttf', 30) | |
| draw = ImageDraw.Draw(background) | |
| draw.text(xy=(303,120), text=user.display_name, fill = (12,103,153), font=font_type)# Name | |
| draw.text(xy=(304, 212), text=str(get_balance(user.id)), fill=(12,103,153), font=font_type) # Hashes | |
| background.save("tmp.png") | |
| await ctx.send(file=discord.File("tmp.png")) | |
| elif is_verifyed(user.id) and not user.id in developers: | |
| basewidth = 125 | |
| response = requests.get(user.avatar_url) | |
| foreground = Image.open(BytesIO(response.content)).convert("RGBA") | |
| background = Image.open("data/images/profile.png").convert("RGBA") | |
| badge_raw = Image.open("data/images/badges/verifyedbadge_big.png").convert("RGBA") | |
| badge = badge_raw.resize((40, 40), PIL.Image.ANTIALIAS) | |
| wpercent = (basewidth / float(foreground.size[0])) | |
| hsize = int((float(foreground.size[1]) * float(wpercent))) | |
| final = foreground.resize((basewidth, hsize), PIL.Image.ANTIALIAS) | |
| background.paste(final, (51,69), final) | |
| background.paste(badge, (50,215), badge) | |
| font_type = ImageFont.truetype('font.ttf', 30) | |
| draw = ImageDraw.Draw(background) | |
| draw.text(xy=(303,120), text=user.display_name, fill = (12,103,153), font=font_type)# Name | |
| draw.text(xy=(304, 212), text=str(get_balance(user.id)), fill=(12,103,153), font=font_type) # Hashes | |
| background.save("tmp.png") | |
| await ctx.send(file=discord.File("tmp.png")) | |
| elif is_verifyed(user.id) and user.id in developers: | |
| basewidth = 125 | |
| response = requests.get(user.avatar_url) | |
| foreground = Image.open(BytesIO(response.content)).convert("RGBA") | |
| background = Image.open("data/images/profile.png").convert("RGBA") | |
| devbadge_raw = Image.open("data/images/badges/devbadge_big.png").convert("RGBA") | |
| devbadge = devbadge_raw.resize((40, 40), PIL.Image.ANTIALIAS) | |
| badge_raw = Image.open("data/images/badges/verifyedbadge_big.png").convert("RGBA") | |
| badge = badge_raw.resize((40, 40), PIL.Image.ANTIALIAS) | |
| wpercent = (basewidth / float(foreground.size[0])) | |
| hsize = int((float(foreground.size[1]) * float(wpercent))) | |
| final = foreground.resize((basewidth, hsize), PIL.Image.ANTIALIAS) | |
| background.paste(final, (51,69), final) | |
| background.paste(devbadge, (50,215), devbadge) | |
| background.paste(badge, (100,215), badge) | |
| font_type = ImageFont.truetype('font.ttf', 30) | |
| draw = ImageDraw.Draw(background) | |
| draw.text(xy=(303,120), text=user.display_name, fill = (12,103,153), font=font_type)# Name | |
| draw.text(xy=(304, 212), text=str(get_balance(user.id)), fill=(12,103,153), font=font_type) # Hashes | |
| background.save("tmp.png") | |
| await ctx.send(file=discord.File("tmp.png")) | |
| else: | |
| basewidth = 125 | |
| response = requests.get(user.avatar_url) | |
| foreground = Image.open(BytesIO(response.content)).convert("RGBA") | |
| background = Image.open("data/images/profile.png").convert("RGBA") | |
| wpercent = (basewidth / float(foreground.size[0])) | |
| hsize = int((float(foreground.size[1]) * float(wpercent))) | |
| final = foreground.resize((basewidth, hsize), PIL.Image.ANTIALIAS) | |
| background.paste(final, (51,69), final) | |
| font_type = ImageFont.truetype('font.ttf', 20) | |
| draw = ImageDraw.Draw(background) | |
| draw.text(xy=(303,120), text=user.display_name, fill = (91,57,19,3 ), font=font_type)# Name | |
| draw.text(xy=(304, 212), text=str(get_balance(user.id)), fill=(91, 57, 19, 3), font=font_type) # Hashes | |
| background.save("tmp.png") | |
| await ctx.send(file=discord.File("tmp.png")) | |
| @client.event | |
| async def on_message(message): | |
| if message.guild == None: | |
| log.info("DM recived.") | |
| if message.author.bot:return | |
| await client.process_commands(message) | |
| client.loop.create_task(checkVotes()) | |
| client.loop.create_task(queue_running()) | |
| client.loop.create_task(send_stats()) | |
| client.loop.create_task(status()) | |
| client.run(config.token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment