done #2
This commit is contained in:
parent
616f7e52a0
commit
f166d4b5e3
|
@ -15,3 +15,5 @@ DISCORD_TARGET_GUILD_ID = ""
|
|||
# ETC
|
||||
# server name
|
||||
RUNNER_NAME = ""
|
||||
# log channel id
|
||||
LOG_CHANNEL_ID =
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import { TCommand } from "../functions.js";
|
||||
import {
|
||||
SlashCommandBuilder,
|
||||
ChatInputCommandInteraction,
|
||||
Collection,
|
||||
} from "discord.js";
|
||||
|
||||
import add_nick_super from "./commands/add_nick_super.js";
|
||||
import add_nick from "./commands/add_nick.js";
|
||||
|
@ -26,3 +30,15 @@ const commands: TCommand[] = [
|
|||
search,
|
||||
];
|
||||
export default commands;
|
||||
|
||||
export type TCommand = {
|
||||
data: SlashCommandBuilder;
|
||||
execute: (interaction: ChatInputCommandInteraction) => Promise<void>;
|
||||
};
|
||||
export function getCommands(): Collection<string, TCommand> {
|
||||
const commandCollection = new Collection<string, TCommand>();
|
||||
for (const command of commands) {
|
||||
commandCollection.set(command.data.name, command);
|
||||
}
|
||||
return commandCollection;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
|
||||
import mojangAPI from "../../wrapper/mojang-api.js";
|
||||
import firebase from "../../wrapper/firebase.js";
|
||||
import { add_user } from "../../functions.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -16,51 +17,6 @@ export default {
|
|||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
const discord_id = interaction.user.id;
|
||||
const mcid = interaction.options.getString("minecraft_id") as string;
|
||||
let mcuuid: string;
|
||||
try {
|
||||
mcuuid = await mojangAPI.getUUIDFromId(mcid);
|
||||
} catch {
|
||||
await interaction.editReply({
|
||||
content:
|
||||
"`에러`: 마인크래프트 닉네임 검색을 실패했습니다. 마인크래프트 닉네임을 정확하게 입력했나요?",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const members = firebase.collection("members");
|
||||
const blacklist = firebase.collection("blacklist");
|
||||
|
||||
if (!(await blacklist.where("discord_id", "==", discord_id).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 디스코드 아이디는 블랙리스트 되었습니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!(await blacklist.where("minecraft_uuid", "==", mcuuid).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 마인크래프트 계정은 블랙리스트 되었습니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!(await members.where("minecraft_uuid", "==", mcuuid).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 마인크래프트 아이디는 이미 등록되었습니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if ((await members.where("discord_id", "==", discord_id).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: `${mcid}(${mcuuid})님 2k2r에 오신것을 환영합니다!`,
|
||||
});
|
||||
} else {
|
||||
await interaction.editReply({
|
||||
content: `${mcid}(${mcuuid})이 성공적으로 부계정으로 등록되었습니다!`,
|
||||
});
|
||||
}
|
||||
await members.add({
|
||||
discord_id,
|
||||
minecraft_uuid: mcuuid,
|
||||
});
|
||||
add_user(interaction, discord_id, mcid, mojangAPI, firebase);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
|
||||
import mojangAPI from "../../wrapper/mojang-api.js";
|
||||
import firebase from "../../wrapper/firebase.js";
|
||||
import { add_user } from "../../functions.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -28,51 +29,6 @@ export default {
|
|||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
const discord_id = interaction.options.getUser("discord")?.id as string;
|
||||
const mcid = interaction.options.getString("minecraft_id") as string;
|
||||
let mcuuid: string;
|
||||
try {
|
||||
mcuuid = await mojangAPI.getUUIDFromId(mcid);
|
||||
} catch {
|
||||
await interaction.editReply({
|
||||
content:
|
||||
"`에러`: 마인크래프트 닉네임 검색을 실패했습니다. 마인크래프트 닉네임을 정확하게 입력했나요?",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const members = firebase.collection("members");
|
||||
const blacklist = firebase.collection("blacklist");
|
||||
|
||||
if (!(await blacklist.where("discord_id", "==", discord_id).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 디스코드 아이디는 블랙리스트 되었습니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!(await blacklist.where("minecraft_uuid", "==", mcuuid).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 마인크래프트 계정은 블랙리스트 되었습니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!(await members.where("minecraft_uuid", "==", mcuuid).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 마인크래프트 아이디는 이미 등록되었습니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if ((await members.where("discord_id", "==", discord_id).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: `${mcid}(${mcuuid})님 2k2r에 오신것을 환영합니다!`,
|
||||
});
|
||||
} else {
|
||||
await interaction.editReply({
|
||||
content: `${mcid}(${mcuuid})이 성공적으로 부계정으로 등록되었습니다!`,
|
||||
});
|
||||
}
|
||||
await members.add({
|
||||
discord_id,
|
||||
minecraft_uuid: mcuuid,
|
||||
});
|
||||
add_user(interaction, discord_id, mcid, mojangAPI, firebase);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -2,10 +2,12 @@ import {
|
|||
SlashCommandBuilder,
|
||||
PermissionFlagsBits,
|
||||
ChatInputCommandInteraction,
|
||||
EmbedBuilder,
|
||||
} from "discord.js";
|
||||
|
||||
import mojangAPI from "../../wrapper/mojang-api.js";
|
||||
import firebase from "../../wrapper/firebase.js";
|
||||
import { embed_to_channel } from "../../functions.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -28,7 +30,9 @@ export default {
|
|||
async execute(interaction: ChatInputCommandInteraction) {
|
||||
const discord_id = interaction.options.getUser("discord")?.id as string;
|
||||
|
||||
const minecraft_id = interaction.options.getString("minecraft_id") as string;
|
||||
const minecraft_id = interaction.options.getString(
|
||||
"minecraft_id"
|
||||
) as string;
|
||||
let minecraft_uuid: string;
|
||||
try {
|
||||
minecraft_uuid = await mojangAPI.getUUIDFromId(minecraft_id);
|
||||
|
@ -49,7 +53,7 @@ export default {
|
|||
members.doc(member.id).delete();
|
||||
});
|
||||
|
||||
let discord_tag;
|
||||
let discord_tag: string;
|
||||
try {
|
||||
const discord_user = await interaction.client.users.fetch(discord_id);
|
||||
discord_tag = discord_user.tag;
|
||||
|
@ -59,12 +63,31 @@ export default {
|
|||
await interaction.editReply({
|
||||
content: `삭제 완료:${discord_tag}(${discord_id})에게서 ${minecraft_id}(${minecraft_uuid})를 제거했습니다.`,
|
||||
});
|
||||
return;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Nick deleted")
|
||||
.setColor(0x0099ff)
|
||||
.setFields([
|
||||
{
|
||||
name: "Command sender",
|
||||
value: `${interaction.user.tag}(${interaction.user.id})`,
|
||||
},
|
||||
{ name: " ", value: " " },
|
||||
{ name: "Targrt Discord Id", value: discord_id },
|
||||
{ name: " ", value: " " },
|
||||
{ name: "Minecraft Id", value: minecraft_id },
|
||||
{ name: "Minecraft Uuid", value: minecraft_uuid },
|
||||
])
|
||||
.setTimestamp(interaction.createdAt);
|
||||
await embed_to_channel(
|
||||
interaction.client,
|
||||
process.env.LOG_CHANNEL_ID,
|
||||
embed
|
||||
);
|
||||
} else {
|
||||
await interaction.editReply({
|
||||
content: `\`에러\`: 해당 계정이 없습니다.`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -2,9 +2,11 @@ import {
|
|||
SlashCommandBuilder,
|
||||
PermissionFlagsBits,
|
||||
ChatInputCommandInteraction,
|
||||
EmbedBuilder,
|
||||
} from "discord.js";
|
||||
|
||||
import firebase from "../../wrapper/firebase.js";
|
||||
import { embed_to_channel } from "../../functions.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -42,6 +44,23 @@ export default {
|
|||
await interaction.editReply({
|
||||
content: `삭제 완료:${discord_tag}의 계정을 모두 제거했습니다.`,
|
||||
});
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("User deleted")
|
||||
.setColor(0x0099ff)
|
||||
.setFields([
|
||||
{
|
||||
name: "Command sender",
|
||||
value: `${interaction.user.tag}(${interaction.user.id})`,
|
||||
},
|
||||
{ name: " ", value: " " },
|
||||
{ name: "Target Discord Id", value: discord_id },
|
||||
])
|
||||
.setTimestamp(interaction.createdAt);
|
||||
await embed_to_channel(
|
||||
interaction.client,
|
||||
process.env.LOG_CHANNEL_ID,
|
||||
embed
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
await interaction.editReply({
|
||||
|
|
|
@ -2,10 +2,11 @@ import {
|
|||
SlashCommandBuilder,
|
||||
PermissionFlagsBits,
|
||||
ChatInputCommandInteraction,
|
||||
EmbedBuilder,
|
||||
} from "discord.js";
|
||||
|
||||
import firebase from "../../wrapper/firebase.js";
|
||||
import { TUser } from "../../functions.js";
|
||||
import { TUser, embed_to_channel } from "../../functions.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -43,5 +44,33 @@ export default {
|
|||
await interaction.editReply({
|
||||
content: "성공적으로 해당 discord id와 minecraft id를 블랙리스팅 했어요.",
|
||||
});
|
||||
|
||||
let UUIDs: string;
|
||||
target_data
|
||||
.map((user) => {
|
||||
user.discord_id;
|
||||
})
|
||||
.map((uuid) => {
|
||||
UUIDs += uuid;
|
||||
UUIDs += "\n";
|
||||
});
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("User deleted")
|
||||
.setColor(0x0099ff)
|
||||
.setFields([
|
||||
{
|
||||
name: "Command sender",
|
||||
value: `${interaction.user.tag}(${interaction.user.id})`,
|
||||
},
|
||||
{ name: " ", value: " " },
|
||||
{ name: "Target Discord Id", value: discord_id },
|
||||
{ name: "UUIDs", value: UUIDs },
|
||||
])
|
||||
.setTimestamp(interaction.createdAt);
|
||||
await embed_to_channel(
|
||||
interaction.client,
|
||||
process.env.LOG_CHANNEL_ID,
|
||||
embed
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ import { REST, Routes } from "discord.js";
|
|||
import { config } from "dotenv";
|
||||
config();
|
||||
|
||||
import { getCommands } from "./functions.js";
|
||||
import { getCommands } from "./command/commands.js";
|
||||
|
||||
const commands = getCommands();
|
||||
// Construct and prepare an instance of the REST module
|
||||
|
|
104
src/functions.ts
104
src/functions.ts
|
@ -1,28 +1,12 @@
|
|||
import {
|
||||
Collection,
|
||||
SlashCommandBuilder,
|
||||
ChatInputCommandInteraction,
|
||||
} from "discord.js";
|
||||
import { ChatInputCommandInteraction, Client, EmbedBuilder } from "discord.js";
|
||||
import { Firestore } from "firebase-admin/firestore";
|
||||
|
||||
import commands from "./command/commands.js";
|
||||
|
||||
export type TCommand = {
|
||||
data: SlashCommandBuilder;
|
||||
execute: (interaction: ChatInputCommandInteraction) => Promise<void>;
|
||||
};
|
||||
export function getCommands(): Collection<string, TCommand> {
|
||||
const commandCollection = new Collection<string, TCommand>();
|
||||
for (const command of commands) {
|
||||
commandCollection.set(command.data.name, command);
|
||||
}
|
||||
return commandCollection;
|
||||
}
|
||||
import { MojangAPI } from "./wrapper/mojang-api.js";
|
||||
|
||||
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 } {
|
||||
|
@ -52,3 +36,85 @@ export function dmSlice(raw: string): string[] {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function add_user(
|
||||
interaction: ChatInputCommandInteraction,
|
||||
discord_id: string,
|
||||
mcid: string,
|
||||
mojangAPI: MojangAPI,
|
||||
firebase: Firestore
|
||||
) {
|
||||
let mcuuid: string;
|
||||
try {
|
||||
mcuuid = await mojangAPI.getUUIDFromId(mcid);
|
||||
} catch {
|
||||
await interaction.editReply({
|
||||
content:
|
||||
"`에러`: 마인크래프트 닉네임 검색을 실패했습니다. 마인크래프트 닉네임을 정확하게 입력했나요?",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const members = firebase.collection("members");
|
||||
const blacklist = firebase.collection("blacklist");
|
||||
|
||||
if (!(await blacklist.where("discord_id", "==", discord_id).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 디스코드 아이디는 블랙리스트 되었습니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!(await blacklist.where("minecraft_uuid", "==", mcuuid).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 마인크래프트 계정은 블랙리스트 되었습니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!(await members.where("minecraft_uuid", "==", mcuuid).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 해당 마인크래프트 아이디는 이미 등록되었습니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if ((await members.where("discord_id", "==", discord_id).get()).empty) {
|
||||
await interaction.editReply({
|
||||
content: `${mcid}(${mcuuid})님 2k2r에 오신것을 환영합니다!`,
|
||||
});
|
||||
} else {
|
||||
await interaction.editReply({
|
||||
content: `${mcid}(${mcuuid})이 성공적으로 부계정으로 등록되었습니다!`,
|
||||
});
|
||||
}
|
||||
await members.add({
|
||||
discord_id,
|
||||
minecraft_uuid: mcuuid,
|
||||
});
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("User Added")
|
||||
.setColor(0x0099ff)
|
||||
.addFields([
|
||||
{
|
||||
name: "Command sender",
|
||||
value: `${interaction.user.tag}(${interaction.user.id})`,
|
||||
},
|
||||
{ name: " ", value: " " },
|
||||
{ name: "Discord Id", value: discord_id },
|
||||
{ name: " ", value: " " },
|
||||
{ name: "Minecraft Id", value: mcid },
|
||||
{ name: "Minecraft Uuid", value: mcuuid },
|
||||
])
|
||||
.setTimestamp(interaction.createdAt);
|
||||
await embed_to_channel(interaction.client, process.env.LOG_CHANNEL_ID, embed);
|
||||
}
|
||||
|
||||
export async function embed_to_channel(
|
||||
client: Client<true>,
|
||||
channel_id: string,
|
||||
embed: EmbedBuilder
|
||||
) {
|
||||
const channel = await client.channels.fetch(channel_id);
|
||||
if (!channel.isTextBased()) return;
|
||||
channel.send({ embeds: [embed] });
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Client, Events, GatewayIntentBits } from "discord.js";
|
|||
import { config } from "dotenv";
|
||||
config();
|
||||
|
||||
import { getCommands } from "./functions.js";
|
||||
import { getCommands } from "./command/commands.js";
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import axios from "axios";
|
|||
|
||||
import TwoWayMap from "../utils/two-way-map.js";
|
||||
|
||||
class MojangAPI {
|
||||
export class MojangAPI {
|
||||
private cache: TwoWayMap<string, string> = new TwoWayMap<string, string>(); // uuid, id
|
||||
|
||||
async getIdFromUUID(minecraft_uuid: string): Promise<string> {
|
||||
|
|
Loading…
Reference in a new issue