2016-07-08 01:05:42 +12:00
|
|
|
#!/usr/local/bin/python3.5
|
|
|
|
|
2016-07-09 11:26:43 +12:00
|
|
|
import discord
|
2016-07-16 11:06:28 +12:00
|
|
|
import traceback
|
2016-07-09 11:26:43 +12:00
|
|
|
from discord.ext import commands
|
2016-07-09 13:27:19 +12:00
|
|
|
from cogs.utils import config
|
2016-07-09 11:26:43 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
extensions = ['cogs.interaction',
|
|
|
|
'cogs.core',
|
|
|
|
'cogs.mod',
|
|
|
|
'cogs.owner',
|
|
|
|
'cogs.stats',
|
2016-07-11 05:28:16 +12:00
|
|
|
'cogs.playlist',
|
2016-07-14 16:00:30 +12:00
|
|
|
'cogs.twitch',
|
|
|
|
'cogs.overwatch']
|
2016-07-08 10:10:24 +12:00
|
|
|
|
2016-07-14 02:30:14 +12:00
|
|
|
bot = commands.Bot(command_prefix=config.commandPrefix, description=config.botDescription, pm_help=True)
|
2016-07-16 03:57:33 +12:00
|
|
|
|
2016-07-08 10:10:24 +12:00
|
|
|
|
|
|
|
# Bot event overrides
|
2016-07-08 01:05:42 +12:00
|
|
|
@bot.event
|
|
|
|
async def on_ready():
|
2016-07-08 10:10:24 +12:00
|
|
|
# Change the status upon connection to the default status
|
2016-07-11 01:58:03 +12:00
|
|
|
await bot.change_status(discord.Game(name=config.defaultStatus, type=0))
|
2016-07-10 04:02:33 +12:00
|
|
|
cursor = config.getCursor()
|
2016-07-08 10:10:24 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
cursor.execute('use {0}'.format(config.db_default))
|
2016-07-08 01:05:42 +12:00
|
|
|
cursor.execute('select channel_id from restart_server where id=1')
|
|
|
|
result = cursor.fetchone()['channel_id']
|
2016-07-08 10:10:24 +12:00
|
|
|
if int(result) != 0:
|
2016-07-09 13:27:19 +12:00
|
|
|
destination = discord.utils.find(lambda m: m.id == result, bot.get_all_channels())
|
|
|
|
await bot.send_message(destination, "I have just finished restarting!")
|
2016-07-08 01:05:42 +12:00
|
|
|
cursor.execute('update restart_server set channel_id=0 where id=1')
|
2016-07-11 01:58:03 +12:00
|
|
|
config.closeConnection()
|
2016-07-08 01:05:42 +12:00
|
|
|
|
2016-07-11 09:57:52 +12:00
|
|
|
|
2016-07-10 04:40:27 +12:00
|
|
|
@bot.event
|
|
|
|
async def on_message(message):
|
|
|
|
if message.author.bot:
|
|
|
|
return
|
|
|
|
await bot.process_commands(message)
|
2016-07-08 10:10:24 +12:00
|
|
|
|
2016-07-11 09:57:52 +12:00
|
|
|
|
2016-07-08 01:05:42 +12:00
|
|
|
@bot.event
|
|
|
|
async def on_member_join(member):
|
2016-07-11 09:57:52 +12:00
|
|
|
await bot.send_message(member.server, "Welcome to the '{0.server.name}' server {0.mention}!".format(member))
|
2016-07-08 01:05:42 +12:00
|
|
|
|
2016-07-08 10:10:24 +12:00
|
|
|
|
2016-07-08 01:05:42 +12:00
|
|
|
@bot.event
|
|
|
|
async def on_member_remove(member):
|
2016-07-11 09:57:52 +12:00
|
|
|
await bot.send_message(member.server, "{0} has left the server, I hope it wasn't because of something I said :c".format(member))
|
2016-07-08 01:05:42 +12:00
|
|
|
|
2016-07-09 13:42:33 +12:00
|
|
|
|
|
|
|
@bot.event
|
|
|
|
async def on_command_error(error, ctx):
|
2016-07-11 23:42:27 +12:00
|
|
|
if isinstance(error, commands.CommandNotFound):
|
2016-07-14 09:24:21 +12:00
|
|
|
fmt = "That is not a valid command! There's a help command for a reason, learn to use it."
|
2016-07-11 23:42:27 +12:00
|
|
|
await bot.send_message(ctx.message.channel, fmt)
|
2016-07-12 00:40:03 +12:00
|
|
|
elif isinstance(error, commands.BadArgument):
|
2016-07-12 03:01:59 +12:00
|
|
|
fmt = "Please provide a valid argument to pass to the command: {}".format(error)
|
2016-07-12 00:40:03 +12:00
|
|
|
await bot.send_message(ctx.message.channel, fmt)
|
2016-07-14 09:16:47 +12:00
|
|
|
elif isinstance(error, commands.CheckFailure):
|
2016-07-14 09:24:21 +12:00
|
|
|
fmt = "You can't tell me what to do!"
|
2016-07-14 09:16:47 +12:00
|
|
|
await bot.send_message(ctx.message.channel, fmt)
|
2016-07-16 11:11:36 +12:00
|
|
|
elif isinstance(error, commands.CommandInvokeError):
|
|
|
|
print('In {0.command.qualified_name}:'.format(ctx), file=sys.stderr)
|
|
|
|
traceback.print_tb(error.original.__traceback__)
|
|
|
|
print('{0.__class__.__name__}: {0}'.format(error.original), file=sys.stderr)
|
2016-07-11 23:43:34 +12:00
|
|
|
else:
|
|
|
|
fmt = 'An error occurred while processing this request: ```py\n{}: {}\n```'
|
2016-07-16 03:48:01 +12:00
|
|
|
await bot.send_message(ctx.message.channel, fmt.format(type(error).__name__, error))
|
2016-07-09 13:42:33 +12:00
|
|
|
|
2016-07-09 13:27:19 +12:00
|
|
|
if __name__ == '__main__':
|
|
|
|
for e in extensions:
|
|
|
|
bot.load_extension(e)
|
|
|
|
bot.run(config.botToken)
|