HungerLib ships a set of time and scheduling utilities designed for common automation patterns around Pterodactyl servers — scheduling restarts at clean clock boundaries, running announcements during a countdown, and waiting for a server to reach a specific power state. All functions are importable directly fromDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/iFamishedX/HungerLib/llms.txt
Use this file to discover all available pages before exploring further.
hungerlib.
snapSchedule
Calculates the next clean restart time by snapping a minimum lead time forward to the nearest preferred minute mark within the hour. This is useful for scheduling restarts at predictable times (e.g. always at :00 or :30) rather than at arbitrary offsets from the current moment.
The minimum number of minutes from now before the restart can be scheduled. The function adds this to
datetime.now() to produce a minimum candidate time.A tuple of minute values within the hour to snap to, in ascending order. The function selects the first snap minute that is strictly greater than the minute of the minimum candidate time. If no snap minute qualifies in the current hour, it snaps to
:00 of the next hour.dict — a dictionary with four keys:
The current time at the moment
snapSchedule was called.now + timedelta(minutes=minimumMinutes) — the earliest acceptable restart time.The snapped
datetime object representing the calculated restart time, with seconds and microseconds zeroed out.The scheduled time formatted as a 12-hour clock string (e.g.
"04:30 PM"), suitable for announcement messages.minimumMinutes=20, the minimum candidate is 3:38 PM. With snapMinutes=(0, 30), neither :00 nor :30 is greater than :38, so the function snaps to 4:00 PM (the top of the next hour).
runCountdownEvents
Blocks the current thread until target_time is reached, firing registered callback functions at specified minute and second marks during the countdown. This is the primary mechanism for running pre-restart announcements.
The
datetime object representing when the countdown ends. The function returns immediately when datetime.now() >= target_time.A dictionary mapping integer minute counts (minutes remaining) to zero-argument callables. Each callable fires exactly once when the remaining time crosses the corresponding minute threshold. For example,
{5: my_func} calls my_func() when 5 minutes remain.A dictionary mapping integer second counts (seconds remaining) to zero-argument callables. Fires exactly once per registered threshold. For example,
{30: my_func} calls my_func() when 30 seconds remain.The polling interval in seconds between each iteration of the countdown loop. Lower values improve callback timing precision at the cost of more CPU wakeups. Defaults to
1.None — the function blocks until the countdown completes and then returns.
waitForOnline
Polls a server’s power state at a regular interval until it reports as online, or until a timeout is reached. Useful for pausing automation after triggering a server start.
A
GenericServer (or MinecraftServer) instance. The function calls server.isOnline() on each tick.The maximum number of seconds to wait before giving up. If the server has not come online within this window, the function returns
False.The number of seconds to sleep between each status check.
bool — True if the server came online within the timeout window, False if the timeout was reached.
waitForOffline
Polls a server’s power state until it reports as offline, or until a timeout is reached. Useful for confirming a clean shutdown before performing further actions such as file operations or backups.
A
GenericServer (or MinecraftServer) instance. The function calls server.isOffline() on each tick.The maximum number of seconds to wait. Returns
False if the server has not gone offline within this window.The number of seconds to sleep between each status check.
bool — True if the server went offline within the timeout, False otherwise.
secsUntil
Returns the number of whole seconds between now and a target datetime.
The future
datetime to measure against. The result is truncated (not rounded) to an integer via int().int — seconds remaining until target. Returns a negative number if target is in the past.
minsUntil
Returns the number of whole minutes between now and a target datetime by integer-dividing the total seconds by 60.
The future
datetime to measure against. Fractional minutes are truncated.int — whole minutes remaining until target. Returns a negative number if target is in the past.