Update src/plugins/replyPingControl/index.ts

Co-authored-by: rini <nil@dissoc.cc>
This commit is contained in:
ant0n 2023-11-12 19:41:08 +00:00 committed by GitHub
parent cab9e55f3c
commit c5fb9f8f24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,37 +24,28 @@ export default definePlugin({
authors: [Devs.ant0n, Devs.MrDiamond], authors: [Devs.ant0n, Devs.MrDiamond],
settings, settings,
patches: [ patches: [{
{ find: "_channelMessages",
find: "_channelMessages", replacement: {
replacement: { match: /receiveMessage\((\i)\)\{/,
match: /receiveMessage\((\i)\)\{/, replace: "$&$self.modifyMentions($1);"
replace: "$&$self.modifyMentions($1);"
}
} }
], }],
modifyMentions(message: MessageJSON) { modifyMentions(message: MessageJSON) {
const user = UserStore.getCurrentUser();
if (!this.isReplyToCurrentUser(message)) return; if (this.getRepliedMessage(message)?.author.id !== user.id)
return;
if (settings.store.alwaysPingOnReply) { if (!settings.store.alwaysPingOnReply)
if (!message.mentions.some(mention => mention.id === UserStore.getCurrentUser().id)) { message.mentions = message.mentions.filter(mention => mention.id !== user.id);
message.mentions.push(this.getCurrentUserMention()); else if (!message.mentions.some(mention => mention.id === user.id))
} message.mentions.push(user as any);
} else {
message.mentions = message.mentions.filter(mention => mention.id !== UserStore.getCurrentUser().id);
}
}, },
isReplyToCurrentUser(message: MessageJSON) { getRepliedMessage(message: MessageJSON) {
if (!message.message_reference) return false; const ref = message.message_reference;
const repliedMessage = MessageStore.getMessage(message.channel_id, message.message_reference.message_id); return ref && MessageStore.getMessage(ref.channel_id, ref.message_id);
return repliedMessage && repliedMessage.author.id === UserStore.getCurrentUser().id;
}, },
getCurrentUserMention() {
return UserStore.getCurrentUser() as unknown as UserJSON;
}
}); });