3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-21 16:55:03 +00:00
zeppelin/backend/src/plugins/Counters/functions/resetAllCounterValues.ts
2021-05-03 19:33:30 +03:00

18 lines
661 B
TypeScript

import { GuildPluginData } from "knub";
import { counterIdLock } from "../../../utils/lockNameHelpers";
import { CountersPluginType } from "../types";
export async function resetAllCounterValues(pluginData: GuildPluginData<CountersPluginType>, counterName: string) {
const config = pluginData.config.get();
const counter = config.counters[counterName];
if (!counter) {
throw new Error(`Unknown counter: ${counterName}`);
}
const counterId = pluginData.state.counterIds[counterName];
const lock = await pluginData.locks.acquire(counterIdLock(counterId));
await pluginData.state.counters.resetAllCounterValues(counterId);
lock.unlock();
}