Skip to content

Commit

Permalink
Merge branch 'FrankerFaceZ:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
smokey019 authored Jan 18, 2024
2 parents 0e284c7 + 9b5b457 commit 99b8cb7
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/7tv-emotes/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main",
"clips"
],
"version": "1.4.17",
"version": "1.4.20",
"short_name": "7TV",
"name": "7TV Emotes",
"author": "Melonify",
Expand All @@ -14,5 +14,5 @@
"website": "https://7tv.app",
"settings": "add_ons.7tv_emotes",
"created": "2021-07-12T23:18:04.000Z",
"updated": "2023-12-22T00:31:14.154Z"
"updated": "2024-01-17T20:14:43.907Z"
}
10 changes: 5 additions & 5 deletions src/7tv-emotes/modules/emotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,21 @@ export default class Emotes extends FrankerFaceZ.utilities.module.Module {
}

if (completed) {
let message = `[7TV] ${body.actor.display_name} `;
let message = `${body.actor.display_name} `;
switch (action) {
case 'ADD': {
message += `added the emote '${emote.value.name}'`;
message += `added the emote ${emote.value.name} (${emote.value.name})`;
break;
}
case 'REMOVE': {
message += `removed the emote '${emote.old_value.name}'`;
message += `removed the emote ${emote.old_value.name}`;
break;
}
case 'UPDATE': {
if (oldEmote?.name !== emote.value.name) {
message += `renamed the emote '${oldEmote.name}' to '${emote.value.name}'`;
message += `renamed the emote ${oldEmote.name} to ${emote.value.name} (${emote.value.name})`;
} else {
message += `updated the emote '${emote.value.name}'`;
message += `updated the emote ${emote.value.name} (${emote.value.name})`;
}
break;
}
Expand Down
19 changes: 16 additions & 3 deletions src/7tv-emotes/modules/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {
this._connect_attempts = 0;

this._session_id = '';
this._last_presence_at = 0;

this._user_id = false;
this._active_channel_set = false;
Expand Down Expand Up @@ -98,6 +99,12 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {
sendPresences(self = false, room_id = undefined) {
if (!this._user_id) return;

// Only send a presence at most every 10 seconds
if (this._last_presence_at && this._last_presence_at > Date.now() - 1000 * 10)
return;

this._last_presence_at = Date.now();

if (room_id) {
this.stv_api.user.updateUserPresences(this._user_id, room_id, self, this._session_id);
return;
Expand All @@ -108,6 +115,8 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {
this.stv_api.user.updateUserPresences(this._user_id, room.id, self, this._session_id);
}
}

this._last_presence_at = Date.now();
}

async roomAdd(room) {
Expand Down Expand Up @@ -197,10 +206,14 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {
delete this._rooms[room.id];
}

addChatNotice(channel, message) {
addChatNotice(channel, message, tokenize = true) {
if (!this.settings.get('addon.seventv_emotes.update_messages')) return;

this.siteChat.addNotice(channel.login, message);
this.siteChat.addNotice(channel.login, {
message,
icon: new URL('https://cdn.frankerfacez.com/static/addons/7tv-emotes/logo.png'),
tokenize
});
}

onMessage({ op: opcode, d: _data }) {
Expand Down Expand Up @@ -287,7 +300,7 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {
this._active_channel_set = newSet.id;

this.emotes.updateChannelSet(channel, newSet.id);
this.addChatNotice(channel, `[7TV] ${body.actor.display_name} updated the active emote set to '${newSet.name}'`);
this.addChatNotice(channel, `${body.actor.display_name} updated the active emote set to ${newSet.name}`);
}

// TODO: Empty data / "updated" array when setting to "No Paint" or "No Badge"
Expand Down
42 changes: 41 additions & 1 deletion src/ffzap-bttv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ class BetterTTV extends Addon {
},
});

this.settings.add('ffzap.betterttv.update_messages', {
default: true,
ui: {
path: 'Add-Ons > BetterTTV Emotes >> Emotes > Live Emote Updates',
title: 'Show update messages',
description: 'Show messages in chat when emotes are updated in the current channel.',
component: 'setting-check-box',
}
});

this.settings.add('ffzap.betterttv.pro_badges', {
default: true,

Expand All @@ -66,7 +76,7 @@ class BetterTTV extends Addon {
description: 'Enable to show BetterTTV Pro emoticons.',
component: 'setting-check-box',
},
});
});

this.chat.context.on('changed:ffzap.betterttv.global_emoticons', this.updateEmotes, this);
this.chat.context.on('changed:ffzap.betterttv.arbitrary_emoticons', this.updateEmotes, this);
Expand Down Expand Up @@ -144,6 +154,25 @@ class BetterTTV extends Addon {
}
}

addEmoteUpdateMessage(bttvChannel, message) {
const channelId = bttvChannel.replace('twitch:', '');
const channel = this.chat.getRoom(channelId);

this.addChatNotice(channel, message);
}

addChatNotice(channel, message, tokenize = true) {
if (!channel.login) return;

if (!this.settings.get('ffzap.betterttv.update_messages')) return;

this.resolve('site.chat').addNotice(channel.login, {
message,
icon: new URL('https://betterttv.com/favicon.png'),
tokenize
});
}

getSocketEvents() {
return {
lookup_user: data => {
Expand Down Expand Up @@ -184,6 +213,7 @@ class BetterTTV extends Addon {
}
},
emote_create: ({ channel, emote: createdEmote }) => {
this.log.info(channel, createdEmote);
const emotes = this.room_emotes[channel];
if (!emotes) return;

Expand All @@ -194,14 +224,21 @@ class BetterTTV extends Addon {
emotes.push(emote);

this.emotes.addEmoteToSet(this.getChannelSetID(channel, false), emote);

this.addEmoteUpdateMessage(channel, `Added the emote ${emote.name} (${emote.name})`);
},
emote_delete: ({ channel, emoteId }) => {
const emotes = this.room_emotes[channel];
if (!emotes) return;

const existingEmote = emotes.find(e => e.id === emoteId);
if (!existingEmote) return;

this.room_emotes[channel] = emotes.filter(e => e.id !== emoteId);

this.emotes.removeEmoteFromSet(this.getChannelSetID(channel, false), emoteId);

this.addEmoteUpdateMessage(channel, `Removed the emote ${existingEmote.name}`);
},
emote_update: ({ channel, ...payload }) => {
const updatedEmote = payload.emote;
Expand All @@ -212,9 +249,12 @@ class BetterTTV extends Addon {
const emote = emotes.find(e => e.id === updatedEmote.id);
if (!emote) return;

const oldName = emote.name;
emote.name = updatedEmote.code;

this.emotes.addEmoteToSet(this.getChannelSetID(channel, false), emote);

this.addEmoteUpdateMessage(channel, `Renamed the emote ${oldName} to ${emote.name} (${emote.name})`);
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/ffzap-bttv/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"load_events": [
"chat-data"
],
"version": "3.3.19",
"version": "3.3.20",
"short_name": "FFZ:AP BTTV",
"name": "BetterTTV Emotes",
"author": "Lordmau5",
"description": "Adds BetterTTV Global Emotes, Channel Emotes and Pro functionality (badges and emotes).",
"website": "https://betterttv.com/",
"settings": "add_ons.better_ttv_emotes",
"created": "2019-09-12T15:31:59.000Z",
"updated": "2023-11-03T20:11:36.053Z"
"updated": "2024-01-17T20:25:24.043Z"
}
Loading

0 comments on commit 99b8cb7

Please sign in to comment.