import client from "./client.js";

export function generalException(location: string) {
    client.noLog.push(location);
    setTimeout(() => {
        client.noLog = client.noLog.filter((i: string) => {
            return i !== location;
        });
    }, 1000);
}

export function messageException(guild: string, channel: string, message: string) {
    generalException(`${guild}/${channel}/${message}`);
}

export function roleException(guild: string, user: string) {
    generalException(`${guild}/${user}`);
}

export function preloadPage(target: string, command: string, message: string) {
    client.preloadPage[target] = {
        command: command,
        argument: message
    }
    setTimeout(() => {
        const object = Object.entries(client.preloadPage).filter((entry) => {
            const [k, _] = entry
            return k !== target;
        })
        client.preloadPage = Object.fromEntries(object);
    }, 60 * 5 * 1000);
}
