edit message form

This commit is contained in:
kdh8219 2023-04-29 18:24:27 +09:00
parent aa76d4222b
commit c099eccbf8
2 changed files with 54 additions and 15 deletions

View file

@ -2,7 +2,7 @@ import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
import firebase from "../../wrapper/firebase.js"; import firebase from "../../wrapper/firebase.js";
import mojangAPI from "../../wrapper/mojang-api.js"; import mojangAPI from "../../wrapper/mojang-api.js";
import { TUser } from "../../functions.js"; import { TUser, dmSlice } from "../../functions.js";
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -37,25 +37,34 @@ export default {
for (const member of member_data) { for (const member of member_data) {
let nickname: string; let nickname: string;
try { try {
nickname = interaction.guild.members.cache.get(discord_id).nickname; nickname = (await interaction.guild.members.fetch(member[0])).nickname;
} catch (e) { } catch (e) {
nickname = `Deleted User`; nickname = ``;
} }
text += nickname; let tag: string;
text += `(${discord_id})`; try {
tag = (await interaction.client.users.fetch(member[0])).tag;
} catch (e) {
tag = `Deleted User#0000`;
}
text += `\`${nickname}\``;
text += `\`${tag}\``;
text += `[${discord_id}]`;
text += " : "; text += "\n";
for (const minecraft_uuid of member[1]) { for (const minecraft_uuid of member[1]) {
text += await mojangAPI.getIdFromUUID(minecraft_uuid); text += " - ";
text += ", "; text += `\`${await mojangAPI.getIdFromUUID(minecraft_uuid)}\``;
text += `[${minecraft_uuid}]`;
text += "\n";
} }
text = text.slice(0, text.length - 2); text = text.slice(0, -1);
text += "\n\n";
} }
const sliced = dmSlice(text);
const buffer_file = { for (const chunc of sliced) {
attachment: Buffer.from(text), await interaction.user.send(chunc);
name: "members.txt", }
}; await interaction.editReply("dm을 확인해주세요.");
await interaction.editReply({ files: [buffer_file] });
}, },
}; };

View file

@ -22,3 +22,33 @@ export type TUser = {
discord_id: string; // id discord_id: string; // id
minecraft_uuid: string; //uuid minecraft_uuid: string; //uuid
}; };
export function dmSlice(raw: string): string[] {
const output: string[] = [];
function slasher(txt: string): { front: string; end: string } {
if (txt.length <= 2000) {
return {
front: txt,
end: "",
};
}
let front = txt.slice(0, 2000);
let end = txt.slice(2000, txt.length);
if (end) {
let tolast = front.slice(front.lastIndexOf("\n"), -1);
front = front.slice(0, front.lastIndexOf("\n"));
end = tolast + end;
}
return { front, end };
}
let slashed = slasher(raw);
while (true) {
output.push(slashed.front);
if (slashed.end) {
slashed = slasher(slashed.end);
} else {
return output;
}
}
}