Geoffrey-Django/Geoffrey.py

118 lines
4.4 KiB
Python
Raw Normal View History

2018-05-21 15:59:35 +00:00
from discord.ext import commands
from discord import Game
from Commands import *
from BotErrors import *
2018-06-03 02:42:31 +00:00
from MinecraftAccountInfoGrabber import *
2018-07-21 18:28:31 +00:00
from BotConfig import *
import asyncio
2018-07-21 18:28:31 +00:00
2018-05-25 16:32:29 +00:00
description = '''
Geoffrey (pronounced JOFF-ree) started his life as an inside joke none of you will understand.
At some point, she was to become an airhorn bot. Now, they know where your stuff is.
2018-05-22 02:41:15 +00:00
Please respect Geoffrey, the bot is very sensitive.
If have a suggestion or if something is borked, you can PM my ding dong of a creator ZeroHD.
*You must use ?register before adding things to Geoffrey*
2018-05-22 02:41:15 +00:00
'''
2018-05-25 16:32:29 +00:00
2018-05-25 22:00:43 +00:00
bad_error_message = 'OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko boingo! The admins at our ' \
2018-06-30 15:07:56 +00:00
'headquarters are working VEWY HAWD to fix this! (Error in command {}: {})'
2018-05-25 22:00:43 +00:00
2018-05-25 16:32:29 +00:00
# Bot Commands ******************************************************************'
bot = commands.Bot(command_prefix=bot_config.prefix, description=description, case_insensitive=True)
2018-06-03 02:42:31 +00:00
2018-05-21 15:59:35 +00:00
@bot.event
async def on_ready():
2018-05-25 16:32:29 +00:00
print('GeoffreyBot')
print('Username: ' + bot.user.name)
print('ID: ' + bot.user.id)
await bot.change_presence(game=Game(name=bot_config.status))
2018-05-25 16:32:29 +00:00
@bot.event
async def on_command_error(error, ctx):
2018-05-25 20:30:47 +00:00
if isinstance(error, commands.CommandNotFound):
error_str = 'Command not found, ding dongs like you can use ?help to see all the commands this bot can do.'
elif isinstance(error, commands.CommandOnCooldown):
return
elif isinstance(error, commands.UserInputError):
error_str = 'Invalid syntax for **{}** you ding dong, please read ?help {}.'\
.format(ctx.invoked_with, ctx.invoked_with)
elif isinstance(error.original, NoPermissionError):
error_str = 'You don\'t have permission for that cool command.'
2018-06-03 02:42:31 +00:00
elif isinstance(error.original, UsernameLookupFailed):
error_str = 'Your user name was not found, either Mojang is having a fucky wucky ' \
'or your nickname is not set correctly. *stares at the Mods*'
elif isinstance(error.original, PlayerNotFound):
error_str = 'Make sure to use ?register first you ding dong.'
elif isinstance(error.original, EntryNameNotUniqueError):
error_str = 'An entry in the database already has that name ding dong.'
elif isinstance(error.original, DatabaseValueError):
2018-07-23 00:01:49 +00:00
error_str = 'Use a shorter name or a smaller value, dong ding.'
elif isinstance(error.original, NotOnServerError):
error_str = 'Command needs to be run on 24CC. Run this command there whoever you are.'.format()
2018-05-25 20:30:47 +00:00
else:
2018-06-30 15:07:56 +00:00
error_str = bad_error_message.format(ctx.invoked_with, error)
2018-05-25 20:30:47 +00:00
2018-08-10 23:03:30 +00:00
await bot.send_message(ctx.message.channel, '{} **Error Running Command:** {}'.format(ctx.message.author.mention,
error_str))
async def username_update():
session = None
await bot.wait_until_ready()
while not bot.is_closed:
session = bot_commands.interface.database.Session()
try:
print("Updating MC usernames...")
session = bot_commands.interface.database.Session()
player_list = session.query(Player).all()
for player in player_list:
player.name = grab_playername(player.mc_uuid)
session.commit()
await asyncio.sleep(600)
except UsernameLookupFailed:
print("Username lookup error, are Mojang's servers down?")
session.rollback()
finally:
print("Done.")
2018-08-10 02:51:46 +00:00
session.close()
2018-06-30 15:53:27 +00:00
if session is not None:
2018-08-10 02:51:46 +00:00
session.close()
2018-06-30 15:53:27 +00:00
# Bot Startup ******************************************************************
bot_commands = Commands()
extensions = ['Add_Commands', 'Delete_Commands', 'Edit_Commands', 'Search_Commands', 'Admin_Commands']
2018-05-21 16:57:20 +00:00
if __name__ == '__main__':
bot_commands = Commands()
for extension in extensions:
try:
bot.load_extension(extension)
except Exception as e:
print('Failed to load extension {}, {}'.format(extension, e))
2018-08-10 23:03:30 +00:00
try:
bot.loop.create_task(username_update())
bot.run(bot_config.token)
except TimeoutError:
print("Disconnected, is Discord offline?")
except:
print("Bye")