RoleColorEverywhere: Add coloring to message contents (#2893)
This commit is contained in:
parent
22a5b18bfa
commit
eaf62d8c1c
|
@ -18,10 +18,14 @@
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
|
import { makeRange } from "@components/PluginSettings/components";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
|
import { findByCodeLazy } from "@webpack";
|
||||||
import { ChannelStore, GuildMemberStore, GuildStore } from "@webpack/common";
|
import { ChannelStore, GuildMemberStore, GuildStore } from "@webpack/common";
|
||||||
|
|
||||||
|
const useMessageAuthor = findByCodeLazy('"Result cannot be null because the message is not null"');
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
chatMentions: {
|
chatMentions: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
|
@ -46,13 +50,21 @@ const settings = definePluginSettings({
|
||||||
default: true,
|
default: true,
|
||||||
description: "Show role colors in the reactors list",
|
description: "Show role colors in the reactors list",
|
||||||
restartNeeded: true
|
restartNeeded: true
|
||||||
}
|
},
|
||||||
|
messageSaturation: {
|
||||||
|
type: OptionType.SLIDER,
|
||||||
|
description: "Intensity of message coloring. 0 to disable.",
|
||||||
|
markers: makeRange(0, 100, 10),
|
||||||
|
default: 30,
|
||||||
|
// This is called only once at startup, but late enough that the store is initialized.
|
||||||
|
get restartNeeded() { return settings.store.messageSaturation === 0; }
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "RoleColorEverywhere",
|
name: "RoleColorEverywhere",
|
||||||
authors: [Devs.KingFish, Devs.lewisakura, Devs.AutumnVN],
|
authors: [Devs.KingFish, Devs.lewisakura, Devs.AutumnVN, Devs.Kyuuhachi],
|
||||||
description: "Adds the top role color anywhere possible",
|
description: "Adds the top role color anywhere possible",
|
||||||
patches: [
|
patches: [
|
||||||
// Chat Mentions
|
// Chat Mentions
|
||||||
|
@ -114,7 +126,15 @@ export default definePlugin({
|
||||||
replace: "$&,style:{color:$self.getColor($2?.id,$1)}"
|
replace: "$&,style:{color:$self.getColor($2?.id,$1)}"
|
||||||
},
|
},
|
||||||
predicate: () => settings.store.reactorsList,
|
predicate: () => settings.store.reactorsList,
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
find: '.Messages.MESSAGE_EDITED,")"',
|
||||||
|
replacement: {
|
||||||
|
match: /(?<=isUnsupported\]:(\i)\.isUnsupported\}\),)(?=children:\[)/,
|
||||||
|
replace: "style:{color:$self.useMessageColor($1)},"
|
||||||
|
},
|
||||||
|
predicate: () => settings.store.messageSaturation !== 0,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
settings,
|
settings,
|
||||||
|
|
||||||
|
@ -148,5 +168,17 @@ export default definePlugin({
|
||||||
color: this.getColor(userId, { guildId })
|
color: this.getColor(userId, { guildId })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
useMessageColor(message: any) {
|
||||||
|
try {
|
||||||
|
const { messageSaturation } = settings.use(["messageSaturation"]);
|
||||||
|
const author = useMessageAuthor(message);
|
||||||
|
if (author.colorString !== undefined && messageSaturation !== 0)
|
||||||
|
return `color-mix(in oklab, ${author.colorString} ${messageSaturation}%, var(--text-normal))`;
|
||||||
|
} catch(e) {
|
||||||
|
console.error("[RCE] failed to get message color", e);
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue