From 17a271e76ee4846c0043ffb2d8161e8e8269d529 Mon Sep 17 00:00:00 2001 From: kdh8219 <65698239+kdh8219@users.noreply.github.com> Date: Sat, 29 Apr 2023 15:16:15 +0900 Subject: [PATCH] mov_blacklist_super --- src/command/commands.ts | 2 + src/command/commands/mov_blacklist_super.js | 53 --------------------- src/command/commands/mov_blacklist_super.ts | 47 ++++++++++++++++++ 3 files changed, 49 insertions(+), 53 deletions(-) delete mode 100755 src/command/commands/mov_blacklist_super.js create mode 100755 src/command/commands/mov_blacklist_super.ts diff --git a/src/command/commands.ts b/src/command/commands.ts index d1205fa..e228ed6 100644 --- a/src/command/commands.ts +++ b/src/command/commands.ts @@ -8,6 +8,7 @@ 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 mov_blacklist_super from "./commands/mov_blacklist_super.js"; import ping from "./commands/ping.js"; const commands: TCommand[] = [ @@ -19,6 +20,7 @@ const commands: TCommand[] = [ get_file, get_members, get_raw_file, + mov_blacklist_super, ping, ]; export default commands; diff --git a/src/command/commands/mov_blacklist_super.js b/src/command/commands/mov_blacklist_super.js deleted file mode 100755 index 77852ab..0000000 --- a/src/command/commands/mov_blacklist_super.js +++ /dev/null @@ -1,53 +0,0 @@ -const { SlashCommandBuilder, 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("mov_blacklist_super") - .setDescription("add user to blacklist") - .addUserOption((option) => - option - .setName("discord") - .setDescription("discord id of blacklister") - .setRequired(true) - ) - .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) - .setDMPermission(false), - async execute(interaction) { - await interaction.deferReply({ ephemeral: true }); - let data = (await firebase.get()).val(); - const discord_id = interaction.options.getUser("discord_id").id; - for (let discord_search_point in data["members"]) { - if (data["members"][discord_search_point].discord == discord_id) { - //이미 등록된 디코가 있을경우 - const blackListing = data["members"][discord_search_point]; - data["members"].splice(discord_search_point, 1); - data["blacklist"].push(blackListing); - await firebase.set(data); - await interaction.editReply({ - content: - "성공적으로 해당 discord id와 minecraft id를 블렉리스팅 했어요!", - ephemeral: true, - }); - return; - } - } //등록되지 않았을경우 - await interaction.editReply({ - content: "`에러`:해당 discord id를 찾을 수 없었어요", - ephemeral: true, - }); - }, -}; diff --git a/src/command/commands/mov_blacklist_super.ts b/src/command/commands/mov_blacklist_super.ts new file mode 100755 index 0000000..82961b7 --- /dev/null +++ b/src/command/commands/mov_blacklist_super.ts @@ -0,0 +1,47 @@ +import { + SlashCommandBuilder, + PermissionFlagsBits, + ChatInputCommandInteraction, +} from "discord.js"; + +import firebase from "../../wrapper/firebase.js"; +import { TUser } from "../../functions.js"; + +export default { + data: new SlashCommandBuilder() + .setName("mov_blacklist_super") + .setDescription("add user to blacklist") + .addUserOption((option) => + option + .setName("discord") + .setDescription("discord id of blacklister") + .setRequired(true) + ) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) + .setDMPermission(false), + async execute(interaction: ChatInputCommandInteraction) { + const discord_id = interaction.options.getUser("discord_id").id; + const blacklist = firebase.collection("blacklist"); + const members = firebase.collection("members"); + const target = await members.where("discord_id", "==", discord_id).get(); + if (target.empty) { + await interaction.editReply({ + content: "`에러`:해당 discord id로 등록된 유저를 찾을 수 없었어요", + }); + return; + } + + const target_datas: TUser[] = []; + target.forEach((doc) => { + target_datas.push(doc.data() as TUser); + members.doc(doc.id).delete(); + }); + target_datas.forEach((user) => { + blacklist.add(user); + }); + + await interaction.editReply({ + content: "성공적으로 해당 discord id와 minecraft id를 블랙리스팅 했어요.", + }); + }, +};