forked from chainsaw_mcginny/RoosterReWrite
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
4.7 KiB
166 lines
4.7 KiB
import logging
|
|
import sys
|
|
import traceback
|
|
|
|
import aiohttp
|
|
import aioredis
|
|
import pendulum
|
|
from discord.ext import commands
|
|
import discord
|
|
from cogs.utils import context
|
|
from cogs.utils.esi import ESI
|
|
|
|
try:
|
|
import config
|
|
except ImportError:
|
|
print("Config not found, have you copied over the example settings?")
|
|
sys.exit(1)
|
|
|
|
|
|
description = """
|
|
Rooster knows all...
|
|
"""
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
initial_cogs = (
|
|
'cogs.about',
|
|
'cogs.who',
|
|
'cogs.insurance',
|
|
'cogs.killwatch',
|
|
'cogs.market',
|
|
'cogs.reminder',
|
|
'cogs.time',
|
|
'cogs.thera',
|
|
'cogs.trivia',
|
|
'cogs.weather',
|
|
'cogs.where',
|
|
'cogs.joinchannel',
|
|
'cogs.route',
|
|
)
|
|
|
|
|
|
class Rooster(commands.Bot):
|
|
def __init__(self):
|
|
super().__init__(
|
|
command_prefix='!',
|
|
description=description,
|
|
pm_help=True,
|
|
help_attrs=dict(hidden=True))
|
|
|
|
self.client_id = config.client_id
|
|
self.session = aiohttp.ClientSession(loop=self.loop)
|
|
self.esi = ESI()
|
|
|
|
self.add_command(self.uptime)
|
|
self.add_command(self.invite)
|
|
self.add_command(self._reload)
|
|
self.add_command(self.load)
|
|
self.add_command(self.unload)
|
|
|
|
for cog in initial_cogs:
|
|
try:
|
|
self.load_extension(cog)
|
|
except Exception as e:
|
|
print(f'Failed to load cog {cog}', file=sys.stderr)
|
|
traceback.print_exc()
|
|
|
|
async def start_redis(self):
|
|
self.redis = await aioredis.create_pool(
|
|
('localhost', 6379), minsize=5, maxsize=10, loop=self.loop)
|
|
|
|
async def on_comand_error(self, ctx, error):
|
|
if isinstance(error, commands.NoPrivateMessage):
|
|
await ctx.author.send('This command cannot be used in Private Messages')
|
|
elif isinstance(error, commands.DisabledCommand):
|
|
await ctx.author.send('Sorry, this command is disabled.')
|
|
elif isinstance(error, commands.CommandInvokeError):
|
|
print(f'In {ctx.command.qualified_name}', file=sys.stderr)
|
|
traceback.print_tb(error.original.__traceback__)
|
|
|
|
async def on_ready(self):
|
|
if not hasattr(self, 'currentuptime'):
|
|
await self.start_redis()
|
|
self.currentuptime = pendulum.now(tz='UTC')
|
|
print('Ready')
|
|
|
|
async def process_commands(self, message):
|
|
ctx = await self.get_context(message, cls=context.Context)
|
|
|
|
if ctx.command is None:
|
|
return
|
|
await self.invoke(ctx)
|
|
|
|
async def on_message(self, message):
|
|
if message.author.bot:
|
|
return
|
|
await self.process_commands(message)
|
|
|
|
async def on_resumed(self):
|
|
print('Resumed...')
|
|
|
|
def run(self):
|
|
super().run(config.token, reconnect=True)
|
|
|
|
@property
|
|
def config(self):
|
|
return __import__('config')
|
|
|
|
@commands.command(hidden=True)
|
|
async def uptime(self, ctx):
|
|
"""
|
|
Returns the uptime
|
|
"""
|
|
await ctx.send(pendulum.now(tz='UTC').diff_for_humans(self.currentuptime, absolute=True))
|
|
|
|
@commands.command(hidden=True)
|
|
@commands.is_owner()
|
|
async def load(self, ctx, *, module):
|
|
"""Loads a module."""
|
|
try:
|
|
self.load_extension(module)
|
|
except Exception as e:
|
|
await ctx.send(f'```py\n{traceback.format_exc()}\n```')
|
|
else:
|
|
await ctx.send('\N{OK HAND SIGN}')
|
|
|
|
@commands.command(hidden=True)
|
|
@commands.is_owner()
|
|
async def unload(self, ctx, *, module):
|
|
"""Unloads a module."""
|
|
try:
|
|
self.unload_extension(module)
|
|
except Exception as e:
|
|
await ctx.send(f'```py\n{traceback.format_exc()}\n```')
|
|
else:
|
|
await ctx.send('\N{OK HAND SIGN}')
|
|
|
|
@commands.command(name='reload', hidden=True)
|
|
@commands.is_owner()
|
|
async def _reload(self, ctx, *, module):
|
|
"""Reloads a module."""
|
|
try:
|
|
self.unload_extension(module)
|
|
self.load_extension(module)
|
|
except Exception as e:
|
|
await ctx.send(f'```py\n{traceback.format_exc()}\n```')
|
|
else:
|
|
await ctx.send('\N{OK HAND SIGN}')
|
|
|
|
@commands.command(hidden=True)
|
|
async def invite(self, ctx):
|
|
"""Joins a server."""
|
|
perms = discord.Permissions.none()
|
|
perms.read_messages = True
|
|
perms.external_emojis = True
|
|
perms.send_messages = True
|
|
perms.manage_roles = False
|
|
perms.manage_channels = True
|
|
perms.ban_members = False
|
|
perms.kick_members = False
|
|
perms.manage_messages = False
|
|
perms.embed_links = True
|
|
perms.read_message_history = True
|
|
perms.attach_files = True
|
|
perms.add_reactions = True
|
|
await ctx.send(f'<{discord.utils.oauth_url(self.client_id, perms)}>')
|
|
|