Skip to content

Commit

Permalink
style: تنسيق الملفات
Browse files Browse the repository at this point in the history
  • Loading branch information
Assayyaad committed Sep 1, 2024
1 parent 7bfbaec commit 6b97ce3
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 215 deletions.
37 changes: 14 additions & 23 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,53 @@
## [3.1.3](https://github.com/DisQada/HalfBot/compare/v3.1.2...v3.1.3) (2024-01-07)


### Bug Fixes

* **DiscordBot:** Pass event args without modifications ([69e0832](https://github.com/DisQada/HalfBot/commit/69e08329fe62a8342258799bf26b63657a4f89d6))
- **DiscordBot:** Pass event args without modifications ([69e0832](https://github.com/DisQada/HalfBot/commit/69e08329fe62a8342258799bf26b63657a4f89d6))

## [3.1.2](https://github.com/DisQada/HalfBot/compare/v3.1.1...v3.1.2) (2024-01-02)


### Bug Fixes

* Eliminate types issues ([3ed25fb](https://github.com/DisQada/HalfBot/commit/3ed25fba4174950553c4d21d3a6393c4eeb66f30))
- Eliminate types issues ([3ed25fb](https://github.com/DisQada/HalfBot/commit/3ed25fba4174950553c4d21d3a6393c4eeb66f30))

## [3.1.1](https://github.com/DisQada/HalfBot/compare/v3.1.0...v3.1.1) (2024-01-02)


### Bug Fixes

* Eliminate types issues ([202084c](https://github.com/DisQada/HalfBot/commit/202084c35a9b7bd825c564934e5c77038f90dce8))
- Eliminate types issues ([202084c](https://github.com/DisQada/HalfBot/commit/202084c35a9b7bd825c564934e5c77038f90dce8))

# [3.1.0](https://github.com/DisQada/HalfBot/compare/v3.0.0...v3.1.0) (2024-01-01)


### Bug Fixes

* **BotOptions:** Identify 'client' prop as optional ([f57c47e](https://github.com/DisQada/HalfBot/commit/f57c47e866d8f6e18cc6618763cd20964a657854))

- **BotOptions:** Identify 'client' prop as optional ([f57c47e](https://github.com/DisQada/HalfBot/commit/f57c47e866d8f6e18cc6618763cd20964a657854))

### Features

* **BotEvent:** Use 'once' property ([51f235c](https://github.com/DisQada/HalfBot/commit/51f235c5e685de086d084cea7f83f465d4db2dca))
* **BotEvet:** Introduce repeating events ([f4920a9](https://github.com/DisQada/HalfBot/commit/f4920a9943e9cde9ef82e88d668e593ad673aaca))

- **BotEvent:** Use 'once' property ([51f235c](https://github.com/DisQada/HalfBot/commit/51f235c5e685de086d084cea7f83f465d4db2dca))
- **BotEvet:** Introduce repeating events ([f4920a9](https://github.com/DisQada/HalfBot/commit/f4920a9943e9cde9ef82e88d668e593ad673aaca))

### Performance Improvements

* Speed up start time ([a544612](https://github.com/DisQada/HalfBot/commit/a5446129db6e669cfc443973a241ee23bb805e25))
- Speed up start time ([a544612](https://github.com/DisQada/HalfBot/commit/a5446129db6e669cfc443973a241ee23bb805e25))

# [3.0.0](https://github.com/DisQada/HalfBot/compare/v2.1.1...v3.0.0) (2023-12-30)


### Bug Fixes

* Use correct type ([d6358ec](https://github.com/DisQada/HalfBot/commit/d6358ecf1ec11a6496e5f4ebbe405936d6cea517))

- Use correct type ([d6358ec](https://github.com/DisQada/HalfBot/commit/d6358ecf1ec11a6496e5f4ebbe405936d6cea517))

### Code Refactoring

* Delete "emojiChars.json" ([99deb8f](https://github.com/DisQada/HalfBot/commit/99deb8ff69776b36658ef668aa1bdf9b96fad0b1))
* Delete "url.js" ([ba3de3e](https://github.com/DisQada/HalfBot/commit/ba3de3eeb216999a225b6ce37187f059290b5ab4))
* Replace bot module classes ([8d7f19c](https://github.com/DisQada/HalfBot/commit/8d7f19c39037a162f3897b44a952f3d7d4bd34f4))

- Delete "emojiChars.json" ([99deb8f](https://github.com/DisQada/HalfBot/commit/99deb8ff69776b36658ef668aa1bdf9b96fad0b1))
- Delete "url.js" ([ba3de3e](https://github.com/DisQada/HalfBot/commit/ba3de3eeb216999a225b6ce37187f059290b5ab4))
- Replace bot module classes ([8d7f19c](https://github.com/DisQada/HalfBot/commit/8d7f19c39037a162f3897b44a952f3d7d4bd34f4))

### BREAKING CHANGES

* the array variable "emojiChars" has been deleted and no longer exists
* the function "isSafe" has been deleted and no longer exists
* BotCommand class and BotEvent class has been deleted and no longer exist, normal JS objects shall now be used instead
- the array variable "emojiChars" has been deleted and no longer exists
- the function "isSafe" has been deleted and no longer exists
- BotCommand class and BotEvent class has been deleted and no longer exist, normal JS objects shall now be used instead

## [2.1.1](https://github.com/DisQada/HalfBot/compare/v2.1.0...v2.1.1) (2023-10-05)

Expand Down
47 changes: 14 additions & 33 deletions src/class/discordBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ export class DiscordBot extends Client {
constructor(options) {
super(
options.client || {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers
]
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers]
}
)

Expand Down Expand Up @@ -113,25 +109,18 @@ export class DiscordBot extends Client {
* @async
*/
async storeData(directory) {
const files = await readFolderPaths(resolve(directory), {
deepSearch: false
})
if (files.length === 0) {
return
}
const files = await readFolderPaths(resolve(directory), { deepSearch: false })
if (files.length === 0) return

for (let i = 0; i < files.length; i++) {
const index1 = files[i].lastIndexOf(sep)
const index2 = files[i].length - '.json'.length
const name = files[i].substring(index1 + sep.length, index2)
const i1 = files[i].lastIndexOf(sep)
const i2 = files[i].length - '.json'.length
const name = files[i].substring(i1 + sep.length, i2)

const data = require(files[i])
if (data) {
if (name === 'config') {
Object.assign(this.data.config, data)
} else {
this.data[name] = data
}
if (name === 'config') Object.assign(this.data.config, data)
else this.data[name] = data
}
}
}
Expand Down Expand Up @@ -173,11 +162,8 @@ export class DiscordBot extends Client {
/** @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)
}
if (data.name === Events.ClientReady || data.once) this.once(data.name, func)
else this.on(data.name, func)

record.name = data.name
break
Expand Down Expand Up @@ -206,16 +192,13 @@ export class DiscordBot extends Client {
await setTimeout(nextWait, undefined)
const value = await execute(this)

if (typeof value === 'number' || typeof value === 'string') {
nextWait = toNumber(value)
} else if (first) {
if (typeof value === 'number' || typeof value === 'string') nextWait = toNumber(value)
else if (first) {
nextWait = toNumber(data.wait)
first = false
}

if (nextWait === 0) {
break
}
if (nextWait === 0) break
}
}

Expand All @@ -240,9 +223,7 @@ export class DiscordBot extends Client {
const paths = findPaths()
.map((fp) => fp.fullPath)
.filter((fp) => fp.includes('command') || fp.includes('event'))
if (paths.length === 0) {
return
}
if (paths.length === 0) return

/** @type {SuccessRecord[]} */
const successRecords = []
Expand Down
45 changes: 13 additions & 32 deletions src/events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,13 @@ export async function interactionCreate(interaction) {
*/
async function quickReply(reply, brand) {
const embed = asEmbed(reply, brand)
const msg = {
embeds: [embed],
ephemeral: true
}
const msg = { embeds: [embed], ephemeral: true }

if (interaction.deferred || interaction.replied) {
await interaction.followUp(msg)
} else {
await interaction.reply(msg)
}
if (interaction.deferred || interaction.replied) await interaction.followUp(msg)
else await interaction.reply(msg)
}

if (!interaction.isCommand()) {
return
}
if (!interaction.isCommand()) return

const command = interaction.bot.commands.get(interaction.commandName)
const brand = interaction.bot.data.config.brand
Expand All @@ -40,9 +32,7 @@ export async function interactionCreate(interaction) {
}

if (command.data.defer !== false) {
await interaction.deferReply({
ephemeral: command.data.ephemeral
})
await interaction.deferReply({ ephemeral: command.data.ephemeral })
}

let reply = await command.execute(interaction)
Expand All @@ -51,27 +41,18 @@ export async function interactionCreate(interaction) {
return
}

if (interaction.replied) {
return
}
if (interaction.replied) return

if (typeof reply === 'string') {
reply = {
embeds: [asEmbed(reply, brand)]
}
} else {
if (reply.embeds) {
// @ts-expect-error
reply.embeds = applyStyle(reply.embeds, brand)
} else if (reply.content) {
if (typeof reply === 'string') reply = { embeds: [asEmbed(reply, brand)] }
else {
// @ts-expect-error
if (reply.embeds) reply.embeds = applyStyle(reply.embeds, brand)
else if (reply.content) {
reply.embeds = [asEmbed(reply.content, brand)]
delete reply.content
}
}

if (interaction.deferred || interaction.replied) {
await interaction.followUp(reply)
} else {
await interaction.reply(reply)
}
if (interaction.deferred || interaction.replied) await interaction.followUp(reply)
else await interaction.reply(reply)
}
19 changes: 5 additions & 14 deletions src/events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export function getGuildId(data, guildIds) {
export function prepareCommands(bot) {
const commands = new Map()

for (const iterator of bot.commands) {
const command = iterator[1]
for (const [_, command] of bot.commands) {
const guildId = getGuildId(command.data, bot.data.config.id.guild)

const commandArray = commands.get(guildId) ?? []
Expand All @@ -54,15 +53,9 @@ export function prepareCommands(bot) {
* @private
*/
async function registerCommands(bot, commandMap) {
for (const iterator of commandMap) {
const commandsData = iterator[1]
const guildId = iterator[0]

if (guildId === '0') {
await bot.application?.commands.set(commandsData)
} else {
await bot.application?.commands.set(commandsData, guildId)
}
for (const [guildId, commandsData] of commandMap) {
if (guildId === '0') await bot.application?.commands.set(commandsData)
else await bot.application?.commands.set(commandsData, guildId)
}
}

Expand All @@ -81,7 +74,5 @@ export async function ready(bot) {
console.log(`-> The Bot '${bot.user.username}' Is Online <-`)
// @ts-expect-error
bot.user.setPresence(bot.data.config.presence)
} else {
console.log('-> Bot Is Online <-')
}
} else console.log('-> Bot Is Online <-')
}
30 changes: 8 additions & 22 deletions src/func/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@
export function asNumber(colour) {
let num

if (typeof colour === 'number') {
num = colour
} else if (typeof colour === 'string') {
num = Number.parseInt(colour.substring(1), 16)
}
if (typeof colour === 'number') num = colour
else if (typeof colour === 'string') num = Number.parseInt(colour.substring(1), 16)

if (num) {
return num
} else {
return 0
}
if (num) return num
else return 0
}

/**
Expand All @@ -39,19 +33,11 @@ export function asNumber(colour) {
export function asString(colour) {
let str

if (typeof colour === 'string') {
str = colour.startsWith('#') ? colour.substring(1) : colour
} else if (typeof colour === 'number') {
str = colour.toString(16)
}
if (typeof colour === 'string') str = colour.startsWith('#') ? colour.substring(1) : colour
else if (typeof colour === 'number') str = colour.toString(16)

if (str) {
while (str.length < 6) {
str = '0' + str
}

while (str.length < 6) str = '0' + str
return `#${str}`
} else {
return `#000000`
}
} else return `#000000`
}
16 changes: 2 additions & 14 deletions src/func/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ function defaultConfig(header, width) {
export function logSuccessRecords(records) {
const data = [['name', 'type', 'deployment']]

if (records.length > 0) {
data.push(
...records.map((r) => {
return [r.name, r.type, r.deployment]
})
)
}
if (records.length > 0) data.push(...records.map((r) => [r.name, r.type, r.deployment]))

const msg = '🟩 Successful registration 🟩'
return table(data, defaultConfig(msg, 30))
Expand All @@ -63,13 +57,7 @@ export function logSuccessRecords(records) {
export function logFailRecords(records) {
const data = [['path', 'message']]

if (records.length > 0) {
data.push(
...records.map((r) => {
return [r.path, r.message]
})
)
}
if (records.length > 0) data.push(...records.map((r) => [r.path, r.message]))

const msg = '🟥 Failure registration 🟥'
return table(data, defaultConfig(msg, 45))
Expand Down
Loading

0 comments on commit 6b97ce3

Please sign in to comment.