import { parentReference } from "https://esm.town/v/stevekrouse/parentReference?v=3";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
import { runVal } from "https://esm.town/v/std/runVal";
export let ratelimit = async (limit: string, key?: string = "default", namespaceId?: string, namespacePassword?: string) : Promise<{
ok: boolean,
status: number,
remaining: number,
reset: number
}> => {
const [max, interval] = limit.split("/")
if (namespaceId) {
return await fetchJSON(
`https://rlimit.com/${namespaceId}/${max}/${interval}/${key}?password=${namespacePassword}®ion=global`,
);
}
const parent = parentReference();
const valUser = parent.userHandle;
return runVal("rlimit.rlimitValFreeTier", {
max: parseInt(max),
interval,
key,
valUser
});
};