1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-11-02 05:02:39 +00:00
modufur/src/main/run.py

98 lines
2.8 KiB
Python
Raw Normal View History

2017-09-24 18:09:02 +00:00
import asyncio
import datetime as dt
import json
import logging
2017-10-02 21:29:39 +00:00
import subprocess
import sys
import traceback as tb
import discord as d
2017-09-24 18:09:02 +00:00
from discord import utils
from discord.ext import commands
from discord.ext.commands import errors as errext
2017-09-24 18:09:02 +00:00
from misc import exceptions as exc
from misc import checks
from utils import utils as u
2017-09-24 18:09:02 +00:00
logging.basicConfig(level=logging.INFO)
2017-10-14 03:38:58 +00:00
bot = commands.Bot(command_prefix=u.config['prefix'], description='Experimental booru bot')
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-14 03:59:14 +00:00
from cogs import booru, info, management, owner, tools
bot.add_cog(tools.Utils(bot))
2017-10-14 03:38:58 +00:00
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))
# bot.loop.create_task(u.clear(booru.temp_urls, 30*60))
2017-10-14 03:38:58 +00:00
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))
# u.notify('C O N N E C T E D')
2017-09-24 15:05:28 +00:00
@bot.event
async def on_error(error, *args, **kwargs):
if isinstance(bot.get_channel(u.config['shutdown_channel']), d.TextChannel):
2017-10-15 05:34:34 +00:00
await bot.get_channel(u.config['shutdown_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)
tb.print_exc()
# u.notify('E R R O R')
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, errext.CheckFailure):
await ctx.send('❌ **Insufficient permissions.**', delete_after=10)
elif not isinstance(error, errext.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)
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):
pass
async def on_reaction_remove(r, u):
pass
async def reaction_add(r, u):
bot.add_listener(on_reaction_add)
print('Reacted')
bot.remove_listener(on_reaction_remove)
async def reaction_remove(r, u):
bot.add_listener(on_reaction_remove)
print('Removed')
bot.remove_listener(on_reaction_remove)
2017-09-24 15:05:28 +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):
test = await ctx.send('Test')
await test.add_reaction('')
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'])