Skip to content

Commit

Permalink
feat: توسعة كائن البيانات في البوت مع بعض التغييرات عليه
Browse files Browse the repository at this point in the history
يمكن الآن استخدام كائن البيانات بشكل أفضل وأكثر سهولة وسلاسة

BREAKING CHANGE: تم إخراج brand وid من data.config
جميع الإستدعاءات القديمة لأي منهما يجب إزالة ".config" منها
  • Loading branch information
Assayyaad committed Sep 3, 2024
1 parent d68add0 commit a4547b3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
21 changes: 12 additions & 9 deletions src/class/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
53 changes: 49 additions & 4 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand All @@ -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
*/

/**
Expand All @@ -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

/**
Expand Down Expand Up @@ -130,7 +175,7 @@ export {}
/**
* @callback CommandFunction
* @param {CommandInteraction} interaction
* @returns {Promise<InteractionReplyOptions | string | void> | InteractionReplyOptions| string | void}
* @returns {Promise<InteractionReplyOptions | string | void> | InteractionReplyOptions | string | void}
*/

// Event
Expand Down

0 comments on commit a4547b3

Please sign in to comment.