This commit is contained in:
kdh8219 2023-05-03 21:24:23 +09:00
parent 616f7e52a0
commit f166d4b5e3
No known key found for this signature in database
GPG key ID: 2B5B609E12BB4C19
11 changed files with 188 additions and 121 deletions

View file

@ -14,4 +14,6 @@ DISCORD_TARGET_GUILD_ID = ""
# ETC # ETC
# server name # server name
RUNNER_NAME="" RUNNER_NAME = ""
# log channel id
LOG_CHANNEL_ID =

View file

@ -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_super from "./commands/add_nick_super.js";
import add_nick from "./commands/add_nick.js"; import add_nick from "./commands/add_nick.js";
@ -26,3 +30,15 @@ const commands: TCommand[] = [
search, search,
]; ];
export default commands; 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;
}

View file

@ -1,6 +1,7 @@
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js"; import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
import mojangAPI from "../../wrapper/mojang-api.js"; import mojangAPI from "../../wrapper/mojang-api.js";
import firebase from "../../wrapper/firebase.js"; import firebase from "../../wrapper/firebase.js";
import { add_user } from "../../functions.js";
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -16,51 +17,6 @@ export default {
async execute(interaction: ChatInputCommandInteraction) { async execute(interaction: ChatInputCommandInteraction) {
const discord_id = interaction.user.id; const discord_id = interaction.user.id;
const mcid = interaction.options.getString("minecraft_id") as string; const mcid = interaction.options.getString("minecraft_id") as string;
let mcuuid: string; add_user(interaction, discord_id, mcid, mojangAPI, firebase);
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,
});
}, },
}; };

View file

@ -6,6 +6,7 @@ import {
import mojangAPI from "../../wrapper/mojang-api.js"; import mojangAPI from "../../wrapper/mojang-api.js";
import firebase from "../../wrapper/firebase.js"; import firebase from "../../wrapper/firebase.js";
import { add_user } from "../../functions.js";
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -28,51 +29,6 @@ export default {
async execute(interaction: ChatInputCommandInteraction) { async execute(interaction: ChatInputCommandInteraction) {
const discord_id = interaction.options.getUser("discord")?.id as string; const discord_id = interaction.options.getUser("discord")?.id as string;
const mcid = interaction.options.getString("minecraft_id") as string; const mcid = interaction.options.getString("minecraft_id") as string;
let mcuuid: string; add_user(interaction, discord_id, mcid, mojangAPI, firebase);
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,
});
}, },
}; };

View file

