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 mojangAPI from "../../wrapper/mojang-api.js";
import { TUser } from "../../functions.js";
import { TUser, dmSlice } from "../../functions.js";
export default {
data: new SlashCommandBuilder()
@ -37,25 +37,34 @@ export default {
for (const member of member_data) {
let nickname: string;
try {
nickname = interaction.guild.members.cache.get(discord_id).nickname;
nickname = (await interaction.guild.members.fetch(member[0])).nickname;
} catch (e) {
nickname = `Deleted User`;
nickname = ``;
}
text += nickname;
text += `(${discord_id})`;
let tag: string;
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]) {
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 buffer_file = {
attachment: Buffer.from(text),
name: "members.txt",
};
await interaction.editReply({ files: [buffer_file] });
const sliced = dmSlice(text);
for (const chunc of sliced) {
await interaction.user.send(chunc);
}
await interaction.editReply("dm을 확인해주세요.");
},
};

View file

@ -22,3 +22,33 @@ export type TUser = {
discord_id: string; // id
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;
}
}
}