Skip to content

Commit

Permalink
better ig
Browse files Browse the repository at this point in the history
  • Loading branch information
yofukashino committed Jun 18, 2024
1 parent 74dbed3 commit 37c31ca
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 68 deletions.
4 changes: 2 additions & 2 deletions src/Components/Instruction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ export default () => (
FluxDispatcher.dispatch({ type: "LAYER_POP_ALL" });
Modules.TransitionUtil?.transitionTo(`/channels/449175561529589761/886287835018178560`);
}}>
#background-request
#click-here-to-request
</Clickable>
</Flex>
</Text.Normal>
<Text.Normal>
<b>🔹</b> Click UPLOAD button and UPLOAD your image from your device.
<b>🔹</b> Type /bg and select the command. Upload for banner in the file option.
<br />
• Only .GIF .PNG .JPG .JPEG will be accepted. <br />
• Max-size: 10MB
Expand Down
1 change: 1 addition & 0 deletions src/Components/USRBGButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export default () => (
...inviteInfo,
});
}}
variant="banner"
/>
);
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { defaultSettings } from "./lib/consts";
import "./style.css";
export const PluginInjector = new Injector();
export const PluginLogger = Logger.plugin("ReUSRBG", "#b380ff");
export const USRDB = new Map<string, Types.USRBD_USER>();
export const USRDB = new Map<string, string>();
export const SettingValues = await settings.init("dev.tharki.ReUSRBG", defaultSettings);
import Settings from "./Components/Settings";
import Injections from "./injections/index";
import Utils from "./lib/utils";
import Types from "./types";

export const start = (): void => {
void Utils.loadUSRBD();
Settings.registerSettings();
void Injections.applyInjections();
void Injections.applyInjections().catch((err) => PluginLogger.error(err));
};

export const stop = (): void => {
Expand Down
2 changes: 1 addition & 1 deletion src/injections/BannerLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default (): void => {
SettingValues.get("nitroBanner", defaultSettings.nitroBanner))
)
return res;
const { img } = USRDB.get(displayProfile?.userId);
const img = USRDB.get(displayProfile?.userId);
res.bannerSrc = img;
return res;
});
Expand Down
26 changes: 0 additions & 26 deletions src/injections/ProfileHeader.tsx

This file was deleted.

28 changes: 28 additions & 0 deletions src/injections/UserProfileContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { util } from "replugged";
import { users as UltimateUserStore } from "replugged/common";
import { PluginInjector, SettingValues, USRDB } from "../index";
import { defaultSettings } from "../lib/consts";
import Modules from "../lib/requiredModules";
import USRBGButton from "../Components/USRBGButton";
import Types from "../types";
export default (): void => {
const { UserProfileContext } = Modules;
PluginInjector.before(UserProfileContext, "render", (args) => {
const [props] = args;
const profileHeader = props?.children?.find((c) =>
/{profileType:\w+,children:\w+}=/.exec(c?.type?.toString()),
);
if (
!profileHeader ||
!props.user ||
!USRDB.has(props.user.id) ||
(props.user?.banner && SettingValues.get("nitroBanner", defaultSettings.nitroBanner))
)
return args;
if (!Array.isArray(profileHeader.props.children)) {
profileHeader.props.children = [profileHeader.props.children];
}
profileHeader.props.children.unshift(<USRBGButton />);
return args;
});
};
4 changes: 2 additions & 2 deletions src/injections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import Modules from "../lib/requiredModules";
import injectBannerLoader from "./BannerLoader";
import injectBanners from "./Banners";
import injectDisplayProfileUtils from "./DisplayProfileUtils";
import injectProfileHeader from "./ProfileHeader";
import injectUserProfileContext from "./UserProfileContext";
export const applyInjections = async (): Promise<void> => {
await Modules.loadModules();
injectBannerLoader();
injectBanners();
injectDisplayProfileUtils();
injectProfileHeader();
injectUserProfileContext();
};

