Username update code now working
parent
959b587e14
commit
7b36784a89
|
@ -60,6 +60,8 @@ class GeoffreyBot(commands.Bot):
|
||||||
logger.info('Failed to load extension {}'.format(extension))
|
logger.info('Failed to load extension {}'.format(extension))
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
self.loop.create_task(self.username_update())
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
logger.info("%s Online, ID: %s", self.user.name, self.user.id)
|
logger.info("%s Online, ID: %s", self.user.name, self.user.id)
|
||||||
info = await self.application_info()
|
info = await self.application_info()
|
||||||
|
@ -128,14 +130,14 @@ class GeoffreyBot(commands.Bot):
|
||||||
user = await self.get_user_info(user_id)
|
user = await self.get_user_info(user_id)
|
||||||
await user.send(msg)
|
await user.send(msg)
|
||||||
|
|
||||||
|
async def username_update(self):
|
||||||
|
await self.wait_until_ready()
|
||||||
|
|
||||||
async def username_update(bot):
|
while not self.is_closed():
|
||||||
await bot.wait_until_ready()
|
session = self.bot_commands.interface.database.Session()
|
||||||
while not bot.is_closed:
|
|
||||||
session = bot.bot_commands.interface.database.Session()
|
|
||||||
try:
|
try:
|
||||||
logger.info("Updating MC usernames...")
|
logger.info("Updating MC usernames...")
|
||||||
session = bot.bot_commands.interface.database.Session()
|
session = self.bot_commands.interface.database.Session()
|
||||||
player_list = session.query(Player).all()
|
player_list = session.query(Player).all()
|
||||||
for player in player_list:
|
for player in player_list:
|
||||||
player.name = grab_playername(player.mc_uuid)
|
player.name = grab_playername(player.mc_uuid)
|
||||||
|
@ -147,10 +149,11 @@ async def username_update(bot):
|
||||||
logger.info("Username lookup error.")
|
logger.info("Username lookup error.")
|
||||||
session.rollback()
|
session.rollback()
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
await bot.send_error_message('Error connecting to the MySQL server, is it offline?')
|
await self.send_error_message('Error connecting to the MySQL server, is it offline?')
|
||||||
logger.info("MySQL connection error")
|
logger.info("MySQL connection error")
|
||||||
finally:
|
finally:
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
await asyncio.sleep(600)
|
await asyncio.sleep(600)
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,7 +161,7 @@ def setup_logging(config):
|
||||||
discord_logger = logging.getLogger('discord')
|
discord_logger = logging.getLogger('discord')
|
||||||
discord_logger.setLevel(logging.INFO)
|
discord_logger.setLevel(logging.INFO)
|
||||||
sql_logger = logging.getLogger('sqlalchemy.engine')
|
sql_logger = logging.getLogger('sqlalchemy.engine')
|
||||||
sql_logger.setLevel(logging.INFO)
|
sql_logger.setLevel(logging.ERROR)
|
||||||
bot_info_logger = logging.getLogger('geoffrey.bot')
|
bot_info_logger = logging.getLogger('geoffrey.bot')
|
||||||
bot_info_logger.setLevel(logging.INFO)
|
bot_info_logger.setLevel(logging.INFO)
|
||||||
log_path = path.abspath(config.log_path)
|
log_path = path.abspath(config.log_path)
|
||||||
|
@ -188,7 +191,6 @@ def start_bot(config_path="{}/GeoffreyConfig.ini".format(path.dirname(path.abspa
|
||||||
|
|
||||||
setup_logging(bot_config)
|
setup_logging(bot_config)
|
||||||
|
|
||||||
bot.loop.create_task(username_update(bot))
|
|
||||||
bot.run(bot_config.token)
|
bot.run(bot_config.token)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
Loading…
Reference in New Issue