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

106 lines
4.5 KiB
Python
Raw Normal View History

2017-09-24 15:05:28 +00:00
import json
try:
with open('config.json') as infile:
config = json.load(infile)
print('\"config.json\" loaded.')
except FileNotFoundError:
with open('config.json', 'w') as outfile:
2017-10-02 19:22:12 +00:00
json.dump({'client_id': 0, 'listed_ids': [0], 'owner_id': 0, 'permissions': 388160, 'prefix': ',', 'shutdown_channel': 0, 'startup_channel': 0, 'token': 'str'}, outfile, indent=4, sort_keys=True)
2017-09-24 15:05:28 +00:00
raise FileNotFoundError('Config file not found: \"config.json\" created with abstract values. Restart \"run.py\" with correct values.')
2017-09-24 18:09:02 +00:00
import asyncio
import discord
2017-10-02 21:29:39 +00:00
import os
import subprocess
2017-09-24 18:09:02 +00:00
import traceback
from discord import utils
from discord.ext import commands
from cogs import booru, info, tools
from misc import checks
from misc import exceptions as exc
bot = commands.Bot(command_prefix=commands.when_mentioned_or(config['prefix']), description='Experimental booru bot')
2017-09-24 15:05:28 +00:00
# Send and print ready message to #testing and console after logon
@bot.event
async def on_ready():
if isinstance(bot.get_channel(config['startup_channel']), discord.TextChannel):
2017-10-02 21:29:39 +00:00
await bot.get_channel(config['startup_channel']).send('Hello how are? **Have day.** 🌈')
2017-09-24 15:05:28 +00:00
print('Connected.')
print('Username: ' + bot.user.name)
print('-------')
# Close connection to Discord - immediate offline
2017-09-24 15:32:35 +00:00
@bot.command(name=',die', aliases=[',d', ',close', ',kill'], brief='Kills the bot', description='BOT OWNER ONLY\nCloses the connection to Discord', hidden=True)
2017-09-24 15:05:28 +00:00
@commands.is_owner()
2017-09-25 19:31:51 +00:00
@checks.del_ctx()
2017-09-24 15:05:28 +00:00
async def die(ctx):
try:
2017-09-27 18:49:21 +00:00
if isinstance(bot.get_channel(config['startup_channel']), discord.TextChannel):
2017-10-02 21:29:39 +00:00
await bot.get_channel(config['shutdown_channel']).send('Am go bye. **Have night.** 💤')
2017-09-24 15:05:28 +00:00
await bot.close()
print('-------')
print('Closed.')
except Exception:
2017-10-02 21:29:39 +00:00
await ctx.send(exc.base + '\n```python' + traceback.format_exc(limit=1) + '```')
2017-09-24 15:05:28 +00:00
traceback.print_exc(limit=1)
2017-10-02 21:29:39 +00:00
@bot.command(name=',restart', aliases=[',res', ',r'], hidden=True)
2017-10-02 19:24:57 +00:00
@commands.is_owner()
2017-10-02 21:29:39 +00:00
async def restart(ctx):
try:
if isinstance(bot.get_channel(config['startup_channel']), discord.TextChannel):
await bot.get_channel(config['shutdown_channel']).send('Am go :b: rite becc. **Have noon.** 💤')
process = subprocess.run(['python3', 'restart.py'])
print(process.returncode)
await bot.close()
print('-------')
print('Closed.')
except Exception:
await ctx.send(exc.base + '\n```python' + traceback.format_exc(limit=1) + '```')
traceback.print_exc(limit=1)
2017-10-02 19:24:57 +00:00
2017-09-24 15:05:28 +00:00
# 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()
2017-09-25 19:31:51 +00:00
@checks.del_ctx()
2017-09-24 15:05:28 +00:00
async def invite(ctx):
try:
2017-09-24 19:30:30 +00:00
await ctx.send('🔗 https://discordapp.com/oauth2/authorize?&client_id=' + str(config['client_id']) + '&scope=bot&permissions=' + str(config['permissions']))
2017-09-24 15:05:28 +00:00
except Exception:
2017-10-02 21:29:39 +00:00
await ctx.send(exc.base + '\n```python' + traceback.format_exc(limit=1) + '```')
2017-09-24 15:05:28 +00:00
traceback.print_exc(limit=1)
@bot.command(brief='[IN TESTING]', description='[IN TESTING]', hidden=True)
async def hi(ctx):
try:
2017-09-25 19:31:51 +00:00
hello = 'Hewwo, ' + ctx.message.author.mention + '.'
2017-09-24 15:05:28 +00:00
if ctx.message.author.id == checks.owner_id:
hello += '.. ***Master.*** uwu'
elif ctx.message.author.guild_permissions.administrator:
hello = hello[:7] + '**Admin** ' + hello[7:]
elif ctx.message.author.guild_permissions.ban_members:
hello = hello[:7] + '**Mod** ' + hello[7:]
await ctx.send(hello)
except Exception:
2017-10-02 21:29:39 +00:00
await ctx.send(exc.base + '\n```python' + traceback.format_exc(limit=1) + '```')
2017-09-24 15:05:28 +00:00
traceback.print_exc(limit=1)
@bot.command(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-09-25 19:31:51 +00:00
embed = discord.Embed(title='Title', type='rich', description='Description.', url='https://static1.e621.net/data/4b/3e/4b3ec0c2e8580f418e4ce019dfd5ac32.png', color=discord.Color.from_rgb(255, 255, 255))
embed = embed.set_image('https://static1.e621.net/data/27/0f/270fd28caa5e6d8bf542a76515848e02.png')
embed = embed.set_footer('Footer')
embed = embed.set_author('Author')
embed = embed.set_thumbnail('https://cdn.discordapp.com/attachments/353251794161500163/357707620561453077/9d803ea3-b7fa-401f-89cf-f32cf21fe772.png')
ctx.send('Embed test', embed=embed)
2017-09-24 15:05:28 +00:00
bot.add_cog(tools.Utils(bot))
bot.add_cog(info.Info(bot))
2017-09-24 15:05:28 +00:00
bot.add_cog(booru.MsG(bot))
bot.run(config['token'])