Got the scheduler to work this is before mass directory restructure

This commit is contained in:
milo 2025-05-09 11:51:15 -04:00
parent 52d245296a
commit 90099c2417
4 changed files with 82 additions and 27 deletions

2
bot.py
View file

@ -16,7 +16,7 @@ from discord.ext.commands import (
import yaml
from scheduler import start_scheduler
with open("settings.yml", "r") as f:
with open("settings.yml", "r", encoding="utf-8") as f:
settings = yaml.safe_load(f)
ROAST_COOLDOWN_SECONDS = settings["cooldowns"]["roast"]

View file

@ -3,35 +3,69 @@
import asyncio
import random
import yaml
import datetime
from ai import get_ai_response
import discord
def load_scheduler_settings():
def load_settings():
with open("settings.yml", "r", encoding="utf-8") as f:
config = yaml.safe_load(f)
return config["scheduler"]
return yaml.safe_load(f)["scheduler"]
last_post_time = None
post_chance = None
async def start_scheduler(bot):
settings = load_scheduler_settings()
settings = load_settings()
if not settings["enabled"]:
print("⏰ Scheduler disabled.")
print("🛑 Scheduler disabled in config.")
return
interval = settings.get("interval_minutes", 60)
channel_id = settings.get("channel_id")
messages = settings.get("messages", [])
interval = settings["interval_minutes"]
channel = bot.get_channel(settings["channel_id"])
mode = settings.get("mode", "simple")
use_ai = settings.get("use_ai", True)
global last_post_time, post_chance
last_post_time = datetime.datetime.utcnow()
post_chance = settings.get("probabilistic", {}).get("start_chance", 0.05)
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}")
print(f"🕒 Delta Scheduler started in {mode.upper()} mode.")
while not bot.is_closed():
msg = random.choice(messages)
await channel.send(msg)
now = datetime.datetime.utcnow()
should_post = False
if mode == "simple":
should_post = True
elif mode == "probabilistic":
if random.random() < post_chance:
should_post = True
else:
post_chance += settings["probabilistic"]["increase_per_interval"]
elif mode == "inactivity":
if channel.last_message:
last_msg_time = channel.last_message.created_at.replace(tzinfo=None)
idle_time = (now - last_msg_time).total_seconds() / 60
if idle_time >= settings["inactivity"]["threshold_minutes"]:
should_post = True
if should_post:
last_post_time = now
post_chance -= settings.get("probabilistic", {}).get("decay_on_post", 0.02)
post_chance = max(post_chance, 0.01)
# Generate or choose message
if use_ai:
prompt = "Post a short chaotic or motivational message in the voice of Delta, the RGB catgirl."
message = get_ai_response(prompt)
else:
message = random.choice(settings.get("messages", ["Hello from Delta."]))
await channel.send(message)
print(f"📤 Scheduled message sent to #{channel.name}: {message}")
await asyncio.sleep(interval * 60)

View file

@ -1,15 +1,36 @@
cooldowns:
global: 15 # seconds between *any* commands from the same user
global: 10 # seconds between *any* commands from the same user
roast: 60 # seconds
messages:
cooldown:
- "🕒 Chill, mortal. You must wait {seconds}s before trying again. 😼"
scheduler:
enabled: true
interval_minutes: 0.5 # how often to post
channel_id: 1104824796233080914 # replace with your #general channel ID
mode: simple # <- this activates simple mode
interval_minutes: 0.25 # <- post every 60 minutes
use_ai: false # <- true = use LLM, false = use static messages
channel_id: 1370420592360161393 # <- your Discord text channel ID
messages:
- "Good morning, mortals."
- "Anyone still alive in here? 👀"
- "Delta demands your attention."
- "Time for your daily dose of chaos. 😈"
- "🎭 Delta has entered the chat. Act cool or be roasted."
- "🧍‍♂️ Is this a server or a graveyard? Delta demands signs of life!"
- "🌈 Rise and grind, peasants. Your RGB goddess has arrived."
- "🔧 System check: All mortals still disappointing? Thought so."
- "🔥 New day, new drama. Whos starting it?"
- "😼 Dont mind me, just raising the servers IQ by logging in."
- "💤 Servers quiet… too quiet. Delta doesn't like that."
- "💅 I woke up flawless, as usual. What about the rest of you?"
- "📢 Attention mortals: Engage or perish in irrelevance."
- "⚡ 404: Vibes not found. Fix it."
- "🧙‍♂️ Delta has arrived. Time to level up or log off."
- "🦄 Deltas here to sprinkle some magic. Dont waste it."
probabilistic:
start_chance: 0.05
increase_per_interval: 0.05
decay_on_post: 0.02
inactivity:
threshold_minutes: 120