aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnInternetTroll <lucafulger@gmail.com>2021-02-24 22:08:47 +0000
committerAnInternetTroll <lucafulger@gmail.com>2021-02-24 22:08:47 +0000
commit46227e1fa61c0864a729396665a6fbcc0a42e446 (patch)
treedea1919e536e38ac5dab15dbc12c21a3c9a4270c
parenta80f7aad3bfb03fc82d2fb594a4ec9210c2e7213 (diff)
downloadsteve-bot-46227e1fa61c0864a729396665a6fbcc0a42e446.tar
steve-bot-46227e1fa61c0864a729396665a6fbcc0a42e446.tar.gz
steve-bot-46227e1fa61c0864a729396665a6fbcc0a42e446.tar.bz2
steve-bot-46227e1fa61c0864a729396665a6fbcc0a42e446.tar.lz
steve-bot-46227e1fa61c0864a729396665a6fbcc0a42e446.tar.xz
steve-bot-46227e1fa61c0864a729396665a6fbcc0a42e446.tar.zst
steve-bot-46227e1fa61c0864a729396665a6fbcc0a42e446.zip
Make !verified asynchronous
-rwxr-xr-xcogs/src.py70
-rwxr-xr-xcogs/utils.py4
2 files changed, 36 insertions, 38 deletions
diff --git a/cogs/src.py b/cogs/src.py
index 72ec722..b96d36a 100755
--- a/cogs/src.py
+++ b/cogs/src.py
@@ -331,44 +331,44 @@ async def verifyNew(self, apiKey=None, userID=None):
else:
await member.remove_roles(RunneRole)
+
async def verifiedCount(self, ctx, modName):
- head = {
- "Accept": "application/json",
- "User-Agent": "mcbeDiscordBot/1.0"
- }
-
- r = requests.get(
- f"https://www.speedrun.com/api/v1/users/{modName}",
- headers=head
- )
- if r.status_code != 200:
- await ctx.send(f"Could not find user {modName}")
- return
- try:
- modID = r.json()['data']['id']
- except:
- await ctx.send("Something went wrong")
- return
-
- hold = []
- temp = requests.get(
- f"https://www.speedrun.com/api/v1/runs?examiner={modID}&max=200",
- headers=head)
- while True:
- if temp.status_code != 200:
+ head = {"Accept": "application/json", "User-Agent": "mcbeDiscordBot/1.0"}
+ async with self.bot.session.get(
+ f"https://www.speedrun.com/api/v1/users/{modName}", headers=head
+ ) as r:
+ if r.status != 200:
+ await ctx.send(f"Could not find user {modName}")
+ return
+ try:
+ modID = await r.json()
+ modID = modID["data"]["id"]
+ except:
await ctx.send("Something went wrong")
return
- temp_json = temp.json()
- hold.extend(temp_json['data'])
- if 'pagination' not in temp_json or temp_json['pagination']['size'] < 200:
- break
- temp = requests.get(
- {item['rel']: item['uri']
- for item in temp_json['pagination']['links']}['next'],
- headers=head)
-
+
+ hold = []
+ async with self.bot.session.get(
+ f"https://www.speedrun.com/api/v1/runs?examiner={modID}&max=200", headers=head
+ ) as temp:
+ while True:
+ if temp.status != 200:
+ await ctx.send("Something went wrong")
+ return
+ temp_json = await temp.json()
+ hold.extend(temp_json["data"])
+ if "pagination" not in temp_json or temp_json["pagination"]["size"] < 200:
+ break
+ temp = await self.bot.session.get(
+ {item["rel"]: item["uri"] for item in temp_json["pagination"]["links"]}[
+ "next"
+ ],
+ headers=head,
+ )
+
await ctx.send(f"{modName} has verified {len(hold)} runs")
+
class Src(commands.Cog):
def __init__(self, bot):
self.bot = bot
@@ -444,8 +444,8 @@ class Src(commands.Cog):
if modName is None:
await ctx.send("Please supply a moderator to view stats of")
return
- await verifiedCount(self, ctx, modName)
-
+ await verifiedCount(self, ctx, modName)
+
@tasks.loop(minutes=10.0)
async def checker(self):
data = json.loads(Path("./api_keys.json").read_text())
diff --git a/cogs/utils.py b/cogs/utils.py
index b4f819f..1ff6820 100755
--- a/cogs/utils.py
+++ b/cogs/utils.py
@@ -398,9 +398,7 @@ class Utils(commands.Cog):
.decode("utf-8")
)
if "women" in text.lower() or "woman" in text.lower():
- await message.channel.send(
- "<:shut:808844274933694474>"
- )
+ await message.channel.send("<:shut:808844274933694474>")
for word in badWords:
if word in message.content.lower().replace(" ", ""):