get_file
This commit is contained in:
parent
a039887832
commit
438136b43a
|
@ -5,6 +5,7 @@ import add_nick from "./commands/add_nick.js";
|
|||
import del_nick_super from "./commands/del_nick_super.js";
|
||||
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 ping from "./commands/ping.js";
|
||||
|
||||
const commands: TCommand[] = [
|
||||
|
@ -13,6 +14,7 @@ const commands: TCommand[] = [
|
|||
del_nick_super,
|
||||
del_user_super,
|
||||
get_blacklist,
|
||||
get_file,
|
||||
ping,
|
||||
];
|
||||
export default commands;
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
const { SlashCommandBuilder, AttachmentBuilder } = 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").setDescription("get the file").setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
const data = (await firebase.get()).val();
|
||||
let is_registed = false;
|
||||
|
||||
text = "{members:[";
|
||||
for (let discord_search_point in data["members"]) {
|
||||
for (let minecraft_search_point in data["members"][discord_search_point].minecraft) {
|
||||
text = text + "'" + data["members"][discord_search_point].minecraft[minecraft_search_point] + "',";
|
||||
}
|
||||
if (data["members"][discord_search_point].discord == interaction.user.id) {
|
||||
is_registed = true;
|
||||
}
|
||||
}
|
||||
text = text.slice(0, -1) + "], blacklist:[";
|
||||
|
||||
for (let discord_search_point in data["blacklist"]) {
|
||||
for (let minecraft_search_point in data["blacklist"][discord_search_point].minecraft) {
|
||||
text = text + "'" + data["blacklist"][discord_search_point].minecraft[minecraft_search_point] + "',";
|
||||
}
|
||||
}
|
||||
text = text.slice(0, -1) + "]}";
|
||||
|
||||
if (is_registed) {
|
||||
const userInfoFile = { attachment: Buffer.from(text), name: "data.json" };
|
||||
await interaction.editReply({ content: `*** 절대 이 파일을 공유하지 마세요***`, files: [userInfoFile] });
|
||||
} else {
|
||||
await interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` });
|
||||
}
|
||||
},
|
||||
};
|
46
src/command/commands/get_file.ts
Executable file
46
src/command/commands/get_file.ts
Executable file
|
@ -0,0 +1,46 @@
|
|||
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
|
||||
|
||||
import firebase from "../../wrapper/firebase.js";
|
||||
import { TUser } from "../../functions.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("get_file")
|
||||
.setDescription("get the file")
|
||||
.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 data: {
|
||||
blacklist: string[];
|
||||
members: string[];
|
||||
} = { blacklist: [], members: [] };
|
||||
(await blacklist.get()).forEach((doc) => {
|
||||
const user = doc.data() as TUser;
|
||||
data.blacklist.push(user.minecraft_uuid);
|
||||
});
|
||||
(await members.get()).forEach((doc) => {
|
||||
const user = doc.data() as TUser;
|
||||
data.members.push(user.minecraft_uuid);
|
||||
});
|
||||
|
||||
const buffered_file = {
|
||||
attachment: Buffer.from(JSON.stringify(data)),
|
||||
name: "data.json",
|
||||
};
|
||||
await interaction.editReply({
|
||||
content: `*** 절대 이 파일을 공유하지 마세요***`,
|
||||
files: [buffered_file],
|
||||
});
|
||||
},
|
||||
};
|
|
@ -9,6 +9,9 @@ initializeApp({
|
|||
clientEmail: process.env.FIREBASE_CERT_CLIENT_EMAIL,
|
||||
privateKey: process.env.FIREBASE_CERT_PRIVATE_KEY?.replace(/\\n/g, "\n"),
|
||||
}),
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
|
||||
const db = getFirestore();
|
||||
|
|
Loading…
Reference in a new issue