From 5dbbcd69e0112311793ebfcf857db88ee48d82c7 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 22 Jul 2018 21:51:22 -0500 Subject: [PATCH] MC Usernames are now updated every 10 minutes --- Commands.py | 6 +++--- DatabaseInterface.py | 3 +++ Geoffrey.py | 20 ++++++++++++++++++++ MinecraftAccountInfoGrabber.py | 4 +++- test_minecraftInfoGrabber.py | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Commands.py b/Commands.py index 9350d4f..840e3b0 100644 --- a/Commands.py +++ b/Commands.py @@ -41,11 +41,11 @@ class Commands: if len(self.interface.find_location_by_owner(session, player)) == 0: if base_name is None: - base_name = "{}'s Base".format() + base_name = "{}'s Base".format(player.name) elif base_name is None: raise EntryNameNotUniqueError - base = self.interface.add_base(session, player, base_name, x_pos, z_pos) + base = self.interface.add_location(session, player, base_name, x_pos, z_pos) base_name = base.name finally: @@ -61,7 +61,7 @@ class Commands: if len(self.interface.find_shop_by_owner(session, player)) == 0: if shop_name is None: - shop_name = "{}'s Shop".format() + shop_name = "{}'s Shop".format(player.name) elif shop_name is None: raise EntryNameNotUniqueError diff --git a/DatabaseInterface.py b/DatabaseInterface.py index 5e9befe..c442da6 100644 --- a/DatabaseInterface.py +++ b/DatabaseInterface.py @@ -135,6 +135,8 @@ class DatabaseInterface: try: player = self.database.query_by_filter(session, Player, expr)[0] + player.name = grab_playername(player.mc_uuid) + session.commit() except IndexError: raise PlayerNotFound return player @@ -151,6 +153,7 @@ class DatabaseInterface: loc_string = loc_string + '\n\n**Tunnels:**' expr = Tunnel.owner.has(Player.name.ilike('%{}%'.format(search))) & Tunnel.location == None + for tunnel in self.database.query_by_filter(session, Tunnel, expr): loc_string = "{}\n{}".format(loc_string, tunnel.full_str()) count += 1 diff --git a/Geoffrey.py b/Geoffrey.py index 6f69975..d9e4c2b 100644 --- a/Geoffrey.py +++ b/Geoffrey.py @@ -4,6 +4,8 @@ from BotErrors import * from MinecraftAccountInfoGrabber import * from itertools import zip_longest from BotConfig import * +import time +import threading command_prefix = '?' description = ''' @@ -310,6 +312,21 @@ def get_args_dict(args): return {} +def update_user_names(bot_commands): + threading.Timer(600, update_user_names, [bot_commands]).start() + session = bot_commands.interface.database.Session() + + player_list = session.query(Player).all() + + for player in player_list: + player.name = grab_playername(player.mc_uuid) + + print("Updating MC usernames...") + session.commit() + + session.close() + + # Bot Startup ****************************************************************** config = read_config() @@ -320,5 +337,8 @@ engine_arg = get_engine_arg(config) bot_commands = Commands(engine_arg) +update_user_names(bot_commands) + bot.run(TOKEN) + diff --git a/MinecraftAccountInfoGrabber.py b/MinecraftAccountInfoGrabber.py index 48b4f29..eebe6f6 100644 --- a/MinecraftAccountInfoGrabber.py +++ b/MinecraftAccountInfoGrabber.py @@ -21,5 +21,7 @@ def grab_UUID(username): def grab_playername(uuid): player_data = grab_json(username_lookup_url.format(uuid)) - return player_data[0]['name'] + + last_index = len(player_data)-1 + return player_data[last_index]['name'] diff --git a/test_minecraftInfoGrabber.py b/test_minecraftInfoGrabber.py index 0d518ca..14350ee 100644 --- a/test_minecraftInfoGrabber.py +++ b/test_minecraftInfoGrabber.py @@ -8,7 +8,7 @@ class TestMinecraftInfoGrabber(TestCase): self.assertEqual(grab_UUID('ZeroHD'), 'fe7e84132570458892032b69ff188bc3') def test_grab_playername(self): - self.assertEqual(grab_playername('fe7e84132570458892032b69ff188bc3'), 'ZeroHD') + self.assertEqual(grab_playername('01c29c443f8d4ab490a56919407a5bd2'), 'CoolZero123') def test_grab_playername_wrong_case(self): self.assertEqual(grab_UUID('zerohd'), 'fe7e84132570458892032b69ff188bc3')