Skip to content

Commit

Permalink
Merge pull request #67 from xp-bot/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
ConnysCode authored Oct 6, 2024
2 parents b1772a0 + 6e5ade4 commit c7e4d3d
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ yarn-error.log*
next-env.d.ts

*.code-workspace
/.vscode/launch.json
/.vscode/launch.json

.idea
14 changes: 9 additions & 5 deletions apis/api-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
IXPUser,
IXPUserBan,
IXPUserPremium,
IXPUserPremiumServers,
IXPUserPremiumServers, XPCommunityExportData,
} from "../models/backend/xp-models";

const backendFetch = async <Body>(route: string, options?: RequestInit) => {
Expand Down Expand Up @@ -322,11 +322,15 @@ export const apiRoutes = {
),
},
guild: {
getExport: (guildID: string) =>
backendAxios<XPCommunityExportData>(`/xp/guild/${guildID}/export`, {
method: `GET`,
}),
getLogs: (guildID: string, page = 1, query?: string) =>
backendAxios<IXPDBLog>(`/xp/guild/${guildID}/logs`, {
method: `GET`,
params: { query, page },
}),
backendAxios<IXPDBLog>(`/xp/guild/${guildID}/logs`, {
method: `GET`,
params: { query, page },
}),
guildMember: {
setGuildMembersXP: (guildID: string, userID: string, xp: number) =>
backendAxios<{}>(`/xp/guild/${guildID}/member/${userID}/xp/${xp}`, {
Expand Down
12 changes: 6 additions & 6 deletions components/desktop/desktop-nav-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ const NavigationItems: ITabButton[] = [
isActive: constant(false),
link: `https://get.xp-bot.net/`,
},
{
text: `Premium`,
isActive: (path: string[]) => isEqual(path[0], `premium`),
isVisible: (user) => isUndefined(user) || !user?.premium.userPremium,
link: `/premium`,
},
// {
// text: `Premium`,
// isActive: (path: string[]) => isEqual(path[0], `premium`),
// isVisible: (user) => isUndefined(user) || !user?.premium.userPremium,
// link: `/premium`,
// },
{
text: `Status`,
isActive: (path: string[]) => isEqual(path[0], `status`),
Expand Down
19 changes: 9 additions & 10 deletions components/mobile/mobile-nav-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { faNoteSticky } from "@fortawesome/free-regular-svg-icons";
import {
faCrown,
faHome,
faServer,
faSignIn,
Expand Down Expand Up @@ -66,13 +65,13 @@ const NavigationItems: {
isVisible: (user) => !isUndefined(user),
icon: faUser,
},
{
text: `Premium`,
isActive: (path: string[]) => isEqual(path[0], `premium`),
link: `/premium`,
isVisible: (user) => isUndefined(user),
icon: faCrown,
},
// {
// text: `Premium`,
// isActive: (path: string[]) => isEqual(path[0], `premium`),
// link: `/premium`,
// isVisible: (user) => isUndefined(user),
// icon: faCrown,
// },
{
text: `Sign In`,
isActive: constant(false),
Expand All @@ -99,7 +98,7 @@ const MobileNavBar: FC<MobileNavBarProps> = () => {
filter(NavigationItems, (item) =>
item.isVisible
? item.isVisible(user.currentUser, currentPath)
: true
: true,
),
({ text, link, isActive, icon }, idx) => (
<Link key={idx} href={link}>
Expand All @@ -116,7 +115,7 @@ const MobileNavBar: FC<MobileNavBarProps> = () => {
<p className="text-xs">{text}</p>
</div>
</Link>
)
),
)}
</div>
</div>
Expand Down
86 changes: 86 additions & 0 deletions models/backend/xp-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,89 @@ export type XPBanTypes =
| `rankingcard`
| `dashboard_login`
| `dashboard_blog_comment_create`;


export interface XPCommunityExportData {
guild: ExportGuild;
guildMembers: ExportGuildMember[];
}

interface ExportGuild {
values: {
messagexp: number;
voicexp: number;
reactionxp: number;
lootXP: number;
fishXP: number;
rollXP: number;
triviaxp: number;
maximumdailyxp: number;
maximumlevel: number;
messagecooldown: number;
gamecooldown: number;
triviacooldown: number;
"req-message-length": number;
voicejoincooldown: number;
};
modules: {
messagexp: boolean;
voicexp: boolean;
reactionxp: boolean;
ignoreafk: boolean;
autonick: boolean;
autonickuseprefix: boolean;
autonickshowstring: boolean;
leaderboard: boolean;
singlerankrole: boolean;
removereachedlevelroles: boolean;
maximumlevel: boolean;
resetonleave: boolean;
enablecommandsinthreads: boolean;
games: boolean;
trivia: boolean;
};
logs: {
levelup?: string;
exceptions?: string;
voicetime?: string;
};
ignored: {
roles: string[];
channels: string[];
};
boosts: {
roles: {
id: string;
percentage: number;
}[];
channels: {
id: string;
percentage: number;
}[];
};
announce: {
current: boolean;
message: string;
ping: boolean;
channelId?: string;
};
leaderboard_message: {
enabled: boolean;
channelId?: string;
messageId?: string;
};
levelroles: {
id: string;
level: number;
}[];
premiumUser: string;
voteFreeUser: string;
}

interface ExportGuildMember {
userId: string;
xp: number;
settings: {
incognito?: boolean | null;
};
}
59 changes: 48 additions & 11 deletions page-tabs/server-tabs/server-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// eslint-disable-next-line import/no-cycle
import {
faBoxesPacking,
faDownload,
faInfoCircle,
faPaintBrush,
faSave,
faToggleOff,
faUpload,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import ButtonCluster, { ButtonFeature } from "components/button-cluster";
Expand All @@ -24,6 +22,7 @@ import { FinalColor } from "extract-colors/lib/types/Color";
import { motion } from "framer-motion";
import {
clone,
constant,
filter,
isEmpty,
isEqual,
Expand All @@ -38,6 +37,9 @@ import { SubmitHandler, useForm } from "react-hook-form";
import { DiscordChannelType } from "utils/discord-utils";
import { getAverageImageColors } from "utils/image-utils";

import { apiRoutes } from "../../apis/api-helper";
import downloadBlob from "../../utils/download-blob";

interface ServerTabSettingsProps {}

interface IBackgroundInputs {
Expand Down Expand Up @@ -89,7 +91,7 @@ const ServerTabSettings: FC<ServerTabSettingsProps> = () => {
url: data.url,
blur: data.blur,
enabled: true,
}
},
);
setEditBG(false);
};
Expand All @@ -109,7 +111,7 @@ const ServerTabSettings: FC<ServerTabSettingsProps> = () => {
url: guild.currentBackground?.url,
blur: guild.currentBackground?.blur,
enabled: false,
}
},
);
setEditBG(false);
};
Expand All @@ -124,7 +126,7 @@ const ServerTabSettings: FC<ServerTabSettingsProps> = () => {
oldValue: `Enabled`,
newValue: `Disabled`,
},
g
g,
);
}
};
Expand All @@ -144,7 +146,7 @@ const ServerTabSettings: FC<ServerTabSettingsProps> = () => {
: `Disabled`,
newValue: channelID,
},
g
g,
);
};

Expand All @@ -156,6 +158,22 @@ const ServerTabSettings: FC<ServerTabSettingsProps> = () => {
? prePreviewBackground
: undefined;

const [downloadedExport, setDownloadedExport] = useState(false);

const downloadExport = async () => {
if (downloadedExport) return;
setDownloadedExport(true);
const data = await apiRoutes.xp.guild
.getExport(guild.guildID)
.then((res) => {
return res.success ? res.body : {};
})
.catch(constant({}));

const blob = new Blob([JSON.stringify(data)], { type: "application/json" });
downloadBlob(blob, "community_export.json");
};

return (
<>
<div>
Expand Down Expand Up @@ -213,7 +231,7 @@ const ServerTabSettings: FC<ServerTabSettingsProps> = () => {
guild.currentDiscordChannels,
(channel) =>
isEqual(channel.type, DiscordChannelType.news) ||
isEqual(channel.type, DiscordChannelType.text)
isEqual(channel.type, DiscordChannelType.text),
) || [],
(channel) => ({
id: channel.id,
Expand All @@ -222,13 +240,32 @@ const ServerTabSettings: FC<ServerTabSettingsProps> = () => {
guild.currentXPGuild?.leaderboard_message.enabled &&
isEqual(
guild.currentXPGuild?.leaderboard_message.channelID,
channel.id
channel.id,
),
})
}),
),
]}
/>
</div>
<div>
<PageTitle title="Community Export" />
<div
className={
!downloadedExport ? `` : `pointer-events-none opacity-75`
}
>
<ButtonCluster
buttons={[
{
text: "Export Community",
icon: faDownload,
disabled: downloadedExport,
onClick: downloadExport,
},
]}
/>
</div>
</div>
{/* <div>
<PageTitle
disableArrow
Expand Down Expand Up @@ -357,8 +394,8 @@ const ServerTabSettings: FC<ServerTabSettingsProps> = () => {
!startsWith(value, `https://`)
? `The URL needs to start with "https://"!`
: !/(https?:\/\/.*\.(?:png|jpg|jpeg))$/.test(value)
? `The Image must directly lead to an exposed image. (.png / .jpg / .jpeg)`
: true,
? `The Image must directly lead to an exposed image. (.png / .jpg / .jpeg)`
: true,
})}
formError={errors.url}
label="Server Background URL"
Expand Down
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ChangelogModal = () => {
...(visibleChanges ? visibleChanges[name] || [] : []),
...change,
];
}
},
);
});

Expand Down
12 changes: 8 additions & 4 deletions pages/premium.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const Premium: NextPage<PremiumProps> = () => {
`premium`,
undefined,
undefined,
headerGradientTypes.premium
headerGradientTypes.premium,
);
}, []);

Expand Down Expand Up @@ -227,10 +227,14 @@ const Premium: NextPage<PremiumProps> = () => {
};

export async function getStaticProps() {
// const blogPosts = await apiRoutes.blog.get.posts();
if (process.env.npm_lifecycle_event === "build")
return {
notFound: true,
};
return {
props: {
// blogPosts: blogPosts.success ? blogPosts.body : [],
redirect: {
destination: "/",
permanent: true,
},
};
}
Expand Down
15 changes: 15 additions & 0 deletions utils/download-blob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default async (blob: Blob, fileName: string, mimeType = "text/csv") => {
if (!(blob instanceof Blob)) {
blob = new Blob([blob], { type: mimeType });
}

const a = document.createElement("a");
a.download = fileName;
a.href = URL.createObjectURL(blob);
a.addEventListener("click", () => {
setTimeout(() => URL.revokeObjectURL(a.href), 30 * 1000);
});
document.body.appendChild(a); // Append to the body to make it part of the DOM
a.click();
document.body.removeChild(a); // Remove from the DOM after clicking
};

0 comments on commit c7e4d3d

Please sign in to comment.