aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnInternetTroll <lucafulger@gmail.com>2020-07-12 19:31:52 +0000
committerAnInternetTroll <lucafulger@gmail.com>2020-07-12 19:31:52 +0000
commit058a82a5a367d38d6c9415c6b66f034476c337c9 (patch)
treea41201970459d04f04f7711d8680708c83e633f2
parent36b282ef5b74370e2faab7e357e742c8167caa88 (diff)
downloadsteve-bot-058a82a5a367d38d6c9415c6b66f034476c337c9.tar
steve-bot-058a82a5a367d38d6c9415c6b66f034476c337c9.tar.gz
steve-bot-058a82a5a367d38d6c9415c6b66f034476c337c9.tar.bz2
steve-bot-058a82a5a367d38d6c9415c6b66f034476c337c9.tar.lz
steve-bot-058a82a5a367d38d6c9415c6b66f034476c337c9.tar.xz
steve-bot-058a82a5a367d38d6c9415c6b66f034476c337c9.tar.zst
steve-bot-058a82a5a367d38d6c9415c6b66f034476c337c9.zip
Started switch from requests to aiohttp
-rwxr-xr-xbot.py2
-rwxr-xr-xcogs/admin.py6
-rwxr-xr-xcogs/general.py193
-rwxr-xr-xcogs/utils.py2
-rwxr-xr-xcustom_commands.json4
5 files changed, 105 insertions, 102 deletions
diff --git a/bot.py b/bot.py
index 12ea846..d405115 100755
--- a/bot.py
+++ b/bot.py
@@ -1,6 +1,7 @@
from discord.ext import commands
import discord
import logging
+import aiohttp
import datetime
import json
@@ -35,6 +36,7 @@ class BedrockBot(commands.Bot):
super().__init__(command_prefix=get_prefix, case_insensitive=True)
self.logger = logging.getLogger('discord')
self.messageBlacklist = []
+ self.session = aiohttp.ClientSession()
with open('custom_commands.json', 'r') as f:
self.custom_commands = json.load(f)
diff --git a/cogs/admin.py b/cogs/admin.py
index 19438b4..3a6299f 100755
--- a/cogs/admin.py
+++ b/cogs/admin.py
@@ -1,7 +1,6 @@
from discord.ext import commands
import discord
import asyncio
-import subprocess
import json
import git
import os
@@ -158,7 +157,7 @@ class Admin(commands.Cog):
@commands.command()
@commands.check(is_botmaster)
async def ban(self, ctx, members: commands.Greedy[discord.Member]=False,
- mute_minutes: int = 0,
+ ban_minutes: int = 0,
*, reason: str = "absolutely no reason"):
"""Mass ban members with an optional mute_minutes parameter to time it"""
@@ -172,11 +171,12 @@ class Admin(commands.Cog):
embed = discord.Embed(title = "You can't ban me, I'm an almighty bot")
await ctx.send(embed = embed)
continue
+ await member.send(f"You have been banned from {ctx.guild.name} for {mute_minutes} minutes because: ```{reason}```")
await ctx.guild.ban(member, reason=reason, delete_message_days=0)
await ctx.send("{0.mention} has been banned by {1.mention} for *{2}*".format(member, ctx.author, reason))
if mute_minutes > 0:
- await asyncio.sleep(mute_minutes * 60)
+ await asyncio.sleep(ban_minutes * 60)
for member in members:
await ctx.guild.unban(member, reason="Time is up")
diff --git a/cogs/general.py b/cogs/general.py
index 0612e67..cf05eb4 100755
--- a/cogs/general.py
+++ b/cogs/general.py
@@ -515,61 +515,61 @@ class General(commands.Cog):
await ctx.send("You need to specify a gamer, gamer")
return
- r = requests.get(f"https://xbl-api.prouser123.me/profile/gamertag/{gamertag}")
- gamer = json.loads(r.text)
+ async with self.bot.session.get(f'https://xbl-api.prouser123.me/profile/gamertag/{gamertag}') as r:
+ gamer = json.loads(await r.text())
- try:
- await ctx.send(f"{gamer['error']}: {gamer['message']}")
- return
- except KeyError:
- pass
-
- for i in gamer["profileUsers"][0]["settings"]:
- if i["id"] == "GameDisplayName":
- gameName = i["value"]
- continue
- if i["id"] == "AppDisplayPicRaw":
- picUrl = i["value"]
- continue
- if i["id"] == "Gamerscore":
- Gamerscore = i["value"]+"<:gamerscore:727131234534424586>"
- continue
- if i["id"] == "AccountTier":
- accountTier = i["value"]
- continue
- if i["id"] == "XboxOneRep":
- reputation = i["value"]
- continue
- if i["id"] == "PreferredColor":
- color = int(json.loads(requests.get(i["value"]).text)["primaryColor"], 16)
- continue
- if i["id"] == "Location":
- location = i["value"]
- continue
- if i["id"] == "Bio":
- #if len(i["value"]) == 0:
- # Bio = "Unknown"
- #else:
- Bio = i["value"]
- continue
- if i["id"] == "Watermarks":
- Watermarks = i["value"]
- continue
- if i["id"] == "RealName":
- RealName = i["value"]
- continue
-
-
- embed=discord.Embed(title=gameName, description=Bio, color=color, timestamp=ctx.message.created_at)
- embed.set_thumbnail(url=picUrl)
- embed.add_field(name="Gamerscore", value=Gamerscore, inline=True)
- if len(location) != 0:
- embed.add_field(name="Location", value=location, inline=True)
- if len(Watermarks) != 0:
- embed.add_field(name="Watermarks", value=Watermarks, inline=True)
- embed.add_field(name="Account Tier", value=accountTier, inline=True)
- embed.add_field(name="Reputation", value=reputation, inline=True)
- await ctx.send(embed=embed)
+ try:
+ await ctx.send(f"{gamer['error']}: {gamer['message']}")
+ return
+ except KeyError:
+ pass
+
+ for i in gamer["profileUsers"][0]["settings"]:
+ if i["id"] == "GameDisplayName":
+ gameName = i["value"]
+ continue
+ if i["id"] == "AppDisplayPicRaw":
+ picUrl = i["value"]
+ continue
+ if i["id"] == "Gamerscore":
+ Gamerscore = i["value"]+"<:gamerscore:727131234534424586>"
+ continue
+ if i["id"] == "AccountTier":
+ accountTier = i["value"]
+ continue
+ if i["id"] == "XboxOneRep":
+ reputation = i["value"]
+ continue
+ if i["id"] == "PreferredColor":
+ color = int(json.loads(requests.get(i["value"]).text)["primaryColor"], 16)
+ continue
+ if i["id"] == "Location":
+ location = i["value"]
+ continue
+ if i["id"] == "Bio":
+ #if len(i["value"]) == 0:
+ # Bio = "Unknown"
+ #else:
+ Bio = i["value"]
+ continue
+ if i["id"] == "Watermarks":
+ Watermarks = i["value"]
+ continue
+ if i["id"] == "RealName":
+ RealName = i["value"]
+ continue
+
+
+ embed=discord.Embed(title=gameName, description=Bio, color=color, timestamp=ctx.message.created_at)
+ embed.set_thumbnail(url=picUrl)
+ embed.add_field(name="Gamerscore", value=Gamerscore, inline=True)
+ if len(location) != 0:
+ embed.add_field(name="Location", value=location, inline=True)
+ if len(Watermarks) != 0:
+ embed.add_field(name="Watermarks", value=Watermarks, inline=True)
+ embed.add_field(name="Account Tier", value=accountTier, inline=True)
+ embed.add_field(name="Reputation", value=reputation, inline=True)
+ await ctx.send(embed=embed)
@commands.command(hidden=True)
async def xboxpresence(self, ctx, *, gamertag=None):
@@ -577,35 +577,35 @@ class General(commands.Cog):
await ctx.send("You need to specify a gamer, gamer")
return
- r = requests.get(f"https://xbl-api.prouser123.me/presence/gamertag/{gamertag}")
- gamer = json.loads(r.text)
+ async with self.bot.session.get(f"https://xbl-api.prouser123.me/presence/gamertag/{gamertag}") as r:
+ gamer = json.loads(await r.text())
- try:
- await ctx.send(f"{gamer['error']}: {gamer['message']}")
- return
- except KeyError:
- pass
+ try:
+ await ctx.send(f"{gamer['error']}: {gamer['message']}")
+ return
+ except KeyError:
+ pass
- state = gamer["state"]
+ state = gamer["state"]
- try:
- game = json.loads(requests.get(f"https://xbl-api.prouser123.me/titleinfo/{gamer['lastSeen']['titleId']}").text)
- gameName = game["titles"][0]["name"]
- gamePic = game["titles"][0]["images"][4]["url"]
- timestamp = dateutil.parser.isoparse(gamer["lastSeen"]["timestamp"])
- lastSeen = True
- except Exception as e:
- print(e)
- lastSeen = False
-
- if lastSeen:
- embed=discord.Embed(title=gamer["gamertag"], description=state, timestamp=timestamp)
- embed.set_thumbnail(url=gamePic)
- embed.add_field(name="Game", value=gameName, inline=True)
- await ctx.send(embed=embed)
- else:
- embed=discord.Embed(title=gamer["gamertag"], description=state, timestamp=ctx.message.created_at)
- await ctx.send(embed=embed)
+ try:
+ game = json.loads(requests.get(f"https://xbl-api.prouser123.me/titleinfo/{gamer['lastSeen']['titleId']}").text)
+ gameName = game["titles"][0]["name"]
+ gamePic = game["titles"][0]["images"][4]["url"]
+ timestamp = dateutil.parser.isoparse(gamer["lastSeen"]["timestamp"])
+ lastSeen = True
+ except Exception as e:
+ print(e)
+ lastSeen = False
+
+ if lastSeen:
+ embed=discord.Embed(title=gamer["gamertag"], description=state, timestamp=timestamp)
+ embed.set_thumbnail(url=gamePic)
+ embed.add_field(name="Game", value=gameName, inline=True)
+ await ctx.send(embed=embed)
+ else:
+ embed=discord.Embed(title=gamer["gamertag"], description=state, timestamp=ctx.message.created_at)
+ await ctx.send(embed=embed)
@commands.command()
async def compile(self, ctx, language=None, *, code=None):
@@ -659,22 +659,23 @@ class General(commands.Cog):
"Content-Type":"application/json"
}
async with ctx.typing():
- r = requests.post("https://wandbox.org/api/compile.json", headers=head, data=json.dumps(body))
- try:
- response = json.loads(r.text)
- #await ctx.send(f"```json\n{json.dumps(response, indent=4)}```")
- print(f"```json\n{json.dumps(response, indent=4)}```")
- except json.decoder.JSONDecodeError:
- await ctx.send(f"```json\n{r.text}```")
-
- try:
- embed=discord.Embed(title="Compiled code")
- embed.add_field(name="Output", value=f'```{response["program_message"]}```', inline=False)
- embed.add_field(name="Exit code", value=response["status"], inline=True)
- embed.add_field(name="Link", value=f"[Permalink]({response['url']})", inline=True)
- await ctx.send(embed=embed)
- except KeyError:
- await ctx.send(f"```json\n{json.dumps(response, indent=4)}```")
+ async with self.bot.session.post("https://wandbox.org/api/compile.json", headers=head, data=json.dumps(body)) as r:
+ #r = requests.post("https://wandbox.org/api/compile.json", headers=head, data=json.dumps(body))
+ try:
+ response = json.loads(await r.text())
+ #await ctx.send(f"```json\n{json.dumps(response, indent=4)}```")
+ print(f"```json\n{json.dumps(response, indent=4)}```")
+ except json.decoder.JSONDecodeError:
+ await ctx.send(f"```json\n{r.text}```")
+
+ try:
+ embed=discord.Embed(title="Compiled code")
+ embed.add_field(name="Output", value=f'```{response["program_message"]}```', inline=False)
+ embed.add_field(name="Exit code", value=response["status"], inline=True)
+ embed.add_field(name="Link", value=f"[Permalink]({response['url']})", inline=True)
+ await ctx.send(embed=embed)
+ except KeyError:
+ await ctx.send(f"```json\n{json.dumps(response, indent=4)}```")
def setup(bot):
bot.add_cog(General(bot))
diff --git a/cogs/utils.py b/cogs/utils.py
index 752a7b7..da18fb3 100755
--- a/cogs/utils.py
+++ b/cogs/utils.py
@@ -1,9 +1,7 @@
from discord.ext import commands
from discord.ext import tasks
import discord
-import requests
import json
-import asyncio
import datetime
# forgot to import this and ended up looking mentally unstable
# troll literally pointed out atleast 4 things I did wrong in 3 lines of code
diff --git a/custom_commands.json b/custom_commands.json
index 884bbf4..a651cc8 100755
--- a/custom_commands.json
+++ b/custom_commands.json
@@ -37,5 +37,7 @@
"!source": "https://github.com/AnInternetTroll/mcbeDiscordBot",
"!sr.c": "https://www.speedrun.com/mcbe",
"!lbsite": "https://aninternettroll.github.io/mcbeVerifierLeaderboard/index.html",
- "!leaderboardsite": "https://aninternettroll.github.io/mcbeVerifierLeaderboard/index.html"
+ "!leaderboardsite": "https://aninternettroll.github.io/mcbeVerifierLeaderboard/index.html",
+ "!stop_crying": "Mods are human, we have lives. If your run isn't verified within 0.1 seconds of you submitting it then please don't Dm us asking us to verify your run. Speedrun.com gives you up to 3 weeks as an estimated time so if after 3 weeks have passed and your run hasn't been verified, then shoot one of us a Dm. If you constantly Dm us and hassle mods, you will get 3 warnings before you become muted and if you still continue, punishments will escalate like other breachments of the rules.",
+ "!staff": "https://media.discordapp.net/attachments/709672550707363931/721226547817873519/tenor.gif"
} \ No newline at end of file