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);
}
