MC Usernames are now updated every 10 minutes

doc_update
Joey Hines 2018-07-22 21:51:22 -05:00
parent 11266bf498
commit 5dbbcd69e0
5 changed files with 30 additions and 5 deletions

View File

@ -41,11 +41,11 @@ class Commands:
if len(self.interface.find_location_by_owner(session, player)) == 0: if len(self.interface.find_location_by_owner(session, player)) == 0:
if base_name is None: if base_name is None:
base_name = "{}'s Base".format() base_name = "{}'s Base".format(player.name)
elif base_name is None: elif base_name is None:
raise EntryNameNotUniqueError 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 base_name = base.name
finally: finally:
@ -61,7 +61,7 @@ class Commands:
if len(self.interface.find_shop_by_owner(session, player)) == 0: if len(self.interface.find_shop_by_owner(session, player)) == 0:
if shop_name is None: if shop_name is None:
shop_name = "{}'s Shop".format() shop_name = "{}'s Shop".format(player.name)
elif shop_name is None: elif shop_name is None:
raise EntryNameNotUniqueError raise EntryNameNotUniqueError

View File

@ -135,6 +135,8 @@ class DatabaseInterface:
try: try:
player = self.database.query_by_filter(session, Player, expr)[0] player = self.database.query_by_filter(session, Player, expr)[0]
player.name = grab_playername(player.mc_uuid)
session.commit()
except IndexError: except IndexError:
raise PlayerNotFound raise PlayerNotFound
return player return player
@ -151,6 +153,7 @@ class DatabaseInterface:
loc_string = loc_string + '\n\n**Tunnels:**' loc_string = loc_string + '\n\n**Tunnels:**'
expr = Tunnel.owner.has(Player.name.ilike('%{}%'.format(search))) & Tunnel.location == None expr = Tunnel.owner.has(Player.name.ilike('%{}%'.format(search))) & Tunnel.location == None
for tunnel in self.database.query_by_filter(session, Tunnel, expr): for tunnel in self.database.query_by_filter(session, Tunnel, expr):
loc_string = "{}\n{}".format(loc_string, tunnel.full_str()) loc_string = "{}\n{}".format(loc_string, tunnel.full_str())
count += 1 count += 1

View File

@ -4,6 +4,8 @@ from BotErrors import *
from MinecraftAccountInfoGrabber import * from MinecraftAccountInfoGrabber import *
from itertools import zip_longest from itertools import zip_longest
from BotConfig import * from BotConfig import *
import time
import threading
command_prefix = '?' command_prefix = '?'
description = ''' description = '''
@ -310,6 +312,21 @@ def get_args_dict(args):
return {} 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 ****************************************************************** # Bot Startup ******************************************************************
config = read_config() config = read_config()
@ -320,5 +337,8 @@ engine_arg = get_engine_arg(config)
bot_commands = Commands(engine_arg) bot_commands = Commands(engine_arg)
update_user_names(bot_commands)
bot.run(TOKEN) bot.run(TOKEN)

View File

@ -21,5 +21,7 @@ def grab_UUID(username):
def grab_playername(uuid): def grab_playername(uuid):
player_data = grab_json(username_lookup_url.format(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']

View File

@ -8,7 +8,7 @@ class TestMinecraftInfoGrabber(TestCase):
self.assertEqual(grab_UUID('ZeroHD'), 'fe7e84132570458892032b69ff188bc3') self.assertEqual(grab_UUID('ZeroHD'), 'fe7e84132570458892032b69ff188bc3')
def test_grab_playername(self): def test_grab_playername(self):
self.assertEqual(grab_playername('fe7e84132570458892032b69ff188bc3'), 'ZeroHD') self.assertEqual(grab_playername('01c29c443f8d4ab490a56919407a5bd2'), 'CoolZero123')
def test_grab_playername_wrong_case(self): def test_grab_playername_wrong_case(self):
self.assertEqual(grab_UUID('zerohd'), 'fe7e84132570458892032b69ff188bc3') self.assertEqual(grab_UUID('zerohd'), 'fe7e84132570458892032b69ff188bc3')