add: emoteMessage.js

This commit is contained in:
Neko Life 2021-05-27 22:52:52 +00:00
parent 3f02eb70d0
commit 986ac3e8d6
3 changed files with 38 additions and 2 deletions

View file

@ -1,6 +1,7 @@
'use strict';
const commando = require("@iceprod/discord.js-commando");
const emoteMessage = require("../../resources/emoteMessage");
const { ranLog, trySend, tryDelete } = require("../../resources/functions");
module.exports = class say extends commando.Command {
@ -17,6 +18,7 @@ module.exports = class say extends commando.Command {
if (!args) {
args = noArgs;
}
args = emoteMessage(this.client, args);
const sendThis = {content:args, disableMentions:"all"};
if (msg.member?.hasPermission("ADMINISTRATOR")) {
sendThis.disableMentions = "none";

View file

@ -1,5 +1,6 @@
'use strict';
const commando = require("@iceprod/discord.js-commando");
const emoteMessage = require("../../resources/emoteMessage");
const { ranLog, errLog, trySend, sentAdCheck, tryReact, findChannelRegEx, cleanMentionID } = require("../../resources/functions");
module.exports = class send extends commando.Command {
@ -19,7 +20,7 @@ module.exports = class send extends commando.Command {
return trySend(this.client, msg, 'Where?!?');
}
const search = cleanMentionID(comarg[0]),
sendTheMes = args.slice(comarg[0].length).trim();
sendTheMes = emoteMessage(this.client, args.slice(comarg[0].length).trim());
let channel;
if (/^\d{17,19}$/.test(search)) {
channel = msg.guild.channels.cache.get(search);
@ -27,7 +28,12 @@ module.exports = class send extends commando.Command {
if (!channel) {
channel = findChannelRegEx(msg, search, ["category", "voice"])[0];
if (!channel) {
return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>");
if (this.client.owners.includes(msg.author.id)) {
channel = this.client.channels.cache.get(search);
}
if (!channel) {
return trySend(this.client, msg, "That channel is like your gf. Doesn't exist <:cathmmLife:772716381874946068>");
}
}
}
if (!channel.permissionsFor(msg.author).has("SEND_MESSAGES") || !channel.permissionsFor(msg.author).has("VIEW_CHANNEL")) {

28
resources/emoteMessage.js Normal file
View file

@ -0,0 +1,28 @@
'use strict';
module.exports = function emoteMessage(client, content) {
const emotes = content.match(/(?<![<a]):\w{1,32}:(?!\d{17,19}>)/g);
if (emotes.length > 0) {
let theEmotes = [];
for (const emoteName of emotes) {
let findThis = emoteName.slice(1, -1);
const findEmote = client.emojis.cache.array();
let found;
for (const emote of findEmote) {
if (emote.name.toLowerCase() === findThis.toLowerCase()) {
found = emote;
break;
}
}
theEmotes.push(found);
}
if (theEmotes.length > 0) {
for (let index = 0; index < emotes.length; index++) {
if (theEmotes[index]) {
content = content.replace(emotes[index], `<${theEmotes[index].animated ? "a" : ""}:${theEmotes[index].name}:${theEmotes[index].id}>`);
}
}
}
}
return content;
}