This snippet is for counting guild custom emoji combo sent in a specific channel. Note that you have to configure the channel_id in the endpoint trigger. The counting is based on the emoji sent in a message. This means that multiple emojis in one message will only count as one. Best played with multiple users and with slowmode on the channel! Keep in mind that only custom emojis in your guild is allowed!
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const message = context.params.event.content;
const CHANNEL_ID = context.params.event.channel_id;
const COMBO_COUNT = 3; //This is the number of emoji combo to win
let id,
ids = message.match(/[^<:]+(?=>)/g);
if (ids && ids.length > 0) {
id = ids[ids.length - 1];
let result = await lib.discord.guilds['@0.2.4'].emojis.list({
guild_id: `${context.params.event.guild_id}`,
});
let emojis = result.map((r) => {
return r.id;
});
if (emojis.includes(id)) {
let lastEmoji = await lib.keyvalue.store['@0.1.16'].get({
key: `LAST_EMOJI_${CHANNEL_ID}`,
defaultValue: {id: ``, count: 0},
});
if (lastEmoji.id == id && lastEmoji.count >= COMBO_COUNT - 1) {
let winner = result.find((r) => r.id == lastEmoji.id);
let emojiBuilder = `<`;
emojiBuilder += winner.animated ? `a:` : `:`;
emojiBuilder += `${winner.name}:${winner.id}>`;
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${CHANNEL_ID}`,
content: `${emojiBuilder} wins! Combo **x${COMBO_COUNT}**`,
});
await lib.keyvalue.store['@0.1.16'].clear({
key: `LAST_EMOJI_${CHANNEL_ID}`,
});
} else if (lastEmoji.id == id) {
let i = lastEmoji.count + 1;
await lib.keyvalue.store['@0.1.16'].set({
key: `LAST_EMOJI_${CHANNEL_ID}`,
value: {id: id, count: i},
});
} else if (lastEmoji.id != id) {
await lib.keyvalue.store['@0.1.16'].set({
key: `LAST_EMOJI_${CHANNEL_ID}`,
value: {id: id, count: 1},
});
}
}
}