From a2648e82ab485b6461af810f11c11d4b732e9b82 Mon Sep 17 00:00:00 2001 From: Supositware Date: Sun, 10 Feb 2019 01:49:01 +0100 Subject: [PATCH] Very hacky embed thingy --- event/listeners/message.js | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/event/listeners/message.js b/event/listeners/message.js index 94457229..be30b7a1 100644 --- a/event/listeners/message.js +++ b/event/listeners/message.js @@ -1,4 +1,5 @@ const { Listener } = require('discord-akairo'); +const { MessageEmbed } = require('discord.js'); const responseObject = require('../../json/reply.json'); const reactObject = require('../../json/react.json'); const imgResponseObject = require('../../json/imgreply.json'); @@ -51,6 +52,82 @@ class messageListener extends Listener { } text = rand.random(text, message); + // THIS SECTION IS VERY VERY BAD MUST CHANGE + if (text.includes('[embed]')) { + text = text.replace(/\[embed\]/, ' '); + + let title; + let desc; + let image; + let thumbnail; + + if (text.includes('[embedImage:')) { + image = text.split(/(\[embedImage:.*?])/); + + for (let i = 0, l = image.length; i < l; i++) { + if (image[i].includes('[embedImage:')) { + image = image[i].replace('[embedImage:', '').slice(0, -1); + i = image.length; + } + } + } + + if (text.includes('[embedThumbnail:')) { + thumbnail = text.split(/(\[embedThumbnail:.*?])/); + + for (let i = 0, l = thumbnail.length; i < l; i++) { + if (thumbnail[i].includes('[embedThumbnail:')) { + thumbnail = thumbnail[i].replace('[embedThumbnail:', '').slice(0, -1); + i = thumbnail.length; + } + } + } + + if (text.includes('[embedTitle:')) { + title = text.split(/(\[embedTitle:.*?])/); + console.log(title); + for (let i = 0, l = title.length; i < l; i++) { + if (title[i].includes('[embedTitle:')) { + title = title[i].replace('[embedTitle:', '').slice(0, -1); + i = title.length; + } + } + } + + if (text.includes('[embedDesc:')) { + desc = text.split(/(\[embedDesc:.*?])/); + console.log(desc); + for (let i = 0, l = desc.length; i < l; i++) { + if (desc[i].includes('[embedDesc:')) { + desc = desc[i].replace('[embedDesc:', '').slice(0, -1); + i = desc.length; + } + } + } + + + if (text.includes('[embedField:')) { + desc = text.split(/(\[embedDesc:.*?])/); + + for (let i = 0, l = desc.length; i < l; i++) { + if (desc[i].includes('[embedDesc:')) { + desc = desc[i].replace('[embedDesc:', '').slice(0, -1); + } + } + } + + const embed = new MessageEmbed() + .setColor() + .setTitle(title) + .setImage(image) + .setThumbnail(thumbnail) + .setDescription(desc) + .setTimestamp(); + + + return message.channel.send(embed); + } + message.channel.send(text); } }