cream channel
This commit is contained in:
parent
4123a692b6
commit
8f04e136b1
|
@ -0,0 +1,22 @@
|
|||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { CommandInteraction, GuildMember } from 'discord.js';
|
||||
import { changeCounterInteraction } from '../lib/counter';
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('decrease2')
|
||||
.setDescription('Decrease the cream counter')
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('amount')
|
||||
.setRequired(false)
|
||||
.setDescription('Amount to decrease the counter by')
|
||||
.setMinValue(1)
|
||||
),
|
||||
|
||||
execute: async (interaction: CommandInteraction, member: GuildMember) => {
|
||||
await interaction.deferReply({ephemeral: true});
|
||||
const amount = Math.trunc(interaction.options.getInteger('amount') || 1);
|
||||
changeCounterInteraction(interaction, member, -amount);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,27 @@
|
|||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { CommandInteraction, GuildMember } from 'discord.js';
|
||||
import { changeCounterInteraction } from '../lib/counter';
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('increase2')
|
||||
.setDescription('Increase the cream counter')
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('amount')
|
||||
.setRequired(false)
|
||||
.setDescription('Amount to increase the counter by')
|
||||
.setMinValue(1)
|
||||
),
|
||||
|
||||
execute: async (interaction: CommandInteraction, member: GuildMember) => {
|
||||
if (member.id !== '212481359589933056')
|
||||
return await interaction.reply({
|
||||
ephemeral: true,
|
||||
content: 'you are not Dragon.'
|
||||
});
|
||||
await interaction.deferReply({ephemeral: true});
|
||||
const amount = Math.trunc(interaction.options.getInteger('amount') || 1);
|
||||
changeCounterInteraction(interaction, member, amount);
|
||||
}
|
||||
};
|
|
@ -3,50 +3,72 @@ import * as fsp from 'fs/promises';
|
|||
import { exists, getSign } from './util';
|
||||
|
||||
const counterFile = './counter.json';
|
||||
const counterFileCream = './counterCream.json';
|
||||
const counterMessageFile = './counterMessageID.txt';
|
||||
const counterCreamMessageFile = './counterCreamMessageID.txt';
|
||||
|
||||
const PISS_CHANNEL = '975802147126018150';
|
||||
export const EMOJI = '🪣';
|
||||
const CREAM_CHANNEL = '1098319707741900910';
|
||||
export const PISS_EMOJI = '🪣';
|
||||
export const CREAM_EMOJI = '<:PoolOfCum:1070350928240181340>';
|
||||
|
||||
function getCounterFile(cream: boolean) {
|
||||
return cream ? counterFileCream : counterFile;
|
||||
}
|
||||
|
||||
let counter = 0;
|
||||
|
||||
export async function initializeCounter() {
|
||||
if (await exists(counterFile)) {
|
||||
counter = parseInt(await fsp.readFile(counterFile, 'utf8'));
|
||||
export async function initializeCounter(cream: boolean) {
|
||||
const filename = getCounterFile(cream);
|
||||
if (await exists(filename)) {
|
||||
counter = parseInt(await fsp.readFile(filename, 'utf8'));
|
||||
} else {
|
||||
counter = 0;
|
||||
await saveCounter();
|
||||
await saveCounter(cream);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveCounter() {
|
||||
fsp.writeFile(counterFile, Math.trunc(counter).toString());
|
||||
async function saveCounter(cream: boolean) {
|
||||
fsp.writeFile(getCounterFile(cream), Math.trunc(counter).toString());
|
||||
}
|
||||
|
||||
export async function changeCounter(delta: number) {
|
||||
export async function changeCounter(delta: number, cream: boolean) {
|
||||
counter += delta;
|
||||
await saveCounter();
|
||||
await saveCounter(cream);
|
||||
return counter;
|
||||
}
|
||||
|
||||
async function getCounterMessageID() {
|
||||
if (await exists(counterMessageFile)) {
|
||||
const str = await fsp.readFile(counterMessageFile, 'utf8');
|
||||
function getCounterMessageFile(cream: boolean) {
|
||||
return cream ? counterMessageFile : counterCreamMessageFile;
|
||||
}
|
||||
|
||||
async function getCounterMessageID(cream: boolean) {
|
||||
const filename = getCounterMessageFile(cream);
|
||||
if (await exists(filename)) {
|
||||
const str = await fsp.readFile(filename, 'utf8');
|
||||
return str;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function saveCounterMessageID(id: string) {
|
||||
return fsp.writeFile(counterMessageFile, id);
|
||||
function saveCounterMessageID(id: string, cream: boolean) {
|
||||
return fsp.writeFile(getCounterMessageFile(cream), id);
|
||||
}
|
||||
|
||||
export async function updateCounter(bot: Client) {
|
||||
const channel = await bot.channels.fetch(PISS_CHANNEL) as TextChannel;
|
||||
const messageID = await getCounterMessageID();
|
||||
function getEmoji(cream: boolean) {
|
||||
return cream ? CREAM_EMOJI : PISS_EMOJI;
|
||||
}
|
||||
|
||||
const content = `[${EMOJI}] x${counter}`;
|
||||
function getChannel(cream: boolean) {
|
||||
return cream ? CREAM_CHANNEL : PISS_CHANNEL;
|
||||
}
|
||||
|
||||
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}`;
|
||||
|
||||
// bit janky
|
||||
try {
|
||||
|
@ -60,30 +82,30 @@ export async function updateCounter(bot: Client) {
|
|||
} catch(err) {
|
||||
const message = await channel.send(content);
|
||||
message.pin();
|
||||
await saveCounterMessageID(message.id);
|
||||
await saveCounterMessageID(message.id, cream);
|
||||
}
|
||||
}
|
||||
|
||||
export async function announceCounterUpdate(bot: Client, member: GuildMember, delta: number) {
|
||||
const channel = await bot.channels.fetch(PISS_CHANNEL) as TextChannel;
|
||||
export async function announceCounterUpdate(bot: Client, member: GuildMember, delta: number, cream: boolean) {
|
||||
const channel = await bot.channels.fetch(getChannel(cream)) as TextChannel;
|
||||
|
||||
const embed = new MessageEmbed()
|
||||
.setAuthor(`${member.user.username}#${member.user.discriminator}`, member.user.displayAvatarURL())
|
||||
.setDescription(`**${member.toString()}** has ${delta > 0 ? 'increased' : 'decreased'} the counter by **${Math.abs(delta)}**.`)
|
||||
.setColor(member.displayColor)
|
||||
.setTimestamp()
|
||||
.setFooter(`[${EMOJI}] x${counter}`);
|
||||
.setFooter(`[${getEmoji(cream)}] x${counter}`);
|
||||
|
||||
await channel.send({
|
||||
embeds: [embed]
|
||||
});
|
||||
}
|
||||
|
||||
export async function changeCounterInteraction(interaction: CommandInteraction, member: GuildMember, amount: number) {
|
||||
const newCount = await changeCounter(amount);
|
||||
await updateCounter(interaction.client);
|
||||
await announceCounterUpdate(interaction.client, member, amount);
|
||||
export async function changeCounterInteraction(interaction: CommandInteraction, member: GuildMember, amount: number, cream: boolean) {
|
||||
const newCount = await changeCounter(amount, cream);
|
||||
await updateCounter(interaction.client, cream);
|
||||
await announceCounterUpdate(interaction.client, member, amount, cream);
|
||||
interaction.followUp({
|
||||
content: `${EMOJI} **You have ${amount > 0 ? 'increased' : 'decreased'} the counter.**\n\`\`\`diff\n ${newCount - amount}\n${getSign(amount)}${Math.abs(amount)}\n ${newCount}\`\`\``
|
||||
content: `${getEmoji(cream)} **You have ${amount > 0 ? 'increased' : 'decreased'} the counter.**\n\`\`\`diff\n ${newCount - amount}\n${getSign(amount)}${Math.abs(amount)}\n ${newCount}\`\`\``
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue