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 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

View File

@ -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

View File

@ -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)

View File

@ -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']

View File

@ -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')