Skip to content

Commit

Permalink
refactor: تحسين بعض الجزئيات في الكود
Browse files Browse the repository at this point in the history
  • Loading branch information
Assayyaad committed Sep 4, 2024
1 parent 84c4aec commit f67e846
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
34 changes: 12 additions & 22 deletions src/class/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Bot extends Client {
channel: {}
},
brand: {
name: 'HalfBot',
name: 'Bot',
color: 0xffffff,
logoUrl: 'https://cdn.discordapp.com/embed/avatars/0.png'
}
Expand Down Expand Up @@ -62,27 +62,23 @@ export class Bot extends Client {
* @returns {Promise<void>}
* @private
*/
async run(options) {
if (!options.directories) options.directories = {}

await Promise.all([
storeFolderPaths([options.directories.root || 'bot'], { deepSearch: true }),
this.storeData(options.directories.data || 'data')
])
async run({ directories, token }) {
const folders = Object.assign({ root: 'bot', data: 'data' }, directories)
await Promise.all([storeFolderPaths([folders.root], { deepSearch: true }), this.storeData(folders.data)])

await this.registerAllModules()
this.listenToEvents()

await this.login(options.token)
await this.login(token)
}

/**
* Inject data from the workspace files.
* @param {string} directory - The path to the directory the json data files.
* @param {string} folder - The path to the directory the json data files.
* @returns {Promise<void>}
*/
async storeData(directory) {
const files = await readFolderPaths(resolve(directory), { deepSearch: false })
async storeData(folder) {
const files = await readFolderPaths(resolve(folder), { deepSearch: false })
if (files.length === 0) return

for (let i = 0; i < files.length; i++) {
Expand Down Expand Up @@ -183,29 +179,23 @@ export class Bot extends Client {
* @param {BotEvent} event - The bot event module.
* @returns {SuccessRecord}
*/
registerEvent(event) {
registerEvent({ data, execute }) {
/** @type {SuccessRecord} */
const record = {
name: '',
type: event.data.module,
type: data.module,
deployment: 'global'
}

if (event.data.module === 'event') {
/** @type {ClientEvent<any>} */ // @ts-expect-error
const e = event
const { data, execute } = e
if (data.module === 'event') {
/** @type {ClientEventFunction<any>} */
const func = (args) => execute(this, args)

if (data.name === Events.ClientReady || data.once) this.once(data.name, func)
else this.on(data.name, func)

record.name = data.name
} else if (event.data.module === 'event-repeat') {
/** @type {RepeatingEvent} */ // @ts-expect-error
const e = event
const { data, execute } = e
} else if (data.module === 'event-repeat') {
/** @type {RepeatingEventFunction} */
const func = async () => {
let first = true
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) {

let reply = await command.execute(interaction)
if (!reply) {
quickReply('Done', brand)
quickReply(':)👍', brand)
return
}

Expand Down
2 changes: 1 addition & 1 deletion src/exports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './options.js'
export { Bot } from './class/bot.js'
export { asNumber, asString } from './func/color.js'
export { asEmbed, applyStyle } from './func/style.js'
export * from './options.js'

0 comments on commit f67e846

Please sign in to comment.