Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
linting be like
Browse files Browse the repository at this point in the history
  • Loading branch information
12944qwerty committed Jan 7, 2023
1 parent d4bbfc2 commit 5702b45
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 107 deletions.
194 changes: 106 additions & 88 deletions src/Badges.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import React from "react";
import { types, webpack } from "replugged";
import { User } from 'discord-types/general';
import { User } from "discord-types/general";

type TooltipType = React.FC<{
text: string;
children: (props: React.HTMLAttributes<HTMLSpanElement>) => JSX.Element;
}>
}>;

const BadgeAssets: Record<string, string> = {
STAFF: '/assets/f62be1ec9bdd82d3d77158ad81830e68.svg',
PARTNER: '/assets/53828e0c0fb6676440ad11b5d2586241.svg',
HYPESQUAD: '/assets/f5354673c9cff61c1dcc70081ef774e5.svg',
HYPESQUAD_ONLINE_HOUSE_1: '/assets/995ecfdbdf94ad84dd4d802c104e4630.svg',
HYPESQUAD_ONLINE_HOUSE_2: '/assets/473dadec13ab7e90e209cc60fccb31c5.svg',
HYPESQUAD_ONLINE_HOUSE_3: '/assets/58f11abcf3c13812bff969baaeb84d82.svg',
BUG_HUNTER_LEVEL_1: '/assets/46f6a28f462889f1a36cfca2591fcade.svg',
BUG_HUNTER_LEVEL_2: '/assets/5c6bb5c4640972078fc993f1b5f503ce.svg',
EARLY_VERIFIED_DEVELOPER: '/assets/877dc8bece1590e63fac6d5a0cd2a225.svg',
ACTIVE_DEVELOPER: '/assets/26c7a60fb1654315e0be26107bd47470.svg',
EARLY_SUPPORTER: '/assets/d66ce47c4ab7817190af9544f97e98cc.svg',
CERTIFIED_MODERATOR: '/assets/2af69d4f9d2ff38a7cf76fab0907ea7a.svg',
PREMIUM: '/assets/e04ce699dcd2fd50d352a384511687a9.svg',
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_1: '/assets/1d3c9e1123aee11a325af328609d1274.svg',
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_2: '/assets/dd50d32cf4fee241b2fa022d8c0435ae.svg',
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_3: '/assets/7294cc730410a1caeceeca736f800b42.svg',
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_4: '/assets/496aa1174817ec391612f745dc8e0725.svg',
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_5: '/assets/ce54a4f8c0e133a6f2d60336e7acac7d.svg',
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_6: '/assets/c0c9db2de008e61a1a720581ca175fa1.svg',
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_7: '/assets/556158300f0dca136d3c902586ff1316.svg',
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_8: '/assets/ba38c1c57dfccb94127e53b7ac502a90.svg',
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_9: '/assets/42ecb902decfc8e83a7446a0904b1e18.svg'
}
STAFF: "/assets/f62be1ec9bdd82d3d77158ad81830e68.svg",
PARTNER: "/assets/53828e0c0fb6676440ad11b5d2586241.svg",
HYPESQUAD: "/assets/f5354673c9cff61c1dcc70081ef774e5.svg",
HYPESQUAD_ONLINE_HOUSE_1: "/assets/995ecfdbdf94ad84dd4d802c104e4630.svg",
HYPESQUAD_ONLINE_HOUSE_2: "/assets/473dadec13ab7e90e209cc60fccb31c5.svg",
HYPESQUAD_ONLINE_HOUSE_3: "/assets/58f11abcf3c13812bff969baaeb84d82.svg",
BUG_HUNTER_LEVEL_1: "/assets/46f6a28f462889f1a36cfca2591fcade.svg",
BUG_HUNTER_LEVEL_2: "/assets/5c6bb5c4640972078fc993f1b5f503ce.svg",
EARLY_VERIFIED_DEVELOPER: "/assets/877dc8bece1590e63fac6d5a0cd2a225.svg",
ACTIVE_DEVELOPER: "/assets/26c7a60fb1654315e0be26107bd47470.svg",
EARLY_SUPPORTER: "/assets/d66ce47c4ab7817190af9544f97e98cc.svg",
CERTIFIED_MODERATOR: "/assets/2af69d4f9d2ff38a7cf76fab0907ea7a.svg",
PREMIUM: "/assets/e04ce699dcd2fd50d352a384511687a9.svg",
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_1: "/assets/1d3c9e1123aee11a325af328609d1274.svg",
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_2: "/assets/dd50d32cf4fee241b2fa022d8c0435ae.svg",
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_3: "/assets/7294cc730410a1caeceeca736f800b42.svg",
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_4: "/assets/496aa1174817ec391612f745dc8e0725.svg",
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_5: "/assets/ce54a4f8c0e133a6f2d60336e7acac7d.svg",
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_6: "/assets/c0c9db2de008e61a1a720581ca175fa1.svg",
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_7: "/assets/556158300f0dca136d3c902586ff1316.svg",
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_8: "/assets/ba38c1c57dfccb94127e53b7ac502a90.svg",
PREMIUM_GUILD_SUBSCRIPTION_LEVEL_9: "/assets/42ecb902decfc8e83a7446a0904b1e18.svg",
};

