From dc1da708a0a08a4a9e8354a5f1e8746036f2a95e Mon Sep 17 00:00:00 2001 From: GitGinocchio Date: Sun, 22 Dec 2024 15:54:10 +0100 Subject: [PATCH] CheapGames update --- notes.txt | 1 + src/commands/games/CheapGames.py | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/notes.txt b/notes.txt index 6eddc61..e8244b5 100644 --- a/notes.txt +++ b/notes.txt @@ -39,6 +39,7 @@ https://apidocs.cheapshark.com/ https://www.freetogame.com/api-doc https://www.gamerpower.com/api-read https://cataas.com/ +https://random-word-api.herokuapp.com/word?lang=it&number=2&length=5 Ignoring exception in command : Traceback (most recent call last): diff --git a/src/commands/games/CheapGames.py b/src/commands/games/CheapGames.py index 311c827..14f8985 100644 --- a/src/commands/games/CheapGames.py +++ b/src/commands/games/CheapGames.py @@ -353,12 +353,16 @@ async def send_giveaway_update(self, update_config : dict): url = f'{baseurl}{endpoint}{'?' if len(params) > 0 else ''}{'&'.join(params)}' + logger.info(f"Fetching games at: {url}") + games : list[dict] = await asyncget(url) + n_send : int = 0 # Number of games to send for game in games: if str(game["id"]) in saved_giveaways and game["published_date"] == saved_giveaways[str(game["id"])]: # Here we are checking if this giveaway is already registered continue + n_send += 1 saved_giveaways[str(game["id"])] = game["published_date"] @@ -369,12 +373,17 @@ async def send_giveaway_update(self, update_config : dict): ui = GiveawayGame(game) message = await channel.send(embed=ui, view=ui) - - try: - await message.publish() - except Exception as e: - print(e) - break # Send only one game at a time + + if message.channel.is_news(): + try: + await message.publish() + except Exception as e: + logger.exception(e) + + if n_send >= 10: # Send only 10 games at a tine + break + + #break # Send only one game at a time async def send_deal_update(self, update_config : dict): return ""