Skip to content

Commit

Permalink
yum
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmaugy committed May 21, 2024
1 parent b3b2d49 commit 9b2fad1
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions bot/reels.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

from typing import TYPE_CHECKING
from dataclasses import dataclass
from datetime import datetime
from datetime import timedelta
from datetime import datetime, timedelta, timezone
from threading import Timer

from discord.mentions import AllowedMentions
Expand All @@ -18,10 +17,15 @@
from discord.abc import MessageableChannel
from typing import Dict

MEAN_LOW = 3600 * 24 * 1 # daily limit
MEAN_HIGH = 3600 * 24 * 7 # weekly high limit
DEFAULT_MEAN = 3600 * 24 * 5
DEFAULT_STD = 3600 * 24 # one day standard deviation
MEAN_LOW = 1 # daily limit
MEAN_HIGH = 7 # weekly high limit
DEFAULT_MEAN = 5
DEFAULT_STD = 1 # one day standard deviation

HOUR_MEAN = 17 # 5pm mu
HOUR_STD = 2 # 2 hour standard deviation

EASTERN_TIME = timezone(timedelta(hours=-4))

class ReelsManager:

Expand Down Expand Up @@ -79,12 +83,17 @@ def force_send(self, reels_id: str):

def _trigger_send_timer(self, reels_id: str, loop=None, now=False):
reel: Reels = self.reels_list[reels_id]
current_dt = datetime.now(EASTERN_TIME)
if now:
new_timeout = 0
else:
new_timeout = random.gauss(reel.timeout_mean, reel.timeout_std)
next_day = random.gauss(reel.timeout_mean, reel.timeout_std)
hour = int(random.gauss(HOUR_MEAN, HOUR_STD))
minute = random.randint(0, 59)
trigger_date = (current_dt + timedelta(days=next_day)).replace(hour=hour, minute=minute)
new_timeout = (trigger_date - current_dt).total_seconds()

reel.last_reel = datetime.now()
reel.last_reel = current_dt
logger.info(f"Next reel for {reels_id} is at {reel.last_reel + timedelta(seconds=new_timeout)}")
loop = asyncio.get_event_loop() if loop is None else loop
t = Timer(new_timeout, self.send_reel, kwargs={'reels_id': reels_id, 'loop': loop})
Expand Down

0 comments on commit 9b2fad1

Please sign in to comment.