export default { applyInjections };
4 changes: 2 additions & 2 deletions src/lib/consts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const USBBG_SERVER_INVITE_CODE = "TeRQEPb";
export const USBBG_SERVER_ID = "449175561529589761";
export const USRBG_URL =
"https://raw.githubusercontent.com/Discord-Custom-Covers/usrbg/master/dist/usrbg.json";
// got link from https://github.com/Rico040/bunny-plugins/blob/master/plugins/userbg/src/index.tsx#L23C40-L23C76
export const USRBG_URL = "https://usrbg.is-hardly.online/users";
export const defaultSettings = {
nitroBanner: true,
settingsBanner: true,
Expand Down
96 changes: 72 additions & 24 deletions src/lib/requiredModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,87 @@ import Types from "../types";
export const Modules: Types.Modules = {};

Modules.loadModules = async (): Promise<void> => {
Modules.IconClasses ??= await webpack.waitForProps<Types.IconClasses>("iconItem");
Modules.InviteActions ??= await webpack.waitForProps<Types.InviteActions>(
"acceptInviteAndTransitionToInviteChannel",
);
Modules.DisplayProfileUtils ??= await webpack.waitForProps<Types.DisplayProfileUtils>(
"getDisplayProfile",
);
Modules.IconClasses ??= await webpack
.waitForProps<Types.IconClasses>(["iconItem"], {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find IconClasses Module");
});

Modules.InviteActions ??= await webpack
.waitForProps<Types.InviteActions>(["acceptInviteAndTransitionToInviteChannel"], {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find InviteActions Module");
});

Modules.DisplayProfileUtils ??= await webpack
.waitForProps<Types.DisplayProfileUtils>(["getDisplayProfile"], { timeout: 10000 })
.catch(() => {
throw new Error("Failed To Find DisplayProfileUtils Module");
});

Modules.UserBannerParent ??= await webpack
.waitForModule<Types.GenericExport>(webpack.filters.bySource("darkenOnHover:"), {
raw: true,
timeout: 10000,
})
.then(({ exports }) => exports);
.then(({ exports }) => exports)
.catch(() => {
throw new Error("Failed To Find UserBannerParent Module");
});

Modules.UserBannerConstructor ??= await webpack
.waitForModule<Types.GenericExport>(webpack.filters.bySource(".bannerSVGWrapper"), {
raw: true,
timeout: 10000,
})
.then(({ exports }) => exports);
Modules.TransitionUtil ??= await webpack.waitForProps<Types.TransitionUtil>(
"transitionTo",
"transitionToGuild",
);
Modules.Invite ??= await webpack.waitForModule<Types.InviteComponent>(
webpack.filters.bySource(".AnalyticsPages.INVITE_EMBED"),
);
Modules.BannerLoader ??= await webpack.waitForProps<Types.BannerLoader>("BannerLoadingStatus");
Modules.HeaderButton ??= await webpack.waitForModule<Types.HeaderButton>(
webpack.filters.bySource(".TooltipContainer,{tooltipClassName"),
);
Modules.ProfileHeader ??= await webpack
.waitForModule<Types.GenericExport>(webpack.filters.bySource(".biteSize]"), {
raw: true,
.then(({ exports }) => exports)
.catch(() => {
throw new Error("Failed To Find UserBannerConstructor Module");
});

Modules.TransitionUtil ??= await webpack
.waitForProps<Types.TransitionUtil>(["transitionTo", "transitionToGuild"], { timeout: 10000 })
.catch(() => {
throw new Error("Failed To Find TransitionUtil Module");
});

Modules.Invite ??= await webpack
.waitForModule<Types.InviteComponent>(
webpack.filters.bySource(".AnalyticsPages.INVITE_EMBED"),
{ timeout: 10000 },
)
.catch(() => {
throw new Error("Failed To Find Invite Module");
});

Modules.BannerLoader ??= await webpack
.waitForProps<Types.BannerLoader>(["BannerLoadingStatus"], {
timeout: 10000,
})
.then(({ exports }) => exports);
.catch(() => {
throw new Error("Failed To Find BannerLoader Module");
});

Modules.HeaderButton ??= await webpack
.waitForModule<Types.HeaderButton>(webpack.filters.bySource('.banner]:"banner"==='), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find HeaderButton Module");
});

Modules.UserProfileContext ??= await webpack
.waitForModule<Types.UserProfileContext>(
webpack.filters.bySource(".UserProfileThemeContextProvider"),
{ timeout: 10000 },
)
.catch(() => {
throw new Error("Failed To Find UserProfileContext Module");
});
};

export default Modules;
8 changes: 7 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ export const loadUSRBD = async (reload?: boolean): Promise<void> => {
const fetchStart = performance.now();
const USRBG_RESPONSE = await fetch(USRBG_URL);
const USRBG_JSON = await USRBG_RESPONSE.json();
for (const USRBG_ITEM of USRBG_JSON) USRDB.set(USRBG_ITEM.uid, USRBG_ITEM);
for (const [USRBG_USERID, USRBG_ETAG] of Object.entries(USRBG_JSON.users))
USRDB.set(
USRBG_USERID,
`${USRBG_JSON.endpoint}/${USRBG_JSON.bucket}/${USRBG_JSON.prefix}${USRBG_USERID}?${
USRBG_ETAG as string
}`,
);
const fetchEnd = performance.now();
PluginLogger.log(
`${reload ? "Reloaded" : "Loaded"} USRBG Database in ${(fetchEnd - fetchStart).toFixed(2)}ms.`,
Expand Down
23 changes: 16 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ export namespace Types {
showPremiumBadgeUpsell: boolean;
user: User;
}

export interface USRBD_USER {
img: string;
uid: string;
_id: string;
}
export type InviteComponent = React.ComponentType<{ code: string; author: User }>;
export interface Invite {
code: string;
Expand Down Expand Up @@ -191,7 +185,22 @@ export namespace Types {
icon?: () => React.ReactNode;
text?: string;
onClick?: () => void;
variant?: "banner" | "icon" | "text";
}>;
export interface UserProfileContext {
$$typeof: symbol;
Overlay: DefaultTypes.AnyFunction;
render: (
props: {
children: React.ReactElement[];
className: string;
displayProfile: DisplayProfile;
profileType: string;
user: User;
},
...args: unknown[]
) => React.ReactElement;
}
export interface Modules {
loadModules?: () => Promise<void>;
IconClasses?: IconClasses;
Expand All @@ -203,7 +212,7 @@ export namespace Types {
Invite?: InviteComponent;
BannerLoader?: BannerLoader;
HeaderButton?: HeaderButton;
ProfileHeader?: GenericModule;
UserProfileContext?: UserProfileContext;
}
export interface Settings {
nitroBanner: boolean;
Expand Down

0 comments on commit 37c31ca

Please sign in to comment.