From fca1fbd02dd9d5907ec8a3dea42c713695717f99 Mon Sep 17 00:00:00 2001 From: Kepka Ludovic Date: Thu, 21 Aug 2025 07:29:04 +0200 Subject: [PATCH] Premier correction Hexas Indispo --- discordbot/__init__.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/discordbot/__init__.py b/discordbot/__init__.py index 9b919a5..b085e41 100644 --- a/discordbot/__init__.py +++ b/discordbot/__init__.py @@ -36,21 +36,24 @@ class DiscordBot(discord.Client): async def updateHumbleBundle(self): while not self.is_closed(): if ConfigurationHelper().getValue('humble_bundle_enable') and ConfigurationHelper().getIntValue('humble_bundle_channel') != 0 : - response = requests.get("http://hexas.shionn.org/humble-bundle/json", headers={ "Content-Type": "application/json" }) - if response.status_code == 200: - bundle = response.json() - if GameBundle.query.filter_by(id=bundle['id']).first() == None : - choice = bundle['choices'][0] - date = datetime.datetime.fromtimestamp(bundle['endDate']/1000,datetime.UTC).strftime("%d %B %Y") - message = f"@here **Humble Bundle** propose un pack de jeu [{bundle['name']}]({bundle['url']}) contenant :\n" - for game in choice["games"]: - message += f"- {game}\n" - message += f"Pour {choice['price']}€, disponible jusqu'au {date}." - await self.get_channel(ConfigurationHelper().getIntValue('humble_bundle_channel')).send(message) - db.session.add(GameBundle(id=bundle['id'], name=bundle['name'], json = json.dumps(bundle))) - db.session.commit() - else: - logging.error(f"Erreur de connexion {response.status_code}") + try : + response = requests.get("http://hexas.shionn.org/humble-bundle/json", headers={ "Content-Type": "application/json" }) + if response.status_code == 200: + bundle = response.json() + if GameBundle.query.filter_by(id=bundle['id']).first() == None : + choice = bundle['choices'][0] + date = datetime.datetime.fromtimestamp(bundle['endDate']/1000,datetime.UTC).strftime("%d %B %Y") + message = f"@here **Humble Bundle** propose un pack de jeu [{bundle['name']}]({bundle['url']}) contenant :\n" + for game in choice["games"]: + message += f"- {game}\n" + message += f"Pour {choice['price']}€, disponible jusqu'au {date}." + await self.get_channel(ConfigurationHelper().getIntValue('humble_bundle_channel')).send(message) + db.session.add(GameBundle(id=bundle['id'], name=bundle['name'], json = json.dumps(bundle))) + db.session.commit() + else: + logging.error(f"Erreur de connexion {response.status_code}") + except Exception as e: + logging.error(f"Erreur de connexion {e}") else: logging.info('Humble bundle est désactivé') # toute les 30 minutes