fix(Moyai): not playing sound when reacting

This commit is contained in:
kmmiio99o 2026-07-02 13:39:04 +02:00
parent ba5c4fe706
commit 400398829e
No known key found for this signature in database
GPG key ID: AC9D7747D423B9BF
2 changed files with 9 additions and 3 deletions

View file

@ -13,6 +13,6 @@
], ],
"main": "src/index.ts", "main": "src/index.ts",
"vendetta": { "vendetta": {
"icon": "ic_speaker" "icon": "VoiceNormalIcon"
} }
} }

View file

@ -64,15 +64,20 @@ function onMessage(event) {
} }
} }
const recentReactions = new Set<string>();
function onReaction(event) { function onReaction(event) {
try { try {
if ( if (
(storage.allowReactions ?? true) && (storage.allowReactions ?? true) &&
event.channelId == SelectedChannelStore.getChannelId() && event.channelId == SelectedChannelStore.getChannelId()
!event.optimistic
) { ) {
const name = event.emoji?.name; const name = event.emoji?.name;
if (name === "🗿" || (name && /moy?ai/i.test(name))) { if (name === "🗿" || (name && /moy?ai/i.test(name))) {
const key = `${event.messageId}:${name}`;
if (recentReactions.has(key)) return;
recentReactions.add(key);
setTimeout(() => recentReactions.delete(key), 500);
playSound(); playSound();
} }
} }
@ -97,6 +102,7 @@ export default {
onUnload: () => { onUnload: () => {
FluxDispatcher.unsubscribe("MESSAGE_CREATE", onMessage); FluxDispatcher.unsubscribe("MESSAGE_CREATE", onMessage);
FluxDispatcher.unsubscribe("MESSAGE_REACTION_ADD", onReaction); FluxDispatcher.unsubscribe("MESSAGE_REACTION_ADD", onReaction);
recentReactions.clear();
}, },
settings: MoyaiSettings, settings: MoyaiSettings,
}; };