Use the command to make a new poll and resend the message and attachments to the poll channel then reacts on it using the emojis included in the message.
//This is the prefix command variant of the poll maker. I made a message.create variant where you only need to send a message with emojis in it in the designated channel.
//This one uses a command and reposts it to the designated poll channel.
//Made by Lilac🍥Syringa🌸
//Prefix command endpoit immediately followed up by a line break doesn't trigger it, keep that in mind.
//Apparently, the regex i'm using does not support emoji (face and hand) tones and specifically black cat emoji. In this case, it thinks they're the normal variant (the default yellow version).
//Example msg:
//!makepoll Favourite Colour? 🟥🟧🟨🟩 (The command can be made on any channels.)
//Then the bot will repost these message to a different channel while removing "!makepoll " part and reacting to its own message with those emojis.
//Attachment supports included, though links are going to be stuffed inside the embed which aren't going to be displayed.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const sleep = async (ms) => new Promise((r) => setTimeout(r, ms));
const secondsCountDown = 5;
const Channel_Id = context.params.event.channel_id
const PollMSG = context.params.event.content;
const PollChannels = `Channel ID of the poll channel here`; //Put the channel id of the designated poll channel here.
//Permissions:
//Send Messages and Create Posts
//Manage Messages
//Add Reactions
//Use External Emojis (optional)
let emojiContent = PollMSG.match(
/(<:.+?:\d+>|(?<=<)a:.+?:\d+(?=>))|(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g
);
//Regex to match both custom and default emojis.
await lib.discord.channels['@0.3.2'].messages.destroy({
//Deletes the original message.
message_id: `${context.params.event.id}`,
channel_id: `${Channel_Id}`,
});
async function RemovePromptMsg(secondsCountDown, Channel_Id, prompt_Message, sleep) {
for (let i = secondsCountDown; i > 0; i--) {
await sleep(1000);
}
var Prompt_destroy = await lib.discord.channels['@0.2.0'].messages.destroy({
message_id: prompt_Message.id,
channel_id: `${Channel_Id}`,
});
return {Prompt_destroy}
//Removes the prompt msg. Which will be referenced below.
}
//Checks if there were valid emojis.
if (emojiContent == null) {
//No emojis detected.
var prompt_Message = await lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${Channel_Id}`,
content: `No emoji detected, please use an emoji so I know what to react with, <@${context.params.event.author.id}>.`,
});
//Prompt msg.
await RemovePromptMsg(secondsCountDown, Channel_Id, prompt_Message, sleep)
return
} else {
//There are emojis detected.
var prompt_Message = await lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${Channel_Id}`,
content: `Poll successfully sent in <#${PollChannels}>, <@${context.params.event.author.id}>.`,
});
}
var PrefixStuff = PollMSG.match(/^.*? /gi);
var StandardMSG = PollMSG.slice(PrefixStuff[0].length)
//Removes the prefix cmd from the message. This should be adaptive to some extent. Autocode cmd needs to have a space thereafter, should be aight.
if (context.params.event.attachments[0] == null) {
//Checks if there are attachments present on the message.
var FileArray = null; //No attachments.
var EmbedField = null
var AttachmentNum = 0
} else {
var EmbedField = [
{
name: `\u200B`,
value: `**__Attachments above__**`
}
]
//Can make EmbedField into null if you don't want this message.
//If there are, it checks, and compiles them.
//The stuff are are similar to Upload Images and Videos to a Channel From a Bot (Improved ver.)
var FileArray = new Array();
for (
var AttachmentNum = 0;
AttachmentNum < context.params.event.attachments.length;
AttachmentNum++
) {
var FileType = context.params.event.attachments[AttachmentNum].content_type.slice(6, 9);
switch (FileType) {
case `qui`:
FileType = `mov`;
break;
case `jpe`:
FileType = `jpg`;
break;
case `x-m`:
FileType = `wmv`;
break;
};
var SpecificBuffer = await lib.http.request['@1.1.5']({
method: 'GET',
url: `${context.params.event.attachments[AttachmentNum].url}`,
}).then((result) => {
return result.body;
});
var CurrentFile = {
file: Buffer.from(SpecificBuffer),
filename: `${context.params.event.attachments[AttachmentNum].id}.${FileType}`,
};
CurrentFile + `,`;
FileArray.push(CurrentFile);
}
}
var mainMSG = await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${PollChannels}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: ``,
description: `${StandardMSG}`,
color: 0xffd085,
fields: EmbedField,
author: {
name: `${context.params.event.author.username}`,
icon_url: `https://cdn.discordapp.com/avatars/${context.params.event.author.id}/${context.params.event.author.avatar}`,
}
}
],
attachments: FileArray,
});
for (let reactCount = 0; reactCount < emojiContent.length; reactCount++) {
//loop function
await lib.discord.channels['@0.2.2'].messages.reactions.create({
emoji: `${emojiContent[reactCount]}`,
message_id: `${mainMSG.id}`,
channel_id: `${PollChannels}`,
});
}
await RemovePromptMsg(secondsCountDown - Math.round((1+AttachmentNum)/2), Channel_Id, prompt_Message, sleep)