get_blacklist
This commit is contained in:
parent
14f36ed237
commit
79f2042536
|
@ -4,6 +4,7 @@ import add_nick_super from "./commands/add_nick_super.js";
|
||||||
import add_nick from "./commands/add_nick.js";
|
import add_nick from "./commands/add_nick.js";
|
||||||
import del_nick_super from "./commands/del_nick_super.js";
|
import del_nick_super from "./commands/del_nick_super.js";
|
||||||
import del_user_super from "./commands/del_user_super.js";
|
import del_user_super from "./commands/del_user_super.js";
|
||||||
|
import get_blacklist from "./commands/get_blacklist.js";
|
||||||
import ping from "./commands/ping.js";
|
import ping from "./commands/ping.js";
|
||||||
|
|
||||||
const commands: TCommand[] = [
|
const commands: TCommand[] = [
|
||||||
|
@ -11,6 +12,7 @@ const commands: TCommand[] = [
|
||||||
add_nick,
|
add_nick,
|
||||||
del_nick_super,
|
del_nick_super,
|
||||||
del_user_super,
|
del_user_super,
|
||||||
|
get_blacklist,
|
||||||
ping,
|
ping,
|
||||||
];
|
];
|
||||||
export default commands;
|
export default commands;
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
const { SlashCommandBuilder } = require("discord.js");
|
|
||||||
const mojangAPI = new (require("mojang-api-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_blacklist").setDescription("show blicklist").setDMPermission(false),
|
|
||||||
async execute(interaction) {
|
|
||||||
await interaction.deferReply({ ephemeral: true });
|
|
||||||
const data = (await firebase.get()).val();
|
|
||||||
for (let discord_search_point in data["members"]) {
|
|
||||||
if (data["members"][discord_search_point].discord == interaction.user.id) {
|
|
||||||
//이미 등록된 디코일경우
|
|
||||||
let message = "";
|
|
||||||
for (let discord_say_point in data["blacklist"]) {
|
|
||||||
let discord_tag;
|
|
||||||
try {
|
|
||||||
const discord = await client.users.fetch(data["blacklist"][discord_say_point].discord);
|
|
||||||
discord_tag = `${discord.username}#${discord.discriminator}`;
|
|
||||||
} catch (e) {
|
|
||||||
discord_tag = `Deleted User#0000`;
|
|
||||||
}
|
|
||||||
|
|
||||||
message = `${message}${discord_tag}(${data["blacklist"][discord_say_point].discord}):`;
|
|
||||||
for (let minecraft_say_point in data["blacklist"][discord_say_point].minecraft) {
|
|
||||||
let minecraft = await mojangAPI.uuidToName(data["blacklist"][discord_say_point].minecraft[minecraft_say_point]);
|
|
||||||
message = `${message}${minecraft.name},`;
|
|
||||||
}
|
|
||||||
message = `${message.slice(0, -1)}\n`;
|
|
||||||
}
|
|
||||||
const userInfoFile = { attachment: Buffer.from(message), name: "data.txt" };
|
|
||||||
await interaction.editReply({ files: [userInfoFile] });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} //신규 디코일 경우
|
|
||||||
await interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` });
|
|
||||||
},
|
|
||||||
};
|
|
61
src/command/commands/get_blacklist.ts
Executable file
61
src/command/commands/get_blacklist.ts
Executable file
|
@ -0,0 +1,61 @@
|
||||||
|
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
|
|
||||||
|
import firebase from "../../wrapper/firebase.js";
|
||||||
|
import { TUser } from "../../functions.js";
|
||||||
|
import mojangAPI from "../../wrapper/mojang-api.js";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("get_blacklist")
|
||||||
|
.setDescription("show blicklist")
|
||||||
|
.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<string, string[]> = 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 text = "";
|
||||||
|
blacklist_data.forEach(async (minecraft_uuids, discord_id) => {
|
||||||
|
let discord_tag: string;
|
||||||
|
try {
|
||||||
|
discord_tag = (await interaction.client.users.fetch(discord_id)).tag;
|
||||||
|
} catch (e) {
|
||||||
|
discord_tag = `Deleted User#0000`;
|
||||||
|
}
|
||||||
|
text += discord_tag;
|
||||||
|
|
||||||
|
text += " : ";
|
||||||
|
minecraft_uuids.forEach(async (minecraft_uuid) => {
|
||||||
|
text += await mojangAPI.getIdFromUUID(minecraft_uuid);
|
||||||
|
text += ", ";
|
||||||
|
});
|
||||||
|
text = text.slice(0, text.length - 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
const buffer_file = {
|
||||||
|
attachment: Buffer.from(text),
|
||||||
|
name: "blacklist.txt",
|
||||||
|
};
|
||||||
|
await interaction.editReply({ files: [buffer_file] });
|
||||||
|
},
|
||||||
|
};
|
|
@ -15,8 +15,8 @@ export function getCommands(): Collection<string, TCommand> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TUser = {
|
export type TUser = {
|
||||||
discord: string; // id
|
discord_id: string; // id
|
||||||
minecraft: string[]; //uuid
|
minecraft_uuid: string; //uuid
|
||||||
};
|
};
|
||||||
|
|
||||||
// export type TData = {
|
// export type TData = {
|
||||||
|
|
Loading…
Reference in a new issue