@ -2,10 +2,12 @@ import {
SlashCommandBuilder, SlashCommandBuilder,
PermissionFlagsBits, PermissionFlagsBits,
ChatInputCommandInteraction, ChatInputCommandInteraction,
EmbedBuilder,
} from "discord.js"; } from "discord.js";
import mojangAPI from "../../wrapper/mojang-api.js"; import mojangAPI from "../../wrapper/mojang-api.js";
import firebase from "../../wrapper/firebase.js"; import firebase from "../../wrapper/firebase.js";
import { embed_to_channel } from "../../functions.js";
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -28,7 +30,9 @@ export default {
async execute(interaction: ChatInputCommandInteraction) { async execute(interaction: ChatInputCommandInteraction) {
const discord_id = interaction.options.getUser("discord")?.id as string; 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; let minecraft_uuid: string;
try { try {
minecraft_uuid = await mojangAPI.getUUIDFromId(minecraft_id); minecraft_uuid = await mojangAPI.getUUIDFromId(minecraft_id);
@ -49,7 +53,7 @@ export default {
members.doc(member.id).delete(); members.doc(member.id).delete();
}); });
let discord_tag; let discord_tag: string;
try { try {
const discord_user = await interaction.client.users.fetch(discord_id); const discord_user = await interaction.client.users.fetch(discord_id);
discord_tag = discord_user.tag; discord_tag = discord_user.tag;
@ -59,12 +63,31 @@ export default {
await interaction.editReply({ await interaction.editReply({
content: `삭제 완료:${discord_tag}(${discord_id})에게서 ${minecraft_id}(${minecraft_uuid})를 제거했습니다.`, 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 { } else {
await interaction.editReply({ await interaction.editReply({
content: `\`에러\`: 해당 계정이 없습니다.`, content: `\`에러\`: 해당 계정이 없습니다.`,
}); });
return;
} }
}, },
}; };

View file

@ -2,9 +2,11 @@ import {
SlashCommandBuilder, SlashCommandBuilder,
PermissionFlagsBits, PermissionFlagsBits,
ChatInputCommandInteraction, ChatInputCommandInteraction,
EmbedBuilder,
} from "discord.js"; } from "discord.js";
import firebase from "../../wrapper/firebase.js"; import firebase from "../../wrapper/firebase.js";
import { embed_to_channel } from "../../functions.js";
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -42,6 +44,23 @@ export default {
await interaction.editReply({ await interaction.editReply({
content: `삭제 완료:${discord_tag}의 계정을 모두 제거했습니다.`, 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; return;
} else { } else {
await interaction.editReply({ await interaction.editReply({

View file

@ -2,10 +2,11 @@ import {
SlashCommandBuilder, SlashCommandBuilder,
PermissionFlagsBits, PermissionFlagsBits,
ChatInputCommandInteraction, ChatInputCommandInteraction,
EmbedBuilder,
} from "discord.js"; } from "discord.js";
import firebase from "../../wrapper/firebase.js"; import firebase from "../../wrapper/firebase.js";
import { TUser } from "../../functions.js"; import { TUser, embed_to_channel } from "../../functions.js";
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -43,5 +44,33 @@ export default {
await interaction.editReply({ await interaction.editReply({
content: "성공적으로 해당 discord id와 minecraft id를 블랙리스팅 했어요.", 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
);
}, },
}; };

View file

@ -2,7 +2,7 @@ import { REST, Routes } from "discord.js";
import { config } from "dotenv"; import { config } from "dotenv";
config(); config();
import { getCommands } from "./functions.js"; import { getCommands } from "./command/commands.js";
const commands = getCommands(); const commands = getCommands();
// Construct and prepare an instance of the REST module // Construct and prepare an instance of the REST module

View file

@ -1,28 +1,12 @@
import { import { ChatInputCommandInteraction, Client, EmbedBuilder } from "discord.js";
Collection, import { Firestore } from "firebase-admin/firestore";
SlashCommandBuilder,
ChatInputCommandInteraction,
} from "discord.js";
import commands from "./command/commands.js"; import { MojangAPI } from "./wrapper/mojang-api.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;
}
export type TUser = { 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[] { export function dmSlice(raw: string): string[] {
const output: string[] = []; const output: string[] = [];
function slasher(txt: string): { front: string; end: 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] });
}

View file

@ -2,7 +2,7 @@ import { Client, Events, GatewayIntentBits } from "discord.js";
import { config } from "dotenv"; import { config } from "dotenv";
config(); config();
import { getCommands } from "./functions.js"; import { getCommands } from "./command/commands.js";
const client = new Client({ intents: [GatewayIntentBits.Guilds] }); const client = new Client({ intents: [GatewayIntentBits.Guilds] });

View file

@ -2,7 +2,7 @@ import axios from "axios";
import TwoWayMap from "../utils/two-way-map.js"; import TwoWayMap from "../utils/two-way-map.js";
class MojangAPI { export class MojangAPI {
private cache: TwoWayMap<string, string> = new TwoWayMap<string, string>(); // uuid, id private cache: TwoWayMap<string, string> = new TwoWayMap<string, string>(); // uuid, id
async getIdFromUUID(minecraft_uuid: string): Promise<string> { async getIdFromUUID(minecraft_uuid: string): Promise<string> {