Addon to MeltedButter77 counting channel snippet. Not only can you count and it gives a β
when it's correct and β when incorrect. It also gives π to each number that is above the highscore, as well as gives a role to the user that ruins the count, and removes the role from the previous user that ruined the count. It also now reacts with π― every time you reach a 100th number! You can also type text in this channel! (if you don't want anoyone to be able to type text in the channel just remove line 12)
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
//gathers information for your guild, channel, and role
const guild = context.params.event.guild_id;//your guild_id
const channel_id = `${process.env.channel}`//your channel_id
const role = `${process.env.role}`//the role you want it to give to someone
//catch (checks that the channel the message is sent in is the counting channel)
if (context.params.event.channel_id === channel_id) {
//this lets it ignore text
if(isNaN(context.params.event.content)) return;
//this creates a new date for the footer
const d = new Date();
const now = d.toLocaleString("en-US", {timeZone: "America/Chicago"});
//this sets the current number, highscore, and the last user to send a message and stores it
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];
//checks to see if the current person is the same as the last person to send a message
if (context.params.event.author.id === lastUser) {
console.log(context.params.event.author.id);
console.log(lastUser);
await lib.discord.channels['@0.3.0'].messages.destroy({
message_id: `${context.params.event.id}`,
channel_id: `${channel_id}`,
});
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: channel_id,
content: ``,
embed: {
title: ``,
description: `Hey! Give someone else a turn you bootyhead! :P`,
color: 0xffc0cb, // may be changed
footer: {
text:`Today at ${now} CST`,
},
},
});
console.log(`Author Error`);
return;
}
//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
let Num1 = Number(currentNumber) +1
if (parseInt(Num1) % 100 === 0) {
await lib.discord.channels['@0.3.0'].messages.reactions.create({
emoji: `π―`,
message_id: `${context.params.event.id}`,
channel_id: `${channel_id}`
});
} else if (Number(currentNumber) + 1 <= highScore) {
await lib.discord.channels['@0.3.0'].messages.reactions.create({
emoji: `β
`,
message_id: `${context.params.event.id}`,
channel_id: `${channel_id}`,
});
} else {
if (Number(currentNumber) +1 > highScore) {
await lib.discord.channels['@0.3.0'].messages.reactions.create({
emoji: `π`,
message_id: `${context.params.event.id}`,
channel_id: `${channel_id}`
});
}
}
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: channel_id,
content: ``,
embed: {
title: ``,
description: `<@${context.params.event.author.id}> ruined it, but this sets our new **High Score** of **${currentNumber}**!`,
color: 0xffc0cb, // may be changed
footer: {
text:`Today at ${now} CST`,
},
},
});
let ruinedIt = await lib.utils.kv['@0.1.16'].get({
key: `count_messup_${guild}`
});
console.log(ruinedIt);
//checks for the last user to ruin it, if there isn't one it saves the current user_id and gives them the role, otherwise it removes the role from the last user to ruin it and then gives it to the current user that ruined it
if (!ruinedIt) {
await lib.discord.guilds['@0.2.4'].members.roles.update({
role_id: `${role}`,
user_id: `${context.params.event.author.id}`,
guild_id: `${guild}`
});
} if (ruinedIt) {
await lib.discord.guilds['@0.2.4'].members.roles.destroy({
role_id: `${role}`,
user_id: `${ruinedIt}`,
guild_id: `${guild}`
});
await lib.discord.guilds['@0.2.4'].members.roles.update({
role_id: `${role}`,
user_id: `${context.params.event.author.id}`,
guild_id: `${guild}`
});
}
await lib.utils.kv['@0.1.16'].set({
key: `count_messup_${guild}`,
value: `${context.params.event.author.id}`
});
//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: channel_id,
content: ``,
embed: {
title: ``,
description: `<@${context.params.event.author.id}> ruined it! Current high score is **${highScore}**.`,
color: 0xffc0cb, // may be changed
footer: {
text:`Today at ${now} CST`,
},
},
});
let ruinedIt = await lib.utils.kv['@0.1.16'].get({
key: `count_messup_${guild}`
});
//checks for the last user to ruin it, if there isn't one it saves the current user_id and gives them the role, otherwise it removes the role from the last user to ruin it and then gives it to the current user that ruined it
if (!ruinedIt) {
await lib.discord.guilds['@0.2.4'].members.roles.update({
role_id: `${role}`,
user_id: `${context.params.event.author.id}`,
guild_id: `${guild}`
});
} if (ruinedIt) {
await lib.discord.guilds['@0.2.4'].members.roles.destroy({
role_id: `${role}`,
user_id: `${ruinedIt}`,
guild_id: `${guild}`
});
await lib.discord.guilds['@0.2.4'].members.roles.update({
role_id: `${role}`,
user_id: `${context.params.event.author.id}`,
guild_id: `${guild}`
});
}
await lib.utils.kv['@0.1.16'].set({
key: `count_messup_${guild}`,
value: `${context.params.event.author.id}`
});
//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}`,
});
}
await lib.discord.channels['@0.3.0'].messages.reactions.create({
emoji: `β`,
message_id: `${context.params.event.id}`,
channel_id: channel_id,
});
}
} else {
console.log(`not counting channel`);
return;
}