1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-24 22:27:28 +00:00

Testing, on_ready cogs, .format conversion, and misc changes

This commit is contained in:
Myned 2017-10-11 02:57:17 -04:00
parent e5fa7c35a6
commit a439d8d917

View file

@ -10,40 +10,58 @@ except FileNotFoundError:
raise FileNotFoundError('Config file not found: \"config.json\" created with abstract values. Restart \"run.py\" with correct values.') raise FileNotFoundError('Config file not found: \"config.json\" created with abstract values. Restart \"run.py\" with correct values.')
import asyncio import asyncio
import discord import datetime as dt
import discord as d
import os import os
import subprocess import subprocess
import sys
import traceback import traceback
from discord import utils from discord import utils
from discord.ext import commands from discord.ext import commands
from cogs import booru, info, tools from cogs import booru, info, owner, management, tools
from misc import checks from misc import checks
from misc import exceptions as exc from misc import exceptions as exc
from utils import utils as u
bot = commands.Bot(command_prefix=commands.when_mentioned_or(config['prefix']), description='Experimental booru bot') import logging
logging.basicConfig(level=logging.INFO)
print('PID {}'.format(os.getpid()))
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():
if isinstance(bot.get_channel(config['startup_channel']), discord.TextChannel): global bot
await bot.get_channel(config['startup_channel']).send('Hello how are? **Have day.** 🌈')
print('Connected.') bot.add_cog(tools.Utils(bot))
print('Username: ' + bot.user.name) 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))
if isinstance(bot.get_channel(config['startup_channel']), d.TextChannel):
await bot.get_channel(config['startup_channel']).send('**Started.** ☀️')
print('CONNECTED')
print(bot.user.name)
print('-------') print('-------')
# Close connection to Discord - immediate offline # Close connection to Discord - immediate offline
@bot.command(name=',die', aliases=[',d', ',close', ',kill'], brief='Kills the bot', description='BOT OWNER ONLY\nCloses the connection to Discord', hidden=True) @bot.command(name=',die', aliases=[',d'], brief='Kills the bot', description='BOT OWNER ONLY\nCloses the connection to Discord', hidden=True)
@commands.is_owner() @commands.is_owner()
@checks.del_ctx() @checks.del_ctx()
async def die(ctx): async def die(ctx):
try: try:
if isinstance(bot.get_channel(config['startup_channel']), discord.TextChannel): if isinstance(bot.get_channel(config['startup_channel']), d.TextChannel):
await bot.get_channel(config['shutdown_channel']).send('Am go bye. **Have night.** 💤') await bot.get_channel(config['shutdown_channel']).send('**Shutting down...** 🌙')
await bot.close() await bot.close()
print('-------') print('-------')
print('Closed.') print('CLOSED')
except Exception: except Exception:
await ctx.send(exc.base + '\n```python' + traceback.format_exc(limit=1) + '```') await ctx.send(exc.base + '\n```' + traceback.format_exc(limit=1) + '```')
traceback.print_exc(limit=1) traceback.print_exc(limit=1)
@bot.command(name=',restart', aliases=[',res', ',r'], hidden=True) @bot.command(name=',restart', aliases=[',res', ',r'], hidden=True)
@ -66,39 +84,36 @@ async def restart(ctx):
@checks.del_ctx() @checks.del_ctx()
async def invite(ctx): async def invite(ctx):
try: try:
await ctx.send('🔗 https://discordapp.com/oauth2/authorize?&client_id=' + str(config['client_id']) + '&scope=bot&permissions=' + str(config['permissions'])) await ctx.send('🔗 https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}'.format(config['client_id'], config['permissions']), delete_after=10)
except Exception: except Exception:
await ctx.send(exc.base + '\n```python' + traceback.format_exc(limit=1) + '```') await ctx.send('{}\n```{}```'.format(exc.base, traceback.format_exc(limit=1)))
traceback.print_exc(limit=1) traceback.print_exc(limit=1)
@bot.command(brief='[IN TESTING]', description='[IN TESTING]', hidden=True) @bot.command(brief='[IN TESTING]', description='[IN TESTING]', hidden=True)
async def hi(ctx): async def hi(ctx):
user = ctx.message.author
try: try:
hello = 'Hewwo, ' + ctx.message.author.mention + '.' hello = 'Hewwo, {}.'.format(user.mention)
if ctx.message.author.id == checks.owner_id: if user.id == checks.owner_id:
hello += '.. ***Master.*** uwu' hello += '.. ***Master.*** uwu'
elif ctx.message.author.guild_permissions.administrator: elif user.guild_permissions.administrator:
hello = hello[:7] + '**Admin** ' + hello[7:] hello = '{} **Admin** {}'.format(hello[:7], hello[7:])
elif ctx.message.author.guild_permissions.ban_members: elif user.guild_permissions.ban_members:
hello = hello[:7] + '**Mod** ' + hello[7:] hello = '{} **Mod** {}'.format(hello[:7], hello[7:])
await ctx.send(hello) await ctx.send(hello)
except Exception: except Exception:
await ctx.send(exc.base + '\n```python' + traceback.format_exc(limit=1) + '```') await ctx.send('{}\n```{}```'.format(exc.base, traceback.format_exc(limit=1)))
traceback.print_exc(limit=1) traceback.print_exc(limit=1)
@bot.command(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 = 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 = d.Embed(title='/post/xxxxxx', url='https://static1.e621.net/data/4b/3e/4b3ec0c2e8580f418e4ce019dfd5ac32.png', timestamp=dt.datetime.utcnow(), color=ctx.me.color)
embed = embed.set_image('https://static1.e621.net/data/27/0f/270fd28caa5e6d8bf542a76515848e02.png') embed.set_image(url='https://static1.e621.net/data/27/0f/270fd28caa5e6d8bf542a76515848e02.png')
embed = embed.set_footer('Footer') embed.set_footer(text='e621', icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
embed = embed.set_author('Author') embed.set_author(name='tags', url=ctx.message.author.avatar_url, icon_url=ctx.message.author.avatar_url)
embed = embed.set_thumbnail('https://cdn.discordapp.com/attachments/353251794161500163/357707620561453077/9d803ea3-b7fa-401f-89cf-f32cf21fe772.png') embed.add_field(name='Link', value='https://static1.e621.net/data/c2/55/c255792b5a307ee6efa51d6bb3edf878.jpg')
ctx.send('Embed test', embed=embed) await ctx.send(embed=embed)
bot.add_cog(tools.Utils(bot))
bot.add_cog(info.Info(bot))
bot.add_cog(booru.MsG(bot))
bot.run(config['token']) bot.run(config['token'])