From 7c0ca61741890eb295e5e6346c595287dac02437 Mon Sep 17 00:00:00 2001 From: d0cplay Date: Sun, 19 Jun 2022 17:52:46 +0200 Subject: [PATCH 1/2] [BUG] Duplicate Map entries Fixes #5 --- main.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index e5769cf..2721f0f 100644 --- a/main.py +++ b/main.py @@ -13,22 +13,22 @@ TOKEN = DATA["TOKEN"] PREFIX = DATA["PREFIX"] SERVERADDRESS = (DATA["SERVER"]["IP"], DATA["SERVER"]["PORT"]) - INTERVAL = 600.0 # Interval in seconds to check the server + INTERVAL = 2.0 #600.0 # Interval in seconds to check the server FIELPATH = "./history.txt" # Path to the file to save the history bot = commands.Bot(PREFIX) -last_map = "" - +last_map: str = "" @bot.event async def on_ready(): logging.log(logging.INFO, f"We have logged in as {bot.user}") await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"Map History")) - queryServer.start(last_map) + queryServer.start() @tasks.loop(seconds=INTERVAL) -async def queryServer(last_map): +async def queryServer(): + global last_map logging.log(logging.DEBUG, "Entering Query loop") try: logging.log( @@ -36,12 +36,17 @@ async def queryServer(last_map): query = a2s.info(SERVERADDRESS) current_map = query.map_name - logging.log(logging.INFO, f"Current map: {current_map}") - with open(FIELPATH, "a") as file: - if current_map != "" and last_map != current_map: + + if not current_map == last_map: + with open(FIELPATH, "a") as file: file.write(f"{current_map}\n") - last_map = current_map - + logging.log(logging.INFO, f"Saved map to File") + logging.log(logging.INFO, f"Current map: {current_map}") + logging.log(logging.INFO, f"Last map: {last_map}") + + last_map = current_map + else: + logging.log(logging.INFO, f"Current map: {current_map}") try: await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"Map History | {current_map}")) except: From 3ef6d6e47a275a9e93e4b40e307fc7c233fe4a83 Mon Sep 17 00:00:00 2001 From: d0cplay Date: Sun, 19 Jun 2022 17:57:58 +0200 Subject: [PATCH 2/2] reverted a var --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2721f0f..2dcca8e 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ TOKEN = DATA["TOKEN"] PREFIX = DATA["PREFIX"] SERVERADDRESS = (DATA["SERVER"]["IP"], DATA["SERVER"]["PORT"]) - INTERVAL = 2.0 #600.0 # Interval in seconds to check the server + INTERVAL = 600.0 # Interval in seconds to check the server FIELPATH = "./history.txt" # Path to the file to save the history bot = commands.Bot(PREFIX)