From e1a582be05a66a5d39bfcb32ea23fc9387c854ae Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 16 Oct 2017 14:06:31 -0400 Subject: [PATCH 1/3] Added json functionality to helper methods --- src/main/utils/utils.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/utils/utils.py b/src/main/utils/utils.py index cba8d02..03bc1e4 100644 --- a/src/main/utils/utils.py +++ b/src/main/utils/utils.py @@ -1,5 +1,5 @@ import asyncio -import json +import json as jsn import os import pickle as pkl import subprocess @@ -19,12 +19,12 @@ print('\nPID : {}\n'.format(os.getpid())) try: with open('config.json') as infile: - config = json.load(infile) + config = jsn.load(infile) print('config.json loaded.') except FileNotFoundError: with open('config.json', 'w') as outfile: - json.dump({'client_id': 0, 'listed_ids': [0], 'owner_id': 0, 'permissions': 126016, 'prefix': ',', - 'shutdown_channel': 0, 'startup_channel': 0, 'token': 'str'}, outfile, indent=4, sort_keys=True) + jsn.dump({'client_id': 0, 'owner_id': 0, 'permissions': 126016, 'playing': 'a game', 'prefix': ',', + 'shutdown_channel': 0, 'startup_channel': 0, 'token': 'str'}, outfile, indent=4, sort_keys=True) raise FileNotFoundError( 'Config file not found: config.json created with abstract values. Restart run.py with correct values.') @@ -42,14 +42,22 @@ def setdefault(filename, default=None): return pkl.load(iofile) -def load(filename): - with open(filename, 'rb') as infile: - return pkl.load(infile) +def load(filename, *, json=False): + if not json: + with open(filename, 'rb') as infile: + return pkl.load(infile) + else: + with open(filename) as infile: + return jsn.load(infile) -def dump(obj, filename): - with open(filename, 'wb') as outfile: - pkl.dump(obj, outfile) +def dump(obj, filename, *, json=False): + if not json: + with open(filename, 'wb') as outfile: + pkl.dump(obj, outfile) + else: + with open(filename, 'w') as outfile: + jsn.dump(obj, outfile, indent=4, sort_keys=True) settings = setdefault('settings.pkl', {'del_ctx': []}) From f610a341bef18fca671ab2932679780e48e3a036 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 16 Oct 2017 14:06:46 -0400 Subject: [PATCH 2/3] Removed listed_ids --- src/main/cogs/tools.py | 2 +- src/main/misc/checks.py | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/cogs/tools.py b/src/main/cogs/tools.py index b67b5d9..4d8f125 100644 --- a/src/main/cogs/tools.py +++ b/src/main/cogs/tools.py @@ -82,7 +82,7 @@ class Utils: print('Service built.') @commands.command(aliases=['up', 'u', 'vid', 'v']) - @checks.is_listed() + @commands.has_permissions(administrator=True) async def upload(self, ctx): global youtube attachments = ctx.message.attachments diff --git a/src/main/misc/checks.py b/src/main/misc/checks.py index 3ffcd07..47c1c6b 100644 --- a/src/main/misc/checks.py +++ b/src/main/misc/checks.py @@ -11,7 +11,6 @@ from discord.ext.commands import errors as errext from utils import utils as u owner_id = u.config['owner_id'] -listed_ids = u.config['listed_ids'] def is_owner(): @@ -32,12 +31,6 @@ def is_mod(): return commands.check(predicate) -def is_listed(): - def predicate(ctx): - return ctx.message.author.id in listed_ids - return commands.check(predicate) - - def owner(ctx): return ctx.message.author.id == owner_id From dabd472753ebd13de3b390c686d8f7c6e5c9e985 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 16 Oct 2017 14:07:10 -0400 Subject: [PATCH 3/3] Added config option "playing" --- src/main/cogs/booru.py | 6 ++---- src/main/cogs/owner.py | 21 ++++++++++++--------- src/main/run.py | 5 +++++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index d2394fb..3bbb532 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -437,8 +437,7 @@ class MsG: raise exc.GoTo elif reaction.emoji == '➡' and reaction.message.content == paginator.content and (user is ctx.author or user.id == u.config['owner_id']): raise exc.Right - else: - return False + return False def on_message(msg): with suppress(ValueError): @@ -611,8 +610,7 @@ class MsG: raise exc.GoTo elif reaction.emoji == '➡' and reaction.message.content == paginator.content and (user is ctx.author or user.id == u.config['owner_id']): raise exc.Right - else: - return False + return False def on_message(msg): with suppress(ValueError): diff --git a/src/main/cogs/owner.py b/src/main/cogs/owner.py index a23bdac..934514f 100644 --- a/src/main/cogs/owner.py +++ b/src/main/cogs/owner.py @@ -59,17 +59,20 @@ class Bot: async def invite(self, ctx): await ctx.send('🔗 https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}'.format(u.config['client_id'], u.config['permissions']), delete_after=10) - @commands.command(aliases=['presence', 'game'], hidden=True) + @commands.command(name=',status', aliases=[',presence', ',game'], hidden=True) @commands.is_owner() @checks.del_ctx() - async def status(self, ctx, game): - try: - if game is not None: - await self.bot.change_presence(game=d.Game(name=game)) - else: - raise exc.NotFound - except exc.NotFound: - await ctx.send('❌ **No game given.**', delete_after=10) + async def status(self, ctx, *, game=None): + if game is not None: + await self.bot.change_presence(game=d.Game(name=game)) + u.config['playing'] = game + u.dump(u.config, 'config.json', json=True) + else: + await self.bot.change_presence(game=None) + u.config['playing'] = 'None' + u.dump(u.config, 'config.json', json=True) + + await ctx.message.add_reaction('✅') class Tools: diff --git a/src/main/run.py b/src/main/run.py index fdb15e9..eff7bba 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -34,6 +34,11 @@ async def on_ready(): # bot.loop.create_task(u.clear(booru.temp_urls, 30*60)) + if u.config['playing'] is not 'None': + await bot.change_presence(game=d.Game(name=u.config['playing'])) + else: + await bot.change_presence(game=None) + if isinstance(bot.get_channel(u.config['startup_channel']), d.TextChannel): await bot.get_channel(u.config['startup_channel']).send('**Started** ☀️ .') print('\n\\ \\ \\ \\ \\ \\ \\ \\ \\\nC O N N E C T E D : {}\n/ / / / / / / / /\n'.format(bot.user.name))