Discord new username 대응
추가적으로 get_members에서 쓰던 로직을 함수로 빼 search에서도 사용하도록 변경.
This commit is contained in:
parent
36b5e30ce4
commit
f73ce8254d
|
@ -4,6 +4,7 @@ import firebase from "../../wrapper/firebase.js";
|
|||
import mojangAPI from "../../wrapper/mojang-api.js";
|
||||
import { TUser } from "../../types.js";
|
||||
import { dm_slice } from "../../functions/dm_slice.js";
|
||||
import { data_to_string } from "../../functions/data_to_string.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -35,36 +36,11 @@ export default {
|
|||
});
|
||||
|
||||
let text = "";
|
||||
for (const member of member_data) {
|
||||
let nickname: string;
|
||||
try {
|
||||
nickname =
|
||||
(await interaction.guild.members.fetch(member[0])).nickname ||
|
||||
(await interaction.client.users.fetch(member[0])).username;
|
||||
} catch (e) {
|
||||
nickname = ` `;
|
||||
}
|
||||
let tag: string;
|
||||
try {
|
||||
tag = (await interaction.client.users.fetch(member[0])).tag;
|
||||
} catch (e) {
|
||||
tag = `Deleted User#0000`;
|
||||
}
|
||||
text += "- ";
|
||||
text += `\`${nickname}\``;
|
||||
text += `【\`${tag}\`】`;
|
||||
text += `[${member[0]}]`;
|
||||
|
||||
text += "\n";
|
||||
for (const minecraft_uuid of member[1]) {
|
||||
text += " - ";
|
||||
text += `\`${await mojangAPI.getIdFromUUID(minecraft_uuid)}\``;
|
||||
text += `[${minecraft_uuid}]`;
|
||||
text += "\n";
|
||||
}
|
||||
text = text.slice(0, -1);
|
||||
for (const [discord_id, minecraft_uuids] of member_data) {
|
||||
text += await data_to_string(interaction, discord_id, minecraft_uuids);
|
||||
text += "\n\n";
|
||||
}
|
||||
|
||||
const sliced = dm_slice(text);
|
||||
for (const chunk of sliced) {
|
||||
await interaction.user.send(chunk);
|
||||
|
|
|
@ -2,6 +2,7 @@ import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
|
|||
|
||||
import firebase from "../../wrapper/firebase.js";
|
||||
import mojangAPI from "../../wrapper/mojang-api.js";
|
||||
import { data_to_string } from "../../functions/data_to_string.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -71,21 +72,14 @@ export default {
|
|||
if (the_data.empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 멤버는 등록되지 않았어요!",
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
let text = "";
|
||||
text +=
|
||||
(await interaction.guild.members.fetch(discord_id)).nickname ||
|
||||
(await interaction.client.users.fetch(discord_id)).username;
|
||||
text += ": ";
|
||||
const minecraft_uuids: Array<string> = [];
|
||||
for (const user of the_data.docs) {
|
||||
const minecraft_uuid = user.data()["minecraft_uuid"];
|
||||
text += await mojangAPI.getIdFromUUID(minecraft_uuid);
|
||||
text += ` [${minecraft_uuid}]`;
|
||||
text += ", ";
|
||||
minecraft_uuids.push(user.data()["minecraft_uuid"]);
|
||||
}
|
||||
text = text.slice(0, -2);
|
||||
const text = await data_to_string(interaction, discord_id, minecraft_uuids);
|
||||
await interaction.editReply({
|
||||
content: text,
|
||||
});
|
||||
|
|
41
src/functions/data_to_string.ts
Normal file
41
src/functions/data_to_string.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { ChatInputCommandInteraction } from "discord.js";
|
||||
|
||||
import mojangAPI from "../wrapper/mojang-api";
|
||||
|
||||
export async function data_to_string(
|
||||
interaction: ChatInputCommandInteraction,
|
||||
discord_id: string,
|
||||
minecraft_uuids: string[]
|
||||
) {
|
||||
let text = "";
|
||||
let nickname: string;
|
||||
let tag: string;
|
||||
try {
|
||||
const guild_user = await interaction.guild.members.fetch(discord_id);
|
||||
if (guild_user) {
|
||||
}
|
||||
const client_user = await interaction.client.users.fetch(discord_id);
|
||||
tag =
|
||||
client_user.tag.split("#")[1] != "0"
|
||||
? client_user.tag
|
||||
: "@" + client_user.tag.split("#")[0];
|
||||
nickname = guild_user.nickname || client_user.username;
|
||||
} catch (e) {
|
||||
nickname = ` `;
|
||||
tag = `Deleted User#0000`;
|
||||
}
|
||||
text += "- ";
|
||||
text += `\`${nickname}\``;
|
||||
text += `【\`${tag}\`】`;
|
||||
text += `[${discord_id}}]`;
|
||||
|
||||
text += "\n";
|
||||
for (const minecraft_uuid of minecraft_uuids) {
|
||||
text += " - ";
|
||||
text += `\`${await mojangAPI.getIdFromUUID(minecraft_uuid)}\``;
|
||||
text += `[${minecraft_uuid}]`;
|
||||
text += "\n";
|
||||
}
|
||||
text = text.slice(0, -1);
|
||||
return text;
|
||||
}
|
Loading…
Reference in a new issue