1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-11-01 21:02:38 +00:00

Added subject-to-change restart reaction to invocation ctx, info_channel

This commit is contained in:
Myned 2017-10-16 16:52:54 -04:00
parent ab67ebc0c4
commit e139ad7106
3 changed files with 22 additions and 10 deletions

View file

@ -29,8 +29,8 @@ class Bot:
async def die(self, ctx): async def die(self, ctx):
await ctx.message.add_reaction('🌙') await ctx.message.add_reaction('🌙')
if isinstance(self.bot.get_channel(u.config['shutdown_channel']), d.TextChannel): if isinstance(self.bot.get_channel(u.config['info_channel']), d.TextChannel):
await self.bot.get_channel(u.config['shutdown_channel']).send('**Shutting down** 🌙 . . .') await self.bot.get_channel(u.config['info_channel']).send('**Shutting down** 🌙 . . .')
# loop = self.bot.loop.all_tasks() # loop = self.bot.loop.all_tasks()
# for task in loop: # for task in loop:
# task.cancel() # task.cancel()
@ -46,8 +46,13 @@ class Bot:
await ctx.message.add_reaction('💤') await ctx.message.add_reaction('💤')
print('\n| | | | | | | | | |\nR E S T A R T I N G\n| | | | | | | | | |\n') 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): if isinstance(self.bot.get_channel(u.config['info_channel']), d.TextChannel):
await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting** 💤 . . .') 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') # u.notify('R E S T A R T I N G')
# loop = self.bot.loop.all_tasks() # loop = self.bot.loop.all_tasks()
# for task in loop: # for task in loop:

View file

@ -5,6 +5,7 @@ import logging
import subprocess import subprocess
import sys import sys
import traceback as tb import traceback as tb
from contextlib import suppress
import discord as d import discord as d
from discord import utils from discord import utils
@ -39,16 +40,21 @@ async def on_ready():
else: else:
await bot.change_presence(game=None) await bot.change_presence(game=None)
if isinstance(bot.get_channel(u.config['startup_channel']), d.TextChannel): if isinstance(bot.get_channel(u.config['info_channel']), d.TextChannel):
await bot.get_channel(u.config['startup_channel']).send('**Started** ☀️ .') 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)) 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') # 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 @bot.event
async def on_error(error, *args, **kwargs): async def on_error(error, *args, **kwargs):
if isinstance(bot.get_channel(u.config['shutdown_channel']), d.TextChannel): if isinstance(bot.get_channel(u.config['info_channel']), d.TextChannel):
await bot.get_channel(u.config['shutdown_channel']).send('**ERROR** ⚠️ {}'.format(error)) await bot.get_channel(u.config['info_channel']).send('**ERROR** ⚠️ {}'.format(error))
await bot.logout() await bot.logout()
u.close(bot.loop) u.close(bot.loop)
print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr) print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr)

View file

@ -23,8 +23,8 @@ try:
print('config.json loaded.') print('config.json loaded.')
except FileNotFoundError: except FileNotFoundError:
with open('config.json', 'w') as outfile: with open('config.json', 'w') as outfile:
jsn.dump({'client_id': 0, 'owner_id': 0, 'permissions': 126016, 'playing': 'a game', 'prefix': ',', jsn.dump({'client_id': 0, 'info_channel': 0, 'owner_id': 0, 'permissions': 126016,
'shutdown_channel': 0, 'startup_channel': 0, 'token': 'str'}, outfile, indent=4, sort_keys=True) 'playing': 'a game', 'prefix': ',', 'token': 'str'}, outfile, indent=4, sort_keys=True)
raise FileNotFoundError( raise FileNotFoundError(
'Config file not found: config.json created with abstract values. Restart run.py with correct values.') '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': []}) settings = setdefault('settings.pkl', {'del_ctx': []})
tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_rev': []}) tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_rev': []})
temp = setdefault('temp/temp.pkl', {})
session = aiohttp.ClientSession() session = aiohttp.ClientSession()