diff --git a/src/command/commands.ts b/src/command/commands.ts index 3fa3f67..d1205fa 100644 --- a/src/command/commands.ts +++ b/src/command/commands.ts @@ -7,6 +7,7 @@ import del_user_super from "./commands/del_user_super.js"; import get_blacklist from "./commands/get_blacklist.js"; import get_file from "./commands/get_file.js"; import get_members from "./commands/get_members.js"; +import get_raw_file from "./commands/get_raw_file.js"; import ping from "./commands/ping.js"; const commands: TCommand[] = [ @@ -17,6 +18,7 @@ const commands: TCommand[] = [ get_blacklist, get_file, get_members, + get_raw_file, ping, ]; export default commands; diff --git a/src/command/commands/get_file_super.js b/src/command/commands/get_file_super.js deleted file mode 100755 index 4331575..0000000 --- a/src/command/commands/get_file_super.js +++ /dev/null @@ -1,44 +0,0 @@ -const { - SlashCommandBuilder, - AttachmentBuilder, - PermissionFlagsBits, -} = require("discord.js"); - -const firebase_admin = require("firebase-admin"); -const { getDatabase } = require("firebase-admin/database"); -const serviceAccount = require("../../firebase/conf.json"); -if (!firebase_admin.apps.length) { - firebase_admin.initializeApp({ - credential: firebase_admin.credential.cert(serviceAccount), - databaseURL: process.env.FIREBASE_URL, - databaseAuthVariableOverride: { - uid: process.env.FIREBASE_UID, - }, - }); -} -const firebase = getDatabase().ref("/"); - -module.exports = { - data: new SlashCommandBuilder() - .setName("get_file_super") - .setDescription("get the file") - .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) - .setDMPermission(false), - async execute(interaction) { - await interaction.deferReply({ ephemeral: true }); - await interaction.editReply( - "해당 커맨드에 버그가 있어서 임시로 비활성화 되었습니다..........." - ); - // const data = (await firebase.get()).val(); - // for (let discord_search_point in data["members"]) { - // if (data["members"][discord_search_point].discord == interaction.user.id) { - // //이미 등록된 디코일경우 - // const userInfoFile = { attachment: Buffer.from([data]), name: "data.json" }; - // await interaction.editReply({ content: `*** 절대 이 파일을 공유하지 마세요***`, files: [userInfoFile] }); - - // return; - // } - // } //신규 디코일 경우 - // await interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` }); - }, -}; diff --git a/src/command/commands/get_raw_file.ts b/src/command/commands/get_raw_file.ts new file mode 100755 index 0000000..1c7b96c --- /dev/null +++ b/src/command/commands/get_raw_file.ts @@ -0,0 +1,61 @@ +import { + ChatInputCommandInteraction, + SlashCommandBuilder, + PermissionFlagsBits, +} from "discord.js"; + +import firebase from "../../wrapper/firebase.js"; +import { TUser } from "../../functions.js"; + +export default { + data: new SlashCommandBuilder() + .setName("get_raw_file") + .setDescription("get the file") + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) + .setDMPermission(false), + async execute(interaction: ChatInputCommandInteraction) { + const discord_id = interaction.user.id; + + const members = firebase.collection("members"); + const blacklist = firebase.collection("blacklist"); + + if ((await members.where("discord_id", "==", discord_id).get()).empty) { + interaction.editReply({ + content: "`에러`: 하나 이상의 아이디를 등록해야 합니다.", + }); + return; + } + + let blacklist_data: Map = new Map(); + (await blacklist.get()).forEach((doc) => { + const user = doc.data() as TUser; + const data_get = blacklist_data.get(user.discord_id); + if (!data_get) { + blacklist_data.set(user.discord_id, [user.minecraft_uuid]); + } else { + data_get.push(user.minecraft_uuid); + blacklist_data.set(user.discord_id, data_get); + } + }); + + let member_data: Map = new Map(); + (await members.get()).forEach((doc) => { + const user = doc.data() as TUser; + const data_get = member_data.get(user.discord_id); + if (!data_get) { + member_data.set(user.discord_id, [user.minecraft_uuid]); + } else { + data_get.push(user.minecraft_uuid); + member_data.set(user.discord_id, data_get); + } + }); + + const buffer_file = { + attachment: Buffer.from( + JSON.stringify({ blacklist: blacklist_data, members: member_data }) + ), + name: "raw_file.txt", + }; + await interaction.editReply({ files: [buffer_file] }); + }, +};