mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 21:02:38 +00:00
stdout and stderr output tweaks, ctx.* shortcut, WIP macOS notifier
This commit is contained in:
parent
42adc28e09
commit
00eec657da
5 changed files with 29 additions and 34 deletions
|
@ -14,7 +14,7 @@ class Info:
|
||||||
|
|
||||||
@commands.command(hidden=True)
|
@commands.command(hidden=True)
|
||||||
async def hi(ctx):
|
async def hi(ctx):
|
||||||
user = ctx.message.author
|
user = ctx.author
|
||||||
|
|
||||||
hello = 'Hewwo, {}.'.format(user.mention)
|
hello = 'Hewwo, {}.'.format(user.mention)
|
||||||
if user.id == checks.owner_id:
|
if user.id == checks.owner_id:
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Administration:
|
||||||
# pass
|
# pass
|
||||||
# @_all.group(name='user')
|
# @_all.group(name='user')
|
||||||
# async def __user(self, ctx, user: d.Member):
|
# async def __user(self, ctx, user: d.Member):
|
||||||
# channels = ctx.message.guild.text_channels
|
# channels = ctx.guild.text_channels
|
||||||
# bulk_history = {}
|
# bulk_history = {}
|
||||||
# bulk = {}
|
# bulk = {}
|
||||||
# history = []
|
# history = []
|
||||||
|
@ -58,7 +58,7 @@ class Administration:
|
||||||
# await channel.delete_messages(chunk)
|
# await channel.delete_messages(chunk)
|
||||||
# await del_sent.edit(content='🗑 **Deleted** `' + str(c) + '/' + str(sum([len(v) for v in bulk.values()])) + '` **messages.**')
|
# await del_sent.edit(content='🗑 **Deleted** `' + str(c) + '/' + str(sum([len(v) for v in bulk.values()])) + '` **messages.**')
|
||||||
# await asyncio.sleep(5)
|
# await asyncio.sleep(5)
|
||||||
# await ctx.send('✅ `' + str(sum([len(v) for v in bulk.values()])) + '` **of** <@' + uid + '>**\'s messages deleted from** ' + ctx.message.guild.name + '**.**')
|
# await ctx.send('✅ `' + str(sum([len(v) for v in bulk.values()])) + '` **of** <@' + uid + '>**\'s messages deleted from** ' + ctx.guild.name + '**.**')
|
||||||
# for channel in channels:
|
# for channel in channels:
|
||||||
# history.extend(await channel.history(limit=None, before=dt.datetime.utcnow() - dt.timedelta(days=14)).flatten())
|
# history.extend(await channel.history(limit=None, before=dt.datetime.utcnow() - dt.timedelta(days=14)).flatten())
|
||||||
# await ch_sent.edit(content='🗄 **Cached** `' + str(channels.index(channel) + 1) + '/' + str(len(channels)) + '` **channels.**')
|
# await ch_sent.edit(content='🗄 **Cached** `' + str(channels.index(channel) + 1) + '/' + str(len(channels)) + '` **channels.**')
|
||||||
|
@ -69,14 +69,14 @@ class Administration:
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def prune_all_user(self, ctx, uid, when=None, reference=None):
|
async def prune_all_user(self, ctx, uid, when=None, reference=None):
|
||||||
def yes(msg):
|
def yes(msg):
|
||||||
if msg.content.lower() == 'y' and msg.channel is ctx.message.channel and msg.author is ctx.message.author:
|
if msg.content.lower() == 'y' and msg.channel is ctx.channel and msg.author is ctx.author:
|
||||||
return True
|
return True
|
||||||
elif msg.content.lower() == 'n' and msg.channel is ctx.message.channel and msg.author is ctx.message.author:
|
elif msg.content.lower() == 'n' and msg.channel is ctx.channel and msg.author is ctx.author:
|
||||||
raise exc.CheckFail
|
raise exc.CheckFail
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
channels = ctx.message.guild.text_channels
|
channels = ctx.guild.text_channels
|
||||||
if reference is not None:
|
if reference is not None:
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
try:
|
try:
|
||||||
|
@ -123,7 +123,7 @@ class Administration:
|
||||||
# print('Deleted {}/{} messages.'.format(history.index(message) + 1, len(history)))
|
# print('Deleted {}/{} messages.'.format(history.index(message) + 1, len(history)))
|
||||||
await del_sent.edit(content='🗑 **Deleted** `{}/{}` **messages.**'.format(history.index(message) + 1, len(history)))
|
await del_sent.edit(content='🗑 **Deleted** `{}/{}` **messages.**'.format(history.index(message) + 1, len(history)))
|
||||||
await asyncio.sleep(self.RATE_LIMIT)
|
await asyncio.sleep(self.RATE_LIMIT)
|
||||||
await del_sent.edit(content='🗑 `{}` **of** <@{}>**\'s messages deleted from** {}**.**'.format(len(history), uid, ctx.message.guild.name))
|
await del_sent.edit(content='🗑 `{}` **of** <@{}>**\'s messages deleted from** {}**.**'.format(len(history), uid, ctx.guild.name))
|
||||||
except exc.CheckFail:
|
except exc.CheckFail:
|
||||||
await ctx.send('❌ **Deletion aborted.**', delete_after=10)
|
await ctx.send('❌ **Deletion aborted.**', delete_after=10)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
|
@ -164,7 +164,7 @@ class Administration:
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def auto_delete(self, ctx):
|
async def auto_delete(self, ctx):
|
||||||
channel = ctx.message.channel
|
channel = ctx.channel
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if channel.id not in u.tasks.setdefault('management', {}).setdefault('auto_delete', []):
|
if channel.id not in u.tasks.setdefault('management', {}).setdefault('auto_delete', []):
|
||||||
|
|
|
@ -32,26 +32,22 @@ class Bot:
|
||||||
# loop = self.bot.loop.all_tasks()
|
# loop = self.bot.loop.all_tasks()
|
||||||
# for task in loop:
|
# for task in loop:
|
||||||
# task.cancel()
|
# task.cancel()
|
||||||
if u.session:
|
|
||||||
await u.session.close()
|
|
||||||
await self.bot.logout()
|
await self.bot.logout()
|
||||||
await self.bot.close()
|
await self.bot.close()
|
||||||
print('- - - - - - -')
|
print('\n/ / / / / / / / / / / /\nD I S C O N N E C T E D\n\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\\n')
|
||||||
print('DISCONNECTED')
|
# u.notify('D I S C O N N E C T E D')
|
||||||
|
|
||||||
@commands.command(name=',restart', aliases=[',res', ',r'], hidden=True)
|
@commands.command(name=',restart', aliases=[',res', ',r'], hidden=True)
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def restart(self, ctx):
|
async def restart(self, ctx):
|
||||||
print('RESTARTING')
|
print('\n| | | | | | | | | |\nR E S T A R T I N G\n| | | | | | | | | |\n')
|
||||||
print('- - - - - - -')
|
|
||||||
if isinstance(self.bot.get_channel(u.config['startup_channel']), d.TextChannel):
|
if isinstance(self.bot.get_channel(u.config['startup_channel']), d.TextChannel):
|
||||||
await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting...** 💤')
|
await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting...** 💤')
|
||||||
|
# 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:
|
||||||
# task.cancel()
|
# task.cancel()
|
||||||
if u.session:
|
|
||||||
await u.session.close()
|
|
||||||
await self.bot.logout()
|
await self.bot.logout()
|
||||||
await self.bot.close()
|
await self.bot.close()
|
||||||
os.execl(sys.executable, 'python3', 'run.py')
|
os.execl(sys.executable, 'python3', 'run.py')
|
||||||
|
@ -109,9 +105,9 @@ class Tools:
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def console(self, ctx):
|
async def console(self, ctx):
|
||||||
def execute(msg):
|
def execute(msg):
|
||||||
if msg.content == 'exit' and msg.author is ctx.message.author:
|
if msg.content == 'exit' and msg.author is ctx.author:
|
||||||
raise exc.Abort
|
raise exc.Abort
|
||||||
elif msg.author is ctx.message.author and msg.channel is ctx.message.channel:
|
elif msg.author is ctx.author and msg.channel is ctx.channel:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -37,10 +37,10 @@ class Utils:
|
||||||
async def last_command(self, ctx):
|
async def last_command(self, ctx):
|
||||||
global command_dict
|
global command_dict
|
||||||
|
|
||||||
if command_dict.get(str(ctx.message.author.id), {}).get('args', None) is not None:
|
if command_dict.get(str(ctx.author.id), {}).get('args', None) is not None:
|
||||||
args = command_dict.get(str(ctx.message.author.id), {})['args']
|
args = command_dict.get(str(ctx.author.id), {})['args']
|
||||||
print(command_dict)
|
print(command_dict)
|
||||||
await ctx.invoke(command_dict.get(str(ctx.message.author.id), {}).get('command', None), args)
|
await ctx.invoke(command_dict.get(str(ctx.author.id), {}).get('command', None), args)
|
||||||
|
|
||||||
# [prefix]ping -> Pong!
|
# [prefix]ping -> Pong!
|
||||||
@commands.command(aliases=['p'], brief='Pong!', description='Returns latency from bot to Discord servers, not to user')
|
@commands.command(aliases=['p'], brief='Pong!', description='Returns latency from bot to Discord servers, not to user')
|
||||||
|
@ -48,8 +48,8 @@ class Utils:
|
||||||
async def ping(self, ctx):
|
async def ping(self, ctx):
|
||||||
global command_dict
|
global command_dict
|
||||||
|
|
||||||
await ctx.send(ctx.message.author.mention + ' 🏓 `' + str(round(self.bot.latency * 1000)) + 'ms`', delete_after=5)
|
await ctx.send(ctx.author.mention + ' 🏓 `' + str(round(self.bot.latency * 1000)) + 'ms`', delete_after=5)
|
||||||
command_dict.setdefault(str(ctx.message.author.id), {}).update({'command': ctx.command})
|
command_dict.setdefault(str(ctx.author.id), {}).update({'command': ctx.command})
|
||||||
|
|
||||||
@commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes')
|
@commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes')
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
|
|
|
@ -6,7 +6,6 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import traceback as tb
|
import traceback as tb
|
||||||
|
|
||||||
import aiohttp as aio
|
|
||||||
import discord as d
|
import discord as d
|
||||||
from discord import utils
|
from discord import utils
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
@ -32,33 +31,33 @@ async def on_ready():
|
||||||
bot.add_cog(info.Info(bot))
|
bot.add_cog(info.Info(bot))
|
||||||
bot.add_cog(booru.MsG(bot))
|
bot.add_cog(booru.MsG(bot))
|
||||||
|
|
||||||
u.session = aio.ClientSession(loop=bot.loop)
|
|
||||||
|
|
||||||
# bot.loop.create_task(u.clear(booru.temp_urls, 30*60))
|
# bot.loop.create_task(u.clear(booru.temp_urls, 30*60))
|
||||||
|
|
||||||
if isinstance(bot.get_channel(u.config['startup_channel']), d.TextChannel):
|
if isinstance(bot.get_channel(u.config['startup_channel']), d.TextChannel):
|
||||||
await bot.get_channel(u.config['startup_channel']).send('**Started.** ☀️')
|
await bot.get_channel(u.config['startup_channel']).send('**Started.** ☀️')
|
||||||
print('CONNECTED')
|
print('\n\\ \\ \\ \\ \\ \\ \\ \\ \\\nC O N N E C T E D : {}\n/ / / / / / / / /\n'.format(bot.user.name))
|
||||||
print(bot.user.name)
|
# u.notify('C O N N E C T E D')
|
||||||
print('- - - - - - -')
|
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_error(error):
|
async def on_error(error):
|
||||||
if u.session:
|
|
||||||
await u.session.close()
|
|
||||||
await bot.logout()
|
await bot.logout()
|
||||||
await bot.close()
|
await bot.close()
|
||||||
print('- - - - - - -')
|
print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr)
|
||||||
print('ERROR')
|
|
||||||
tb.print_exc()
|
tb.print_exc()
|
||||||
|
# u.notify('E R R O R')
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_command_error(ctx, error):
|
async def on_command_error(ctx, error):
|
||||||
if not isinstance(error, commands.errors.CommandNotFound):
|
if not isinstance(error, commands.errors.CommandNotFound):
|
||||||
|
print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format(
|
||||||
|
error), file=sys.stderr)
|
||||||
tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
|
tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
|
||||||
await ctx.send('{}\n```\n{}```'.format(exc.base, error))
|
await exc.send_error(ctx, error)
|
||||||
|
# u.notify('C O M M A N D E R R O R')
|
||||||
|
else:
|
||||||
|
print('INVALID COMMAND : {}'.format(error), file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
async def on_reaction_add(r, u):
|
async def on_reaction_add(r, u):
|
||||||
|
|
Loading…
Reference in a new issue