feat: add role, member, message (#2571)

This commit is contained in:
Jonathan Ho
2022-11-03 18:38:54 +08:00
committed by GitHub
parent db55d25f70
commit 66c8352c3e

View File

@@ -1,4 +1,4 @@
import { createBot } from "https://deno.land/x/discordeno@17.1.0/mod.ts";
import { Channel, createBot, Guild, Member, Message, Role, User } from "https://deno.land/x/discordeno@17.1.0/mod.ts";
import {
hideDate,
hideEUDText,
@@ -17,24 +17,7 @@ const bot = createBot({
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) => {
const cleanPayload = <T extends Object>(payload: T): T => loopObject(payload, (value, key) => {
if (typeof value !== "string") return value;
// IF ITS A NUMBER MASK NUMBER
@@ -48,16 +31,26 @@ const cleanPayload = (payload: any) => loopObject(payload, (value, key) => {
return hideEUDText(value);
});
const guild = cleanPayload(await bot.rest.runMethod(bot.rest, "GET", bot.constants.routes.GUILD(guildId, true)))
const guild = cleanPayload(await bot.rest.runMethod<Guild>(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 channels = await bot.rest.runMethod<Channel[]>(bot.rest, "GET", bot.constants.routes.GUILD_CHANNELS(guildId));
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))
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)));
const user = cleanPayload(await bot.rest.runMethod<User>(bot.rest, "GET", bot.constants.routes.USER(bot.id)));
await Deno.writeTextFile(`cache/cachedObject/user.json`, JSON.stringify(user, undefined, 2))
const dirtyRole = (await bot.rest.runMethod<Role[]>(bot.rest, "GET", bot.constants.routes.GUILD_ROLES(guildId))).find((role) => role.name === "a role")
const role = { ...cleanPayload(dirtyRole!), permissions: dirtyRole!.permissions }
await Deno.writeTextFile(`cache/cachedObject/role.json`, JSON.stringify(role, undefined, 2))
const member = cleanPayload((await bot.rest.runMethod<Member[]>(bot.rest, "GET", bot.constants.routes.GUILD_MEMBERS(guildId)))[0])
await Deno.writeTextFile(`cache/cachedObject/member.json`, JSON.stringify(member, undefined, 2))
const message = cleanPayload((await bot.rest.runMethod<Message[]>(bot.rest, "GET", bot.constants.routes.CHANNEL_MESSAGES(channels.find((channel) => channel.name === "text-channel")!.id)))[0])
await Deno.writeTextFile(`cache/cachedObject/message.json`, JSON.stringify(message, undefined, 2))