Got the scheduler to work this is before mass directory restructure
This commit is contained in:
parent
52d245296a
commit
90099c2417
4 changed files with 82 additions and 27 deletions
Binary file not shown.
2
bot.py
2
bot.py
|
|
@ -16,7 +16,7 @@ from discord.ext.commands import (
|
||||||
import yaml
|
import yaml
|
||||||
from scheduler import start_scheduler
|
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)
|
settings = yaml.safe_load(f)
|
||||||
|
|
||||||
ROAST_COOLDOWN_SECONDS = settings["cooldowns"]["roast"]
|
ROAST_COOLDOWN_SECONDS = settings["cooldowns"]["roast"]
|
||||||
|
|
|
||||||
72
scheduler.py
72
scheduler.py
|
|
@ -3,35 +3,69 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
import yaml
|
import yaml
|
||||||
|
import datetime
|
||||||
|
from ai import get_ai_response
|
||||||
|
|
||||||
import discord
|
def load_settings():
|
||||||
|
|
||||||
def load_scheduler_settings():
|
|
||||||
with open("settings.yml", "r", encoding="utf-8") as f:
|
with open("settings.yml", "r", encoding="utf-8") as f:
|
||||||
config = yaml.safe_load(f)
|
return yaml.safe_load(f)["scheduler"]
|
||||||
return config["scheduler"]
|
|
||||||
|
last_post_time = None
|
||||||
|
post_chance = None
|
||||||
|
|
||||||
async def start_scheduler(bot):
|
async def start_scheduler(bot):
|
||||||
settings = load_scheduler_settings()
|
settings = load_settings()
|
||||||
|
|
||||||
if not settings["enabled"]:
|
if not settings["enabled"]:
|
||||||
print("⏰ Scheduler disabled.")
|
print("🛑 Scheduler disabled in config.")
|
||||||
return
|
return
|
||||||
|
|
||||||
interval = settings.get("interval_minutes", 60)
|
interval = settings["interval_minutes"]
|
||||||
channel_id = settings.get("channel_id")
|
channel = bot.get_channel(settings["channel_id"])
|
||||||
messages = settings.get("messages", [])
|
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()
|
await bot.wait_until_ready()
|
||||||
|
print(f"🕒 Delta Scheduler started in {mode.upper()} mode.")
|
||||||
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():
|
while not bot.is_closed():
|
||||||
msg = random.choice(messages)
|
now = datetime.datetime.utcnow()
|
||||||
await channel.send(msg)
|
|
||||||
|
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)
|
await asyncio.sleep(interval * 60)
|
||||||
|
|
|
||||||
35
settings.yml
35
settings.yml
|
|
@ -1,15 +1,36 @@
|
||||||
cooldowns:
|
cooldowns:
|
||||||
global: 15 # seconds between *any* commands from the same user
|
global: 10 # seconds between *any* commands from the same user
|
||||||
roast: 60 # seconds
|
roast: 60 # seconds
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
cooldown:
|
cooldown:
|
||||||
- "🕒 Chill, mortal. You must wait {seconds}s before trying again. 😼"
|
- "🕒 Chill, mortal. You must wait {seconds}s before trying again. 😼"
|
||||||
|
|
||||||
scheduler:
|
scheduler:
|
||||||
enabled: true
|
enabled: true
|
||||||
interval_minutes: 0.5 # how often to post
|
mode: simple # <- this activates simple mode
|
||||||
channel_id: 1104824796233080914 # replace with your #general channel ID
|
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:
|
messages:
|
||||||
- "Good morning, mortals."
|
- "🎭 Delta has entered the chat. Act cool or be roasted."
|
||||||
- "Anyone still alive in here? 👀"
|
- "🧍♂️ Is this a server or a graveyard? Delta demands signs of life!"
|
||||||
- "Delta demands your attention."
|
- "🌈 Rise and grind, peasants. Your RGB goddess has arrived."
|
||||||
- "Time for your daily dose of chaos. 😈"
|
- "🔧 System check: All mortals still disappointing? Thought so."
|
||||||
|
- "🔥 New day, new drama. Who’s starting it?"
|
||||||
|
- "😼 Don’t mind me, just raising the server’s IQ by logging in."
|
||||||
|
- "💤 Server’s 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."
|
||||||
|
- "🦄 Delta’s here to sprinkle some magic. Don’t waste it."
|
||||||
|
|
||||||
|
probabilistic:
|
||||||
|
start_chance: 0.05
|
||||||
|
increase_per_interval: 0.05
|
||||||
|
decay_on_post: 0.02
|
||||||
|
|
||||||
|
inactivity:
|
||||||
|
threshold_minutes: 120
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue