Fix custom emojis in reaction roles
This commit is contained in:
parent
0f0ca1dc57
commit
65a9bb2c65
1 changed files with 10 additions and 9 deletions
|
@ -3,7 +3,7 @@ import { CustomEmoji, errorMessage, isSnowflake } from "../utils";
|
||||||
import { GuildReactionRoles } from "../data/GuildReactionRoles";
|
import { GuildReactionRoles } from "../data/GuildReactionRoles";
|
||||||
import { Channel, Message, TextChannel } from "eris";
|
import { Channel, Message, TextChannel } from "eris";
|
||||||
|
|
||||||
type ReactionRolePair = [string, string];
|
type ReactionRolePair = [string, string, string?];
|
||||||
|
|
||||||
export class ReactionRolesPlugin extends Plugin {
|
export class ReactionRolesPlugin extends Plugin {
|
||||||
public static pluginName = "reaction_roles";
|
public static pluginName = "reaction_roles";
|
||||||
|
@ -80,9 +80,9 @@ export class ReactionRolesPlugin extends Plugin {
|
||||||
.map(v => v.split("=").map(v => v.trim())) // tslint:disable-line
|
.map(v => v.split("=").map(v => v.trim())) // tslint:disable-line
|
||||||
.map(
|
.map(
|
||||||
(pair): ReactionRolePair => {
|
(pair): ReactionRolePair => {
|
||||||
const customEmojiMatch = pair[0].match(/^<:(.*?):(\d+)>$/);
|
const customEmojiMatch = pair[0].match(/^<a?:(.*?):(\d+)>$/);
|
||||||
if (customEmojiMatch) {
|
if (customEmojiMatch) {
|
||||||
return [`${customEmojiMatch[1]}:${customEmojiMatch[2]}`, pair[1]];
|
return [customEmojiMatch[2], pair[1], customEmojiMatch[1]];
|
||||||
} else {
|
} else {
|
||||||
return pair as ReactionRolePair;
|
return pair as ReactionRolePair;
|
||||||
}
|
}
|
||||||
|
@ -112,9 +112,11 @@ export class ReactionRolesPlugin extends Plugin {
|
||||||
for (const rolePair of toRemove) {
|
for (const rolePair of toRemove) {
|
||||||
await this.reactionRoles.removeFromMessage(targetMessage.id, rolePair[0]);
|
await this.reactionRoles.removeFromMessage(targetMessage.id, rolePair[0]);
|
||||||
|
|
||||||
for (const reaction of Object.values(targetMessage.reactions)) {
|
for (const emoji of Object.keys(targetMessage.reactions)) {
|
||||||
if (reaction.emoji.id === rolePair[0] || reaction.emoji.name === rolePair[0]) {
|
const emojiId = emoji.includes(":") ? emoji.split(":")[1] : emoji;
|
||||||
reaction.remove(this.bot.user.id);
|
|
||||||
|
if (emojiId === rolePair[0]) {
|
||||||
|
targetMessage.removeReaction(emoji, this.bot.user.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,10 +128,9 @@ export class ReactionRolesPlugin extends Plugin {
|
||||||
for (const rolePair of toAdd) {
|
for (const rolePair of toAdd) {
|
||||||
let emoji;
|
let emoji;
|
||||||
|
|
||||||
if (isSnowflake(rolePair[0])) {
|
if (rolePair[2]) {
|
||||||
// Custom emoji
|
// Custom emoji
|
||||||
const guildEmoji = guildEmojis.find(e => e.id === emoji.id);
|
emoji = `${rolePair[2]}:${rolePair[0]}`;
|
||||||
emoji = `${guildEmoji.name}:${guildEmoji.id}`;
|
|
||||||
} else {
|
} else {
|
||||||
// Unicode emoji
|
// Unicode emoji
|
||||||
emoji = rolePair[0];
|
emoji = rolePair[0];
|
||||||
|
|
Loading…
Add table
Reference in a new issue