mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-30 23:40:07 +00:00
* add Benchmark (customSmallerIsBetter) benchmark result for bdedcbc78b28b94bde4d5d6c00ec776e2d51ef36 * add Benchmark (customSmallerIsBetter) benchmark result for b7f88d5ac4ad690aebe83c190c75b2715ddc1ece * add Benchmark (customSmallerIsBetter) benchmark result for b6ad848bb51b4b9f263fc3d25b7cd6ca239224b1 * add Benchmark (customSmallerIsBetter) benchmark result for d6c362e108fde17d808a3eef4b2d4a523efe00bf * add Benchmark (customSmallerIsBetter) benchmark result for ece1249fb7d4c838a6ab9008da489d820bf38918 * add Benchmark (customSmallerIsBetter) benchmark result for dabd97a10de654d157f027b75c7066a50dcac268 * clean repo * chore: add vscode setting * feat: add generate cache * ci: add auto run generate cache per day * add Benchmark (customSmallerIsBetter) benchmark result for 4b05ab9141d69b59bbd4df048b1f7572b475ba6b * fix: data * ci: fix name * ci: change name * delete before PR * fix: censor object * chore: add license back Co-authored-by: github-action-benchmark <github@users.noreply.github.com>
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import { createBot } from "https://deno.land/x/discordeno@17.1.0/mod.ts";
|
|
import {
|
|
hideDate,
|
|
hideEUDText,
|
|
hideHash,
|
|
hideSnowflake,
|
|
loopObject
|
|
} from "https://raw.githubusercontent.com/discordeno/benchmarks/main/utils.ts";
|
|
|
|
const token = Deno.env.get("DISCORD_TOKEN");
|
|
if (!token) throw new Error("Token was not provided.");
|
|
|
|
const guildId = 1034163795146330163n
|
|
|
|
const bot = createBot({
|
|
token,
|
|
botId: BigInt(atob(token.split(".")[0])),
|
|
});
|
|
|
|
const sortValues = (object: any) => {
|
|
for (const key of Object.keys(object)) {
|
|
if (Array.isArray(object[key])) {
|
|
if (object[key].length > 0 && typeof object[key][0] === "object") {
|
|
object[key].forEach((element: any) => {
|
|
sortValues(element)
|
|
});
|
|
} else {
|
|
object[key].sort();
|
|
}
|
|
}
|
|
if (typeof object[key] === "object" && object[key] !== null) {
|
|
sortValues(object[key])
|
|
}
|
|
}
|
|
}
|
|
|
|
const cleanPayload = (payload: any) => loopObject(payload, (value, key) => {
|
|
if (typeof value !== "string") return value;
|
|
|
|
// IF ITS A NUMBER MASK NUMBER
|
|
if (/^\d+$/.test(value)) return hideSnowflake(value);
|
|
if (["icon", "banner", "splash", "avatar"].includes(key)) {
|
|
return hideHash(value);
|
|
}
|
|
// IF ITS DATE REGEX
|
|
if (Date.parse(value)) return hideDate();
|
|
|
|
return hideEUDText(value);
|
|
});
|
|
|
|
const guild = cleanPayload(await bot.rest.runMethod(bot.rest, "GET", bot.constants.routes.GUILD(guildId, true)))
|
|
await Deno.writeTextFile(`cache/cachedObject/guild.json`, JSON.stringify(guild, undefined, 2))
|
|
const channels = await bot.rest.runMethod(bot.rest, "GET", bot.constants.routes.GUILD_CHANNELS(guildId)) as any[];
|
|
|
|
const channelNames = ["rules", "announcement-channel", "moderator-channel", "text-channel", "stage-channel", "voice-channel"]
|
|
|
|
for (const channelName of channelNames) {
|
|
const channel = cleanPayload(channels.find((channel) => channel.name === channelName))
|
|
await Deno.writeTextFile(`cache/cachedObject/${channelName}.json`, JSON.stringify(channel, undefined, 2))
|
|
}
|
|
|
|
const user = cleanPayload(await bot.rest.runMethod(bot.rest, "GET", bot.constants.routes.USER(bot.id)));
|
|
await Deno.writeTextFile(`cache/cachedObject/user.json`, JSON.stringify(user, undefined, 2))
|