Skip to content

Commit

Permalink
First Message Highlight 1.1.0
Browse files Browse the repository at this point in the history
* Added: `First Time Chatter` highlight option
* Added: `Returning Chatter` highlight option
  • Loading branch information
Lordmau5 committed Jan 16, 2024
1 parent 0b66a86 commit 2404340
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 46 deletions.
237 changes: 193 additions & 44 deletions src/first-message-highlighter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,61 @@ class FirstMessageHighlight extends Addon {
this.inject('chat');
this.inject('site');

this.settings.add('first_message_highlight.enabled', {
default: true,
ui: {
path: 'Add-Ons > First Message Highlight >> Current Session >> Settings @{"sort": -1}',
title: 'Highlight first messages',
description: 'Highlight first messages from users for this session.',
component: 'setting-check-box',
sort: -1
}
});

this.settings.add('first_message_highlight.only_moderated_channels', {
default: false,
ui: {
path: 'Add-Ons > First Message Highlight >> Current Session >> Settings',
title: 'Highlight only when moderating',
description: 'Only highlight messages in chats where you are a moderator.',
component: 'setting-check-box',
sort: -1
}
});

this.settings.add('first_message_highlight.forget_user_after', {
default: 0,
ui: {
path: 'Add-Ons > First Message Highlight >> Current Session >> Settings',
title: 'Forget User After',
description: 'Forget a user after a specified amount of time so they can be highlighted again.',
component: 'setting-select-box',
data: [
{ value: 0, title: 'Disabled' },
{ value: 1000 * 60 * 5, title: '5 Minutes' },
{ value: 1000 * 60 * 15, title: '15 Minutes' },
{ value: 1000 * 60 * 30, title: '30 Minutes' },
{ value: 1000 * 60 * 60, title: '60 Minutes' },
{ value: 1000 * 60 * 60 * 2, title: '2 Hours' },
{ value: 1000 * 60 * 60 * 3, title: '3 Hours' },
],
}
});

this.settings.add('first_message_highlight.highlight_color', {
default: '#3C1A1A',
ui: {
path: 'Add-Ons > First Message Highlight >> Current Session >> Highlights',
title: 'Highlight Color',
description: 'Highlight color to add to the message',
component: 'setting-color-box'
}
});

this.settings.add('first_message_highlight.priority', {
default: 0,
ui: {
path: 'Add-Ons > First Message Highlight >> Highlights',
path: 'Add-Ons > First Message Highlight >> Current Session >> Highlights',
title: 'Highlight Priority',
description: 'Priority of the highlight',
component: 'setting-text-box',
Expand All @@ -20,87 +71,132 @@ class FirstMessageHighlight extends Addon {
}
});

this.settings.add('first_message_highlight.highlight_color', {
default: '#3C1A1A',
this.settings.add('first_message_highlight.highlight_historical', {
default: true,
ui: {
path: 'Add-Ons > First Message Highlight >> Highlights',
title: 'Highlight Color',
description: 'Highlight color to add to the message',
component: 'setting-color-box'
path: 'Add-Ons > First Message Highlight >> Current Session >> Historical Messages',
title: 'Highlight logged historical messages',
description: 'Highlight messages from before you joined the chat.',
component: 'setting-check-box'
}
});

this.settings.add('first_message_highlight.remember_historical', {
default: true,
ui: {
path: 'Add-Ons > First Message Highlight >> Historical Messages',
path: 'Add-Ons > First Message Highlight >> Current Session >> Historical Messages',
title: 'Remember historical messages',
description: 'Remember logged user messages from before you joined the chat.',
component: 'setting-check-box'
}
});

this.settings.add('first_message_highlight.highlight_historical', {
default: true,
// First Time Chatter
this.settings.add('first_message_highlight.first_time_chatter', {
default: false,
ui: {
path: 'Add-Ons > First Message Highlight >> Historical Messages',
title: 'Highlight logged historical messages',
description: 'Highlight messages from before you joined the chat.',
component: 'setting-check-box'
path: 'Add-Ons > First Message Highlight >> First Time Chatter @{"sort": 10}',
title: 'Highlight first time chatters',
description: 'Highlight messages from first time chatters.',
component: 'setting-check-box',
sort: -1
}
});

this.settings.add('first_message_highlight.only_moderated_channels', {
this.settings.add('first_message_highlight.first_time_chatter_only_moderated_channels', {
default: false,
ui: {
path: 'Add-Ons > First Message Highlight >> Settings',
path: 'Add-Ons > First Message Highlight >> First Time Chatter',
title: 'Highlight only when moderating',
description: 'Only highlight messages in chats where you are a moderator.',
component: 'setting-check-box'
component: 'setting-check-box',
sort: -1
}
});

this.settings.add('first_message_highlight.forget_user_after', {
this.settings.add('first_message_highlight.first_time_chatter_color', {
default: '#C832C866',
ui: {
path: 'Add-Ons > First Message Highlight >> First Time Chatter',
title: 'Highlight Color',
component: 'setting-color-box'
}
});

this.settings.add('first_message_highlight.first_time_chatter_priority', {
default: 0,
ui: {
path: 'Add-Ons > First Message Highlight >> Settings',
title: 'Forget User After',
description: 'Forget a user after a specified amount of time so they can be highlighted again.',
component: 'setting-select-box',
data: [
{ value: 0, title: 'Disabled' },
{ value: 1000 * 60 * 5, title: '5 Minutes' },
{ value: 1000 * 60 * 15, title: '15 Minutes' },
{ value: 1000 * 60 * 30, title: '30 Minutes' },
{ value: 1000 * 60 * 60, title: '60 Minutes' },
{ value: 1000 * 60 * 60 * 2, title: '2 Hours' },
{ value: 1000 * 60 * 60 * 3, title: '3 Hours' },
],
path: 'Add-Ons > First Message Highlight >> First Time Chatter',
title: 'Highlight Priority',
description: 'Priority of the highlight',
component: 'setting-text-box',
type: 'number',
process: 'to_int'
}
});

// Returning Chatter
this.settings.add('first_message_highlight.returning_chatter', {
default: false,
ui: {
path: 'Add-Ons > First Message Highlight >> Returning Chatter @{"sort": 11}',
title: 'Highlight returning chatters',
description: 'Highlight messages from returning chatters.',
component: 'setting-check-box',
sort: -1
}
});

this.chat.addHighlightReason('first-message', "User's first message during this session");
this.settings.add('first_message_highlight.returning_chatter_only_moderated_channels', {
default: false,
ui: {
path: 'Add-Ons > First Message Highlight >> Returning Chatter',
title: 'Highlight only when moderating',
description: 'Only highlight messages in chats where you are a moderator.',
component: 'setting-check-box',
sort: -1
}
});

this.settings.add('first_message_highlight.returning_chatter_color', {
default: '#3296E666',
ui: {
path: 'Add-Ons > First Message Highlight >> Returning Chatter',
title: 'Highlight Color',
component: 'setting-color-box'
}
});

this.settings.add('first_message_highlight.returning_chatter_priority', {
default: 0,
ui: {
path: 'Add-Ons > First Message Highlight >> Returning Chatter',
title: 'Highlight Priority',
description: 'Priority of the highlight',
component: 'setting-text-box',
type: 'number',
process: 'to_int'
}
});

this.chat.addHighlightReason('first-message', "First message from a user during this session");
this.chat.addHighlightReason('first-time-chatter', "First messages from a user new to the channel");
this.chat.addHighlightReason('returning-chatter', "First messages from a user returning to the channel");

const outerThis = this;
this.messageHighlighter = {
type: 'message_highlighter',
priority: 0,

process(tokens, msg) {
if (!outerThis.chat.context.get('context.moderator')
&& this.settings.get('first_message_highlight.only_moderated_channels')) return;

if (msg.isHistorical) {
if (this.settings.get('first_message_highlight.remember_historical')
&& !outerThis.shouldHighlight(msg)) return;
// First Time Chatter
outerThis.highlightFirstTimeChatter(this, msg);

if (this.settings.get('first_message_highlight.highlight_historical'))
outerThis.highlightMessage(this, msg);
return;
}
// Returning Chatter
outerThis.highlightReturningChatter(this, msg);

if(outerThis.shouldHighlight(msg))
outerThis.highlightMessage(this, msg);
// First Message
outerThis.highlightMessage(this, msg);
}
}
}
Expand Down Expand Up @@ -163,13 +259,66 @@ class FirstMessageHighlight extends Addon {
}

highlightMessage(ctx, msg) {
if (this.settings.get('first_message_highlight.only_moderated_channels')) {
if (!this.chat.context.get('context.moderator'))
return;
}

const shouldHighlight = this.shouldHighlight(msg);

if (msg.isHistorical) {
if (this.settings.get('first_message_highlight.remember_historical')
&& !shouldHighlight) return;

if (!this.settings.get('first_message_highlight.highlight_historical'))
return;
}

if (!shouldHighlight) return;

ctx.applyHighlight(
msg,
this.settings.get('first_message_highlight.priority'),
this.settings.get('first_message_highlight.highlight_color'),
'first-message'
);
}

highlightFirstTimeChatter(ctx, msg) {
if (!this.chat.context.get('first_message_highlight.first_time_chatter')) return;

if (this.settings.get('first_message_highlight.first_time_chatter_only_moderated_channels')) {
if (!this.chat.context.get('context.moderator'))
return;
}

if (!msg.ffz_first_msg) return;

ctx.applyHighlight(
msg,
this.settings.get('first_message_highlight.first_time_chatter_priority'),
this.settings.get('first_message_highlight.first_time_chatter_color'),
'first-time-chatter'
);
}

highlightReturningChatter(ctx, msg) {
if (!this.chat.context.get('first_message_highlight.returning_chatter')) return;

if (this.settings.get('first_message_highlight.returning_chatter_only_moderated_channels')) {
if (!this.chat.context.get('context.moderator'))
return;
}

if (!msg.ffz_returning) return;

ctx.applyHighlight(
msg,
this.settings.get('first_message_highlight.returning_chatter_priority'),
this.settings.get('first_message_highlight.returning_chatter_color'),
'returning-chatter'
);
}
}

FirstMessageHighlight.register();
4 changes: 2 additions & 2 deletions src/first-message-highlighter/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"enabled": true,
"requires": [],
"version": "1.0.3",
"version": "1.1.0",
"icon": "https://i.imgur.com/Db2zP1l.png",
"short_name": "first_msg_highlight",
"name": "First Message Highlight",
"author": "deko_ration",
"description": "Addon to highlight the first message of a user during the current session. Useful for community-driven chats and welcoming.",
"settings": "add_ons.first_message_highlight",
"created": "2021-12-01T14:32:46.254Z",
"updated": "2023-12-19T19:07:09.545Z"
"updated": "2024-01-16T20:13:28.279Z"
}

0 comments on commit 2404340

Please sign in to comment.