diff --git a/source/commands/settings/language.js b/source/commands/settings/language.js new file mode 100644 index 00000000..85a3b576 --- /dev/null +++ b/source/commands/settings/language.js @@ -0,0 +1,168 @@ +const { getDatabase, ref, child, update } = require("firebase/database"); + +module.exports.run = (client, message, args) => { + const input = args.join(" "); + const inputOption = args[0] ? args[0].toLowerCase() : ""; + const inputValue = args[1] ? args[1].toLowerCase() : ""; + + const guildID = message.guild.id; + const prefix = client.config.prefix; + const lang = client.config.lang.code; + const support = client.config.lang.support; + const dbRef = child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), guildID), "config"); + + if (!input) { + return message.channel.send({ + "embeds": [ + { + "title": client.translate.commands.language.title, + "description": client.translate.commands.language.description + .replace("%s1", support[lang]) + .replace("%s2", (prefix + module.exports.help.usage)) + .replace("%s3", ("/" + module.exports.help.usage)), + "color": 14684245, + "timestamp": new Date(), + "footer": { + "text": client.translate.commands.language.data_at + } + } + ] + }); + } + + switch (inputOption) { + case "set": + if (!inputValue) return message.reply(client.translate.commands.language.empty_value); + if (inputValue === lang) return message.reply(client.translate.commands.language.already_set.replace("%s", support[inputValue])); + if (!Array.from(Object.keys(support)).includes(inputValue)) return message.reply(client.translate.commands.language.language_not_support.replace("%s1", inputValue).replace("%s2", Object.keys(support))); + + client.config.lang.code = inputValue; + client.translate = require("../../languages/" + inputValue + ".json"); + + update(dbRef, { + "language": inputValue + }).then(() => { + message.channel.send(client.translate.commands.language.set_success.replace("%s", support[inputValue])); + }); + break; + default: + return message.reply(client.translate.commands.language.invalid_options.replace("%s", inputOption)); + } +} + +module.exports.help = { + "name": "language", + "description": "Sets language for the bot.", + "usage": "language [option: set] ", + "category": "settings", + "aliases": ["lang", "ภาษา"], + "userPermissions": ["MANAGE_GUILD"], + "clientPermissions": ["SEND_MESSAGES"] +} + +module.exports.interaction = { + "data": { + "name": module.exports.help.name, + "name_localizations": { + "en-US": "language", + "th": "ภาษา" + }, + "description": module.exports.help.description, + "description_localizations": { + "en-US": "Sets language for the bot.", + "th": "ตั้งค่าภาษาสำหรับบอท" + }, + "options": [ + { + "type": 1, + "name": "current", + "name_localizations": { + "th": "ปัจจุบัน" + }, + "description": "See the language that is currently being used.", + "description_localizations": { + "th": "ดูภาษาที่กำลังใช้งานอยู่" + }, + "required": false + }, + { + "type": 1, + "name": "set", + "name_localizations": { + "th": "ตั้งค่า" + }, + "description": "Sets language for the bot.", + "description_localizations": { + "th": "ตั้งค่าภาษาสำหรับบอท" + }, + "required": false, + "options": [ + { + "type": 3, + "name": "value", + "name_localizations": { + "th": "ค่า" + }, + "description": "The language code.", + "description_localizations": { + "th": "รหัสภาษา" + }, + "required": true, + "choices": [ + { + "name": "English", + "value": "en" + }, + { + "name": "ไทย", + "value": "th" + } + ] + } + ] + } + ] + }, + async execute(interaction) { + const subCommand = interaction.options.getSubcommand(); + const inputValue = interaction.options.get("value"); + + const guildID = interaction.guild.id; + const prefix = interaction.client.config.prefix; + const lang = interaction.client.config.lang.code; + const support = interaction.client.config.lang.support; + const dbRef = child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), guildID), "config"); + + if (subCommand === "current") { + await interaction.editReply({ + "embeds": [ + { + "title": interaction.client.translate.commands.language.title, + "description": interaction.client.translate.commands.language.description + .replace("%s1", support[lang]) + .replace("%s2", (prefix + module.exports.help.usage)) + .replace("%s3", ("/" + module.exports.help.usage)), + "color": 14684245, + "timestamp": new Date(), + "footer": { + "text": interaction.client.translate.commands.language.data_at + } + } + ] + }); + } + + if (subCommand === "set") { + if (inputValue.value === lang) return await interaction.editReply(interaction.client.translate.commands.language.already_set.replace("%s", support[inputValue])); + + interaction.client.config.lang.code = inputValue.value; + interaction.client.translate = require("../../languages/" + inputValue.value + ".json"); + + update(dbRef, { + "language": inputValue.value + }).then(async () => { + await interaction.editReply(interaction.client.translate.commands.language.set_success.replace("%s", support[inputValue.value])); + }); + } + } +}; \ No newline at end of file diff --git a/source/commands/settings/notify.js b/source/commands/settings/notify.js new file mode 100644 index 00000000..94579859 --- /dev/null +++ b/source/commands/settings/notify.js @@ -0,0 +1,433 @@ +const { getDatabase, ref, child, get, set } = require("firebase/database"); + +module.exports.run = (client, message, args) => { + const input = args.join(" "); + const inputType = args[0]; + const inputOption = args[1] ? args[1].toLowerCase() : ""; + const inputChannel = args[2]; + + const guildID = message.guild.id; + const prefix = client.config.prefix; + const type = ["alert", "channelCreate", "channelDelete", "channelPinsUpdate", "channelUpdate", "emojiCreate", "emojiDelete", "emojiUpdate", "guildMemberAdd", "guildMemberRemove"]; + const dbRef = child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), guildID), "config"); + + get(child(dbRef, "notification")).then(snapshot => { + if (snapshot.exists()) { + const alert = snapshot.val().alert; + const channelCreate = snapshot.val().channelCreate; + const channelDelete = snapshot.val().channelDelete; + const channelPinsUpdate = snapshot.val().channelPinsUpdate; + const channelUpdate = snapshot.val().channelUpdate; + const emojiCreate = snapshot.val().emojiCreate; + const emojiDelete = snapshot.val().emojiDelete; + const emojiUpdate = snapshot.val().emojiUpdate; + const guildMemberAdd = snapshot.val().guildMemberAdd; + const guildMemberRemove = snapshot.val().guildMemberRemove; + + if (!input) { + return message.channel.send({ + "embeds": [ + { + "title": client.translate.commands.notify.title, + "description": client.translate.commands.notify.description + .replace("%s1", (alert ? ("<#" + alert + ">") : client.translate.commands.notify.not_set)) + .replace("%s2", (channelCreate ? ("<#" + channelCreate + ">") : client.translate.commands.notify.not_set)) + .replace("%s3", (channelDelete ? ("<#" + channelDelete + ">") : client.translate.commands.notify.not_set)) + .replace("%s4", (channelPinsUpdate ? ("<#" + channelPinsUpdate + ">") : client.translate.commands.notify.not_set)) + .replace("%s5", (channelUpdate ? ("<#" + channelUpdate + ">") : client.translate.commands.notify.not_set)) + .replace("%s6", (emojiCreate ? ("<#" + emojiCreate + ">") : client.translate.commands.notify.not_set)) + .replace("%s7", (emojiDelete ? ("<#" + emojiDelete + ">") : client.translate.commands.notify.not_set)) + .replace("%s8", (emojiUpdate ? ("<#" + emojiUpdate + ">") : client.translate.commands.notify.not_set)) + .replace("%s9", (guildMemberAdd ? ("<#" + guildMemberAdd + ">") : client.translate.commands.notify.not_set)) + .replace("%s10", (guildMemberRemove ? ("<#" + guildMemberRemove + ">") : client.translate.commands.notify.not_set)) + .replace("%s11", (prefix + module.exports.help.usage)) + .replace("%s12", ("/" + module.exports.help.usage)), + "color": 14684245, + "timestamp": new Date(), + "footer": { + "text": client.translate.commands.notify.data_at + } + } + ] + }); + } + + switch (inputOption) { + case "set": + if (!inputType) return message.reply(client.translate.commands.notify.empty_type.replace("%s", type.join(", "))); + if (!type.includes(inputType)) return message.reply(client.translate.commands.notify.type_not_found.replace("%s", type.join(", "))); + if (!inputChannel) return message.reply(client.translate.commands.notify.empty_config_channel); + + const channel = message.guild.channels.cache.find(channels => (channels.id === inputChannel) || (channels.name === inputChannel)); + + if (!channel) return message.reply(client.translate.commands.notify.channel_not_found); + + set(child(child(dbRef, "notification"), inputType), channel.id.toString()).then(() => { + message.channel.send(client.translate.commands.notify.set_success.replace("%s1", inputType).replace("%s2", channel.name)); + }); + break; + case "remove": + if (!inputType) return message.reply(client.translate.commands.notify.empty_type.replace("%s", type.join(", "))); + if (!type.includes(inputType)) return message.reply(client.translate.commands.notify.type_not_found.replace("%s", type.join(", "))); + + set(child(child(dbRef, "notification"), inputType), false).then(() => { + message.channel.send(client.translate.commands.notify.remove_success.replace("%s", inputType)); + }); + break; + default: + return message.reply(client.translate.commands.notify.invalid_options.replace("%s", inputOption)); + } + } else { + set(child(dbRef, "notification"), { + "alert": false, + "channelCreate": false, + "channelDelete": false, + "channelPinsUpdate": false, + "channelUpdate": false, + "emojiCreate": false, + "emojiDelete": false, + "emojiUpdate": false, + "guildMemberAdd": false, + "guildMemberRemove": false + }).then(() => { + module.exports.run(client, message, args); + }); + } + }); +} + +module.exports.help = { + "name": "notify", + "description": "Set up the notifications you want.", + "usage": "notify [option: set, remove] ", + "category": "settings", + "aliases": ["notification", "การแจ้งเตือน"], + "userPermissions": ["MANAGE_GUILD"], + "clientPermissions": ["SEND_MESSAGES"] +} + +module.exports.interaction = { + "data": { + "name": module.exports.help.name, + "name_localizations": { + "en-US": "notify", + "th": "การแจ้งเตือน" + }, + "description": module.exports.help.description, + "description_localizations": { + "en-US": "Set up the notifications you want.", + "th": "ตั้งค่าการแจ้งเตือนที่คุณต้องการ" + }, + "options": [ + { + "type": 1, + "name": "info", + "name_localizations": { + "th": "ข้อมูล" + }, + "description": "Receive information about each channel's notification.", + "description_localizations": { + "th": "รับข้อมูลการแจ้งเตือนของแต่ละช่อง" + }, + "required": false + }, + { + "type": 1, + "name": "set", + "name_localizations": { + "th": "ตั้งค่า" + }, + "description": "The type of notification you want to set.", + "description_localizations": { + "th": "ประเภทของการแจ้งเตือนที่คุณต้องการตั้งค่า" + }, + "required": false, + "options": [ + { + "type": 3, + "name": "type", + "name_localizations": { + "th": "ประเภท" + }, + "description": "The type of notification you want to set.", + "description_localizations": { + "th": "ประเภทของการแจ้งเตือนที่คุณต้องการตั้งค่า" + }, + "required": true, + "choices": [ + { + "name": "General", + "name_localizations": { + "th": "ทั่วไป" + }, + "value": "alert" + }, + { + "name": "Channel (Create)", + "name_localizations": { + "th": "ช่อง (สร้าง)" + }, + "value": "channelCreate" + }, + { + "name": "Channel (Delete)", + "name_localizations": { + "th": "ช่อง (ลบ)" + }, + "value": "channelDelete" + }, + { + "name": "Channel (Pins Update)", + "name_localizations": { + "th": "ช่อง (อัปเดตพิน)" + }, + "value": "channelPinsUpdate" + }, + { + "name": "Channel (Update)", + "name_localizations": { + "th": "ช่อง (อัพเดท)" + }, + "value": "channelUpdate" + }, + { + "name": "Emoji (Create)", + "name_localizations": { + "th": "อีโมจิ (สร้าง)" + }, + "value": "emojiCreate" + }, + { + "name": "Emoji (Delete)", + "name_localizations": { + "th": "อีโมจิ (ลบ)" + }, + "value": "emojiDelete" + }, + { + "name": "Emoji (Update)", + "name_localizations": { + "th": "อีโมจิ (อัพเดท)" + }, + "value": "emojiUpdate" + }, + { + "name": "Guild (Members Join)", + "name_localizations": { + "th": "เซิร์ฟเวอร์ (สมาชิกเข้าร่วม)" + }, + "value": "guildMemberAdd" + }, + { + "name": "Guild (Members Leave)", + "name_localizations": { + "th": "เซิร์ฟเวอร์ (สมาชิกออก)" + }, + "value": "guildMemberRemove" + } + ] + }, + { + "type": 7, + "name": "channel", + "name_localizations": { + "th": "ช่อง" + }, + "description": "The channel you want to set the notification.", + "description_localizations": { + "th": "ช่องที่คุณต้องการตั้งค่าการแจ้งเตือน" + }, + "required": true, + "channel_types": [ + 0, + 5, + 10, + 11, + 12, + 15 + ] + } + ] + }, + { + "type": 1, + "name": "remove", + "name_localizations": { + "th": "ลบ" + }, + "description": "The type of notification you want to remove.", + "description_localizations": { + "th": "ประเภทของการแจ้งเตือนที่คุณต้องการลบ" + }, + "required": false, + "options": [ + { + "type": 3, + "name": "type", + "name_localizations": { + "th": "ประเภท" + }, + "description": "The type of notification you want to remove.", + "description_localizations": { + "th": "ประเภทของการแจ้งเตือนที่คุณต้องการลบ" + }, + "required": true, + "choices": [ + { + "name": "General", + "name_localizations": { + "th": "ทั่วไป" + }, + "value": "alert" + }, + { + "name": "Channel (Create)", + "name_localizations": { + "th": "ช่อง (สร้าง)" + }, + "value": "channelCreate" + }, + { + "name": "Channel (Delete)", + "name_localizations": { + "th": "ช่อง (ลบ)" + }, + "value": "channelDelete" + }, + { + "name": "Channel (Pins Update)", + "name_localizations": { + "th": "ช่อง (อัปเดตพิน)" + }, + "value": "channelPinsUpdate" + }, + { + "name": "Channel (Update)", + "name_localizations": { + "th": "ช่อง (อัพเดท)" + }, + "value": "channelUpdate" + }, + { + "name": "Emoji (Create)", + "name_localizations": { + "th": "อีโมจิ (สร้าง)" + }, + "value": "emojiCreate" + }, + { + "name": "Emoji (Delete)", + "name_localizations": { + "th": "อีโมจิ (ลบ)" + }, + "value": "emojiDelete" + }, + { + "name": "Emoji (Update)", + "name_localizations": { + "th": "อีโมจิ (อัพเดท)" + }, + "value": "emojiUpdate" + }, + { + "name": "Guild (Members Join)", + "name_localizations": { + "th": "เซิร์ฟเวอร์ (สมาชิกเข้าร่วม)" + }, + "value": "guildMemberAdd" + }, + { + "name": "Guild (Members Leave)", + "name_localizations": { + "th": "เซิร์ฟเวอร์ (สมาชิกออก)" + }, + "value": "guildMemberRemove" + } + ] + } + ] + } + ] + }, + async execute(interaction) { + const subCommand = interaction.options.getSubcommand(); + const inputType = interaction.options.get("type"); + const inputChannel = interaction.options.get("channel"); + + const guildID = interaction.guild.id; + const prefix = interaction.client.config.prefix; + const dbRef = child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), guildID), "config"); + + get(child(dbRef, "notification")).then(async snapshot => { + if (snapshot.exists()) { + const alert = snapshot.val().alert; + const channelCreate = snapshot.val().channelCreate; + const channelDelete = snapshot.val().channelDelete; + const channelPinsUpdate = snapshot.val().channelPinsUpdate; + const channelUpdate = snapshot.val().channelUpdate; + const emojiCreate = snapshot.val().emojiCreate; + const emojiDelete = snapshot.val().emojiDelete; + const emojiUpdate = snapshot.val().emojiUpdate; + const guildMemberAdd = snapshot.val().guildMemberAdd; + const guildMemberRemove = snapshot.val().guildMemberRemove; + + if (subCommand === "info") { + return await interaction.editReply({ + "embeds": [ + { + "title": interaction.client.translate.commands.notify.title, + "description": interaction.client.translate.commands.notify.description + .replace("%s1", (alert ? ("<#" + alert + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s2", (channelCreate ? ("<#" + channelCreate + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s3", (channelDelete ? ("<#" + channelDelete + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s4", (channelPinsUpdate ? ("<#" + channelPinsUpdate + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s5", (channelUpdate ? ("<#" + channelUpdate + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s6", (emojiCreate ? ("<#" + emojiCreate + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s7", (emojiDelete ? ("<#" + emojiDelete + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s8", (emojiUpdate ? ("<#" + emojiUpdate + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s9", (guildMemberAdd ? ("<#" + guildMemberAdd + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s10", (guildMemberRemove ? ("<#" + guildMemberRemove + ">") : interaction.client.translate.commands.notify.not_set)) + .replace("%s11", (prefix + module.exports.help.usage)) + .replace("%s12", ("/" + module.exports.help.usage)), + "color": 14684245, + "timestamp": new Date(), + "footer": { + "text": interaction.client.translate.commands.notify.data_at + } + } + ] + }); + } + + if (subCommand === "set") { + const channel = interaction.guild.channels.cache.find(channels => (channels.id === inputChannel.value) || (channels.name === inputChannel.value)); + + if (!channel) return await interaction.editReply(interaction.client.translate.commands.notify.channel_not_found); + + await set(child(child(dbRef, "notification"), inputType.value), channel.id.toString()); + await interaction.editReply(interaction.client.translate.commands.notify.set_success.replace("%s1", inputType.value).replace("%s2", channel.name)); + } + + if (subCommand === "remove") { + await set(child(child(dbRef, "notification"), inputType.value), false); + await interaction.editReply(interaction.client.translate.commands.notify.remove_success.replace("%s", inputType.value)); + } + } else { + set(child(dbRef, "notification"), { + "alert": false, + "channelCreate": false, + "channelDelete": false, + "channelPinsUpdate": false, + "channelUpdate": false, + "emojiCreate": false, + "emojiDelete": false, + "emojiUpdate": false, + "guildMemberAdd": false, + "guildMemberRemove": false + }).then(() => { + module.exports.interaction.execute(interaction); + }); + } + }); + } +}; \ No newline at end of file diff --git a/source/commands/settings/personal.js b/source/commands/settings/personal.js new file mode 100644 index 00000000..844a241d --- /dev/null +++ b/source/commands/settings/personal.js @@ -0,0 +1,227 @@ +const { getDatabase, ref, child, get, set } = require("firebase/database"); + +module.exports.run = (client, message, args) => { + const input = args.join(" "); + const inputType = args[0] ? args[0].toLowerCase() : ""; + const inputBoolean = args[1] ? args[1].toLowerCase() : ""; + + const guildID = message.guild.id; + const authorID = message.author.id; + const prefix = client.config.prefix; + const type = ["avatar", "info", "uid"] + const dbRef = child(child(child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), guildID), "data/users"), authorID), "access"); + + get(dbRef).then(snapshot => { + if (snapshot.exists()) { + const avatar = snapshot.val().avatar; + const info = snapshot.val().info; + const uid = snapshot.val().uid; + + if (!input) { + return message.channel.send({ + "embeds": [ + { + "title": client.translate.commands.personal.title, + "description": client.translate.commands.personal.description + .replace("%s1", (avatar ? client.translate.commands.personal.yes : client.translate.commands.personal.no)) + .replace("%s2", (info ? client.translate.commands.personal.yes : client.translate.commands.personal.no)) + .replace("%s3", (uid ? client.translate.commands.personal.yes : client.translate.commands.personal.no)) + .replace("%s4", (prefix + module.exports.help.usage)) + .replace("%s5", ("/" + module.exports.help.usage)), + "color": 14684245, + "timestamp": new Date(), + "footer": { + "text": client.translate.commands.personal.data_at + } + } + ] + }); + } + if (!inputType) return message.reply(client.translate.commands.personal.empty_type.replace("%s", type.join(", "))); + if (!type.includes(inputType)) return message.reply(client.translate.commands.personal.type_not_found.replace("%s", type.join(", "))); + if (!inputBoolean) return message.reply(client.translate.commands.personal.empty_value); + + switch (inputBoolean) { + case "true": + set(child(dbRef, inputType), true).then(() => { + message.channel.send(client.translate.commands.personal.true_success.replace("%s", inputType)); + }); + break; + case "false": + set(child(dbRef, inputType), false).then(() => { + message.channel.send(client.translate.commands.personal.false_success.replace("%s", inputType)); + }); + break; + default: + return message.reply(client.translate.commands.personal.invalid_value); + } + } else { + set(dbRef, { + "avatar": false, + "info": false, + "uid": false + }).then(() => { + module.exports.run(client, message, args); + }); + } + }); +} + +module.exports.help = { + "name": "personal", + "description": "Set up about your information.", + "usage": "personal [type] ", + "category": "settings", + "aliases": ["pers", "ส่วนตัว", "ข้อมูลส่วนตัว"], + "clientPermissions": ["SEND_MESSAGES"] +} + +module.exports.interaction = { + "data": { + "name": module.exports.help.name, + "name_localizations": { + "en-US": "personal", + "th": "ข้อมูลส่วนตัว" + }, + "description": module.exports.help.description, + "description_localizations": { + "en-US": "Set up about your information.", + "th": "ตั้งค่าเกี่ยวกับข้อมูลของคุณ" + }, + "options": [ + { + "type": 1, + "name": "current", + "name_localizations": { + "th": "ปัจจุบัน" + }, + "description": "See your current settings.", + "description_localizations": { + "th": "ดูการตั้งค่าปัจจุบันของคุณ" + }, + "required": false, + }, + { + "type": 1, + "name": "set", + "name_localizations": { + "th": "ตั้งค่า" + }, + "description": "Set your permission to see your personal. (Specific to Shioru)", + "description_localizations": { + "th": "ตั้งค่าการอนุญาตของคุณเพื่อดูส่วนบุคคลของคุณ (เฉพาะ Shioru)" + }, + "required": false, + "options": [ + { + "type": 3, + "name": "type", + "name_localizations": { + "th": "ประเภท" + }, + "description": "The type of personal you want to set.", + "description_localizations": { + "th": "ประเภทส่วนบุคคลที่คุณต้องการตั้งค่า" + }, + "required": true, + "choices": [ + { + "name": "Avatar", + "name_localizations": { + "th": "รูปภาพประจำตัว" + }, + "value": "avatar" + }, + { + "name": "Information", + "name_localizations": { + "th": "ข้อมูล" + }, + "value": "info" + }, + { + "name": "User ID", + "name_localizations": { + "th": "ID ผู้ใช้" + }, + "value": "uid" + } + ] + }, + { + "type": 5, + "name": "boolean", + "name_localizations": { + "th": "ตรรกะ" + }, + "description": "True means allow and False means not allowed.", + "description_localizations": { + "th": "True หมายถึงอนุญาตและ Flase หมายถึงไม่อนุญาต" + }, + "required": true + } + ] + } + ] + }, + async execute(interaction) { + const subCommand = interaction.options.getSubcommand(); + const inputType = interaction.options.get("type").value; + const inputBoolean = interaction.options.get("boolean").value; + + const guildID = interaction.guild.id; + const authorID = interaction.user.id; + const prefix = interaction.client.config.prefix; + const dbRef = child(child(child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), guildID), "data/users"), authorID), "access"); + + get(dbRef).then(async snapshot => { + if (snapshot.exists()) { + const avatar = snapshot.val().avatar; + const info = snapshot.val().info; + const uid = snapshot.val().uid; + + if (subCommand === "current") { + return await interaction.editReply({ + "embeds": [ + { + "title": interaction.client.translate.commands.personal.title, + "description": interaction.client.translate.commands.personal.description + .replace("%s1", (avatar ? interaction.client.translate.commands.personal.yes : interaction.client.translate.commands.personal.no)) + .replace("%s2", (info ? interaction.client.translate.commands.personal.yes : interaction.client.translate.commands.personal.no)) + .replace("%s3", (uid ? interaction.client.translate.commands.personal.yes : interaction.client.translate.commands.personal.no)) + .replace("%s4", (prefix + module.exports.help.usage)) + .replace("%s5", ("/" + module.exports.help.usage)), + "color": 14684245, + "timestamp": new Date(), + "footer": { + "text": interaction.client.translate.commands.personal.data_at + } + } + ] + }); + } + + if (subCommand === "set") { + switch (inputBoolean) { + case true: + await set(child(dbRef, inputType), true); + await interaction.editReply(interaction.client.translate.commands.personal.true_success.replace("%s", inputType)); + break; + case false: + await set(child(dbRef, inputType), false); + await interaction.editReply(interaction.client.translate.commands.personal.false_success.replace("%s", inputType)); + break; + } + } + } else { + set(dbRef, { + "avatar": false, + "info": false, + "uid": false + }).then(() => { + module.exports.interaction.execute(interaction); + }); + } + }); + } +}; \ No newline at end of file diff --git a/source/commands/settings/prefix.js b/source/commands/settings/prefix.js new file mode 100644 index 00000000..5a4106c8 --- /dev/null +++ b/source/commands/settings/prefix.js @@ -0,0 +1,174 @@ +const { getDatabase, ref, child, set } = require("firebase/database"); + +module.exports.run = (client, message, args) => { + const input = args.join(" "); + const inputOption = args[0] ? args[0].toLowerCase() : ""; + const inputValue = args[1]; + + const guildID = message.guild.id; + const prefix = client.config.prefix; + const dbRef = child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), guildID), "config"); + + if (!input) { + return message.channel.send({ + "embeds": [ + { + "title": client.translate.commands.prefix.title, + "description": client.translate.commands.prefix.description + .replace("%s1", prefix) + .replace("%s2", (prefix + module.exports.help.usage)) + .replace("%s3", ("/" + module.exports.help.usage)), + "color": 14684245, + "timestamp": new Date(), + "footer": { + "text": client.translate.commands.prefix.data_at + } + } + ] + }); + } + + switch (inputOption) { + case "set": + if (!inputValue) return message.reply(client.translate.commands.prefix.empty_value); + if (inputValue === prefix) return message.reply(client.translate.commands.prefix.already_set.replace("%s", inputValue)); + if (inputValue.length > 5) return message.reply(client.translate.commands.prefix.too_long); + + client.config.prefix = inputValue; + + set(child(dbRef, "prefix"), inputValue).then(() => { + message.channel.send(client.translate.commands.prefix.set_success.replace("%s", inputValue)); + }); + break; + case "default": + client.config.prefix = "S"; + + set(child(dbRef, "prefix"), "S").then(() => { + message.channel.send(client.translate.commands.prefix.default_success); + }); + break; + default: + return message.reply(client.translate.commands.prefix.this_options_not_found.replace("%s", inputOption)); + } +} + +module.exports.help = { + "name": "prefix", + "description": "Set the bot prefix for the server.", + "usage": "prefix [option: set, default] ", + "category": "settings", + "aliases": ["pf", "คำนำหน้า"], + "userPermissions": ["MANAGE_GUILD"], + "clientPermissions": ["SEND_MESSAGES"] +} + +module.exports.interaction = { + "data": { + "name": module.exports.help.name, + "name_localizations": { + "en-US": "prefix", + "th": "คำนำหน้า" + }, + "description": module.exports.help.description, + "description_localizations": { + "en-US": "Set the bot prefix for the server.", + "th": "ตั้งค่าคำนำหน้าบอทสำหรับเซิร์ฟเวอร์" + }, + "options": [ + { + "type": 1, + "name": "current", + "name_localizations": { + "th": "ปัจจุบัน", + }, + "description": "Displays the current prefix.", + "description_localizations": { + "th": "แสดงคำนำหน้าปัจจุบัน" + }, + "required": false + }, + { + "type": 1, + "name": "set", + "name_localizations": { + "th": "ตั้งค่า", + }, + "description": "Sets the prefix for the bot.", + "description_localizations": { + "th": "ตั้งค่าคำนำหน้าสำหรับบอท" + }, + "required": false, + "options": [ + { + "type": 3, + "name": "value", + "name_localizations": { + "th": "ค่า", + }, + "description": "The new prefix.", + "description_localizations": { + "th": "คำนำหน้าใหม่" + }, + "required": true, + "max_value": 5 + } + ] + }, + { + "type": 1, + "name": "default", + "name_localizations": { + "th": "ค่าเริ่มต้น", + }, + "description": "Sets the prefix for the bot to the default prefix.", + "description_localizations": { + "th": "ตั้งค่าคำนำหน้าสำหรับบอทเป็นคำนำหน้าเริ่มต้น" + }, + "required": false + } + ] + }, + async execute(interaction) { + const subCommand = interaction.options.getSubcommand(); + const inputValue = interaction.options.get("value"); + + const guildID = interaction.guild.id; + const prefix = interaction.client.config.prefix; + const dbRef = child(child(ref(getDatabase(), "Shioru/apps/discord/guilds"), guildID), "config"); + + if (subCommand === "current") { + return await interaction.editReply({ + "embeds": [ + { + "title": interaction.client.translate.commands.prefix.title, + "description": interaction.client.translate.commands.prefix.description + .replace("%s1", prefix) + .replace("%s2", (prefix + module.exports.help.usage)) + .replace("%s3", ("/" + module.exports.help.usage)), + "color": 14684245, + "timestamp": new Date(), + "footer": { + "text": interaction.client.translate.commands.prefix.data_at + } + } + ] + }); + } + + if (subCommand === "set") { + if (inputValue.value === prefix) return await interaction.editReply(interaction.client.translate.commands.prefix.already_set.replace("%s", inputValue.value)); + + interaction.client.config.prefix = inputValue.value; + + await set(child(dbRef, "prefix"), inputValue.value); + await interaction.editReply(interaction.client.translate.commands.prefix.set_success.replace("%s", inputValue.value)); + } + + if (subCommand === "default") { + interaction.client.config.prefix = "S"; + + await set(child(dbRef, "prefix"), "S"); + await interaction.editReply(interaction.client.translate.commands.prefix.default_success); + } + } +} \ No newline at end of file