aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbot.py25
-rwxr-xr-xcogs/admin.py24
-rwxr-xr-xcogs/src.py8
-rwxr-xr-xmain.py80
4 files changed, 74 insertions, 63 deletions
diff --git a/bot.py b/bot.py
index 9e4f78c..3b46971 100755
--- a/bot.py
+++ b/bot.py
@@ -7,15 +7,8 @@ import datetime
import json
extensions = [
- "cogs.utils",
- "cogs.admin",
- "cogs.src",
- "cogs.trans",
- "cogs.player",
- "cogs.general",
- "cogs.webserver",
- "cogs.logs",
- "cogs.twitter"
+ "cogs.utils", "cogs.admin", "cogs.src", "cogs.trans", "cogs.player",
+ "cogs.general", "cogs.webserver", "cogs.logs", "cogs.twitter"
]
@@ -32,10 +25,13 @@ def get_prefix(bot, message):
# If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list.
return commands.when_mentioned_or(*prefixes)(bot, message)
-class BedrockBot(commands.Bot):
+class BedrockBot(commands.Bot):
def __init__(self):
- super().__init__(command_prefix=get_prefix, case_insensitive=True, allowed_mentions=discord.AllowedMentions(everyone=False, users=True, roles=False))
+ super().__init__(command_prefix=get_prefix,
+ case_insensitive=True,
+ allowed_mentions=discord.AllowedMentions(
+ everyone=False, users=True, roles=False))
self.logger = logging.getLogger('discord')
self.messageBlacklist = []
self.session = aiohttp.ClientSession()
@@ -47,7 +43,6 @@ class BedrockBot(commands.Bot):
self.config = json.load(f)
config = self.config
-
async def on_ready(self):
self.uptime = datetime.datetime.utcnow()
@@ -60,11 +55,11 @@ class BedrockBot(commands.Bot):
except json.decoder.JSONDecodeError:
self.blacklist = []
- with open('video_blacklist.json', 'r') as f:
+ with open('runs_blacklist.json', 'r') as f:
try:
- self.video_blacklist = json.load(f)
+ self.runs_blacklist = json.load(f)
except json.decoder.JSONDecodeError:
- self.video_blacklist = []
+ self.runs_blacklist = {"videos": [], "players": []}
for extension in extensions:
self.load_extension(extension)
diff --git a/cogs/admin.py b/cogs/admin.py
index e1ed9bf..9b35be0 100755
--- a/cogs/admin.py
+++ b/cogs/admin.py
@@ -241,19 +241,33 @@ class Admin(commands.Cog):
@commands.check(is_mod)
async def blacklistvideo(self, ctx, uri):
"""Set runs from a specific url to be auto rejected"""
- with open('video_blacklist.json', 'w') as f:
- self.bot.video_blacklist.append(uri)
+ with open('runs_blacklist.json', 'w') as f:
+ self.bot.video_blacklist["videos"].append(uri)
json.dump(self.bot.video_blacklist, f, indent=4)
await ctx.send(f'Blacklisted runs from `{uri}`')
@commands.command()
@commands.check(is_mod)
- async def video_blacklist(self, ctx):
- """Sends a list of blacklisted uris"""
+ async def blacklistplayer(self, ctx, player):
+ """Set runs from a specific player to be auto rejected"""
+ with open('runs_blacklist.json', 'w') as f:
+ self.bot.video_blacklist["players"].append(uri)
+ json.dump(self.bot.video_blacklist, f, indent=4)
+ await ctx.send(f'Blacklisted runs from `{player}`')
+
+ @commands.command()
+ @commands.check(is_mod)
+ async def runs_blacklist(self, ctx):
+ """Sends a list of blacklisted videos and players"""
message = '```The following URIs are blacklisted:\n'
- for uri in self.bot.video_blacklist:
+ for uri in self.bot.runs_blacklist["videos"]:
message += f'{uri}, '
await ctx.send(f'{message[:-2]}```')
+ message = '```The following players are blacklisted:\n'
+ for player in self.bot.runs_blacklist["players"]:
+ message += f'{player}, '
+ await ctx.send(f'{message[:-2]}```')
+
def setup(bot):
bot.add_cog(Admin(bot))
diff --git a/cogs/src.py b/cogs/src.py
index 8afe1b5..58e72af 100755
--- a/cogs/src.py
+++ b/cogs/src.py
@@ -22,7 +22,7 @@ async def rejectRun(self, apiKey, ctx, run, reason):
},
data=json.dumps(reject))
if r.status_code == 200 or r.status_code == 204:
- await ctx.send("Run rejected succesfully")
+ await ctx.send(f'Run rejected succesfully for {reason}')
else:
await ctx.send("Something went wrong")
await ctx.message.author.send(
@@ -102,12 +102,14 @@ async def pendingRuns(self, ctx):
if key == 'category' and not level:
categoryName = value["data"]["name"]
if key == 'videos':
- if value['links'][0]['uri'] in self.bot.video_blacklist:
+ if value['links'][0]['uri'] in self.bot.runs_blacklist["videos"]:
await rejectRun(
self, self.bot.config['api_key'], ctx, run_id,
'Detected as spam by our automatic filter')
if key == 'players':
- if value["data"][0]['rel'] == 'guest':
+ if value["data"[0]["names"]["international"] in self.bot.runs_blacklist["players"]:
+ await rejectRun(self, self.bot.config['api_key'], ctx, run_id, 'Banned player. https://www.speedrun.com/mcbe/thread/5cuo8/1#d2m6x')
+ elif value["data"][0]['rel'] == 'guest':
player = value["data"][0]['name']
else:
player = value["data"][0]["names"]["international"]
diff --git a/main.py b/main.py
index 3bf6112..1db2821 100755
--- a/main.py
+++ b/main.py
@@ -8,60 +8,60 @@ from bot import BedrockBot
def check_jsons():
- try:
- f = open('config.json', 'r')
- except FileNotFoundError:
- token = input('BOT SETUP - Enter bot token: ')
- with open('config.json', 'w+') as f:
- json.dump({"token": token}, f, indent=4)
-
- try:
- f = open('blacklist.json', 'r')
- except FileNotFoundError:
- with open('blacklist.json', 'w+') as f:
- json.dump([], f, indent=4)
-
- try:
- f = open('video_blacklist.json', 'r')
- except FileNotFoundError:
- with open('video_blacklist.json', 'w+') as f:
- json.dump([], f, indent=4)
+ try:
+ f = open('config.json', 'r')
+ except FileNotFoundError:
+ token = input('BOT SETUP - Enter bot token: ')
+ with open('config.json', 'w+') as f:
+ json.dump({"token": token}, f, indent=4)
+
+ try:
+ f = open('blacklist.json', 'r')
+ except FileNotFoundError:
+ with open('blacklist.json', 'w+') as f:
+ json.dump([], f, indent=4)
+
+ try:
+ f = open('runs_blacklist.json', 'r')
+ except FileNotFoundError:
+ with open('runs_blacklist.json', 'w+') as f:
+ json.dump({"videos": [], "players": []}, f, indent=4)
def setup_logging():
- FORMAT = '%(asctime)s - [%(levelname)s]: %(message)s'
- DATE_FORMAT = '%d/%m/%Y (%H:%M:%S)'
+ FORMAT = '%(asctime)s - [%(levelname)s]: %(message)s'
+ DATE_FORMAT = '%d/%m/%Y (%H:%M:%S)'
- logger = logging.getLogger('discord')
- logger.setLevel(logging.INFO)
+ logger = logging.getLogger('discord')
+ logger.setLevel(logging.INFO)
- file_handler = logging.FileHandler(filename='discord.log',
- mode='a',
- encoding='utf-8')
- file_handler.setFormatter(
- logging.Formatter(fmt=FORMAT, datefmt=DATE_FORMAT))
- file_handler.setLevel(logging.INFO)
- logger.addHandler(file_handler)
+ file_handler = logging.FileHandler(filename='discord.log',
+ mode='a',
+ encoding='utf-8')
+ file_handler.setFormatter(
+ logging.Formatter(fmt=FORMAT, datefmt=DATE_FORMAT))
+ file_handler.setLevel(logging.INFO)
+ logger.addHandler(file_handler)
- console_handler = logging.StreamHandler()
- console_handler.setFormatter(
- logging.Formatter(fmt=FORMAT, datefmt=DATE_FORMAT))
- console_handler.setLevel(logging.WARNING)
- logger.addHandler(console_handler)
+ console_handler = logging.StreamHandler()
+ console_handler.setFormatter(
+ logging.Formatter(fmt=FORMAT, datefmt=DATE_FORMAT))
+ console_handler.setLevel(logging.WARNING)
+ logger.addHandler(console_handler)
def run_bot():
- bot = BedrockBot()
- bot.run()
+ bot = BedrockBot()
+ bot.run()
if __name__ == "__main__":
- init_colorama(autoreset=True)
+ init_colorama(autoreset=True)
- setup_logging()
+ setup_logging()
- check_jsons()
+ check_jsons()
- run_bot()
+ run_bot()