Skip to content

Commit

Permalink
IrcColors: Fix causing react errors sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckyz committed Jan 30, 2025
1 parent 414539f commit 1eff1a0
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/plugins/ircColors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import definePlugin, { OptionType } from "@utils/types";
import { useMemo } from "@webpack/common";

// Calculate a CSS color string based on the user ID
function calculateNameColorForUser(id: string) {
function calculateNameColorForUser(id?: string) {
const { lightness } = settings.use(["lightness"]);
const idHash = useMemo(() => h64(id), [id]);
const idHash = useMemo(() => id ? h64(id) : null, [id]);

return `hsl(${idHash % 360n}, 100%, ${lightness}%)`;
return idHash && `hsl(${idHash % 360n}, 100%, ${lightness}%)`;
}

const settings = definePluginSettings({
Expand Down Expand Up @@ -70,16 +70,10 @@ export default definePlugin({

calculateNameColorForMessageContext(context: any) {
const id = context?.message?.author?.id;
if (id == null) {
return null;
}
return calculateNameColorForUser(id);
},
calculateNameColorForListContext(context: any) {
const id = context?.user?.id;
if (id == null) {
return null;
}
return calculateNameColorForUser(id);
}
});

0 comments on commit 1eff1a0

Please sign in to comment.