feat: Implement delayed start for daily rank changes check
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8db5a25595
commit
1e953b8146
@ -8,6 +8,7 @@ import utils
|
|||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import asyncio
|
||||||
|
|
||||||
sentry_sdk.init(
|
sentry_sdk.init(
|
||||||
dsn="https://272f1e4ecb3847ac8d24be796515e558@o4506942768021504.ingest.us.sentry.io/4506986058743808",
|
dsn="https://272f1e4ecb3847ac8d24be796515e558@o4506942768021504.ingest.us.sentry.io/4506986058743808",
|
||||||
@ -133,7 +134,7 @@ async def heartbeat():
|
|||||||
async def check_rank_changes(channel):
|
async def check_rank_changes(channel):
|
||||||
logger.info("Checking for rank changes")
|
logger.info("Checking for rank changes")
|
||||||
try:
|
try:
|
||||||
data = dota.check_rank_changes_for_discord()
|
data = await dota.check_rank_changes_for_discord()
|
||||||
if data:
|
if data:
|
||||||
logger.info(f"Sending rank changes: {data}")
|
logger.info(f"Sending rank changes: {data}")
|
||||||
await channel.send(content=data['content'], embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']])
|
await channel.send(content=data['content'], embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']])
|
||||||
@ -141,24 +142,24 @@ async def check_rank_changes(channel):
|
|||||||
logger.error(f"Error checking rank changes: {e}")
|
logger.error(f"Error checking rank changes: {e}")
|
||||||
sentry_sdk.capture_exception(e)
|
sentry_sdk.capture_exception(e)
|
||||||
|
|
||||||
|
@check_rank_changes.before_loop
|
||||||
|
async def before_check_rank_changes():
|
||||||
|
# 等待到晚上9点再开始第一次运行
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
target_time = now.replace(hour=21, minute=0, second=0, microsecond=0)
|
||||||
|
if now >= target_time:
|
||||||
|
target_time = target_time + datetime.timedelta(days=1)
|
||||||
|
|
||||||
|
seconds_until_target = (target_time - now).total_seconds()
|
||||||
|
await asyncio.sleep(seconds_until_target)
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
channel = bot.get_channel(channel_id)
|
channel = bot.get_channel(channel_id)
|
||||||
send_message.start(channel)
|
send_message.start(channel)
|
||||||
heartbeat.start()
|
heartbeat.start()
|
||||||
|
|
||||||
# Start the rank check task and make it run at a specific time (e.g., noon)
|
# 启动天梯检查任务
|
||||||
check_rank_changes.start(channel)
|
check_rank_changes.start(channel)
|
||||||
|
|
||||||
# Calculate time until next noon
|
|
||||||
now = datetime.datetime.now()
|
|
||||||
target_time = now.replace(hour=21, minute=0, second=0, microsecond=0)
|
|
||||||
if now >= target_time:
|
|
||||||
target_time = target_time + datetime.timedelta(days=1)
|
|
||||||
|
|
||||||
# Adjust first run to happen at noon
|
|
||||||
seconds_until_target = (target_time - now).total_seconds()
|
|
||||||
check_rank_changes.change_interval(hours=24)
|
|
||||||
check_rank_changes.next_iteration = discord.utils.utcnow() + datetime.timedelta(seconds=seconds_until_target)
|
|
||||||
|
|
||||||
bot.run('MTE1MjE2NTc3NDMwNDIyMzI2Mg.GEi-17.VvuIkRy_cFD9XF6wtTagY95LKEbTxKaxy-FxGw') # 这里替换成你自己的 token
|
bot.run('MTE1MjE2NTc3NDMwNDIyMzI2Mg.GEi-17.VvuIkRy_cFD9XF6wtTagY95LKEbTxKaxy-FxGw') # 这里替换成你自己的 token
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user