get_members
This commit is contained in:
parent
438136b43a
commit
9285063cf9
|
@ -6,6 +6,7 @@ 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 get_blacklist from "./commands/get_blacklist.js";
|
||||||
import get_file from "./commands/get_file.js";
|
import get_file from "./commands/get_file.js";
|
||||||
|
import get_members from "./commands/get_members.js";
|
||||||
import ping from "./commands/ping.js";
|
import ping from "./commands/ping.js";
|
||||||
|
|
||||||
const commands: TCommand[] = [
|
const commands: TCommand[] = [
|
||||||
|
@ -15,6 +16,7 @@ const commands: TCommand[] = [
|
||||||
del_user_super,
|
del_user_super,
|
||||||
get_blacklist,
|
get_blacklist,
|
||||||
get_file,
|
get_file,
|
||||||
|
get_members,
|
||||||
ping,
|
ping,
|
||||||
];
|
];
|
||||||
export default commands;
|
export default commands;
|
||||||
|
|
84
src/command/commands/get_members.ts
Executable file
84
src/command/commands/get_members.ts
Executable file
|
@ -0,0 +1,84 @@
|
||||||
|
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
|
|
||||||
|
import firebase from "../../wrapper/firebase.js";
|
||||||
|
import mojangAPI from "../../wrapper/mojang-api.js";
|
||||||
|
import { TUser } from "../../functions.js";
|
||||||
|
// let message = "";
|
||||||
|
// const cache_at = new Date();
|
||||||
|
// try {
|
||||||
|
// (async () => {
|
||||||
|
// const data = (await firebase.get()).val();
|
||||||
|
// for (let discord_search_point in data["members"]) {
|
||||||
|
// try {
|
||||||
|
// let discord = await client.users.fetch(data["members"][discord_search_point].discord);
|
||||||
|
// message = `${message}\`${discord.username}#${discord.discriminator}(${data["members"][discord_search_point].discord}):`;
|
||||||
|
// } catch (e) {
|
||||||
|
// message = `${message}\`Deleted User#0000(${data["members"][discord_search_point].discord}):`;
|
||||||
|
// }
|
||||||
|
// for (let minecraft_search_point in data["members"][discord_search_point].minecraft) {
|
||||||
|
// let minecraft = await mojangAPI.uuidToName(data["members"][discord_search_point].minecraft[minecraft_search_point]);
|
||||||
|
// message = `${message}${minecraft.name}(${minecraft.id}), `;
|
||||||
|
// }
|
||||||
|
// message = `${message.slice(0, -2)}\`\n`;
|
||||||
|
// }
|
||||||
|
// message.replaceAll(/_/g, "\\_");
|
||||||
|
// })();
|
||||||
|
// } catch {
|
||||||
|
// message = "`에러`: 캐싱중 에러 발생. `/ping`의 runner와 함께 <@945705462966411275>(kdh8219#5087)에게 문의주세요";
|
||||||
|
// }
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName("get_members")
|
||||||
|
.setDescription("show users")
|
||||||
|
.setDMPermission(false),
|
||||||
|
async execute(interaction: ChatInputCommandInteraction) {
|
||||||
|
const discord_id = interaction.user.id;
|
||||||
|
|
||||||
|
const members = firebase.collection("members");
|
||||||
|
|
||||||
|
if ((await members.where("discord_id", "==", discord_id).get()).empty) {
|
||||||
|
interaction.editReply({
|
||||||
|
content: "`에러`: 하나 이상의 아이디를 등록해야 합니다.",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let member_data: Map<string, string[]> = 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let text = "";
|
||||||
|
member_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 += `(${discord_id})`;
|
||||||
|
|
||||||
|
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: "members.txt",
|
||||||
|
};
|
||||||
|
await interaction.editReply({ files: [buffer_file] });
|
||||||
|
},
|
||||||
|
};
|
|
@ -1,85 +0,0 @@
|
||||||
const { SlashCommandBuilder, Client, GatewayIntentBits } = require("discord.js");
|
|
||||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
|
||||||
|
|
||||||
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("/");
|
|
||||||
let message = "";
|
|
||||||
const cache_at = new Date();
|
|
||||||
try {
|
|
||||||
(async () => {
|
|
||||||
const data = (await firebase.get()).val();
|
|
||||||
for (let discord_search_point in data["members"]) {
|
|
||||||
try {
|
|
||||||
let discord = await client.users.fetch(data["members"][discord_search_point].discord);
|
|
||||||
message = `${message}\`${discord.username}#${discord.discriminator}(${data["members"][discord_search_point].discord}):`;
|
|
||||||
} catch (e) {
|
|
||||||
message = `${message}\`Deleted User#0000(${data["members"][discord_search_point].discord}):`;
|
|
||||||
}
|
|
||||||
for (let minecraft_search_point in data["members"][discord_search_point].minecraft) {
|
|
||||||
let minecraft = await mojangAPI.uuidToName(data["members"][discord_search_point].minecraft[minecraft_search_point]);
|
|
||||||
message = `${message}${minecraft.name}(${minecraft.id}), `;
|
|
||||||
}
|
|
||||||
message = `${message.slice(0, -2)}\`\n`;
|
|
||||||
}
|
|
||||||
message.replaceAll(/_/g, "\\_");
|
|
||||||
})();
|
|
||||||
} catch {
|
|
||||||
message = "`에러`: 캐싱중 에러 발생. `/ping`의 runner와 함께 <@945705462966411275>(kdh8219#5087)에게 문의주세요";
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
data: new SlashCommandBuilder().setName("get_users").setDescription("show users").setDMPermission(false),
|
|
||||||
async execute(interaction) {
|
|
||||||
await interaction.deferReply({ ephemeral: true });
|
|
||||||
let isUser = false;
|
|
||||||
const data = (await firebase.get()).val();
|
|
||||||
for (let discord_search_point in data["members"]) {
|
|
||||||
if (data["members"][discord_search_point].discord == interaction.user.id) {
|
|
||||||
isUser = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isUser) {
|
|
||||||
await interaction.editReply({ content: `2000자를 넘어 DM으로 나눠 발송합니다.\n\`\`\`\nCaching at:${cache_at}\`\`\`` });
|
|
||||||
const dm = await client.users.fetch(interaction.member.user.id, false);
|
|
||||||
function slasher(txt) {
|
|
||||||
let front = txt.slice(0, 2001);
|
|
||||||
let end = txt.slice(2001, -1);
|
|
||||||
if (end) {
|
|
||||||
let tolast = front.slice(front.lastIndexOf("\n"), -1);
|
|
||||||
front = front.slice(0, front.lastIndexOf("\n"));
|
|
||||||
end = tolast + end;
|
|
||||||
}
|
|
||||||
return { front, end };
|
|
||||||
}
|
|
||||||
let { front, end } = slasher(message);
|
|
||||||
dm.send(front);
|
|
||||||
while (true) {
|
|
||||||
if (end) {
|
|
||||||
let message_ = end;
|
|
||||||
let slashed = slasher(message_);
|
|
||||||
front = slashed.front;
|
|
||||||
end = slashed.end;
|
|
||||||
dm.send(front);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
Loading…
Reference in a new issue