2017-09-24 18:09:02 +00:00
|
|
|
import asyncio
|
2017-10-11 06:57:17 +00:00
|
|
|
import datetime as dt
|
2017-10-13 02:28:16 +00:00
|
|
|
import json
|
2017-10-17 21:59:58 +00:00
|
|
|
# import logging as log
|
2017-10-02 21:29:39 +00:00
|
|
|
import subprocess
|
2017-10-11 06:57:17 +00:00
|
|
|
import sys
|
2017-10-13 02:28:16 +00:00
|
|
|
import traceback as tb
|
2017-10-16 20:52:54 +00:00
|
|
|
from contextlib import suppress
|
2017-10-13 02:28:16 +00:00
|
|
|
|
|
|
|
import discord as d
|
2017-09-24 18:09:02 +00:00
|
|
|
from discord import utils
|
|
|
|
from discord.ext import commands
|
2017-10-15 03:41:42 +00:00
|
|
|
from discord.ext.commands import errors as errext
|
2017-10-13 02:28:16 +00:00
|
|
|
|
2017-09-24 18:09:02 +00:00
|
|
|
from misc import exceptions as exc
|
2017-10-13 02:28:16 +00:00
|
|
|
from misc import checks
|
2017-10-11 06:57:17 +00:00
|
|
|
from utils import utils as u
|
2017-09-24 18:09:02 +00:00
|
|
|
|
2017-10-17 21:59:58 +00:00
|
|
|
# log.basicConfig(level=log.INFO)
|
2017-10-11 06:57:17 +00:00
|
|
|
|
2017-10-14 03:38:58 +00:00
|
|
|
bot = commands.Bot(command_prefix=u.config['prefix'], description='Experimental booru bot')
|
2017-10-13 02:28:16 +00:00
|
|
|
|
|
|
|
|
2017-10-14 03:38:58 +00:00
|
|
|
# Send and print ready message to #testing and console after logon
|
2017-09-24 15:05:28 +00:00
|
|
|
@bot.event
|
|
|
|
async def on_ready():
|
2017-10-17 23:04:45 +00:00
|
|
|
from cogs import booru, info, management, owner, tools
|
2017-10-14 03:59:14 +00:00
|
|
|
|
2017-10-17 23:04:45 +00:00
|
|
|
bot.add_cog(tools.Utils(bot))
|
|
|
|
bot.add_cog(owner.Bot(bot))
|
|
|
|
bot.add_cog(owner.Tools(bot))
|
|
|
|
bot.add_cog(management.Administration(bot))
|
|
|
|
bot.add_cog(info.Info(bot))
|
|
|
|
bot.add_cog(booru.MsG(bot))
|
2017-10-11 06:57:17 +00:00
|
|
|
|
2017-10-17 23:04:45 +00:00
|
|
|
# bot.loop.create_task(u.clear(booru.temp_urls, 30*60))
|
2017-10-11 06:57:17 +00:00
|
|
|
|
2017-10-17 23:04:45 +00:00
|
|
|
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)
|
2017-10-16 18:07:10 +00:00
|
|
|
|
2017-10-17 23:04:45 +00:00
|
|
|
print('\n\\ \\ \\ \\ \\ \\ \\ \\ \\\nC O N N E C T E D : {}\n/ / / / / / / / /\n'.format(bot.user.name))
|
2017-10-18 18:09:13 +00:00
|
|
|
await bot.get_channel(u.config['info_channel']).send('**Started** \N{BLACK SUN WITH RAYS} .')
|
2017-10-17 23:04:45 +00:00
|
|
|
# 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'])
|
2017-10-18 18:09:13 +00:00
|
|
|
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
|
2017-10-17 23:04:45 +00:00
|
|
|
u.temp.clear()
|
2017-09-24 15:05:28 +00:00
|
|
|
|
2017-10-13 02:28:16 +00:00
|
|
|
|
2017-10-14 19:29:01 +00:00
|
|
|
@bot.event
|
2017-10-15 03:41:42 +00:00
|
|
|
async def on_error(error, *args, **kwargs):
|
2017-10-17 23:04:45 +00:00
|
|
|
print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr)
|
|
|
|
tb.print_exc()
|
|
|
|
await bot.get_user(u.config['owner_id']).send('**ERROR** ⚠ `{}`'.format(error))
|
|
|
|
await bot.get_channel(u.config['info_channel']).send('**ERROR** ⚠ `{}`'.format(error))
|
|
|
|
# u.notify('E R R O R')
|
|
|
|
await bot.logout()
|
|
|
|
u.close(bot.loop)
|
2017-10-14 19:29:01 +00:00
|
|
|
|
|
|
|
|
2017-10-13 02:28:16 +00:00
|
|
|
@bot.event
|
|
|
|
async def on_command_error(ctx, error):
|
2017-10-17 23:04:45 +00:00
|
|
|
if isinstance(error, errext.CheckFailure):
|
2017-10-18 18:09:13 +00:00
|
|
|
await ctx.send('\N{NO ENTRY} **Insufficient permissions.**', delete_after=10)
|
|
|
|
await ctx.message.add_reaction('\N{NO ENTRY}')
|
2017-10-17 23:04:45 +00:00
|
|
|
elif isinstance(error, errext.CommandNotFound):
|
|
|
|
print('INVALID COMMAND : {}'.format(error), file=sys.stderr)
|
2017-10-18 18:09:13 +00:00
|
|
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
2017-10-17 23:04:45 +00:00
|
|
|
else:
|
|
|
|
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)
|
|
|
|
await bot.get_user(u.config['owner_id']).send('**COMMAND ERROR** ⚠ `{}`'.format(error))
|
|
|
|
await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** ⚠ `{}`'.format(error))
|
|
|
|
await exc.send_error(ctx, error)
|
|
|
|
await ctx.message.add_reaction('⚠')
|
|
|
|
# u.notify('C O M M A N D E R R O R')
|
2017-10-13 02:28:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def on_reaction_add(r, u):
|
2017-10-17 23:04:45 +00:00
|
|
|
pass
|
2017-10-13 02:28:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def on_reaction_remove(r, u):
|
2017-10-17 23:04:45 +00:00
|
|
|
pass
|
2017-10-14 01:51:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def reaction_add(r, u):
|
2017-10-17 23:04:45 +00:00
|
|
|
bot.add_listener(on_reaction_add)
|
|
|
|
print('Reacted')
|
|
|
|
bot.remove_listener(on_reaction_remove)
|
2017-10-14 01:51:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def reaction_remove(r, u):
|
2017-10-17 23:04:45 +00:00
|
|
|
bot.add_listener(on_reaction_remove)
|
|
|
|
print('Removed')
|
|
|
|
bot.remove_listener(on_reaction_remove)
|
2017-10-13 02:28:16 +00:00
|
|
|
|
2017-09-24 15:05:28 +00:00
|
|
|
|
2017-10-11 06:57:17 +00:00
|
|
|
@bot.command(name=',test', hidden=True)
|
2017-09-25 19:31:51 +00:00
|
|
|
@commands.is_owner()
|
2017-09-24 15:05:28 +00:00
|
|
|
@checks.del_ctx()
|
|
|
|
async def test(ctx):
|
2017-10-18 18:09:13 +00:00
|
|
|
test = await ctx.send('\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}')
|
|
|
|
await test.add_reaction('\N{THUMBS UP SIGN}')
|
|
|
|
await test.add_reaction('#\u20e3')
|
2017-10-17 23:04:45 +00:00
|
|
|
# bot.add_listener(on_reaction_add)
|
|
|
|
# bot.add_listener(on_reaction_remove)
|
2017-09-24 15:05:28 +00:00
|
|
|
|
2017-10-14 03:38:58 +00:00
|
|
|
bot.run(u.config['token'])
|