version 1.0
This commit is contained in:
commit
6c3905ef7e
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# 인증정보
|
||||
/firebase
|
||||
|
||||
# 패키지
|
||||
/node_modules
|
90
commands/add_nick.js
Executable file
90
commands/add_nick.js
Executable file
|
@ -0,0 +1,90 @@
|
|||
const { SlashCommandBuilder } = require("discord.js");
|
||||
const mojangAPI = new (require("mojang-api-js"))();
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("add_nick")
|
||||
.setDescription("Add your nickname on the list and share it to 2k2rs")
|
||||
.addStringOption((option) => option.setName("minecraft_id").setDescription("id of the minecraft account").setRequired(true))
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
let minecraft;
|
||||
try {
|
||||
minecraft = await mojangAPI.nameToUuid(interaction.options.getString("minecraft_id"));
|
||||
} catch (err) {
|
||||
if (err.message == "204 status code") {
|
||||
await interaction.editReply({
|
||||
content: "`에러`: 닉네임 검색을 실패했어요(닉네임을 정확하게 입력했나요?)",
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let data = (await firebase.get()).val();
|
||||
|
||||
for (let discord_search_point in data["blacklist"]) {
|
||||
if (data["blacklist"][discord_search_point].discord == interaction.user.id) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`:해당 디스코드 아이디는 블랙리스팅 되었습니다! ~~2k2r에서 꺼져주세요!~~",
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
for (let minecraft_search_point in data["blacklist"][discord_search_point].minecraft) {
|
||||
if (data["blacklist"][discord_search_point].minecraft[minecraft_search_point] == minecraft.id) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`:해당 마인크래프트 아이디는 블랙리스팅 되었습니다!",
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let discord_search_point in data["members"]) {
|
||||
for (let minecraft_search_point in data["members"][discord_search_point].minecraft) {
|
||||
if (data["members"][discord_search_point].minecraft[minecraft_search_point] == minecraft.id) {
|
||||
await interaction.editReply({
|
||||
content: "`에러`:해당 마인크래프트 아이디는 이미 등록되었습니다!",
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
} //신규 마크일 경우
|
||||
if (data["members"][discord_search_point].discord == interaction.user.id) {
|
||||
await interaction.editReply({
|
||||
content: `${minecraft.name}(${minecraft.id})이 성공적으로 부계정으로 등록되었습니다!`,
|
||||
ephemeral: true,
|
||||
});
|
||||
data["members"][discord_search_point].minecraft.push(minecraft.id);
|
||||
await firebase.set(data);
|
||||
return;
|
||||
}
|
||||
} //신규 디코일 경우
|
||||
await interaction.editReply({
|
||||
content: `${minecraft.name}(${minecraft.id})님 2k2r에 오신것을 환영합니다!`,
|
||||
ephemeral: true,
|
||||
});
|
||||
data["members"].push({
|
||||
discord: interaction.user.id,
|
||||
minecraft: [minecraft.id],
|
||||
});
|
||||
await firebase.set(data);
|
||||
},
|
||||
};
|
72
commands/add_nick_super.js
Executable file
72
commands/add_nick_super.js
Executable file
|
@ -0,0 +1,72 @@
|
|||
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
|
||||
const mojangAPI = new (require("mojang-api-js"))();
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: "https://two-k-two-r-name-bot-default-rtdb.firebaseio.com",
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("add_nick_super")
|
||||
.setDescription("Add your nickname on the list and share it to 2k2rs")
|
||||
.addUserOption((option) => option.setName("discord").setDescription("discord account").setRequired(true))
|
||||
.addStringOption((option) => option.setName("minecraft_id").setDescription("id of the minecraft account").setRequired(true))
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
let minecraft;
|
||||
try {
|
||||
minecraft = await mojangAPI.nameToUuid(interaction.options.getString("minecraft_id"));
|
||||
} catch (err) {
|
||||
if (err.message == "204 status code") {
|
||||
await interaction.editReply({ content: "`에러`: 닉네임 검색을 실패했어요(닉네임을 정확하게 입력했나요?)", ephemeral: true });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let data = (await firebase.get()).val();
|
||||
const discord_id = interaction.options.getUser("discord").id;
|
||||
|
||||
for (let discord_search_point in data["blacklist"]) {
|
||||
if (data["blacklist"][discord_search_point].discord == discord_id) {
|
||||
await interaction.editReply({ content: "`에러`:해당 디스코드 아이디는 블랙리스팅 되었습니다!", ephemeral: true });
|
||||
return;
|
||||
}
|
||||
for (let minecraft_search_point in data["blacklist"][discord_search_point].minecraft) {
|
||||
if (data["blacklist"][discord_search_point].minecraft[minecraft_search_point] == minecraft["id"]) {
|
||||
await interaction.editReply({ content: "`에러`:해당 마인크래프트 아이디는 블랙리스팅 되었습니다!", ephemeral: true });
|
||||
return;
|
||||
}
|
||||
} //신규 마크일 경우
|
||||
} //신규 디코일 경우
|
||||
|
||||
for (let discord_search_point in data["members"]) {
|
||||
for (let minecraft_search_point in data["members"][discord_search_point].minecraft) {
|
||||
if (data["members"][discord_search_point].minecraft[minecraft_search_point] == minecraft["id"]) {
|
||||
await interaction.editReply({ content: "`에러`:해당 마인크래프트 아이디는 이미 등록되었습니다!", ephemeral: true });
|
||||
return;
|
||||
}
|
||||
} //신규 마크일 경우
|
||||
if (data["members"][discord_search_point].discord == discord_id) {
|
||||
await interaction.editReply({ content: `${minecraft["name"]}(${minecraft["id"]})이 성공적으로 부계정으로 등록되었습니다!`, ephemeral: true });
|
||||
data["members"][discord_search_point].minecraft.push(minecraft["id"]);
|
||||
await firebase.set(data);
|
||||
return;
|
||||
}
|
||||
} //신규 디코일 경우
|
||||
await interaction.editReply({ content: `${minecraft["name"]}(${minecraft["id"]})님 2k2r에 오신것을 환영합니다!`, ephemeral: true });
|
||||
data["members"].push({ discord: discord_id, minecraft: [minecraft["id"]] });
|
||||
await firebase.set(data);
|
||||
},
|
||||
};
|
75
commands/del_nick_super.js
Executable file
75
commands/del_nick_super.js
Executable file
|
@ -0,0 +1,75 @@
|
|||
const { SlashCommandBuilder, PermissionFlagsBits, Client, GatewayIntentBits } = require("discord.js");
|
||||
const mojangAPI = new (require("mojang-api-js"))();
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("del_nick_super")
|
||||
.setDescription("del someone nickname on the list")
|
||||
.addUserOption((option) => option.setName("discord").setDescription("discord account").setRequired(true))
|
||||
.addStringOption((option) => option.setName("minecraft_id").setDescription("id of the minecraft account").setRequired(true))
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
let minecraft;
|
||||
try {
|
||||
minecraft = await mojangAPI.nameToUuid(interaction.options.getString("minecraft_id"));
|
||||
} catch (err) {
|
||||
if (err.message == "204 status code") {
|
||||
await interaction.editReply({ content: "에러: 닉네임 검색을 실패했어요(닉네임을 정확하게 입력했나요?)", ephemeral: true });
|
||||
return;
|
||||
}
|
||||
}
|
||||
let data = await (await firebase.get()).val();
|
||||
const discord_id = interaction.options.getUser("discord").id;
|
||||
for (let discord_search_point in data["members"]) {
|
||||
if (data["members"][discord_search_point].discord == discord_id) {
|
||||
//이미 등록된 디코일경우
|
||||
for (let minecraft_search_point in data["members"][discord_search_point].minecraft) {
|
||||
if (data["members"][discord_search_point].minecraft[minecraft_search_point] == minecraft.id) {
|
||||
//이미 등록된 마크일경우
|
||||
data["members"][discord_search_point].minecraft.splice(minecraft_search_point, 1);
|
||||
if (data["members"][discord_search_point].minecraft.length == 0) {
|
||||
data["members"].splice(discord_search_point, 1);
|
||||
}
|
||||
|
||||
await firebase.set(data);
|
||||
|
||||
let discord_tag;
|
||||
try {
|
||||
const discord = await client.users.fetch(discord_id);
|
||||
discord_tag = `${discord.username}#${discord.discriminator}`;
|
||||
} catch (e) {
|
||||
discord_tag = `Deleted User#0000`;
|
||||
}
|
||||
await interaction.editReply({
|
||||
content: `삭제 완료:${discord_tag}(${discord_id})에게서 ${minecraft.name}(${minecraft.id})를 제거했습니다.`,
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
} //신규 마크일경우
|
||||
await interaction.editReply({ content: `\`에러\`: 해당 유저에게 해당 마인크래프트 계정이 없습니다.`, ephemeral: true });
|
||||
return;
|
||||
}
|
||||
} //신규 디코일 경우
|
||||
await interaction.editReply({ content: `\`에러\`: 해당 유저를 찾을 수 없습니다.`, ephemeral: true });
|
||||
},
|
||||
};
|
43
commands/del_user_super.js
Executable file
43
commands/del_user_super.js
Executable file
|
@ -0,0 +1,43 @@
|
|||
const { SlashCommandBuilder, PermissionFlagsBits, Client, GatewayIntentBits } = require("discord.js");
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
// const { token } = require('../config.json');
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("del_user_super")
|
||||
.setDescription("del someone on the list")
|
||||
.addUserOption((option) => option.setName("discord").setDescription("discord account").setRequired(true))
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
let data = (await firebase.get()).val();
|
||||
const discord_id = interaction.options.getUser("discord").id;
|
||||
for (let discord_search_point in data["members"]) {
|
||||
if (data["members"][discord_search_point].discord == discord_id) {
|
||||
//이미 등록된 디코일경우
|
||||
data["members"].splice(discord_search_point, 1);
|
||||
await firebase.set(data);
|
||||
await interaction.editReply({ content: `삭제 완료:<@${discord_id}>를 제거했습니다.`, ephemeral: true });
|
||||
return;
|
||||
}
|
||||
} //신규 디코일 경우
|
||||
await interaction.editReply({ content: `\`에러\`: 해당 유저를 찾을 수 없습니다.`, ephemeral: true });
|
||||
},
|
||||
};
|
17
commands/dm.trash
Executable file
17
commands/dm.trash
Executable file
|
@ -0,0 +1,17 @@
|
|||
const { SlashCommandBuilder, Client, GatewayIntentBits } = require("discord.js");
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder().setName("test").setDescription("test of dm").setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
await interaction.editReply("DM으로 확인하세요");
|
||||
|
||||
// client.users.fetch(interaction.member.user.id, false).then((user) => {
|
||||
// user.send("hello world");
|
||||
// });
|
||||
const user = await client.users.fetch(interaction.member.user.id, false);
|
||||
user.send("hello world");
|
||||
},
|
||||
};
|
50
commands/get_blacklist.js
Executable file
50
commands/get_blacklist.js
Executable file
|
@ -0,0 +1,50 @@
|
|||
const { SlashCommandBuilder } = require("discord.js");
|
||||
const mojangAPI = new (require("mojang-api-js"))();
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder().setName("get_blacklist").setDescription("show blicklist").setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
const data = (await firebase.get()).val();
|
||||
for (let discord_search_point in data["members"]) {
|
||||
if (data["members"][discord_search_point].discord == interaction.user.id) {
|
||||
//이미 등록된 디코일경우
|
||||
let message = "";
|
||||
for (let discord_say_point in data["blacklist"]) {
|
||||
let discord_tag;
|
||||
try {
|
||||
const discord = await client.users.fetch(data["blacklist"][discord_say_point].discord);
|
||||
discord_tag = `${discord.username}#${discord.discriminator}`;
|
||||
} catch (e) {
|
||||
discord_tag = `Deleted User#0000`;
|
||||
}
|
||||
|
||||
message = `${message}${discord_tag}(${data["blacklist"][discord_say_point].discord}):`;
|
||||
for (let minecraft_say_point in data["blacklist"][discord_say_point].minecraft) {
|
||||
let minecraft = await mojangAPI.uuidToName(data["blacklist"][discord_say_point].minecraft[minecraft_say_point]);
|
||||
message = `${message}${minecraft.name},`;
|
||||
}
|
||||
message = `${message.slice(0, -1)}\n`;
|
||||
}
|
||||
const userInfoFile = { attachment: Buffer.from(message), name: "data.txt" };
|
||||
await interaction.editReply({ files: [userInfoFile] });
|
||||
return;
|
||||
}
|
||||
} //신규 디코일 경우
|
||||
await interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` });
|
||||
},
|
||||
};
|
49
commands/get_file.js
Executable file
49
commands/get_file.js
Executable file
|
@ -0,0 +1,49 @@
|
|||
const { SlashCommandBuilder, AttachmentBuilder } = require("discord.js");
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder().setName("get_file").setDescription("get the file").setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
const data = (await firebase.get()).val();
|
||||
let is_registed = false;
|
||||
|
||||
text = "{members:[";
|
||||
for (let discord_search_point in data["members"]) {
|
||||
for (let minecraft_search_point in data["members"][discord_search_point].minecraft) {
|
||||
text = text + "'" + data["members"][discord_search_point].minecraft[minecraft_search_point] + "',";
|
||||
}
|
||||
if (data["members"][discord_search_point].discord == interaction.user.id) {
|
||||
is_registed = true;
|
||||
}
|
||||
}
|
||||
text = text.slice(0, -1) + "], blacklist:[";
|
||||
|
||||
for (let discord_search_point in data["blacklist"]) {
|
||||
for (let minecraft_search_point in data["blacklist"][discord_search_point].minecraft) {
|
||||
text = text + "'" + data["blacklist"][discord_search_point].minecraft[minecraft_search_point] + "',";
|
||||
}
|
||||
}
|
||||
text = text.slice(0, -1) + "]}";
|
||||
|
||||
if (is_registed) {
|
||||
const userInfoFile = { attachment: Buffer.from(text), name: "data.json" };
|
||||
await interaction.editReply({ content: `*** 절대 이 파일을 공유하지 마세요***`, files: [userInfoFile] });
|
||||
} else {
|
||||
await interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` });
|
||||
}
|
||||
},
|
||||
};
|
34
commands/get_file_super.js
Executable file
34
commands/get_file_super.js
Executable file
|
@ -0,0 +1,34 @@
|
|||
const { SlashCommandBuilder, AttachmentBuilder, PermissionFlagsBits } = require("discord.js");
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder().setName("get_file_super").setDescription("get the file").setDefaultMemberPermissions(PermissionFlagsBits.Administrator).setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
await interaction.editReply("해당 커맨드에 버그가 있어서 임시로 비활성화 되었습니다...........")
|
||||
// const data = (await firebase.get()).val();
|
||||
// for (let discord_search_point in data["members"]) {
|
||||
// if (data["members"][discord_search_point].discord == interaction.user.id) {
|
||||
// //이미 등록된 디코일경우
|
||||
// const userInfoFile = { attachment: Buffer.from([data]), name: "data.json" };
|
||||
// await interaction.editReply({ content: `*** 절대 이 파일을 공유하지 마세요***`, files: [userInfoFile] });
|
||||
|
||||
// return;
|
||||
// }
|
||||
// } //신규 디코일 경우
|
||||
// await interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` });
|
||||
},
|
||||
};
|
85
commands/get_users.js
Executable file
85
commands/get_users.js
Executable file
|
@ -0,0 +1,85 @@
|
|||
const { SlashCommandBuilder, Client, GatewayIntentBits } = require("discord.js");
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
const mojangAPI = new (require("mojang-api-js"))();
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
let message = "";
|
||||
const cache_at = new Date();
|
||||
try {
|
||||
(async () => {
|
||||
const data = (await firebase.get()).val();
|
||||
for (let discord_search_point in data["members"]) {
|
||||
try {
|
||||
let discord = await client.users.fetch(data["members"][discord_search_point].discord);
|
||||
message = `${message}\`${discord.username}#${discord.discriminator}(${data["members"][discord_search_point].discord}):`;
|
||||
} catch (e) {
|
||||
message = `${message}\`Deleted User#0000(${data["members"][discord_search_point].discord}):`;
|
||||
}
|
||||
for (let minecraft_search_point in data["members"][discord_search_point].minecraft) {
|
||||
let minecraft = await mojangAPI.uuidToName(data["members"][discord_search_point].minecraft[minecraft_search_point]);
|
||||
message = `${message}${minecraft.name}(${minecraft.id}), `;
|
||||
}
|
||||
message = `${message.slice(0, -2)}\`\n`;
|
||||
}
|
||||
message.replaceAll(/_/g, "\\_");
|
||||
})();
|
||||
} catch {
|
||||
message = "`에러`: 캐싱중 에러 발생. `/ping`의 runner와 함께 <@945705462966411275>(kdh8219#5087)에게 문의주세요";
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder().setName("get_users").setDescription("show users").setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
let isUser = false;
|
||||
const data = (await firebase.get()).val();
|
||||
for (let discord_search_point in data["members"]) {
|
||||
if (data["members"][discord_search_point].discord == interaction.user.id) {
|
||||
isUser = true;
|
||||
}
|
||||
}
|
||||
if (isUser) {
|
||||
await interaction.editReply({ content: `2000자를 넘어 DM으로 나눠 발송합니다.\n\`\`\`\nCaching at:${cache_at}\`\`\`` });
|
||||
const dm = await client.users.fetch(interaction.member.user.id, false);
|
||||
function slasher(txt) {
|
||||
let front = txt.slice(0, 2001);
|
||||
let end = txt.slice(2001, -1);
|
||||
if (end) {
|
||||
let tolast = front.slice(front.lastIndexOf("\n"), -1);
|
||||
front = front.slice(0, front.lastIndexOf("\n"));
|
||||
end = tolast + end;
|
||||
}
|
||||
return { front, end };
|
||||
}
|
||||
let { front, end } = slasher(message);
|
||||
dm.send(front);
|
||||
while (true) {
|
||||
if (end) {
|
||||
let message_ = end;
|
||||
let slashed = slasher(message_);
|
||||
front = slashed.front;
|
||||
end = slashed.end;
|
||||
dm.send(front);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` });
|
||||
}
|
||||
},
|
||||
};
|
41
commands/mov_blacklist_super.js
Executable file
41
commands/mov_blacklist_super.js
Executable file
|
@ -0,0 +1,41 @@
|
|||
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("mov_blacklist_super")
|
||||
.setDescription("add user to blacklist")
|
||||
.addUserOption((option) => option.setName("discord").setDescription("discord id of blacklister").setRequired(true))
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
let data = (await firebase.get()).val();
|
||||
const discord_id = interaction.options.getUser("discord_id").id;
|
||||
for (let discord_search_point in data["members"]) {
|
||||
if (data["members"][discord_search_point].discord == discord_id) {
|
||||
//이미 등록된 디코가 있을경우
|
||||
const blackListing = data["members"][discord_search_point];
|
||||
data["members"].splice(discord_search_point, 1);
|
||||
data["blacklist"].push(blackListing);
|
||||
await firebase.set(data);
|
||||
await interaction.editReply({ content: "성공적으로 해당 discord id와 minecraft id를 블렉리스팅 했어요!", ephemeral: true });
|
||||
return;
|
||||
}
|
||||
} //등록되지 않았을경우
|
||||
await interaction.editReply({ content: "`에러`:해당 discord id를 찾을 수 없었어요", ephemeral: true }); //TODO:
|
||||
},
|
||||
};
|
15
commands/ping.js
Executable file
15
commands/ping.js
Executable file
|
@ -0,0 +1,15 @@
|
|||
const { SlashCommandBuilder, Client, GatewayIntentBits } = require("discord.js");
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder().setName("ping").setDescription("check ping").setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
const defer = await interaction.reply({ content: "Pinging...", fetchReply: true, ephemeral: true });
|
||||
interaction.editReply({
|
||||
content: `**PONG🏓**\n\`\`\`\n${/*Websocket heartbeat: ${client.ws.ping}ms.*/ ""}\nRoundtrip latency: ${defer.createdTimestamp - interaction.createdTimestamp}ms\nRunner: ${
|
||||
process.env.RUNNER_NAME
|
||||
}\n\`\`\``,
|
||||
});
|
||||
},
|
||||
};
|
110
commands/search.js
Executable file
110
commands/search.js
Executable file
|
@ -0,0 +1,110 @@
|
|||
const { SlashCommandBuilder, Client, GatewayIntentBits } = require("discord.js");
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
const mojangAPI = new (require("mojang-api-js"))();
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("search")
|
||||
.setDescription("search info")
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName("by_discord")
|
||||
.setDescription("search info by discord")
|
||||
.addUserOption((option) => option.setName("discord").setDescription("discord account").setRequired(true))
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName("by_minecraft")
|
||||
.setDescription("search info by minecraft")
|
||||
.addStringOption((option) => option.setName("minecraft").setDescription("minecraft id").setRequired(true))
|
||||
)
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
const data = (await firebase.get()).val();
|
||||
let is_2k2r = false;
|
||||
let found = false;
|
||||
if (interaction.options.getSubcommand() === "by_discord") {
|
||||
let result = "";
|
||||
const searching_discord_id = interaction.options.getUser("discord").id;
|
||||
const requester_discord_id = interaction.user.id;
|
||||
for (let discord_search_point in data["members"]) {
|
||||
const this_discord = data["members"][discord_search_point].discord;
|
||||
if (this_discord == requester_discord_id) {
|
||||
is_2k2r = true;
|
||||
}
|
||||
if (this_discord == searching_discord_id) {
|
||||
found = true;
|
||||
result = data["members"][discord_search_point].minecraft;
|
||||
}
|
||||
}
|
||||
if (is_2k2r) {
|
||||
if (!found) {
|
||||
interaction.editReply({ content: `\`에러\`: 해당 디스코드 계정은 등록되지 않았어요!` });
|
||||
return;
|
||||
}
|
||||
let mcid = "";
|
||||
for (let mcuuid in result) {
|
||||
mcid = mcid + (await mojangAPI.uuidToName(result[mcuuid])).name + ",";
|
||||
}
|
||||
interaction.editReply({ content: `${interaction.options.getUser("discord")}:${mcid.slice(0, -1)}` });
|
||||
} else {
|
||||
interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` });
|
||||
}
|
||||
} else {
|
||||
let minecraft;
|
||||
try {
|
||||
minecraft = await mojangAPI.nameToUuid(interaction.options.getString("minecraft"));
|
||||
} catch (err) {
|
||||
if (err.message == "204 status code") {
|
||||
await interaction.editReply({ content: "`에러`: 닉네임 검색을 실패했어요(닉네임을 정확하게 입력했나요?)" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
const requester_discord_id = interaction.user.id;
|
||||
let searched_discord;
|
||||
let searched_minecraft;
|
||||
for (let discord_search_point in data["members"]) {
|
||||
for (let minecraft_search_point in data["members"][discord_search_point].minecraft) {
|
||||
if (data["members"][discord_search_point].minecraft[minecraft_search_point] == minecraft.id) {
|
||||
searched_minecraft = data["members"][discord_search_point].minecraft;
|
||||
searched_discord = data["members"][discord_search_point].discord;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (data["members"][discord_search_point].discord == requester_discord_id) {
|
||||
is_2k2r = true;
|
||||
}
|
||||
}
|
||||
if (is_2k2r) {
|
||||
if (!found) {
|
||||
interaction.editReply({ content: `\`에러\`: 해당 마인크래프트 아이디는 등록되지 않았어요!` });
|
||||
return;
|
||||
}
|
||||
let mcid = "";
|
||||
for (let mcuuid in searched_minecraft) {
|
||||
mcid = mcid + (await mojangAPI.uuidToName(searched_minecraft[mcuuid])).name + ",";
|
||||
}
|
||||
interaction.editReply({ content: `<@${searched_discord}>:${mcid.slice(0, -1)}` });
|
||||
} else {
|
||||
interaction.editReply({ content: `\`에러\`:하나 이상의 아이디를 등록해야만 합니다. \`/add_nick\`을 살펴보세요.` });
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
15
commands/user.trash
Executable file
15
commands/user.trash
Executable file
|
@ -0,0 +1,15 @@
|
|||
const { SlashCommandBuilder, Client, GatewayIntentBits } = require("discord.js");
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
client.login(process.env.DISCORD_TOKEN);
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("test")
|
||||
.setDescription("켈켈켈")
|
||||
.addUserOption((option) => option.setName("user").setDescription("description...").setRequired(true))
|
||||
.setDMPermission(false),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
await interaction.editReply(`${interaction.options.getUser("user").id}`);
|
||||
},
|
||||
};
|
32
deploy.js
Executable file
32
deploy.js
Executable file
|
@ -0,0 +1,32 @@
|
|||
require("dotenv").config();
|
||||
|
||||
const { REST, Routes } = require("discord.js");
|
||||
const fs = require("node:fs");
|
||||
|
||||
const commands = [];
|
||||
// Grab all the command files from the commands directory you created earlier
|
||||
const commandFiles = fs.readdirSync("./commands").filter((file) => file.endsWith(".js"));
|
||||
|
||||
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`./commands/${file}`);
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
|
||||
// Construct and prepare an instance of the REST module
|
||||
const rest = new REST({ version: "10" }).setToken(process.env.DISCORD_TOKEN);
|
||||
|
||||
// and deploy your commands!
|
||||
(async () => {
|
||||
try {
|
||||
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
||||
|
||||
// The put method is used to fully refresh all commands in the guild with the current set
|
||||
const data = await rest.put(Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID), { body: commands });
|
||||
|
||||
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
|
||||
} catch (error) {
|
||||
// And of course, make sure you catch and log any errors!
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
41
main.js
Executable file
41
main.js
Executable file
|
@ -0,0 +1,41 @@
|
|||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { Client, Collection, Events, GatewayIntentBits } = require("discord.js");
|
||||
require("dotenv").config();
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
client.commands = new Collection();
|
||||
const commandsPath = path.join(__dirname, "commands");
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith(".js"));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath);
|
||||
client.commands.set(command.data.name, command);
|
||||
}
|
||||
|
||||
client.once(Events.ClientReady, (c) => {
|
||||
console.log(`Ready: discord client as ${c.user.tag}`);
|
||||
});
|
||||
|
||||
client.on(Events.InteractionCreate, async (interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) return;
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
try {
|
||||
await interaction.reply({ content: "There was an error while executing this command!", ephemeral: true });
|
||||
} catch (e) {
|
||||
await interaction.editReply({ content: "There was an error while executing this command!", ephemeral: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_TOKEN);
|
3
nodemon.json
Executable file
3
nodemon.json
Executable file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"ignore":["data.json","temp_users.json"]
|
||||
}
|
9
package.json
Executable file
9
package.json
Executable file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"discord.js": "^14.6.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"firebase-admin": "^11.2.0",
|
||||
"mojang-api-js": "^1.0.1",
|
||||
"nodemon": "^2.0.20"
|
||||
}
|
||||
}
|
22
test/firebase.js
Executable file
22
test/firebase.js
Executable file
|
@ -0,0 +1,22 @@
|
|||
require("dotenv").config();
|
||||
|
||||
const firebase_admin = require("firebase-admin");
|
||||
const { getDatabase } = require("firebase-admin/database");
|
||||
const serviceAccount = require("../firebase/conf.json");
|
||||
if (!firebase_admin.apps.length) {
|
||||
firebase_admin.initializeApp({
|
||||
credential: firebase_admin.credential.cert(serviceAccount),
|
||||
databaseURL: process.env.FIREBASE_URL,
|
||||
databaseAuthVariableOverride: {
|
||||
uid: process.env.FIREBASE_UID,
|
||||
},
|
||||
});
|
||||
}
|
||||
const firebase = getDatabase().ref("/");
|
||||
|
||||
// firebase.set();
|
||||
// (await firebase.get()).val();
|
||||
|
||||
(async () => {
|
||||
console.log((await firebase.get()).val());
|
||||
})();
|
Loading…
Reference in a new issue