A counting moderator but if a user gets the number wrong it resets! Tracks your High Score as well, how high can your server get? This Game requires teamwork as a user cannot count twice in a row, however if a user does there is no penalty.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
//catch
if (context.params.event.channel_id !== `${process.env.countingChannel}`) {
console.log(`not counting channel`);
return;
}
let countingKey = await lib.utils.kv['@0.1.16'].get({
key: `counting_${context.params.event.guild_id}`,
defaultValue: `0_0_0`,
});
let currentNumber = countingKey.split(`_`)[0];
let highScore = countingKey.split(`_`)[1];
let lastUser = countingKey.split(`_`)[2];
try {
if (context.params.event.author.id === lastUser) {
await lib.discord.channels['@0.3.0'].messages.destroy({
message_id: `${context.params.event.id}`,
channel_id: `${process.env.countingChannel}`,
});
console.log(`Author Error`);
return;
}
} catch (e) {
null;
}
//if number is one more than the counting number
if (
Number(context.params.event.content.split(' ')[0]) ===
Number(Number(currentNumber) + 1)
) {
//set new number
await lib.utils.kv['@0.1.16'].set({
key: `counting_${context.params.event.guild_id}`,
value: Number(Number(currentNumber) + 1) + `_` + highScore + `_${context.params.event.author.id}`,
});
//react
await lib.discord.channels['@0.3.0'].messages.reactions.create({
emoji: `✅`,
message_id: `${context.params.event.id}`,
channel_id: `${process.env.countingChannel}`,
});
console.log(Number(Number(currentNumber) + 1) + `_` + highScore + `_${context.params.event.author.id}`);
} else {
//if current number is higher than highScore
if (Number(currentNumber) > highScore) {
//fail message, new High Score
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${process.env.countingChannel}`,
content: `<@${context.params.event.author.id}> ruined it, but this sets our new **High Score** of **${currentNumber}**!`,
});
//set new score
await lib.utils.kv['@0.1.16'].set({
key: `counting_${context.params.event.guild_id}`,
value: Number(0) + `_` + currentNumber + `_${context.params.event.author.id}`,
});
} else {
//fail message
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${process.env.countingChannel}`,
content: `<@${context.params.event.author.id}> ruined it! Current high score is **${highScore}**.`,
});
//set new score
await lib.utils.kv['@0.1.16'].set({
key: `counting_${context.params.event.guild_id}`,
value: Number(0) + `_` + highScore + `_${context.params.event.author.id}`,
});
}
//react message
await lib.discord.channels['@0.3.0'].messages.reactions.create({
emoji: `❌`,
message_id: `${context.params.event.id}`,
channel_id: `${process.env.countingChannel}`,
});
}