add task to reload subscriptions every 24h

This commit is contained in:
un1xx committed 2025-08-27 21:35:35 +05:30
1 parent 4137b8bd36
commit 252c97f5b2
2 files changed
+14 -3

No files matched your search

+4 -3
View File
@@ -7,6 +7,7 @@ from typing import List, Literal, Optional
import discord
from discord.ext import commands, tasks
from discord.guild import GuildChannel
import pnwkit
import pytz
from pnwkit import Order, OrderBy
@@ -113,7 +114,7 @@ class Misc(commands.Cog):
)
def seconds_until_target(self, hour: int, minute: int = 0):
now = datetime.datetime.utcnow()
now = datetime.datetime.now()
target = now.replace(hour=hour, minute=minute, second=0, microsecond=0)
if target < now:
target += datetime.timedelta(days=1)
@@ -135,9 +136,9 @@ class Misc(commands.Cog):
for nation in res.nations:
if nation.vacation_mode_turns != 0:
continue
utcnow = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
utcnow = datetime.datetime.now().replace(tzinfo=pytz.utc)
delta = utcnow - nation.last_active
if delta > datetime.timedelta(days=4, hours=12):
if delta > datetime.timedelta(days=3, hours=12):
inactives.append(nation)
if inactives:
await channel.send(
+10
View File
@@ -74,6 +74,16 @@ class WarMonitor(commands.Cog):
self.monitored_wars = []
self.allied_nations = []
@tasks.loop(hours=24)
async def reload_subscriptions(self):
self.war_create_task.cancel()
self.war_update_task.cancel()
self.war_attacks_task.cancel()
self.war_create_task = self.bot.loop.create_task(self.war_create_subscription())
self.war_update_task = self.bot.loop.create_task(self.war_update_subscription())
self.war_attacks_task = self.bot.loop.create_task(self.warattack_subscription())
@commands.Cog.listener()
async def on_ready(self):
category = await self.bot.fetch_channel(CATEGORY)