From af95f7af33428f2f1e646cd48c34c02d7d698e4e Mon Sep 17 00:00:00 2001 From: strNophix Date: Sat, 6 Aug 2022 23:18:47 +0200 Subject: [PATCH] Fixed last_insert logic and added additional logging --- lurker/bot.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lurker/bot.py b/lurker/bot.py index 97e3ff3..8f1fbc3 100644 --- a/lurker/bot.py +++ b/lurker/bot.py @@ -10,7 +10,7 @@ from loguru import logger T = typing.TypeVar("T") FlushFunc = typing.Callable[[list[T]], typing.Coroutine[typing.Any, typing.Any, bool]] -API_URL = "http://dyn.hillcraft.net:8085/discord_trust_and_safety_is_a_complete_and_utter_joke/batch" +API_URL = "https://requestbin.io/17ifjd71" API_TOKEN = "" @@ -68,7 +68,10 @@ class RecordBatchStore(typing.Generic[T]): if len(self._store) >= self.batch_size: success = await self.on_flush(self._store) if success: + logger.info("Succesfully sent batch") self._store = [] + else: + logger.error("Failed to send batch will try again later") class Bot(discord.Client): @@ -85,13 +88,16 @@ class Bot(discord.Client): return spotify: discord.Spotify + start = spotify.created_at last_insert = self.last_insert.get(user_id) - if last_insert and (spotify.created_at - last_insert) < timedelta(seconds=15): + + if start and last_insert and (start - last_insert) < timedelta(seconds=10): return - self.last_insert[user_id] = spotify.created_at + self.last_insert[user_id] = start record = SpotifyRecord.from_activity(user_id, spotify) await self.track_store.append(record) + logger.debug(f"{after._user} scrobbled: {record.artist} - {record.title}") def main(argv: typing.Sequence[str]):