Skip to content

Commit bf6091b

Browse files
committed
Fix Kick emote detection
1 parent 4c19c95 commit bf6091b

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

multi-alerts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ function getTranslation(key, fallback = '') {
267267
function formatTranslation(key, fallback, values = {}) {
268268
let template = getTranslation(key, fallback);
269269
Object.keys(values).forEach((valueKey) => {
270-
template = template.replace(new RegExp(`\\{${valueKey}\\}`, 'g'), values[valueKey]);
270+
const replacement = values[valueKey] == null ? '' : String(values[valueKey]);
271+
template = template.replace(new RegExp(`\\{${valueKey}\\}`, 'g'), () => replacement);
271272
});
272273
return template;
273274
}

sources/kick.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@
690690
const KICK_BADGE_SELECTOR = ".badge-tooltip img[src], .badge-tooltip svg, .base-badge img[src], .base-badge svg, .badge img[src], .badge svg, div[data-state] img[src], div[data-state] svg";
691691
const KICK_MESSAGE_CONTENT_SELECTOR = ".chat-entry-content, .chat-emote-container, .break-all, seventv-container, .seventv-painted-content, span[class*='font-normal'], div[class*='font-normal']";
692692
const KICK_MOD_ACTIONS_SELECTOR = "[style*='chatroom-mod-actions-display'], button[aria-label='Delete'], button[aria-label='Pin'], button[aria-label='Reply'], button[aria-label='Ban'], button[aria-label='Timeout'], button[aria-label='Block']";
693+
const KICK_MOD_ACTIONS_CLOSEST_SELECTOR = "button[aria-label='Delete'], button[aria-label='Pin'], button[aria-label='Reply'], button[aria-label='Ban'], button[aria-label='Timeout'], button[aria-label='Block']";
693694

694695
function getKickUsernameButton(ele) {
695696
return ele.querySelector("button.inline.font-bold[data-prevent-expand]")
@@ -704,7 +705,7 @@
704705
if (node.matches && node.matches(KICK_MOD_ACTIONS_SELECTOR)) {
705706
return true;
706707
}
707-
return Boolean(node.closest && node.closest(KICK_MOD_ACTIONS_SELECTOR));
708+
return Boolean(node.closest && node.closest(KICK_MOD_ACTIONS_CLOSEST_SELECTOR));
708709
}
709710

710711
function isKickMessageTextNode(node) {

sources/websocket/twitch.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ try{
375375
function formatTranslation(key, fallback, values = {}) {
376376
let template = getTranslation(key, fallback);
377377
Object.keys(values).forEach(function(valueKey) {
378-
template = template.replace(new RegExp("\\{" + valueKey + "\\}", "g"), values[valueKey]);
378+
const replacement = values[valueKey] == null ? '' : String(values[valueKey]);
379+
template = template.replace(new RegExp("\\{" + valueKey + "\\}", "g"), function() {
380+
return replacement;
381+
});
379382
});
380383
return template;
381384
}
@@ -2322,10 +2325,18 @@ async function ensureChatClientInstance() {
23222325
case 'anonsubgift':
23232326
case 'submysterygift':
23242327
case 'anonsubmysterygift':
2328+
const giftRecipient = parsedMessage.tags['msg-param-recipient-display-name'] ||
2329+
parsedMessage.tags['msg-param-recipient-user-name'] ||
2330+
(normalizedPayload && normalizedPayload.raw && normalizedPayload.raw.recipient) ||
2331+
(normalizedPayload && normalizedPayload.recipient) ||
2332+
'';
23252333
const giftMessage = formatTranslation('twitch-gifted-a-sub-message', '{name} gifted a sub', {
23262334
name: displayName || getTranslation('someone', 'Someone')
23272335
});
2328-
eventData.chatmessage = useTranslatedNoticeText ? giftMessage : (systemMsg || giftMessage);
2336+
const giftMessageWithRecipient = giftRecipient
2337+
? giftMessage + ' ' + getTranslation('membership-to-word', 'to') + ' ' + giftRecipient
2338+
: giftMessage;
2339+
eventData.chatmessage = useTranslatedNoticeText ? giftMessageWithRecipient : (systemMsg || giftMessageWithRecipient);
23292340
eventData.event = 'subscription_gift';
23302341
if (settings.limitedtwitchmemberchat) {
23312342
eventData.membership = getSubscriberLabel();

0 commit comments

Comments
 (0)