Skip to content

Commit

Permalink
Fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
Bitslayn committed Jun 15, 2024
1 parent cb082d4 commit 561429f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 95 deletions.
13 changes: 3 additions & 10 deletions plugins/btw.bitslayn.channelIcons/src/ChannelExample.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { capitalizeWords } from "./helpers";
import { config } from "./icons";
import { WordConfig } from "./types";

const advancedChannelNames: WordConfig = config.get("advancedChannelNames");
import { lowercaseExceptions, specialCases } from "./index";

const ChannelExample = ({ id, name }) => {
let channelName;
if (config.get("changeChannelNames", [])) {
channelName = capitalizeWords(
name,
advancedChannelNames.specialCases,
advancedChannelNames.lowercaseExceptions
);
channelName = capitalizeWords(name, specialCases, lowercaseExceptions);
} else {
channelName = decapitalizeWords(name, advancedChannelNames.specialCases);
console.log(advancedChannelNames);
channelName = decapitalizeWords(name, specialCases);
}
return (
<div className="channelExample">
Expand Down
5 changes: 4 additions & 1 deletion plugins/btw.bitslayn.channelIcons/src/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ export function randomNumber(max: number): number {
return buffer[0] % max;
}

// eslint-disable-next-line consistent-return
export function getCurrentChannelObject(): ColoredChannel {
return config.get("coloredChannels")[SelectedChannelStore.getCurrentlySelectedChannelId()];
if (config.get("coloredChannels")) {
return config.get("coloredChannels")[SelectedChannelStore.getCurrentlySelectedChannelId()];
}
}

export function getChannelObject(channelId: string): ColoredChannel {
Expand Down
121 changes: 43 additions & 78 deletions plugins/btw.bitslayn.channelIcons/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
ChannelStoreChannel,
ColoredChannel,
ModalsModule,
WordConfig,
int2hexModule,
} from "./types";
import { Divider } from "replugged/components";
Expand All @@ -53,49 +52,40 @@ const ChannelMention = webpack.getBySource(
/*const ChannelAutocomplete = webpack.getBySource("AutocompleteRowContent");
console.log(ChannelAutocomplete);*/

if (!config.get("advancedChannelNames")) {
// I'll figure this out another time. It works locally so that's all that matters.
function fetchDataAndExtract(): WordConfig {
const extractedData: WordConfig = {
specialCases: {
css: "CSS",
js: "JS",
html: "HTML",
xml: "XML",
json: "JSON",
sql: "SQL",
php: "PHP",
export const specialCases: { [key: string]: string } = {
css: "CSS",
js: "JS",
html: "HTML",
xml: "XML",
json: "JSON",
sql: "SQL",
php: "PHP",

faq: "FAQ",
qotd: "QOTD",
},
lowercaseExceptions: new Set([
"a",
"ad",
"an",
"and",
"as",
"at",
"but",
"by",
"for",
"in",
"is",
"nor",
"of",
"on",
"or",
"so",
"the",
"to",
"up",
"yet",
]),
};
return extractedData;
}
config.set("advancedChannelNames", fetchDataAndExtract());
}
faq: "FAQ",
qotd: "QOTD",
};
export const lowercaseExceptions: Set<string> = new Set([
"a",
"ad",
"an",
"and",
"as",
"at",
"but",
"by",
"for",
"in",
"is",
"nor",
"of",
"on",
"or",
"so",
"the",
"to",
"up",
"yet",
]);

function injectSavedChannelsStyles(): void {
const coloredChannels: any = config.get("coloredChannels", []);
Expand Down Expand Up @@ -370,15 +360,15 @@ export function start(): void {
const headerObj = a?.[0]?.children?.props?.children;
if (headerObj && getCurrentChannelObject()?.color) {
const ChannelObject = getCurrentChannelObject();
headerObj[2] = <span style={{ color: ChannelObject.color }}>{headerObj[2]}</span>;
headerObj[2] = <span style={{ color: ChannelObject?.color }}>{headerObj[2]}</span>;
// clearChildrenAddPath(ChannelObject.icon)
}
});

inject.before(Header.default, "Icon", (a: any) => {
inject.before(Header?.default, "Icon", (a: any) => {
const ChannelObject = getCurrentChannelObject();
const CurrentChannel: ChannelStoreChannel = ChannelStore.getChannel(
SelectedChannelStore.getCurrentlySelectedChannelId()
SelectedChannelStore?.getCurrentlySelectedChannelId()
) as ChannelStoreChannel;
const CustomIcon = ChannelNames?.slice()
.reverse()
Expand Down Expand Up @@ -447,12 +437,7 @@ export function start(): void {
const channel: any = ChannelStore.getChannel(channelInstance.channel.id);
const oldName: string = channel.name;
if (!isChannelIdExists(channel.id)) {
const advancedChannelNames: WordConfig = config.get("advancedChannelNames");
channel.name = capitalizeWords(
oldName,
advancedChannelNames.specialCases,
advancedChannelNames.lowercaseExceptions
);
channel.name = capitalizeWords(oldName, specialCases, lowercaseExceptions);
changedChannelNames.push({ channelid: channel.id, oldName });
}
}
Expand All @@ -476,10 +461,12 @@ export function getChangedChannelNames(): any[] {

export function stop(): void {
inject.uninjectAll();
const Channels = Object.keys(config.get("coloredChannels"));
Channels.forEach((channelId: string) => {
document.querySelector(`[data-channel-style="${channelId}"]`).remove();
});
if (config.get("coloredChannels")) {
const Channels = Object.keys(config.get("coloredChannels"));
Channels.forEach((channelId: string) => {
document.querySelector(`[data-channel-style="${channelId}"]`).remove();
});
}
ChannelNames.forEach(channel =>
channel.name.forEach(x => {
if (document.querySelector(`[data-channel-named-style="${x}"]`)) {
Expand Down Expand Up @@ -563,28 +550,6 @@ export function Settings(): JSX.Element {
))}
</div>
</components.Category>
{/* <components.Category // I'll figure that out another time
title="Advanced Settings"
note="Do not touch unless you know what you're doing. These can crash the plugin if used incorrectly.">
<components.FormItem title="Recommended Icons">
<components.TextArea rows={10} />
</components.FormItem>
<components.FormItem title="Abbreviation Wordlist (All capitals)">
<components.TextArea rows={10} value={advancedChannelNames.specialCases} />
</components.FormItem>
<components.FormItem title="Blacklisted Words (All lowercase)">
<components.TextArea
rows={10}
value={Array.from(advancedChannelNames.lowercaseExceptions.entries.toString()).join("")}
/>
</components.FormItem>
<components.ButtonItem
button="Reset"
color={colorBrands.colorDanger}></components.ButtonItem>
<components.ButtonItem
button="Confirm"
color={colorBrands.colorBrand}></components.ButtonItem>
</components.Category> */}
</div>
);
}
6 changes: 0 additions & 6 deletions plugins/btw.bitslayn.channelIcons/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ export interface ColoredChannel {
icon: string;
}

export interface WordConfig {
specialCases: { [key: string]: string };
lowercaseExceptions: Set<string>;
}

export interface ChannelStoreChannel {
id: string;
type: number;
Expand Down Expand Up @@ -40,7 +35,6 @@ export interface Settings {
coloredChannelPills: boolean;
suggestedColors: string[];
icons: IconData[];
advancedChannelNames: WordConfig;
}
export interface BrandColors {
button: string;
Expand Down

0 comments on commit 561429f

Please sign in to comment.