oops! 3
This commit is contained in:
parent
df53475884
commit
e75d3a2e8f
|
@ -16,26 +16,44 @@ function getCounterFile(cream: boolean) {
|
|||
return cream ? counterFileCream : counterFile;
|
||||
}
|
||||
|
||||
let counter = 0;
|
||||
let pissCounter = 0;
|
||||
let creamCounter = 0;
|
||||
|
||||
export async function initializeCounter(cream: boolean) {
|
||||
const filename = getCounterFile(cream);
|
||||
if (await exists(filename)) {
|
||||
counter = parseInt(await fsp.readFile(filename, 'utf8'));
|
||||
const count = parseInt(await fsp.readFile(filename, 'utf8'));
|
||||
if (cream) {
|
||||
creamCounter = count;
|
||||
} else {
|
||||
pissCounter = count;
|
||||
}
|
||||
} else {
|
||||
counter = 0;
|
||||
if (cream) {
|
||||
creamCounter = 0;
|
||||
} else {
|
||||
pissCounter = 0;
|
||||
}
|
||||
await saveCounter(cream);
|
||||
}
|
||||
}
|
||||
|
||||
function getCounter(cream: boolean) {
|
||||
return cream ? creamCounter : pissCounter;
|
||||
}
|
||||
|
||||
async function saveCounter(cream: boolean) {
|
||||
fsp.writeFile(getCounterFile(cream), Math.trunc(counter).toString());
|
||||
fsp.writeFile(getCounterFile(cream), Math.trunc(getCounter(cream)).toString());
|
||||
}
|
||||
|
||||
export async function changeCounter(delta: number, cream: boolean) {
|
||||
counter += delta;
|
||||
if (cream) {
|
||||
creamCounter += delta;
|
||||
} else {
|
||||
pissCounter += delta;
|
||||
}
|
||||
await saveCounter(cream);
|
||||
return counter;
|
||||
return getCounter(cream);
|
||||
}
|
||||
|
||||
function getCounterMessageFile(cream: boolean) {
|
||||
|
@ -68,7 +86,7 @@ export async function updateCounter(bot: Client, cream: boolean) {
|
|||
const channel = await bot.channels.fetch(getChannel(cream)) as TextChannel;
|
||||
const messageID = await getCounterMessageID(cream);
|
||||
|
||||
const content = `[${getEmoji(cream)}] x${counter}`;
|
||||
const content = `[${getEmoji(cream)}] x${getCounter(cream)}`;
|
||||
|
||||
// bit janky
|
||||
try {
|
||||
|
@ -94,7 +112,7 @@ export async function announceCounterUpdate(bot: Client, member: GuildMember, de
|
|||
.setDescription(`**${member.toString()}** has ${delta > 0 ? 'increased' : 'decreased'} the counter by **${Math.abs(delta)}**.`)
|
||||
.setColor(member.displayColor)
|
||||
.setTimestamp()
|
||||
.setFooter(`[${getEmoji(cream)}] x${counter}`);
|
||||
.setFooter(`[${getEmoji(cream)}] x${getCounter(cream)}`);
|
||||
|
||||
await channel.send({
|
||||
embeds: [embed]
|
||||
|
|
Loading…
Reference in New Issue