Sends a special gif when a comment has reactions that resemble the konami code. I.e. 2x🔼, 2x🔽, 2x◀, 2x▶, 1x🅱️, 1x🅰️ in that exact order and quantity.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const {message_id, channel_id} = context.params.event;
const {reactions} = await lib.discord.channels['@0.1.2'].messages.retrieve({
message_id,
channel_id,
});
// Get a random gif to embed when the konami is activated
const gifs = [
'https://media.giphy.com/media/4hnQDVKVARZ6w/giphy.gif',
'https://media.giphy.com/media/PiQejEf31116URju4V/giphy.gif',
'https://media.giphy.com/media/4H3Ii5eLChYul9p7NL/giphy.gif',
];
const randomGif = gifs[Math.floor(Math.random() * gifs.length)];
// Checks if the given emoji is in the right position and has the right count
const isValid = (index, emoji, count) => {
const reaction = reactions[index];
return (
!!reaction && reaction.emoji.name === emoji && reaction.count === count
);
};
// Is the code in the right order and with the right counts?
if (
reactions.length === 6 &&
isValid(0, '🔼', 2) &&
isValid(1, '🔽', 2) &&
isValid(2, '◀', 2) &&
isValid(3, '▶', 2) &&
isValid(4, '🅱️', 1) &&
isValid(5, '🅰️', 1)
) {
// Lock the message from further konamis
await lib.discord.channels['@0.1.2'].messages.reactions.create({
channel_id,
message_id,
emoji: `🎮`,
});
// Konami!
await lib.discord.channels['@0.1.2'].messages.create({
channel_id,
content: `Konami activated! 🎮`,
embed: {
type: 'rich',
title: '',
description: '',
color: 0x00ffff,
image: {
url: randomGif,
},
},
});
}