Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IrcColors: Allow coloring only users with no color and DMs only #3186

Merged
merged 9 commits into from
Jan 31, 2025
37 changes: 34 additions & 3 deletions src/plugins/ircColors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,25 @@ const settings = definePluginSettings({
restartNeeded: true,
type: OptionType.BOOLEAN,
default: true
},
applyColorOnlyToUsersWithoutColor: {
description: "Apply colors only to users who don't have a predefined color",
restartNeeded: false,
type: OptionType.BOOLEAN,
default: false
},
applyColorOnlyInDms: {
description: "Apply colors only in direct messages; do not apply colors in servers.",
restartNeeded: false,
type: OptionType.BOOLEAN,
default: false
}
});

export default definePlugin({
name: "IrcColors",
description: "Makes username colors in chat unique, like in IRC clients",
authors: [Devs.Grzesiek11],
authors: [Devs.Grzesiek11, Devs.jamesbt365],
settings,

patches: [
Expand All @@ -70,10 +82,29 @@ export default definePlugin({

calculateNameColorForMessageContext(context: any) {
const id = context?.message?.author?.id;
return calculateNameColorForUser(id);
const colorString = context?.author?.colorString;
const color = calculateNameColorForUser(id);

if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) {
return colorString;
}

return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString)
? color
: colorString;
},
calculateNameColorForListContext(context: any) {
const id = context?.user?.id;
return calculateNameColorForUser(id);
const colorString = context?.colorString;
const color = calculateNameColorForUser(id);

if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) {
return colorString;
}

return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString)
? color
: colorString;
}

jamesbt365 marked this conversation as resolved.
Show resolved Hide resolved
});