LibreY/misc/cooldowns.php

23 lines
630 B
PHP
Raw Normal View History

2023-08-25 08:23:53 -07:00
<?php
function load_cooldowns() {
2023-08-25 11:09:06 -07:00
if (function_exists("apcu_fetch"))
return apcu_exists("cooldowns") ? apcu_fetch("cooldowns") : array();
return array();
2023-08-25 08:23:53 -07:00
}
function save_cooldowns($cooldowns) {
2023-08-25 11:09:06 -07:00
if (function_exists("apcu_store"))
apcu_store("cooldowns", $cooldowns);
2023-08-25 08:23:53 -07:00
}
function set_cooldown($instance, $timeout, $cooldowns) {
$cooldowns[$instance] = time() + $timeout;
save_cooldowns($cooldowns);
return $cooldowns;
}
function has_cooldown($instance, $cooldowns) {
return ($cooldowns[$instance] ?? 0) > time();
}
?>