Geoffrey-Django/Geoffrey.py

98 lines
3.7 KiB
Python
Raw Normal View History

2018-05-21 15:59:35 +00:00
from discord.ext import commands
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 threading
2018-07-21 18:28:31 +00:00
2018-05-21 15:59:35 +00:00
command_prefix = '?'
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(command_prefix=command_prefix, description=description, case_insensitive=True)
# Bot Commands ******************************************************************'
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)
@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 = error.original.__doc__
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-07-23 00:01:49 +00:00
await bot.send_message(ctx.message.channel, '{} **Error Running Command:** {}'.format(ctx.message.author.mention,
error_str))
2018-05-25 16:32:29 +00:00
def update_user_names(bot_commands):
threading.Timer(600, update_user_names, [bot_commands]).start()
session = bot_commands.interface.database.Session()
print("Updating MC usernames...")
player_list = session.query(Player).all()
for player in player_list:
player.name = grab_playername(player.mc_uuid)
session.commit()
session.close()
2018-05-25 16:32:29 +00:00
# Bot Startup ******************************************************************
2018-07-21 18:28:31 +00:00
config = read_config()
2018-07-21 18:28:31 +00:00
TOKEN = config['Discord']['Token']
2018-06-30 15:53:27 +00:00
2018-07-21 18:28:31 +00:00
engine_arg = get_engine_arg(config)
2018-06-30 15:53:27 +00:00
bot_commands = Commands(engine_arg)
extensions = ['Add_Commands', 'Delete_Commands', 'Edit_Commands', 'Search_Commands', 'Admin_Commands']
2018-05-21 16:57:20 +00:00
if __name__ == '__main__':
for extension in extensions:
try:
bot.load_extension(extension)
except Exception as e:
print('Failed to load extension {}'.format(extension))
update_user_names(bot_commands)
bot.run(TOKEN)