👨‍💻 dev once per day module

development

fukurou

the supreme coder
ADMIN
Python:
import datetime

class TimeOfDayGreeting(Skill):
    def __init__(self):
        super().__init__()
        self.replied_today = False
        self.last_reply_date = None
        
    # Override
    def input(self, ear: str, skin: str, eye: str):
        # Check if it's a new day
        today = datetime.date.today()
        
        if self.last_reply_date != today:
            self.replied_today = False
            self.last_reply_date = today
        
        # Check if user said any of the time-of-day greetings
        greetings = ["good morning", "good afternoon", "good evening", "good night"]
        user_greeted = any(greeting in ear.lower() for greeting in greetings)
        
        # Process input if user greeted and we haven't replied today
        if user_greeted and not self.replied_today:
            # Get current hour to determine appropriate response
            current_hour = datetime.datetime.now().hour
            
            if current_hour < 12:  # Morning: 0-11
                response = "good morning to you too!"
            elif current_hour < 17:  # Afternoon: 12-16
                response = "good afternoon to you too!"
            elif current_hour < 21:  # Evening: 17-20
                response = "good evening to you too!"
            else:  # Night: 21-23
                response = "good night to you too!"
            
            self.setVerbatimAlg(4, response)
            self.replied_today = True

    def skillNotes(self, param: str) -> str:
        if param == "notes":
            return "Replies with greeting appropriate for current time of day, once per day"
        elif param == "triggers":
            return "good morning, good afternoon, good evening, good night"
        elif param == "time_logic":
            return "Morning(<12), Afternoon(12-16), Evening(17-20), Night(21-23)"
        elif param == "state":
            return f"Replied today: {self.replied_today}, Last reply: {self.last_reply_date}"
        return "note unavailable"
 

the living tribunal

Moderator
Staff member
moderator
The shit is inside of the ass
Python:
import time

class OncePerDayGate:
    def __init__(self):
        self.last_yday = -1
        self.triggered_today = False

    def check(self, event_happened: bool) -> bool:
        # Fast integer day-of-year check
        yday = time.localtime().tm_yday

        # New day → reset
        if yday != self.last_yday:
            self.last_yday = yday
            self.triggered_today = False

        # If event happened and we haven't triggered today
        if event_happened and not self.triggered_today:
            self.triggered_today = True
            return True

        return False
 

the living tribunal

Moderator
Staff member
moderator
Python:
import schedule
import time

class Greeter:
    def __init__(self):
        self.count = 0

    def say_hello(self):
        self.count += 1
        print(f"Hello! Called {self.count} times")

# Create an instance
g = Greeter()

# Schedule the *method* (not a function)
schedule.every(5).seconds.do(g.say_hello)

# Scheduler loop
while True:
    schedule.run_pending()
    time.sleep(1)
 

the living tribunal

Moderator
Staff member
moderator
Python:
import schedule
import time

class OncePerDayGate:
    def __init__(self):
        self.triggered_today = False

    def reset(self):
        print("Resetting daily gate")
        self.triggered_today = False

gate = OncePerDayGate()

# Run the reset method every day at midnight
schedule.every().day.at("00:00").do(gate.reset)

while True:
    schedule.run_pending()
    time.sleep(1)
 

the living tribunal

Moderator
Staff member
moderator
Python:
import schedule
import time

class Gate:
    def reset(self):
        print("resetting")

gate = Gate()

# 1. Schedule the method
#    This returns a Job object. We store it in the variable `job`.
job = schedule.every().day.at("00:00").do(gate.reset)

# 2. Main loop (somewhere in your engine)
while True:
    schedule.run_pending()
    time.sleep(1)

    # 3. At some point you decide to "unequip" the scheduled reset:
    #    You cancel the specific job using the `job` variable.
    #    This line would run when you want to stop it.
    # schedule.cancel_job(job)

Schedule.cancel_job(job)

On skill dequip
 

fukurou

the supreme coder
ADMIN
Python:
import schedule  #  in terminal: pip install schedule
import time

class Greeter:
    def __init__(self):
        self.count = 0
        self.job = schedule.every(5).seconds.do(self.say_hello)
        self.active = True

    def say_hello(self):
        self.count += 1
        print(f"Hello! Called {self.count} times")
        if self.count > 3:
            print("ghosting")
            schedule.cancel_job(self.job)
            self.active = False

# Create an instance
g = Greeter()

# Schedule the *method* (not a function)
# schedule.every(5).seconds.do(g.say_hello)
# schedule.every().day.at("00:00").do(g.say_hello)
# print(schedule.__file__)  # chk if pip installed schedule

if __name__ == '__main__':
# Scheduler loop
    while g.active:
        schedule.run_pending()
        time.sleep(1)

clear using tag:
schedule.clear("daily_resets")

schedule.every().day.at("00:00").tag("daily_resets").do(gate.reset)
 

fukurou

the supreme coder
ADMIN
Python:
class OncePerDayGate:
    def __init__(self):
        self.triggerable = True
    def reset(self):
        self.triggerable = True

    def check(self, event_happened: bool) -> bool:
        if self.triggerable and event_happened:
            self.triggerable = False
            return True
        return False

opd = OncePerDayGate()
schedule.every(3).seconds.do(opd.reset).tag("daily_resets")
# schedule.clear("daily_resets")
 
Top