3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

starboard: fix starboards accepting any emoji instead of just the specified one

This commit is contained in:
Dragory 2019-11-30 23:39:12 +02:00
parent 29d0bc3a18
commit 546835d421

View file

@ -10,6 +10,7 @@ import {
TDeepPartialProps,
tNullable,
tDeepPartial,
UnknownUser,
} from "../utils";
import path from "path";
import moment from "moment-timezone";
@ -181,13 +182,34 @@ export class StarboardPlugin extends ZeppelinPlugin<TConfigSchema> {
}
}
const user = await this.resolveUser(userId);
if (user instanceof UnknownUser) return;
if (user.bot) return;
const config = this.getConfigForMemberIdAndChannelId(userId, msg.channel.id);
const applicableStarboards = Object.values(config.boards).filter(board => board.enabled);
const applicableStarboards = Object.values(config.boards)
.filter(board => board.enabled)
// Can't star messages in the starboard channel itself
.filter(board => board.channel_id !== msg.channel.id)
// Matching emoji
.filter(board => {
return board.star_emoji.some((boardEmoji: string) => {
if (emoji.id) {
// Custom emoji
const customEmojiMatch = boardEmoji.match(/^<?:.+?:(\d+)>?$/);
if (customEmojiMatch) {
return customEmojiMatch[1] === emoji.id;
}
return boardEmoji === emoji.id;
} else {
// Unicode emoji
return emoji.name === boardEmoji;
}
});
});
for (const starboard of applicableStarboards) {
// Can't star messages in the starboard channel itself
if (msg.channel.id === starboard.channel_id) continue;
// Save reaction into the database
await this.starboardReactions.createStarboardReaction(msg.id, userId).catch();