· 5 years ago · Oct 01, 2020, 06:26 PM
1# obtain proper libraries for hypixel stats and discord.py
2import discord
3from discord.ext import commands
4import aiohttp
5import asyncpraw
6import random
7
8#initialize stuff
9client = commands.Bot(command_prefix = ".")
10
11reddit = asyncpraw.Reddit(client_id="aa",
12 client_secret="bb",
13 user_agent="script: Python (by /u/cc)")
14
15client.session = aiohttp.ClientSession()
16
17
18@client.command()
19async def hystats(ctx,mcuser):
20 async with client.session.get(f'https://api.slothpixel.me/api/players/{mcuser}') as r:
21 res = await r.json() # returns dict
22 await ctx.send(res['total_coins'])
23
24@client.group()
25async def gd(ctx):
26 if ctx.invoked_subcommand is None:
27 await ctx.send("Please add a subcommand! (profile, level)")
28@gd.command()
29async def profile(ctx,username):
30 async with client.session.get(url = f'https://gdbrowser.com/api/profile/{username}') as r:
31 res = await r.json()
32
33 if res == "-1":
34 await ctx.send("error! you either entered the name wrong/gdbrowser api is down. try again later")
35 else:
36 embed = discord.Embed(title = f"GD Stats for {res['username']}")
37 embed.set_thumbnail(url = f'https://gdbrowser.com/icon/{username}')
38 embed.add_field(name = 'Stars', value = res['stars'], inline=False)
39 embed.add_field(name = 'Coins', value = res['coins'],inline=False)
40 embed.add_field(name = 'Demons', value = res['demons'],inline=False)
41 embed.set_footer(text="All info is obtained from https://gdbrowser.com")
42 await ctx.send(embed=embed)
43@gd.command()
44async def level(ctx, id: int):
45 async with client.session.get(f'https://gdbrowser.com/api/level/{id}') as r:
46 res = await r.json()
47 embed = discord.Embed(title = f"GD Level: {res['name']}")
48 embed.add_field(name="Author", value = res['author'],inline=False)
49 embed.add_field(name="Difficulty", value = res['difficulty'],inline=False)
50 embed.add_field(name="Downloads", value = res['downloads'],inline=False)
51 embed.add_field(name="Stars", value = res['stars'],inline=False)
52 embed.add_field(name="Song Name", value = res['songName'],inline=False)
53 await ctx.send(embed=embed)
54
55@client.command()
56async def mcserver(ctx,ip):
57 async with client.session.get(f'https://api.mcsrvstat.us/2/{ip}') as r:
58 res = await r.json()
59 embed = discord.Embed(title = f"Server Stats for {res['hostname']}")
60 motdpath = res['motd']['clean']
61 if len(motdpath) == 2:
62 embed.description = (f"""**MOTD:** {res['motd']['clean'][0]}
63 {res['motd']['clean'][1]}
64 **Players:** {res['players']['online']}/{res['players']['max']}
65 **Version:** {res['version']}""")
66 else:
67 embed.description = (f"""**MOTD:** {res['motd']['clean'][0]}
68 **Players:** {res['players']['online']}/{res['players']['max']}
69 **Version:** {res['version']}""")
70
71
72 await ctx.send(embed=embed)
73
74
75
76@client.command()
77async def dadjoke(ctx):
78
79 async with client.session.get(url='https://icanhazdadjoke.com/slack') as r:
80 res = await r.json()
81 await ctx.send(res['attachments'][0]['text'])
82
83
84
85#sends a message to the console when the bot is connected
86@client.event
87async def on_ready():
88 print(f"{client.user} is ready!")
89
90
91#basic ping command
92@client.command(brief = "Tells you the ping in ms", description = "Tells you the time to connect from idiot.exes pc to the discord server (in ms)")
93async def ping(ctx):
94 await ctx.send(f"pong! {round(client.latency * 1000, 4)} ms")
95
96
97#funny meme command
98@client.command(brief = "haha brrr go brrrr", description = "brrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr")
99async def brr(ctx):
100 await ctx.send("https://i.clouds.tf/hys8/7nvo.png")
101
102@client.command()
103async def poll(ctx, *, question):
104 pollembed = discord.Embed(title= question, colour = discord.Colour(0x7289da))
105 pollembed.set_author(name=f"{ctx.author.name} asks: ")
106 pogmessage = await ctx.send(embed=pollembed)
107 await pogmessage.add_reaction("\U0001f44d")
108 await pogmessage.add_reaction("\U0001f44e")
109
110
111
112#links the skyleamoe page for a given user
113@client.command()
114async def sbprof(ctx,mcname,profile = None):
115 if profile == None:
116 await ctx.send(f"https://sky.shiiyu.moe/stats/{mcname}")
117 else:
118 await ctx.send(f'https://sky.shiiyu.moe/stats/{mcname}/{profile}')
119
120@client.command()
121async def meme(ctx):
122 sub = await reddit.subreddit("memes").random()
123 await ctx.send(sub.url)
124
125
126
127
128
129
130
131
132#uses my api key to run the code and start sending it over to discord
133client.run("no")
134