From c751b7613ea62e4eeaaacd6b18240d855eef7aae Mon Sep 17 00:00:00 2001 From: milo Date: Fri, 9 May 2025 18:34:39 -0400 Subject: [PATCH] Moved logic into simple on the scheduler dir. Cleaned up code and made things more modular --- src/scheduler/__init__.py | 75 +++--------------- .../__pycache__/__init__.cpython-310.pyc | Bin 2071 -> 1123 bytes .../__pycache__/inactivity.cpython-310.pyc | Bin 0 -> 175 bytes .../__pycache__/probabilistic.cpython-310.pyc | Bin 0 -> 178 bytes .../__pycache__/simple.cpython-310.pyc | Bin 0 -> 1052 bytes src/scheduler/simple.py | 34 ++++++++ 6 files changed, 47 insertions(+), 62 deletions(-) create mode 100644 src/scheduler/__pycache__/inactivity.cpython-310.pyc create mode 100644 src/scheduler/__pycache__/probabilistic.cpython-310.pyc create mode 100644 src/scheduler/__pycache__/simple.cpython-310.pyc diff --git a/src/scheduler/__init__.py b/src/scheduler/__init__.py index 8453d7f..0c48895 100644 --- a/src/scheduler/__init__.py +++ b/src/scheduler/__init__.py @@ -1,78 +1,29 @@ -# __init__.py formaly scheduler.py - import os -import asyncio -import random import yaml -import datetime -from ai import get_ai_response +import asyncio +from . import simple, probabilistic, inactivity def load_settings(): - base_dir = os.path.dirname(os.path.dirname(__file__)) # go up one level from /scheduler/ + base_dir = os.path.dirname(os.path.dirname(__file__)) # go up from /scheduler/ settings_path = os.path.join(base_dir, "settings.yml") with open(settings_path, "r", encoding="utf-8") as f: return yaml.safe_load(f) -last_post_time = None -post_chance = None - async def start_scheduler(bot): settings = load_settings() - scheduler_settings = settings["scheduler"] + scheduler_settings = settings.get("scheduler", {}) if not scheduler_settings.get("enabled", False): print("🛑 Scheduler disabled in config.") return + mode = scheduler_settings.get("mode", "simple").lower() - interval = scheduler_settings["interval_minutes"] - channel_id = scheduler_settings["channel_id"] - channel = bot.get_channel(channel_id) - mode = scheduler_settings.get("mode", "simple") - use_ai = scheduler_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() - print(f"🕒 Delta Scheduler started in {mode.upper()} mode.") - - while not bot.is_closed(): - 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(scheduler_settings.get("messages", ["Hello from Delta."])) - - await channel.send(message) - print(f"📤 Scheduled message sent to #{channel.name}: {message}") - - await asyncio.sleep(interval * 60) + if mode == "simple": + await simple.run(bot, scheduler_settings, settings) + elif mode == "probabilistic": + await probabilistic.run(bot, scheduler_settings, settings) + elif mode == "inactivity": + await inactivity.run(bot, scheduler_settings, settings) + else: + print(f"❓ Unknown scheduler mode: {mode}") diff --git a/src/scheduler/__pycache__/__init__.cpython-310.pyc b/src/scheduler/__pycache__/__init__.cpython-310.pyc index 6922a8c849ed6f37af8dc1cb17c9590ba6c1b6ce..f3eee1f44ffb8b7751c579fe2e32d9e97ac9532d 100644 GIT binary patch delta 649 zcmZuu&2AGh5cb$!uNx&Hq5<^~K_s}WkhpL|P;rDyFBJ!JLFsyFt?o}`J5&`L6;xiJ z$^ikYlzjnSf(PL4Bb@pM9FSnV(1K7c&ChzinQy-JyTLcvuX?=>!Sm(SjlJ*eq(6d3 zCwE5AsA4%Q_=FeHBr3#208v~;Z^v(UVC2Iv#!h1JC@&wOuYs-5YM z&b4(q^&MSKQ>R~Qci6lKSYLhsbtJIG2JRvBV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k9pP=k1v7dXifK_%JfA_m(ZgIWeGWoMHUZ*(!Ebxzg&GZ z{`T@>a`*E1_D$FiNeE(6hX7ar{!mB&0hbWXMMlzaz?33AX7TAh3l9WOSSY%4J6Qa3v7eskSMc;hEyCx<&c(2Org*c) zg$im)LkTW0HCs&=;V=OunrRNT$sg$?6NhFcB}x~j#>IZkTD=H^X&w@&7Nbn_6sj?y zN2W9yf^SWQt2jx8V$}GOWK;}Hy->8U0uliDHKQ@nrYzYoB?&VPEi@zvRCJM1W!wSz zMB1N<@sqywkMY17NSLB{mWevb5-vRE5?O-W`bqGiq=mu_N0iJU>S6|Y4w&D zcFQeT$!)vkg3(b8VmE@ATU(>X9JuNg4u~q8Ldl-{2vT$~1OpaU6_t2S)~v48dCs2T z*nmxS8;J9n4;8fT1lYrY8{jIg!&mj7wmK~wI92R9fdf2F9s78_m^Y#7Hi6%BJiHAO zp6dZ^IZbEF(m&+|P~5J`5)ATHOJ1;~X2~-^j6-dJ^o9BCA!+$t_Q9u9y diff --git a/src/scheduler/__pycache__/inactivity.cpython-310.pyc b/src/scheduler/__pycache__/inactivity.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4e8fc5b61ea0692c255de7d4cf3492cce22c7d17 GIT binary patch literal 175 zcmd1j<>g`kg2&df8DJVjAOl7q#{r0oS%5?eLokCTqu)w~B9JhG_!X3F6%$&VT2vg9 zo0(pk8sndr>Qas5198;W} pk(yGPlUfv$nU|Pcl3A8nQmI!^d5gm)Hyg`kg6r0@86f&Gh(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o100*(xTqIJKxa zCO0#^G&ROQFV&?evn(~nB|o_|H#M)MIL0GCH&wwWF)1b`vp6}wC`BPDza*x(C^@D$ tIU_ZtG$*wvrl2T4DKRNCC$qRDGg+^o@)n0pZazrL4rE<16OdqG000UtE&Kog literal 0 HcmV?d00001 diff --git a/src/scheduler/__pycache__/simple.cpython-310.pyc b/src/scheduler/__pycache__/simple.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c6715db44f279ebaa9b55e66cbf6dbf07e8f09fb GIT binary patch literal 1052 zcmYjQPm2^e6i-ssRn;{;fBb_Ys00?ohGkBB5D^g>*b!uQarDw#OA#xX?no+WlGMnI z)v$}pet|uT*bQF%9DCmnkgEsrCVSkIue#gW3FN(cFE8)?-Y>7r=4OsyeR_3s@+?N^ zV`rRS1dIo;-47r*;#i^4O5+h;+GIpP6BX6*D8>-MdOYIsA83?te29j<&u|kR3~|^V z3tuu>TH&TfJ5fd5$$E7#64-ykcK?9*9eeZw&G7;;(qfLUp;-i)fR0-^yC5K=WVT{q-k3l=V~z>Z*z0jS`l!%FAQ1 zd;0We<2+^5O^o#vau_cwYAmhc^w`KsP;*50g!1hBrSHj) z4{62xSX#9kvh@XbdSPEEW$2ML^(uO|xw-=Np8m2z^(#FT+EZ`ncc2P!;;pm6bA1 zaNCVxNG#Lb)FG)RT`wVaLh}%72IW%bPIM(r=s6|CbeM^C zQfFq!zP*a=#xbO8Y!?0o6r!$$WC}z~eMr{?eL(g)9R7Du-7TIuVO>$naU+VKwAi!o zK*gS^ni}YF#lEQpeaxO0T)N6wP61TmY*n1$D%|pwcc&*IvW?ClvAYF={Fal9WH`qI zyahTVIgW80#o)P2cF2`Z{%dbS=rFaHK-uk1q#y!ea!Hx(cdjmGiTIr8hAd?FYST^D ReGHZxfXEP3f{HO2kgxGqDVqQQ literal 0 HcmV?d00001 diff --git a/src/scheduler/simple.py b/src/scheduler/simple.py index e69de29..2d03e22 100644 --- a/src/scheduler/simple.py +++ b/src/scheduler/simple.py @@ -0,0 +1,34 @@ +import asyncio +import random +import datetime +from ai import get_ai_response + +last_post_time = None + +async def run(bot, scheduler_settings, full_settings): + global last_post_time + last_post_time = datetime.datetime.utcnow() + + interval = scheduler_settings["interval_minutes"] + channel_id = scheduler_settings["channel_id"] + channel = bot.get_channel(channel_id) + use_ai = scheduler_settings.get("use_ai", True) + + await bot.wait_until_ready() + print("📆 Simple scheduler active.") + + while not bot.is_closed(): + now = datetime.datetime.utcnow() + last_post_time = now + + # 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(scheduler_settings.get("messages", ["Hello from Delta."])) + + await channel.send(message) + print(f"📤 [Simple] Sent to #{channel.name}: {message}") + + await asyncio.sleep(interval * 60)