type userFlags = {
STAFF: number;
Expand All @@ -45,116 +45,134 @@ type userFlags = {
VERIFIED_DEVELOPER: number;
ACTIVE_DEVELOPER: number;
PREMIUM_EARLY_SUPPORTER: number;
}

const constants = webpack.getBySource("ACTIVE_DEVELOPER:1") as types.ModuleExports
const UserFlags = webpack.getExportsForProps(constants, ["ACTIVE_DEVELOPER", "HYPESQUAD_ONLINE_HOUSE_1"]) as userFlags;
const { profileBadge18 } = webpack.getByProps('profileBadge18') as Record<string, string>;

export function badge(args: { kind: string, param?: number | string }, Tooltip: TooltipType, Messages: Record<string, string & {format: (args: unknown) => string}>): JSX.Element {
};

const constants = webpack.getBySource("ACTIVE_DEVELOPER:1") as types.ModuleExports;
const UserFlags = webpack.getExportsForProps(constants, [
"ACTIVE_DEVELOPER",
"HYPESQUAD_ONLINE_HOUSE_1",
]) as userFlags;
const { profileBadge18 } = webpack.getByProps("profileBadge18") as Record<string, string>;

export function badge(
args: { kind: string; param?: number | string },
Tooltip: TooltipType,
Messages: Record<string, string & { format: (args: unknown) => string }>,
): JSX.Element {
let tooltip: string, asset: string;
const { kind, param } = args;


if (kind === 'staff') {
tooltip = Messages.STAFF_BADGE_TOOLTIP
asset = BadgeAssets.STAFF
if (kind === "staff") {
tooltip = Messages.STAFF_BADGE_TOOLTIP;
asset = BadgeAssets.STAFF;
}

if (kind === 'partner') {
tooltip = Messages.PARTNER_BADGE_TOOLTIP
asset = BadgeAssets.PARTNER
if (kind === "partner") {
tooltip = Messages.PARTNER_BADGE_TOOLTIP;
asset = BadgeAssets.PARTNER;
}

if (kind === 'certifiedPedo') {
tooltip = Messages.CERTIFIED_MODERATOR_BADGE_TOOLTIP
asset = BadgeAssets.CERTIFIED_MODERATOR
if (kind === "certifiedPedo") {
tooltip = Messages.CERTIFIED_MODERATOR_BADGE_TOOLTIP;
asset = BadgeAssets.CERTIFIED_MODERATOR;
}

if (kind === 'hypesquad') {
tooltip = Messages.HYPESQUAD_BADGE_TOOLTIP
asset = BadgeAssets.HYPESQUAD
if (kind === "hypesquad") {
tooltip = Messages.HYPESQUAD_BADGE_TOOLTIP;
asset = BadgeAssets.HYPESQUAD;
}

if (kind === 'hypesquadOnline') {
tooltip = Messages.HYPESQUAD_ONLINE_BADGE_TOOLTIP.format({ houseName: Messages[`HYPESQUAD_HOUSE_${param}`] })
asset = BadgeAssets[`HYPESQUAD_ONLINE_HOUSE_${param}`]
if (kind === "hypesquadOnline") {
tooltip = Messages.HYPESQUAD_ONLINE_BADGE_TOOLTIP.format({
houseName: Messages[`HYPESQUAD_HOUSE_${param}`],
});
asset = BadgeAssets[`HYPESQUAD_ONLINE_HOUSE_${param}`];
}

if (kind === 'hunter') {
tooltip = Messages.BUG_HUNTER_BADGE_TOOLTIP
asset = BadgeAssets[`BUG_HUNTER_LEVEL_${param}`]
if (kind === "hunter") {
tooltip = Messages.BUG_HUNTER_BADGE_TOOLTIP;
asset = BadgeAssets[`BUG_HUNTER_LEVEL_${param}`];
}

if (kind === 'verifiedDev') {
tooltip = Messages.VERIFIED_DEVELOPER_BADGE_TOOLTIP
asset = BadgeAssets.EARLY_VERIFIED_DEVELOPER
if (kind === "verifiedDev") {
tooltip = Messages.VERIFIED_DEVELOPER_BADGE_TOOLTIP;
asset = BadgeAssets.EARLY_VERIFIED_DEVELOPER;
}

if (kind === 'activeDev') {
tooltip = Messages.ACTIVE_DEVELOPER_BADGE_TOOLTIP
asset = BadgeAssets.ACTIVE_DEVELOPER
if (kind === "activeDev") {
tooltip = Messages.ACTIVE_DEVELOPER_BADGE_TOOLTIP;
asset = BadgeAssets.ACTIVE_DEVELOPER;
}

if (kind === 'earlySupporter') {
tooltip = Messages.EARLY_SUPPORTER_TOOLTIP
asset = BadgeAssets.EARLY_SUPPORTER
if (kind === "earlySupporter") {
tooltip = Messages.EARLY_SUPPORTER_TOOLTIP;
asset = BadgeAssets.EARLY_SUPPORTER;
}

if (kind === 'premium') {
tooltip = Messages.PREMIUM_BADGE_TOOLTIP.format({ date: new Date(param!) })
asset = BadgeAssets.PREMIUM
if (kind === "premium") {
tooltip = Messages.PREMIUM_BADGE_TOOLTIP.format({ date: new Date(param!) });
asset = BadgeAssets.PREMIUM;
}

if (kind === 'boosting') {
tooltip = Messages.PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP.format({ date: new Date(param!) })
asset = BadgeAssets.PREMIUM_GUILD_SUBSCRIPTION_LEVEL_1//${userLevel.getUserLevel(param)}`]
if (kind === "boosting") {
tooltip = Messages.PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP.format({ date: new Date(param!) });
asset = BadgeAssets.PREMIUM_GUILD_SUBSCRIPTION_LEVEL_1; //${userLevel.getUserLevel(param)}`]
}

return (
<Tooltip text={tooltip!}>
{(props: React.HTMLAttributes<HTMLSpanElement>) => (
<span {...props} role="button" tabIndex={0}>
<img alt='' src={asset} className={profileBadge18}/>
<img alt="" src={asset} className={profileBadge18} />
</span>
)}
</Tooltip>
)
);
}

export const cache: Record<string, User> = {}
export const cache: Record<string, User> = {};

// function fetchBadges(id: string): {premiumSince: unknown, premiumGuildSince: unknown} {

// }

export default function Badges(Tooltip: TooltipType, Messages: {}) {
return (props: { user: User, premium: { premiumSince: string, premiumGuildSince: string } & Record<string, string> }): JSX.Element => {
return (props: {
user: User;
premium: { premiumSince: string; premiumGuildSince: string } & Record<string, string>;
}): JSX.Element => {
const { user, premium } = props;
if (!Tooltip) {
console.log("Tooltip not found");
return <></>;
}

const badges = [
(user.publicFlags & UserFlags.STAFF) !== 0 && { kind: 'staff' },
(user.publicFlags & UserFlags.PARTNER) !== 0 && { kind: 'partner' },
(user.publicFlags & UserFlags.CERTIFIED_MODERATOR) !== 0 && { kind: 'certifiedPedo' },
(user.publicFlags & UserFlags.HYPESQUAD) !== 0 && { kind: 'hypesquad' },
(user.publicFlags & UserFlags.HYPESQUAD_ONLINE_HOUSE_1) !== 0 && { kind: 'hypesquadOnline', param: 1 },
(user.publicFlags & UserFlags.HYPESQUAD_ONLINE_HOUSE_2) !== 0 && { kind: 'hypesquadOnline', param: 2 },
(user.publicFlags & UserFlags.HYPESQUAD_ONLINE_HOUSE_3) !== 0 && { kind: 'hypesquadOnline', param: 3 },
(user.publicFlags & UserFlags.BUG_HUNTER_LEVEL_1) !== 0 && { kind: 'hunter', param: 1 },
(user.publicFlags & UserFlags.BUG_HUNTER_LEVEL_2) !== 0 && { kind: 'hunter', param: 2 },
(user.publicFlags & UserFlags.VERIFIED_DEVELOPER) !== 0 && { kind: 'verifiedDev' },
(user.publicFlags & UserFlags.ACTIVE_DEVELOPER) !== 0 && { kind: 'activeDev' },
(user.publicFlags & UserFlags.PREMIUM_EARLY_SUPPORTER) !== 0 && { kind: 'earlySupporter' },
premium && { kind: 'premium', param: premium.premiumSince },
premium && { kind: 'boosting', param: premium.premiumGuildSince },
(user.publicFlags & UserFlags.STAFF) !== 0 && { kind: "staff" },
(user.publicFlags & UserFlags.PARTNER) !== 0 && { kind: "partner" },
(user.publicFlags & UserFlags.CERTIFIED_MODERATOR) !== 0 && { kind: "certifiedPedo" },
(user.publicFlags & UserFlags.HYPESQUAD) !== 0 && { kind: "hypesquad" },
(user.publicFlags & UserFlags.HYPESQUAD_ONLINE_HOUSE_1) !== 0 && {
kind: "hypesquadOnline",
param: 1,
},
(user.publicFlags & UserFlags.HYPESQUAD_ONLINE_HOUSE_2) !== 0 && {
kind: "hypesquadOnline",
param: 2,
},
(user.publicFlags & UserFlags.HYPESQUAD_ONLINE_HOUSE_3) !== 0 && {
kind: "hypesquadOnline",
param: 3,
},
(user.publicFlags & UserFlags.BUG_HUNTER_LEVEL_1) !== 0 && { kind: "hunter", param: 1 },
(user.publicFlags & UserFlags.BUG_HUNTER_LEVEL_2) !== 0 && { kind: "hunter", param: 2 },
(user.publicFlags & UserFlags.VERIFIED_DEVELOPER) !== 0 && { kind: "verifiedDev" },
(user.publicFlags & UserFlags.ACTIVE_DEVELOPER) !== 0 && { kind: "activeDev" },
(user.publicFlags & UserFlags.PREMIUM_EARLY_SUPPORTER) !== 0 && { kind: "earlySupporter" },
premium && { kind: "premium", param: premium.premiumSince },
premium && { kind: "boosting", param: premium.premiumGuildSince },
].filter(Boolean);

return <div className="badges">
{badges.map((b) => b && badge(b, Tooltip, Messages))}
</div>
}
return <div className="badges">{badges.map((b) => b && badge(b, Tooltip, Messages))}</div>;
};
}
42 changes: 27 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@
import { Injector, common, webpack } from "replugged";
import { Channel, Message, User } from 'discord-types/general';
import { Channel, Message, User } from "discord-types/general";
import "./styles.css";
const { React } = common;

import badges from "./Badges";

const injector = new Injector();

type premiumProfile = { premiumSince: string, premiumGuildSince: string } & Record<string, string>
type premiumProfile = { premiumSince: string; premiumGuildSince: string } & Record<string, string>;

export async function start(): Promise<void> {
const tooltipMod = await webpack.waitForModule<Record<string, React.FC>>(
webpack.filters.bySource(/shouldShowTooltip:!1/)
webpack.filters.bySource(/shouldShowTooltip:!1/),
);
const Tooltip = tooltipMod && webpack.getFunctionBySource<React.FC>(/shouldShowTooltip:!1/, tooltipMod);
const Tooltip =
tooltipMod && webpack.getFunctionBySource<React.FC>(/shouldShowTooltip:!1/, tooltipMod);
if (!Tooltip) {
console.error("Failed to find Tooltip component");
return;
}
const Messages = webpack.getByProps("Messages", "getLanguages")?.Messages as Record<string, unknown>;
const Messages = webpack.getByProps("Messages", "getLanguages")?.Messages as Record<
string,
unknown
>;
const Badges = badges(Tooltip, Messages);
const { getUserProfile } = await webpack.waitForModule<Record<string, (id: string) => premiumProfile>>(webpack.filters.byProps('getUserProfile'));
const { getUserProfile } = await webpack.waitForModule<
Record<string, (id: string) => premiumProfile>
>(webpack.filters.byProps("getUserProfile"));

const mod = await webpack.waitForModule<{
Z: (...args: Array<{
decorations: React.ReactElement[][],
message: Message,
author: User,
channel: Channel
}>) => unknown;
Z: (
...args: Array<{
decorations: React.ReactElement[][];
message: Message;
author: User;
channel: Channel;
}>
) => unknown;
}>(webpack.filters.bySource('"BADGES"'));

injector.after(mod, 'Z', ([ args ], res: React.ReactElement) => {
injector.after(mod, "Z", ([args], res: React.ReactElement) => {
const { author } = args.message;
res?.props?.children[3]?.props?.children?.splice(1, 0, React.createElement(Badges, {user: author, premium: getUserProfile(author.id)}));
res?.props?.children[3]?.props?.children?.splice(
1,
0,
React.createElement(Badges, { user: author, premium: getUserProfile(author.id) }),
);

return res;
})
});
}

export function stop(): void {
Expand Down
32 changes: 28 additions & 4 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,48 @@
* I will change this, but I'm too lazy to understand and change atm
*/

.name-3Vmqxm .badges, .header-2jRmjb .badges, .repliedMessage-3Z6XBG .badges, .nameAndDecorators-3ERwy2 .badges, .nameAndDecorators-2A8Bbk .badges, .threadMessageAccessory-2W9mjC .badges, .morebadges .badges {
.name-3Vmqxm .badges,
.header-2jRmjb .badges,
.repliedMessage-3Z6XBG .badges,
.nameAndDecorators-3ERwy2 .badges,
.nameAndDecorators-2A8Bbk .badges,
.threadMessageAccessory-2W9mjC .badges,
.morebadges .badges {
display: flex;
align-items: center;
background-color: transparent !important;
margin-left: 3px;
}
.name-3Vmqxm .badges div:not(.overflow-1wOqNV), .header-2jRmjb .badges div:not(.overflow-1wOqNV), .repliedMessage-3Z6XBG .badges div:not(.overflow-1wOqNV), .nameAndDecorators-3ERwy2 .badges div:not(.overflow-1wOqNV), .nameAndDecorators-2A8Bbk .badges div:not(.overflow-1wOqNV), .threadMessageAccessory-2W9mjC .badges div:not(.overflow-1wOqNV), .morebadges .badges div:not(.overflow-1wOqNV) {
.name-3Vmqxm .badges div:not(.overflow-1wOqNV),
.header-2jRmjb .badges div:not(.overflow-1wOqNV),
.repliedMessage-3Z6XBG .badges div:not(.overflow-1wOqNV),
.nameAndDecorators-3ERwy2 .badges div:not(.overflow-1wOqNV),
.nameAndDecorators-2A8Bbk .badges div:not(.overflow-1wOqNV),
.threadMessageAccessory-2W9mjC .badges div:not(.overflow-1wOqNV),
.morebadges .badges div:not(.overflow-1wOqNV) {
height: 20px;
width: 20px;
flex-shrink: 0;
background-size: 20px 20px;
background-repeat: no-repeat;
background-position: center;
}
.name-3Vmqxm .badges div:not([class]), .header-2jRmjb .badges div:not([class]), .repliedMessage-3Z6XBG .badges div:not([class]), .nameAndDecorators-3ERwy2 .badges div:not([class]), .nameAndDecorators-2A8Bbk .badges div:not([class]), .threadMessageAccessory-2W9mjC .badges div:not([class]), .morebadges .badges div:not([class]) {
.name-3Vmqxm .badges div:not([class]),
.header-2jRmjb .badges div:not([class]),
.repliedMessage-3Z6XBG .badges div:not([class]),
.nameAndDecorators-3ERwy2 .badges div:not([class]),
.nameAndDecorators-2A8Bbk .badges div:not([class]),
.threadMessageAccessory-2W9mjC .badges div:not([class]),
.morebadges .badges div:not([class]) {
margin-left: 3px;
}
.name-3Vmqxm .badges:empty, .header-2jRmjb .badges:empty, .repliedMessage-3Z6XBG .badges:empty, .nameAndDecorators-3ERwy2 .badges:empty, .nameAndDecorators-2A8Bbk .badges:empty, .threadMessageAccessory-2W9mjC .badges:empty, .morebadges .badges:empty {
.name-3Vmqxm .badges:empty,
.header-2jRmjb .badges:empty,
.repliedMessage-3Z6XBG .badges:empty,
.nameAndDecorators-3ERwy2 .badges:empty,
.nameAndDecorators-2A8Bbk .badges:empty,
.threadMessageAccessory-2W9mjC .badges:empty,
.morebadges .badges:empty {
display: none;
}
.badges {
Expand Down

0 comments on commit 5702b45

Please sign in to comment.