Skip to content

Commit

Permalink
No Bad Emotes 1.1.0
Browse files Browse the repository at this point in the history
* Added: New setting to escape filtered emotes in your outgoing chat messages. This ensures that you don't inadvertently use one of the emotes you've hidden when chatting by adding an invisible character to the appropriate words, stopping other users' clients from treating the words as emotes.
  • Loading branch information
SirStendec committed Jan 25, 2024
1 parent b616bf9 commit 3830681
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 49 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@
"js-levenshtein": "^1.1.6",
"reconnecting-websocket": "^4.4.0",
"sortablejs": "^1.14.0",
"spark-md5": "^3.0.2"
"spark-md5": "^3.0.2",
"unescape-js": "^1.1.4"
},
"pnpm": {
"overrides": {
"ansi-regex@>2.1.1 <5.0.1": ">=5.0.1",
"chalk@<4": ">=4 <5",
"glob-parent@<5.1.2": ">=5.1.2"
}
}
Expand Down
65 changes: 19 additions & 46 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions src/no-bad-emotes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { has, addWordSeparators, glob_to_regex, escape_regex } = FrankerFaceZ.utilities.object;

import unescape from 'unescape-js';

const COMMON_WORDS = require('./common.json');

Expand Down Expand Up @@ -31,6 +32,41 @@ class NoBadEmotes extends Addon {
this.doesEmoteMatch = this.doesEmoteMatch.bind(this);

// Settings
this.settings.add('addon.nobademotes.process-outgoing', {
default: false,
ui: {
path: 'Add-Ons > No Bad Emotes >> General',
title: 'Escape filtered emotes in outgoing chat messages.',
description: 'The filtering this add-on performs is client-only, so normally your filtering only affects what you see. If you enable this, any messages you send will be modified based on your filtering rules to prevent you from inadvertently using an emote that you have filtered out.',
component: 'setting-check-box'
}
});

this.settings.add('addon.nobademotes.outgoing-escape', {
default: '\\u{E0002}{NAME}',
process(ctx, val) {
try {
return unescape(val);
} catch(err) {
return `\u{E0002}{NAME}`;
}
},
ui: {
path: 'Add-Ons > No Bad Emotes >> Advanced @{"sort": 99}',
title: 'Escape Character',
description: 'The character(s) to add to an emote\'s name when escaping filtered emotes in outgoing chat messages. Use `\'{\'NAME\'}\'` where the emote\'s name should go. Standard escape sequences are supported.',
component: 'setting-text-box',
validate(val) {
try {
unescape(val);
return true;
} catch(err) {
return false;
}
}
}
});

this.settings.add('addon.nobademotes.no-filter-personal', {
default: false,
ui: {
Expand Down Expand Up @@ -163,6 +199,8 @@ class NoBadEmotes extends Addon {
// Call this before adding our filter so we only process once.
this.onUseCommon(this.settings.get('addon.nobademotes.use-common'));

this.on('chat:pre-send-message', this.processOutbound);

this.emotes.addFilter({
type: 'nobademotes',
test: this.doesEmoteMatch
Expand All @@ -171,6 +209,7 @@ class NoBadEmotes extends Addon {

onDisable() {
this.emotes.removeFilter('nobademotes');
this.off('chat:pre-send-message', this.processOutbound);
}

// Common Words
Expand Down Expand Up @@ -229,6 +268,41 @@ class NoBadEmotes extends Addon {
}


// Outbound Messages

processOutbound(event) {
if ( ! this.settings.get('addon.nobademotes.process-outgoing') )
return;

const site = this.resolve('site'),
user = site?.getUser?.();

const bad_emotes = new Set;

for(const set of this.emotes.getSets(user?.id, user?.login, null, event.channel)) {
for(const emote of Object.values(set.disabled_emotes)) {
if ( emote?.name )
bad_emotes.add(emote.name);
}
}

if ( ! bad_emotes.size )
return;

const out = [],
char = this.settings.get('addon.nobademotes.outgoing-escape');

for(const word of event.message.split(/ /g)) {
if ( bad_emotes.has(word) ) {
out.push(char.replace(/\{NAME\}/g, word));
} else
out.push(word);
}

event.message = out.join(' ');
}


// Filtering

doesEmoteMatch(emote, set) {
Expand Down
4 changes: 2 additions & 2 deletions src/no-bad-emotes/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"enabled": true,
"requires": [],
"version": "1.0.0",
"version": "1.1.0",
"icon": "https://cdn.frankerfacez.com/badge/2/4/solid",
"short_name": "NoBadEmotes",
"name": "No Bad Emotes",
"author": "SirStendec",
"description": "This add-on removes undesired emotes from chat, so you only see the words. Tired of people using replacing stupidly common words like 'the' with emotes using platforms without any sort of common sense restrictions? Just grab this.",
"settings": "add_ons.no_bad_emotes",
"created": "2024-01-24T20:02:45.938Z",
"updated": "2024-01-24T20:02:45.938Z"
"updated": "2024-01-25T20:52:46.515Z"
}

0 comments on commit 3830681

Please sign in to comment.