From a4547b3df5bcd3f163d30852364446b552ffae10 Mon Sep 17 00:00:00 2001 From: Assayyaad Date: Tue, 3 Sep 2024 15:09:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=D8=AA=D9=88=D8=B3=D8=B9=D8=A9=20=D9=83?= =?UTF-8?q?=D8=A7=D8=A6=D9=86=20=D8=A7=D9=84=D8=A8=D9=8A=D8=A7=D9=86=D8=A7?= =?UTF-8?q?=D8=AA=20=D9=81=D9=8A=20=D8=A7=D9=84=D8=A8=D9=88=D8=AA=20=D9=85?= =?UTF-8?q?=D8=B9=20=D8=A8=D8=B9=D8=B6=20=D8=A7=D9=84=D8=AA=D8=BA=D9=8A?= =?UTF-8?q?=D9=8A=D8=B1=D8=A7=D8=AA=20=D8=B9=D9=84=D9=8A=D9=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit يمكن الآن استخدام كائن البيانات بشكل أفضل وأكثر سهولة وسلاسة BREAKING CHANGE: تم إخراج brand وid من data.config جميع الإستدعاءات القديمة لأي منهما يجب إزالة ".config" منها --- src/class/bot.js | 21 +++++++------ src/events/interactionCreate.js | 2 +- src/events/ready.js | 2 +- src/options.js | 53 ++++++++++++++++++++++++++++++--- 4 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/class/bot.js b/src/class/bot.js index ce37bb7..23d9bcf 100644 --- a/src/class/bot.js +++ b/src/class/bot.js @@ -18,17 +18,20 @@ export class Bot extends Client { */ data = { config: { - id: { - guild: {} - }, - brand: { - name: 'HalfBot', - color: 0xffffff, - logoUrl: 'https://cdn.discordapp.com/embed/avatars/0.png' - }, presence: { status: 'online' } + }, + id: { + role: {}, + user: {}, + guild: {}, + channel: {} + }, + brand: { + name: 'HalfBot', + color: 0xffffff, + logoUrl: 'https://cdn.discordapp.com/embed/avatars/0.png' } } @@ -111,7 +114,7 @@ export class Bot extends Client { const data = (await import(files[i])).default if (data) { - if (name === 'config') Object.assign(this.data.config, data) + if (typeof this.data[name] === 'object') Object.assign(this.data[name], data) else this.data[name] = data } } diff --git a/src/events/interactionCreate.js b/src/events/interactionCreate.js index ecf4f08..1c5d1fc 100644 --- a/src/events/interactionCreate.js +++ b/src/events/interactionCreate.js @@ -24,7 +24,7 @@ export async function interactionCreate(interaction) { if (!interaction.isCommand()) return const command = interaction.bot.commands.get(interaction.commandName) - const brand = interaction.bot.data.config.brand + const brand = interaction.bot.data.brand if (!command) { quickReply('Error: Unknown command', brand) diff --git a/src/events/ready.js b/src/events/ready.js index c04efc6..65fc5e0 100644 --- a/src/events/ready.js +++ b/src/events/ready.js @@ -35,7 +35,7 @@ export function prepareCommands(bot) { const commands = new Map() for (const [_, command] of bot.commands) { - const guildId = getGuildId(command.data, bot.data.config.id.guild) + const guildId = getGuildId(command.data, bot.data.id.guild) const commandArray = commands.get(guildId) ?? [] commandArray.push(command.data) diff --git a/src/options.js b/src/options.js index a140c0f..c9f8895 100644 --- a/src/options.js +++ b/src/options.js @@ -40,17 +40,19 @@ export {} * @property {string} [data='data'] - The Path to the directory the json data files. */ +/** @typedef {BaseData & KeyAnyObj} BotData */ + /** - * @typedef {object} BotData + * @typedef {object} BaseData * @property {Config} config + * @property {Brand} brand - The container of the bot's brand information. + * @property {IDs} id - The container of all IDs. */ // Config /** * @typedef {object} Config - * @property {IDs} id - The container of all IDs. - * @property {Brand} brand - The container of the bot's brand information. * @property {PresenceData} presence */ @@ -65,7 +67,17 @@ export {} /** * The container of all IDs * @typedef {object} IDs + * @property {RoleIDs} role The IDs of all roles + * @property {KeyAnyObj} user The IDs of all users * @property {GuildIDs} guild The IDs of all servers + * @property {ChannelIDs} channel The IDs of all channels + * @property {KeyAnyObj} [thread] The IDs of all threads + * @property {KeyAnyObj} [message] The IDs of all messages + * @property {EmojiIDs} [emoji] The IDs of all emojis + * @property {KeyAnyObj} [sticker] The IDs of all stickers + * @property {KeyAnyObj} [command] The IDs of all commands + * @property {KeyAnyObj} [webhook] The IDs of all webhooks + * @property {KeyAnyObj} [invite] The IDs of all invites */ /** @@ -75,6 +87,39 @@ export {} * @property {string} [support] The id of the support / main */ +/** + * @typedef {object} ChannelIDs + * @property {string} [dev] The id of the development / testing server + * @property {string} [error] The id of the error log channel + * @property {string} [rules] The id of the rules channel + * @property {string} [welcome] The id of the welcome channel + */ + +/** + * @typedef {object} RoleIDs + * @property {string[] | KeyStrObj} [categories] The ids of all role categories + * @property {string} [admin] The id of the admin role + * @property {string} [mod] The id of the mod role + */ + +/** + * @typedef {object} UserIDs + * @property {string} [owner] The id of the bot owner + * @property {string[] | KeyStrObj} [dev] The id of the developer + * @property {string[] | KeyStrObj} [support] The id of the support team + */ + +/** + * @typedef {object} EmojiIDs + * @property {string} [yes] The id of the checkmark emoji + * @property {string} [no] The id of the cross emoji + * @property {string} [up] The id of the up arrow emoji + * @property {string} [down] The id of the down arrow emoji + */ + +/** @typedef {{[key:string]:string}} KeyStrObj */ +/** @typedef {{[key:string]:any}} KeyAnyObj */ + // Record /** @@ -130,7 +175,7 @@ export {} /** * @callback CommandFunction * @param {CommandInteraction} interaction - * @returns {Promise | InteractionReplyOptions| string | void} + * @returns {Promise | InteractionReplyOptions | string | void} */ // Event