Skip to content

Commit

Permalink
Merge branch 'main' into immervoll/issue8
Browse files Browse the repository at this point in the history
  • Loading branch information
immervoll authored Jun 19, 2022
2 parents b139a86 + 3ef6d6e commit b771abc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,36 @@
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(
logging.INFO, f"Connecting to {SERVERADDRESS[0]}:{SERVERADDRESS[1]}")

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}"))
Expand Down

0 comments on commit b771abc

Please sign in to comment.