Skip to content

Commit d52f52b

Browse files
committed
v5 Update 9 (Hotfix)
Ah yes. Bugs. Nothing's perfect, ay? * Fixed Reaction Roles to fully support custom emojis (and error checking if emoji is not resolvable) * Created 'guildDelete' event. * Added new function to 'app.js' to help out returning emoji data. * Added reason for Reaction Roles.
1 parent b16aafa commit d52f52b

5 files changed

Lines changed: 62 additions & 20 deletions

File tree

src/app/cfg/app.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,18 @@ const app = {
320320
for (var i = 0; i < length; i++) { code += random.charAt(Math.floor(Math.random() * random.length)); };
321321
return code;
322322
},
323+
getEmoji: function(app, emojiID, full = false) {
324+
var emoji = app.client.emojis.cache.find(e => e.id === emojiID) || null;
325+
326+
var theEmoji = emoji;
327+
if (emoji && full) {
328+
theEmoji = "<";
329+
if (emoji.animated)
330+
emoji += ":a";
331+
theEmoji += ":" + emoji["name"] + ":" + emoji["id"] + ">";
332+
};
333+
return theEmoji || null;
334+
},
323335
getID: function(string) { return string.replace(/[<#@&!>]/g, ''); },
324336
doesArrayStartsWith: function(string, array) { return array.findIndex((item) => { return item.startsWith(string); }, string) != -1; },
325337

src/app/cmds/Moderation/reactionroles.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ module.exports = {
2222
try {
2323
if (!serverSettings) throw new Error("No server in database"); // How did they even do this command?
2424
var cData = [];
25-
await message.guild.channels.cache.forEach(channel => {
26-
if (channel.type == "GUILD_TEXT")
27-
cData.push({
28-
label: "#" + ((channel["id"] == message.channel.id) ? `${channel["name"]} (This channel)` : channel["name"]),
29-
description: channel["topic"] || "No topic.",
30-
value: channel["id"]
31-
});
25+
var bigChannelSize = (message.guild.channels.cache.size > 25),
26+
filteredChannels = await message.guild.channels.cache.filter(c => c.type == "GUILD_TEXT").map(x => ({ x, r: Math.random() })).sort((a, b) => a.r - b.r).map(a => a.x).slice(0, 25);
27+
await filteredChannels.forEach(channel => {
28+
var topic = (channel["topic"]) ? channel["topic"].match(/.{1,100}/g)[0] : "No topic.";
29+
cData.push({
30+
label: "#" + ((channel["id"] == message.channel.id) ? `${channel["name"]} (This channel)` : channel["name"]),
31+
description: topic,
32+
value: channel["id"]
33+
});
3234
});
3335

3436
var channelID = 0,
@@ -38,11 +40,13 @@ module.exports = {
3840
customDesc = "";
3941

4042

43+
var warning = (bigChannelSize) ? app.config.system.emotes.warning + "**You have more than the amount of channels we can show (25).** The list is random. If you do not see your desired channel, send `cancel` and rerun this command." : "";
44+
4145
await app.functions.msgHandler(msg, {
4246
embeds: [{
4347
title: `${app.config.system.emotes.question} Reaction Roles - Select Channel`,
4448
color: app.config.system.embedColors.purple,
45-
description: "Alright - from the dropdown - What channel are we going to be setting this up in?"
49+
description: "Alright - from the dropdown - What channel are we going to be setting this up in?\n" + warning,
4650
}],
4751
components: [new MessageActionRow()
4852
.addComponents(
@@ -141,8 +145,6 @@ module.exports = {
141145
const filter = m => { return m.author.id === message.author.id };
142146
const collector = message.channel.createMessageCollector({ filter, time: 90000, errors: ["time"] });
143147

144-
var reactionroles = [];
145-
146148
collector.on("collect", async m => {
147149
if (m.content == "done") {
148150
collector.stop("done");
@@ -158,7 +160,7 @@ module.exports = {
158160
}, 1, true, (async() => {
159161
var channel = message.guild.channels.cache.get(channelID),
160162
reactionsList = [];
161-
for (var reaction in reactions) { reactionsList.push(reactions[reaction]["emoji"] + " " + reactions[reaction]["roleMsg"]); };
163+
for (var reaction in reactions) { reactionsList.push((app.functions.getEmoji(app, reactions[reaction]["emoji"]["id"], true) || reactions[reaction]["emoji"]["name"]) + " " + reactions[reaction]["roleMsg"]); };
162164
await channel.send({
163165
embeds: [{
164166
title: customTitle,
@@ -167,7 +169,7 @@ module.exports = {
167169
}).then(msg => {
168170
messageID = msg.id;
169171

170-
for (var reaction in reactions) { msg.react(reactions[reaction]["emoji"]); };
172+
for (var reaction in reactions) { msg.react(reactions[reaction]["emoji"]["id"]); };
171173
}).catch(err => new Error(err));
172174

173175
var data = JSON.parse(serverSettings["reactionRoles"]) || {};
@@ -205,12 +207,34 @@ module.exports = {
205207
roleMsg = splitMsg[1],
206208
roleID = app.functions.getID(splitMsg[2]) || splitMsg[2];
207209

210+
console.log(emoji);
211+
if (emoji.startsWith("<:") || emoji.startsWith(":")) {
212+
emoji = app.functions.getID(emoji);
213+
if (emoji.startsWith("a:")) emoji = emoji.split("a:")[1]
214+
emoji = emoji.split(":")[2];
215+
216+
const theEmoji = await app.client.emojis.cache.find(e => e.id === emoji) || false;
217+
218+
if (!theEmoji) {
219+
m.react(app.config.system.emotes.error).catch(err => {});
220+
app.functions.msgHandler(m, { content: "Cannot use that custom emoji. Must be emoji from server I'm in!\n(You can also use built-in Discord emojis)" }, 0, true, (async errMsg => { setTimeout(() => { errMsg.delete() }, 10000) }));
221+
return;
222+
};
223+
emoji = { name: theEmoji["name"], id: theEmoji["id"] };
224+
} else
225+
emoji = { name: emoji, id: 0 };
208226
reactions.push({
209227
emoji: emoji,
210228
roleID: roleID,
211229
roleMsg: roleMsg
212230
});
213231

232+
if (exMsg) {
233+
var embs = exMsg.embeds;
234+
embs[0].description += ((reactions.length < 1) ? "\n" : "") + "\n" + ((app.functions.getEmoji(app, emoji["id"], true) || emoji["name"]) + " " + roleMsg);
235+
exMsg.edit({ embeds: embs }).catch(err => {});
236+
};
237+
214238
m.react(app.config.system.emotes.success).catch(err => {});
215239
};
216240
});

src/app/evts/guildDelete.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = async(app, oldGuild) => {
2+
app.logger.info("DISCORD", `Removed from the server: ${oldGuild.name} (${oldGuild.id}).`);
3+
};

src/app/evts/messageReactionAdd.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ module.exports = async(app, reaction, user) => {
2424
for (var i = 0; i < reactionRoles.length; i++) {
2525
try {
2626
var data = reactionRoles[i];
27-
if (data["emoji"] === reactionThing) {
27+
if (data["emoji"]["name"] === reactionThing || data["emoji"]["id"] == reactionThing) {
2828
const member = guild.members.cache.get(user.id),
2929
role = guild.roles.cache.get(data["roleID"]);
30-
member.roles.add(role).catch(err => {});
30+
member.roles.add(role, "Reaction Role").catch(err => {});
31+
return;
3132
};
3233
} catch (Ex) {
33-
app.logger.error("SYS", `Unable to give user ${user.id} the role ${data["roleID"]}...`)
34+
app.logger.error("SYS", `Unable to give user ${user.id} the role ${data["roleID"]}...`);
35+
return;
3436
};
35-
return;
3637
};
3738
};
3839
};

src/app/evts/messageReactionRemove.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ module.exports = async(app, reaction, user) => {
2424
for (var i = 0; i < reactionRoles.length; i++) {
2525
try {
2626
var data = reactionRoles[i];
27-
if (data["emoji"] === reactionThing) {
27+
if (data["emoji"]["name"] === reactionThing || data["emoji"]["id"] == reactionThing) {
2828
const member = guild.members.cache.get(user.id),
2929
role = guild.roles.cache.get(data["roleID"]);
30-
member.roles.remove(role).catch(err => {});
30+
member.roles.remove(role, "Reaction Role").catch(err => {});
31+
32+
return;
3133
};
3234
} catch (Ex) {
33-
app.logger.error("SYS", `Unable to remove user ${user.id} from role ${data["roleID"]}...`)
35+
app.logger.error("SYS", `Unable to remove user ${user.id} from role ${data["roleID"]}...`);
36+
return;
3437
};
35-
return;
3638
};
3739
};
3840
};

0 commit comments

Comments
 (0)