Fixed last_insert logic and added additional logging
This commit is contained in:
parent
593894bc4f
commit
af95f7af33
@ -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]):
|
||||
|
Loading…
x
Reference in New Issue
Block a user