mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 23:10:36 +01:00
Ajout de log pour la notification de live
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
from twitchAPI.twitch import Twitch
|
from twitchAPI.twitch import Twitch
|
||||||
from twitchAPI.object.api import Stream
|
from twitchAPI.object.api import Stream
|
||||||
|
|
||||||
@@ -14,23 +16,30 @@ async def checkOnlineStreamer(twitch: Twitch) :
|
|||||||
for alert in alerts :
|
for alert in alerts :
|
||||||
stream = next((s for s in streams if s.user_login == alert.login), None)
|
stream = next((s for s in streams if s.user_login == alert.login), None)
|
||||||
if stream :
|
if stream :
|
||||||
|
logging.info(f'Streamer en ligne : {alert.login}')
|
||||||
if not alert.online and alert.enable :
|
if not alert.online and alert.enable :
|
||||||
|
logging.info(f'N\'etait pas en ligne auparavant : {alert.login}')
|
||||||
await _notifyAlert(alert, stream)
|
await _notifyAlert(alert, stream)
|
||||||
alert.online = True
|
alert.online = True
|
||||||
else :
|
else :
|
||||||
|
logging.info(f'Streamer hors ligne : {alert.login}')
|
||||||
alert.online = False
|
alert.online = False
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
async def _notifyAlert(alert : LiveAlert, stream : Stream):
|
async def _notifyAlert(alert : LiveAlert, stream : Stream):
|
||||||
message : str = alert.message.format(stream)
|
message : str = alert.message.format(stream)
|
||||||
|
logging.info(f'Message de notification : {message}')
|
||||||
bot.loop.create_task(_sendMessage(alert.notify_channel, message))
|
bot.loop.create_task(_sendMessage(alert.notify_channel, message))
|
||||||
|
|
||||||
async def _sendMessage(channel : int, message : str) :
|
async def _sendMessage(channel : int, message : str) :
|
||||||
|
logging.info(f'Envoi de notification : {message}')
|
||||||
await bot.get_channel(channel).send(message)
|
await bot.get_channel(channel).send(message)
|
||||||
|
logging.info(f'Notification envoyé')
|
||||||
|
|
||||||
async def _retreiveStreams(twitch: Twitch, alerts : list[LiveAlert]) -> list[Stream] :
|
async def _retreiveStreams(twitch: Twitch, alerts : list[LiveAlert]) -> list[Stream] :
|
||||||
streams : list[Stream] = []
|
streams : list[Stream] = []
|
||||||
async for stream in twitch.get_streams(user_login = [alert.login for alert in alerts]):
|
async for stream in twitch.get_streams(user_login = [alert.login for alert in alerts]):
|
||||||
streams.append(stream)
|
streams.append(stream)
|
||||||
|
logging.info(f'Ces streams sont en ligne : {streams}')
|
||||||
return streams
|
return streams
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user