From 90099c2417bd53abab7e832be3dc07bcea4f5cd0 Mon Sep 17 00:00:00 2001 From: milo Date: Fri, 9 May 2025 11:51:15 -0400 Subject: [PATCH] Got the scheduler to work this is before mass directory restructure --- __pycache__/scheduler.cpython-310.pyc | Bin 1179 -> 1904 bytes bot.py | 2 +- scheduler.py | 72 +++++++++++++++++++------- settings.yml | 35 ++++++++++--- 4 files changed, 82 insertions(+), 27 deletions(-) diff --git a/__pycache__/scheduler.cpython-310.pyc b/__pycache__/scheduler.cpython-310.pyc index 25bce367fc854e72a450aa771a91252f1a095488..f4a8f007023b667e0610d3fd04d33df1680c215f 100644 GIT binary patch literal 1904 zcmYjS&5s*36t`z4Gn22~>^9wQS_H$#fkm)VPpztoRsE5nl(WDiVoHB?LGA0Z#l0SX>aN-Z*oC=Si|!kNj*uKR^H8hu?^1vxcDk zvhniZRu!SY?c!u}U~v_?+5til#VLyCBaU&oc4DU--PncENxiHRS1_V3^&X+vrcE4Di zAdRO^fo7OiI_N%f0GJ2gk&Dq?bRMbBLyVFAK88+#x8>g+Hx$#F=Y6$(n572Gab=|U z-nj@^LY60j!j`G3WWeYsWpc|ko*1&+c!vbUtBUNgUMdI$dA#==N$b9UuO*kdA1NkP zH{<;g>wb{4>yjU^?sbujGL~!A-4Pj!Zjs$CbIsyk+!-3~^&;*2VU_9nv_3;Rcz`4=ciz$g zAgp!}UG1O?hy?koAlm}jCxyG;nA82{{t9H<+G9Kk3%>|A(R6i&==wP{sTNf@--7d} zI_N<~KCxPhK>l9%#J9S^lBGp$dV1zuggbOg2Xy1eT33-j(KC~pUMp%xcv8=6fN;G$ zwMjdDJafQv^}?N=D(W+Q!V6~sT^oFGuBbmn&phh~eR{f4ICQ-Y-d;-1eIsw$sFW%B z(rpv4ob0BMaIZlu|M}tRm(ks2{zZ^3)g{##cNWrZA2ag9mmmZVsi`CA&Q3O7kRcC{3j9*>ef&fB&6r&##Q462Z4$ zMb}xX$q5{#IHMNE*pKWL+waGxd7el{;D#ZSy(Ox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ord.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"] diff --git a/scheduler.py b/scheduler.py index d85af1d..2066e31 100644 --- a/scheduler.py +++ b/scheduler.py @@ -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) diff --git a/settings.yml b/settings.yml index cafc23e..966998e 100644 --- a/settings.yml +++ b/settings.yml @@ -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. ๐Ÿ˜ˆ" \ No newline at end of file + - "๐ŸŽญ 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. 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