38 lines
962 B
Python
38 lines
962 B
Python
|
|
# scheduler.py
|
||
|
|
|
||
|
|
import asyncio
|
||
|
|
import random
|
||
|
|
import yaml
|
||
|
|
|
||
|
|
import discord
|
||
|
|
|
||
|
|
def load_scheduler_settings():
|
||
|
|
with open("settings.yml", "r", encoding="utf-8") as f:
|
||
|
|
config = yaml.safe_load(f)
|
||
|
|
return config["scheduler"]
|
||
|
|
|
||
|
|
async def start_scheduler(bot):
|
||
|
|
settings = load_scheduler_settings()
|
||
|
|
|
||
|
|
if not settings["enabled"]:
|
||
|
|
print("⏰ Scheduler disabled.")
|
||
|
|
return
|
||
|
|
|
||
|
|
interval = settings.get("interval_minutes", 60)
|
||
|
|
channel_id = settings.get("channel_id")
|
||
|
|
messages = settings.get("messages", [])
|
||
|
|
|
||
|
|
await bot.wait_until_ready()
|
||
|
|
|
||
|
|
channel = bot.get_channel(channel_id)
|
||
|
|
if not channel:
|
||
|
|
print(f"⚠️ Scheduler Error: Channel ID {channel_id} not found.")
|
||
|
|
return
|
||
|
|
|
||
|
|
print(f"🕒 Delta Scheduler active — posting every {interval}min in #{channel.name}")
|
||
|
|
|
||
|
|
while not bot.is_closed():
|
||
|
|
msg = random.choice(messages)
|
||
|
|
await channel.send(msg)
|
||
|
|
await asyncio.sleep(interval * 60)
|