aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnInternetTroll <lucafulger@gmail.com>2020-05-30 16:19:56 +0000
committerAnInternetTroll <lucafulger@gmail.com>2020-05-30 16:19:56 +0000
commit6606b4df2a7872e71d2bac8cdec4f28049814557 (patch)
tree3942e8f6a1b5d2501c102c2b39613abba59fb4b4
parent74767a86e68b98cfeced0e89e4eaf4943202d9b6 (diff)
downloadsteve-bot-6606b4df2a7872e71d2bac8cdec4f28049814557.tar
steve-bot-6606b4df2a7872e71d2bac8cdec4f28049814557.tar.gz
steve-bot-6606b4df2a7872e71d2bac8cdec4f28049814557.tar.bz2
steve-bot-6606b4df2a7872e71d2bac8cdec4f28049814557.tar.lz
steve-bot-6606b4df2a7872e71d2bac8cdec4f28049814557.tar.xz
steve-bot-6606b4df2a7872e71d2bac8cdec4f28049814557.tar.zst
steve-bot-6606b4df2a7872e71d2bac8cdec4f28049814557.zip
Better verify command
Diffstat (limited to '')
-rw-r--r--[-rwxr-xr-x].gitignore0
-rw-r--r--[-rwxr-xr-x].vscode/settings.json0
-rw-r--r--[-rwxr-xr-x]bot.py5
-rw-r--r--[-rwxr-xr-x]cogs/admin.py12
-rw-r--r--[-rwxr-xr-x]cogs/help.py0
-rw-r--r--[-rwxr-xr-x]cogs/src.py164
-rw-r--r--[-rwxr-xr-x]cogs/trans.py0
-rw-r--r--[-rwxr-xr-x]cogs/utils.py0
-rw-r--r--[-rwxr-xr-x]custom_commands.json0
-rw-r--r--[-rwxr-xr-x]main.py0
10 files changed, 88 insertions, 93 deletions
diff --git a/.gitignore b/.gitignore
index 28f7323..28f7323 100755..100644
--- a/.gitignore
+++ b/.gitignore
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 478c149..478c149 100755..100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
diff --git a/bot.py b/bot.py
index 432352b..fe635ff 100755..100644
--- a/bot.py
+++ b/bot.py
@@ -10,12 +10,13 @@ extensions = [
"cogs.utils",
"cogs.admin",
"cogs.src",
- "cogs.help"
+ "cogs.help",
+ "cogs.trans"
]
def get_prefix(bot, message):
"""A callable Prefix for our bot. This could be edited to allow per server prefixes."""
- prefixes = ['/', '!', 'steve ', 'Steve ', 'STEVE ']
+ prefixes = ['/', '!', 'steve ', 'Steve ', 'STEVE ', '@']
# Check to see if we are outside of a guild. e.g DM's etc.
#if not message.guild:
diff --git a/cogs/admin.py b/cogs/admin.py
index d8de2ad..8f100c1 100755..100644
--- a/cogs/admin.py
+++ b/cogs/admin.py
@@ -85,5 +85,17 @@ class Admin(commands.Cog):
await ctx.send(f'Some unknown error happened while trying to reload extension {ext} (check logs)')
self.bot.logger.exception(f'Failed to reload extension {ext}:')
+ @commands.command()
+ @commands.check(is_mod)
+ async def connect(self, ctx):
+ await ctx.author.voice.channel.connect()
+ await ctx.send(f"Joined channel {ctx.author.voice.channel.name}")
+
+ @commands.command()
+ @commands.check(is_mod)
+ async def disconnect(self, ctx):
+ await ctx.voice_client.disconnect()
+ await ctx.send(f"Left channel {ctx.author.voice.channel.name}")
+
def setup(bot):
bot.add_cog(Admin(bot))
diff --git a/cogs/help.py b/cogs/help.py
index ac330f1..ac330f1 100755..100644
--- a/cogs/help.py
+++ b/cogs/help.py
diff --git a/cogs/src.py b/cogs/src.py
index 422e20c..c83afbc 100755..100644
--- a/cogs/src.py
+++ b/cogs/src.py
@@ -7,6 +7,7 @@ import requests
import json
import asyncio
import dateutil.parser
+from pathlib import Path
async def rejectRun(self, apiKey, ctx, run, reason):
await ctx.message.delete()
@@ -62,87 +63,6 @@ async def deleteRun(self, apiKey, ctx, run):
await ctx.send("Something went wrong")
await ctx.message.author.send(f"```json\n{json.dumps(json.loads(r.text),indent=4)}```")
-
-@tasks.loop(minutes=2.0)
-async def checkForWR(self):
- with open('api_keys.json', 'r+') as file:
- api_keys = json.load(file)
-
- for runner in api_keys:
- verifyRole(api_keys[runner], False)
-
-
-def verifyRole(apiKey, isNewbie):
- head = {
- "X-API-Key": apiKey,
- "Accept": "application/json",
- "User-Agent": "mcbeDiscordBot/1.0"
- }
- r = requests.get(
- 'https://www.speedrun.com/api/v1/profile', headers=head)
-
- # print(r.text)
- try:
- profile = json.loads(r.text)
- except json.decoder.JSONDecodeError:
- return
- pbs = requests.get(profile["data"]["links"][3]["uri"])
- pbs = json.loads(pbs.text)
-
- if isNewbie == True:
- with open('api_keys.json', 'r') as file:
- api_keys = json.load(file)
-
- api_keys[profile["data"]["names"]["international"]] = apiKey
-
- with open('api_keys.json', 'w') as file:
- json.dump(api_keys, file, indent=4)
-
- print(r.status_code)
-
- for i in pbs["data"]:
- if i["place"] == 1:
- if i["run"]["game"] == "yd4ovvg1" or i["run"]["game"] == "v1po7r76":
- if not i["run"]["level"]:
- return True
- if i["run"]["game"] == "yd4ovvg1" or i["run"]["game"] == "v1po7r76":
- # I have no shame
- return 'No but plays the game'
-
-
-async def verifyRoleCommand(self, ctx, apiKey):
- with open('api_keys.json', 'r+') as file:
- api_keys = json.load(file)
- alreadyHasRole = False
- for runner in api_keys:
- if api_keys[runner] == apiKey:
- alreadyHasRole = True
-
- if alreadyHasRole == True:
- # Kindness is a gift and they show no respect to steve bot!
- ctx.send("You already have a role dumbass")
- else:
- server = self.bot.get_guild(574267523869179904)
- # Troll is mentally challenged I guess ¯\_(ツ)_/¯
- RunneRole = server.get_role(574268937454223361)
- WrRole = server.get_role(583622436378116107)
-
- hasRecord = verifyRole(apiKey, True)
-
- if hasRecord == True:
- await ctx.send("WR boi")
- await server.get_member(ctx.message.author.id).add_roles(WrRole)
- print("WR boi")
- elif hasRecord == 'No but plays the game':
- # Yeah idk how useful these comments are but idc
- # print(i)
- await ctx.send("Runner")
- await server.get_member(ctx.message.author.id).add_roles(RunneRole)
- # print("minecraft")
-
- #print(json.dumps(pbs,sort_keys=True, indent=4))
-
-
async def clear(self):
async for msg in self.bot.get_channel(699713639866957905).history():
await msg.delete()
@@ -210,10 +130,64 @@ async def pendingRuns(self, ctx):
embed_stats = discord.Embed(title='Pending Run Stats', description=f"Full Game Runs: {mcbe_runs}\nIndividual Level Runs: {mcbeil_runs}\nCategory Extension Runs: {mcbece_runs}", color=16711680 + i * 60)
await self.bot.get_channel(699713639866957905).send(embed=embed_stats)
+
+async def verifyNew(self, apiKey=None, userID=None):
+ if apiKey==None:
+ head = {
+ "Accept": "application/json",
+ "User-Agent": "mcbeDiscordBot/1.0"
+ }
+ else:
+ head = {
+ "X-API-Key": apiKey,
+ "Accept": "application/json",
+ "User-Agent": "mcbeDiscordBot/1.0"
+ }
+ server = self.bot.get_guild(574267523869179904)
+ # Troll is mentally challenged I guess ¯\_(ツ)_/¯
+ RunneRole = server.get_role(574268937454223361)
+ WrRole = server.get_role(583622436378116107)
+ #if userID == None:
+ # return
+ #else:
+ user = self.bot.get_user(int(userID))
+ data = json.loads(Path('./api_keys.json').read_text())
+
+ if str(user.id) in data:
+ pbs = requests.get(f"https://www.speedrun.com/api/v1/users/{data[str(user.id)]}/personal-bests", headers=head)
+ pbs = json.loads(pbs.text)
+ else:
+ r = requests.get(
+ 'https://www.speedrun.com/api/v1/profile', headers=head)
+ # print(r.text)
+ if r.status_code >= 400:
+ await user.send(f"```json\n{r.text}```")
+ return
+ try:
+ profile = json.loads(r.text)
+ except json.decoder.JSONDecodeError:
+ return
+ srcUserID = profile["data"]["id"]
+ with open('api_keys.json', 'w') as file:
+ data[user.id] = srcUserID
+ json.dump(data, file, indent=4)
+ pbs = requests.get(profile["data"]["links"][3]["uri"], headers=head)
+ pbs = json.loads(pbs.text)
+
+ for i in pbs["data"]:
+ if i["place"] == 1:
+ if i["run"]["game"] == "yd4ovvg1" or i["run"]["game"] == "v1po7r76":
+ if not i["run"]["level"]:
+ await server.get_member(user.id).add_roles(WrRole)
+ if i["run"]["game"] == "yd4ovvg1" or i["run"]["game"] == "v1po7r76":
+ # I have no shame
+ await server.get_member(user.id).add_roles(RunneRole)
+
class Src(commands.Cog):
def __init__(self, bot):
self.bot = bot
+ self.checker.start()
async def is_mod(ctx):
return ctx.author.guild_permissions.manage_channels
@@ -225,16 +199,6 @@ class Src(commands.Cog):
await clear(self)
await pendingRuns(self, ctx)
- @commands.command()
- async def verify(self, ctx, apiKey=None):
- if apiKey == None:
- await ctx.send(f"Please try again this command by getting an apiKey from https://www.speedrun.com/api/auth then do `{ctx.prefix}verify <apiKey>` in my DMs or anywhere in this server. \nBe careful who you share this key with. To learn more check out https://github.com/speedruncomorg/api/blob/master/authentication.md")
- return
- elif ctx.guild != None:
- await ctx.message.delete()
- async with ctx.typing():
- await verifyRoleCommand(self, ctx, apiKey)
-
@commands.command(description="Reject runs quickly")
@commands.check(is_mod)
@commands.guild_only()
@@ -253,6 +217,24 @@ class Src(commands.Cog):
async def delete(self, ctx, apiKey, run):
await deleteRun(self, apiKey, ctx, run)
+ @commands.command()
+ async def verify(self, ctx, apiKey=None, userID=None):
+ #if apiKey == None:
+ # await ctx.send(f"Please try again this command by getting an apiKey from https://www.speedrun.com/api/auth then do `{ctx.prefix}verify <apiKey>` in my DMs or anywhere in this server. \nBe careful who you share this key with. To learn more check out https://github.com/speedruncomorg/api/blob/master/authentication.md")
+ # return
+ if ctx.guild != None:
+ await ctx.message.delete()
+ async with ctx.typing():
+ if userID == None:
+ userID = ctx.message.author.id
+ await verifyNew(self, apiKey, userID)
+
+ @tasks.loop(minutes=2.0)
+ async def checker(self):
+ data = json.loads(Path('./api_keys.json').read_text())
+ for key,value in data.items():
+ await verifyNew(self, None, key)
+
def setup(bot):
bot.add_cog(Src(bot))
diff --git a/cogs/trans.py b/cogs/trans.py
index a34a7bf..a34a7bf 100755..100644
--- a/cogs/trans.py
+++ b/cogs/trans.py
diff --git a/cogs/utils.py b/cogs/utils.py
index f1cfeba..f1cfeba 100755..100644
--- a/cogs/utils.py
+++ b/cogs/utils.py
diff --git a/custom_commands.json b/custom_commands.json
index 6558699..6558699 100755..100644
--- a/custom_commands.json
+++ b/custom_commands.json
diff --git a/main.py b/main.py
index 9f713bf..9f713bf 100755..100644
--- a/main.py
+++ b/main.py