mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 21:02:38 +00:00
WIP testing for dual reaction add/remove event listeners, moved commands
This commit is contained in:
parent
1f794ffd6f
commit
8f304893e3
1 changed files with 41 additions and 76 deletions
117
src/main/run.py
117
src/main/run.py
|
@ -1,4 +1,21 @@
|
||||||
|
import asyncio
|
||||||
|
import datetime as dt
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import traceback as tb
|
||||||
|
|
||||||
|
import aiohttp as aio
|
||||||
|
import discord as d
|
||||||
|
from discord import utils
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
from cogs import booru, info, management, owner, tools
|
||||||
|
from misc import exceptions as exc
|
||||||
|
from misc import checks
|
||||||
|
from utils import utils as u
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open('config.json') as infile:
|
with open('config.json') as infile:
|
||||||
|
@ -6,24 +23,12 @@ 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:
|
||||||
json.dump({'client_id': 0, 'listed_ids': [0], 'owner_id': 0, 'permissions': 126016, 'prefix': ',', 'shutdown_channel': 0, 'startup_channel': 0, 'token': 'str'}, outfile, indent=4, sort_keys=True)
|
json.dump({'client_id': 0, 'listed_ids': [0], 'owner_id': 0, 'permissions': 126016, 'prefix': ',',
|
||||||
raise FileNotFoundError('Config file not found: \"config.json\" created with abstract values. Restart \"run.py\" with correct values.')
|
'shutdown_channel': 0, 'startup_channel': 0, '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.')
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import datetime as dt
|
|
||||||
import discord as d
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import traceback
|
|
||||||
from discord import utils
|
|
||||||
from discord.ext import commands
|
|
||||||
from cogs import booru, info, owner, management, tools
|
|
||||||
from misc import checks
|
|
||||||
from misc import exceptions as exc
|
|
||||||
from utils import utils as u
|
|
||||||
|
|
||||||
import logging
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
print('PID {}'.format(os.getpid()))
|
print('PID {}'.format(os.getpid()))
|
||||||
|
@ -31,16 +36,19 @@ print('PID {}'.format(os.getpid()))
|
||||||
bot = commands.Bot(command_prefix=config['prefix'], description='Experimental booru bot')
|
bot = commands.Bot(command_prefix=config['prefix'], description='Experimental booru bot')
|
||||||
|
|
||||||
# Send and print ready message to #testing and console after logon
|
# Send and print ready message to #testing and console after logon
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
global bot
|
|
||||||
|
|
||||||
bot.add_cog(tools.Utils(bot))
|
bot.add_cog(tools.Utils(bot))
|
||||||
|
bot.add_cog(owner.Bot(bot, config))
|
||||||
bot.add_cog(owner.Tools(bot))
|
bot.add_cog(owner.Tools(bot))
|
||||||
bot.add_cog(management.Administration(bot))
|
bot.add_cog(management.Administration(bot))
|
||||||
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(config['startup_channel']), d.TextChannel):
|
if isinstance(bot.get_channel(config['startup_channel']), d.TextChannel):
|
||||||
|
@ -49,71 +57,28 @@ async def on_ready():
|
||||||
print(bot.user.name)
|
print(bot.user.name)
|
||||||
print('-------')
|
print('-------')
|
||||||
|
|
||||||
# Close connection to Discord - immediate offline
|
|
||||||
@bot.command(name=',die', aliases=[',d'], brief='Kills the bot', description='BOT OWNER ONLY\nCloses the connection to Discord', hidden=True)
|
|
||||||
@commands.is_owner()
|
|
||||||
@checks.del_ctx()
|
|
||||||
async def die(ctx):
|
|
||||||
try:
|
|
||||||
if isinstance(bot.get_channel(config['startup_channel']), d.TextChannel):
|
|
||||||
await bot.get_channel(config['shutdown_channel']).send('**Shutting down...** 🌙')
|
|
||||||
await bot.close()
|
|
||||||
print('-------')
|
|
||||||
print('CLOSED')
|
|
||||||
except Exception:
|
|
||||||
await ctx.send(exc.base + '\n```' + traceback.format_exc(limit=1) + '```')
|
|
||||||
traceback.print_exc(limit=1)
|
|
||||||
|
|
||||||
@bot.command(name=',restart', aliases=[',res', ',r'], hidden=True)
|
@bot.event
|
||||||
@commands.is_owner()
|
async def on_command_error(ctx, error):
|
||||||
@checks.del_ctx()
|
print(error)
|
||||||
async def restart(ctx):
|
await ctx.send('{}\n```\n{}```'.format(exc.base, error))
|
||||||
try:
|
|
||||||
print('RESTARTING')
|
|
||||||
print('-------')
|
|
||||||
if isinstance(bot.get_channel(config['startup_channel']), d.TextChannel):
|
|
||||||
await bot.get_channel(config['shutdown_channel']).send('**Restarting...** 💤')
|
|
||||||
os.execl(sys.executable, 'python3', 'run.py')
|
|
||||||
except Exception:
|
|
||||||
await ctx.send('{}\n```{}```'.format(exc.base, traceback.format_exc(limit=1)))
|
|
||||||
traceback.print_exc(limit=1)
|
|
||||||
|
|
||||||
# Invite bot to bot owner's server
|
|
||||||
@bot.command(name=',invite', aliases=[',inv', ',link'], brief='Invite the bot', description='BOT OWNER ONLY\nInvite the bot to a server (Requires admin)', hidden=True)
|
|
||||||
@commands.is_owner()
|
|
||||||
@checks.del_ctx()
|
|
||||||
async def invite(ctx):
|
|
||||||
try:
|
|
||||||
await ctx.send('🔗 https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}'.format(config['client_id'], config['permissions']), delete_after=10)
|
|
||||||
except Exception:
|
|
||||||
await ctx.send('{}\n```{}```'.format(exc.base, traceback.format_exc(limit=1)))
|
|
||||||
traceback.print_exc(limit=1)
|
|
||||||
|
|
||||||
@bot.command(brief='[IN TESTING]', description='[IN TESTING]', hidden=True)
|
async def on_reaction_add(r, u):
|
||||||
async def hi(ctx):
|
print('Reacted')
|
||||||
user = ctx.message.author
|
|
||||||
try:
|
|
||||||
hello = 'Hewwo, {}.'.format(user.mention)
|
async def on_reaction_remove(r, u):
|
||||||
if user.id == checks.owner_id:
|
print('Removed')
|
||||||
hello += '.. ***Master.*** uwu'
|
|
||||||
elif user.guild_permissions.administrator:
|
|
||||||
hello = '{} **Admin** {}'.format(hello[:7], hello[7:])
|
|
||||||
elif user.guild_permissions.ban_members:
|
|
||||||
hello = '{} **Mod** {}'.format(hello[:7], hello[7:])
|
|
||||||
await ctx.send(hello)
|
|
||||||
except Exception:
|
|
||||||
await ctx.send('{}\n```{}```'.format(exc.base, traceback.format_exc(limit=1)))
|
|
||||||
traceback.print_exc(limit=1)
|
|
||||||
|
|
||||||
@bot.command(name=',test', hidden=True)
|
@bot.command(name=',test', hidden=True)
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def test(ctx):
|
async def test(ctx):
|
||||||
embed = d.Embed(title='/post/xxxxxx', url='https://static1.e621.net/data/4b/3e/4b3ec0c2e8580f418e4ce019dfd5ac32.png', timestamp=dt.datetime.utcnow(), color=ctx.me.color)
|
test = await ctx.send('Test')
|
||||||
embed.set_image(url='https://static1.e621.net/data/27/0f/270fd28caa5e6d8bf542a76515848e02.png')
|
await test.add_reaction('✅')
|
||||||
embed.set_footer(text='e621', icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
bot.add_listener(on_reaction_add)
|
||||||
embed.set_author(name='tags', url=ctx.message.author.avatar_url, icon_url=ctx.message.author.avatar_url)
|
bot.add_listener(on_reaction_remove)
|
||||||
embed.add_field(name='Link', value='https://static1.e621.net/data/c2/55/c255792b5a307ee6efa51d6bb3edf878.jpg')
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
bot.run(config['token'])
|
bot.run(config['token'])
|
||||||
|
|
Loading…
Reference in a new issue