From e139ad7106d87bec9a4704c1378ebd68da8579c6 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 16 Oct 2017 16:52:54 -0400 Subject: [PATCH] Added subject-to-change restart reaction to invocation ctx, info_channel --- src/main/cogs/owner.py | 13 +++++++++---- src/main/run.py | 14 ++++++++++---- src/main/utils/utils.py | 5 +++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/cogs/owner.py b/src/main/cogs/owner.py index 8fde2af..67eb692 100644 --- a/src/main/cogs/owner.py +++ b/src/main/cogs/owner.py @@ -29,8 +29,8 @@ class Bot: async def die(self, ctx): await ctx.message.add_reaction('🌙') - if isinstance(self.bot.get_channel(u.config['shutdown_channel']), d.TextChannel): - await self.bot.get_channel(u.config['shutdown_channel']).send('**Shutting down** 🌙 . . .') + if isinstance(self.bot.get_channel(u.config['info_channel']), d.TextChannel): + await self.bot.get_channel(u.config['info_channel']).send('**Shutting down** 🌙 . . .') # loop = self.bot.loop.all_tasks() # for task in loop: # task.cancel() @@ -46,8 +46,13 @@ class Bot: await ctx.message.add_reaction('💤') print('\n| | | | | | | | | |\nR E S T A R T I N G\n| | | | | | | | | |\n') - if isinstance(self.bot.get_channel(u.config['shutdown_channel']), d.TextChannel): - await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting** 💤 . . .') + if isinstance(self.bot.get_channel(u.config['info_channel']), d.TextChannel): + await self.bot.get_channel(u.config['info_channel']).send('**Restarting** 💤 . . .') + + u.temp['restart_ch'] = ctx.channel.id + u.temp['restart_msg'] = ctx.message.id + u.dump(u.temp, 'temp/temp.pkl') + # u.notify('R E S T A R T I N G') # loop = self.bot.loop.all_tasks() # for task in loop: diff --git a/src/main/run.py b/src/main/run.py index eff7bba..c052590 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -5,6 +5,7 @@ import logging import subprocess import sys import traceback as tb +from contextlib import suppress import discord as d from discord import utils @@ -39,16 +40,21 @@ async def on_ready(): 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** ☀️ .') + if isinstance(bot.get_channel(u.config['info_channel']), d.TextChannel): + await bot.get_channel(u.config['info_channel']).send('**Started** ☀️ .') print('\n\\ \\ \\ \\ \\ \\ \\ \\ \\\nC O N N E C T E D : {}\n/ / / / / / / / /\n'.format(bot.user.name)) # u.notify('C O N N E C T E D') + if u.temp: + channel = bot.get_channel(u.temp['restart_ch']) + message = await channel.get_message(u.temp['restart_msg']) + await message.add_reaction('✅') + u.temp.clear() @bot.event async def on_error(error, *args, **kwargs): - if isinstance(bot.get_channel(u.config['shutdown_channel']), d.TextChannel): - await bot.get_channel(u.config['shutdown_channel']).send('**ERROR** ⚠️ {}'.format(error)) + if isinstance(bot.get_channel(u.config['info_channel']), d.TextChannel): + await bot.get_channel(u.config['info_channel']).send('**ERROR** ⚠️ {}'.format(error)) await bot.logout() u.close(bot.loop) print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr) diff --git a/src/main/utils/utils.py b/src/main/utils/utils.py index 03bc1e4..b29c4fc 100644 --- a/src/main/utils/utils.py +++ b/src/main/utils/utils.py @@ -23,8 +23,8 @@ try: print('config.json loaded.') except FileNotFoundError: with open('config.json', 'w') as outfile: - 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) + jsn.dump({'client_id': 0, 'info_channel': 0, 'owner_id': 0, 'permissions': 126016, + 'playing': 'a game', 'prefix': ',', '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.') @@ -62,6 +62,7 @@ def dump(obj, filename, *, json=False): settings = setdefault('settings.pkl', {'del_ctx': []}) tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_rev': []}) +temp = setdefault('temp/temp.pkl', {}) session = aiohttp.ClientSession()