Skip to content

Commit

Permalink
Merge pull request #65 from RezkyRizaldi/v14
Browse files Browse the repository at this point in the history
V1.35.2
  • Loading branch information
RezkyRizaldi authored Nov 28, 2022
2 parents d00f08a + a8acd81 commit 253e26e
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 101 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "borobot",
"version": "1.35.1",
"version": "1.35.2",
"description": "A simple Discord Bot build with Discord.js",
"displayName": "Borobot",
"bugs": {
Expand Down Expand Up @@ -42,7 +42,6 @@
"@napi-rs/canvas": "^0.1.30",
"@vitalets/google-translate-api": "^9.0.0",
"anime-images-api": "^2.0.0",
"ascii-table": "^0.0.9",
"axios": "^1.1.3",
"canvas": "^2.10.2",
"change-case": "^4.1.2",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/misc/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2101,11 +2101,11 @@ module.exports = {
name: '🐣 Spawn',
value: entity.spawns
? entity.spawns
.map((spawn) =>
!/^[A-Z|\d+]/.test(spawn)
.map((spawn) => {
return !/^[A-Z|\d+]/.test(spawn)
? capitalCase(spawn)
: spawn,
)
: spawn;
})
.join(', ')
: italic('Unknown'),
},
Expand Down
18 changes: 9 additions & 9 deletions src/commands/mod/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ module.exports = {

if (!bannedUser) throw "This user isn't banned.";

const u = await guild.members.unban(
const banUser = await guild.members.unban(
bannedUser,
'ban temporary duration has passed.',
);

if (!u.bot) {
return u
if (!banUser.bot) {
return banUser
.send({
content: `Congratulations! You have been unbanned from ${bold(
guild,
Expand All @@ -218,7 +218,7 @@ module.exports = {
.catch(
async () =>
await interaction.followUp({
content: `Could not send a DM to ${u}.`,
content: `Could not send a DM to ${banUser}.`,
ephemeral: true,
}),
);
Expand All @@ -237,14 +237,14 @@ module.exports = {

if (!bannedUser) throw "This user isn't banned.";

const u = await guild.members.unban(bannedUser, reason);
const banUser = await guild.members.unban(bannedUser, reason);

await interaction.editReply({
content: `Successfully ${bold('unbanned')} ${u.tag}.`,
content: `Successfully ${bold('unbanned')} ${banUser.tag}.`,
});

if (!u.bot) {
return u
if (!banUser.bot) {
return banUser
.send({
content: `Congratulations! You have been unbanned from ${bold(
guild,
Expand All @@ -253,7 +253,7 @@ module.exports = {
.catch(
async () =>
await interaction.followUp({
content: `Could not send a DM to ${u}.`,
content: `Could not send a DM to ${banUser}.`,
ephemeral: true,
}),
);
Expand Down
10 changes: 6 additions & 4 deletions src/commands/mod/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ module.exports = {
{
messages.filter((message) => {
if (message.author.id === member.id && amount > i) {
filteredMessages.set(message.id, message);
i++;

return filteredMessages.set(message.id, message);
}

return message;
});

if (!filteredMessages.size) {
Expand All @@ -121,10 +122,11 @@ module.exports = {

messages.filter((message) => {
if (membersWithRole.includes(message.author.id) && amount > i) {
filteredMessages.set(message.id, message);
i++;

return filteredMessages.set(message.id, message);
}

return message;
});

if (!filteredMessages.size) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/systems/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ module.exports = {
.then(async (messages) => {
await distube.play(
voiceChannel,
searchResults[+messages.first().content - 1].name,
searchResults[Number(messages.first().content) - 1].name,
{ textChannel, member },
);

Expand Down
17 changes: 0 additions & 17 deletions src/functions/handlers/handleCommands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const AsciiTable = require('ascii-table');
const { REST, Routes } = require('discord.js');
const fs = require('fs');
const path = require('path');
Expand All @@ -9,18 +8,11 @@ const path = require('path');
*/
module.exports = (client) => {
client.handleCommands = async () => {
const table = new AsciiTable();

table.setHeading('Name', 'Category', 'Type', 'Status');

/** @type {{ commands: import('discord.js').Collection<String, { data: import('discord.js').SlashCommandBuilder, type: String, execute(): Promise<void> }>, commandArray: import('discord.js').RESTPostAPIChatInputApplicationCommandsJSONBody[] }} */
const { commands, commandArray } = client;
const commandPath = path.join(__dirname, '..', '..', 'commands');
const commandFolders = fs.readdirSync(commandPath);

/** @type {String[]} */
const arr = [];

for (const folder of commandFolders) {
const commandSubPath = path.join(commandPath, folder);
const commandFiles = fs
Expand All @@ -35,17 +27,8 @@ module.exports = (client) => {

commands.set(command.data.name, command);
commandArray.push(command.data.toJSON());
table.addRow(
command?.data.name ?? file,
folder,
command?.type ?? 'None',
'✅',
);
table.sort((a, b) => a[0].localeCompare(b[0]));
arr.push(file);
}
}
table.setTitle(`Commands${arr.length ? ` (${arr.length})` : ''}`);

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);

Expand Down
9 changes: 0 additions & 9 deletions src/functions/handlers/handleComponents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const AsciiTable = require('ascii-table');
const fs = require('fs');
const path = require('path');

Expand All @@ -8,10 +7,6 @@ const path = require('path');
*/
module.exports = (client) => {
client.handleComponents = () => {
const table = new AsciiTable('Components');

table.setHeading('Name', 'Status');

const componentPath = path.join(__dirname, '..', '..', 'components');

if (fs.existsSync(componentPath)) {
Expand All @@ -24,10 +19,6 @@ module.exports = (client) => {
const filePath = path.join(componentPath, file);
const component = require(filePath);

table.setTitle(
`Components${componentFiles.length && ` (${componentFiles.length})`}`,
);
table.addRow(component.data.name, '✅');
components.set(component.data.name, component);
}
}
Expand Down
44 changes: 0 additions & 44 deletions src/functions/handlers/handleEvents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const AsciiTable = require('ascii-table');
const { Events } = require('discord.js');
const { Events: DistubeEvents } = require('distube');
const fs = require('fs');
const path = require('path');

Expand All @@ -10,11 +7,6 @@ const path = require('path');
*/
module.exports = (client) => {
client.handleEvents = () => {
const table = new AsciiTable('Events');

table.setHeading('Name', 'Instance', 'Status');

let total;
const eventPath = path.join(__dirname, '..', '..', 'events');
const eventFolders = fs.readdirSync(eventPath);

Expand All @@ -30,16 +22,6 @@ module.exports = (client) => {
const filePath = path.join(eventSubPath, file);
const event = require(filePath);

if (!Object.values(Events).includes(event.name)) {
table.addRow(
event?.name ?? file,
`${folder.charAt(0).toUpperCase()}${folder.slice(1)}`,
'❌ -> invalid event name.',
);

continue;
}

event.once
? client.once(
event.name,
Expand All @@ -49,49 +31,23 @@ module.exports = (client) => {
event.name,
async (...args) => await event.execute(...args, client),
);

table.addRow(
event.name,
`${folder.charAt(0).toUpperCase()}${folder.slice(1)}`,
'✅',
);
}

total = eventFiles.length;
break;

case 'distube':
for (const file of eventFiles) {
const filePath = path.join(eventSubPath, file);
const event = require(filePath);

if (!Object.values(DistubeEvents).includes(event.name)) {
table.addRow(
event?.name ?? file,
`${folder.charAt(0).toUpperCase()}${folder.slice(1)}`,
'❌ -> invalid event name.',
);

continue;
}

client.distube.on(
event.name,
async (...args) => await event.execute(...args, client),
);

table.addRow(
event.name,
`${folder.charAt(0).toUpperCase()}${folder.slice(1)}`,
'✅',
);
}

total += eventFiles.length;
break;
}
}

table.setTitle(`Events ${total > 0 ? `(${total})` : ''}`);
};
};
5 changes: 3 additions & 2 deletions src/utils/applyHexColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const convert = require('color-convert');
* @param {String} color
* @returns {String} The hex color code.
*/
module.exports = (color) =>
!/^[#]?[0-9A-F]{6}$/i.test(color)
module.exports = (color) => {
return !/^[#]?[0-9A-F]{6}$/i.test(color)
? convert.keyword.hex(color)
: !color.startsWith('#')
? `#${color}`
: color;
};
8 changes: 4 additions & 4 deletions src/utils/applyTitleCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
module.exports = (string) =>
string
.split(' ')
.map((word) =>
![
.map((word) => {
return ![
'of',
'the',
'and',
Expand All @@ -21,6 +21,6 @@ module.exports = (string) =>
'but',
].includes(word)
? word.charAt(0).toUpperCase() + word.slice(1)
: word,
)
: word;
})
.join(' ');
5 changes: 3 additions & 2 deletions src/utils/getFormattedParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const { paramCase } = require('change-case');
* @param {String} query
* @returns {String} The formatted query param.
*/
module.exports = (query) =>
query.toLowerCase().includes('itto')
module.exports = (query) => {
return query.toLowerCase().includes('itto')
? 'arataki-itto'
: query.toLowerCase() === 'hutao'
? 'hu-tao'
Expand All @@ -29,3 +29,4 @@ module.exports = (query) =>
: query.toLowerCase() === 'yunjin'
? 'yun-jin'
: paramCase(query);
};
2 changes: 1 addition & 1 deletion src/utils/serverMute.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const findOrCreateRole = async (interaction) => {
);
});

return new Promise((resolve) => resolve(mutedRole));
return Promise.resolve(mutedRole);
};

/**
Expand Down
9 changes: 7 additions & 2 deletions src/utils/truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
* @param {Number} [trim=3]
* @returns {String} The truncated string.
*/
module.exports = (str, max, trim = 3) =>
str ? (str.length > max ? `${str.slice(0, max - trim)}...` : str) : null;
module.exports = (str, max, trim = 3) => {
return str
? str.length > max
? `${str.slice(0, max - trim)}...`
: str
: null;
};

0 comments on commit 253e26e

Please sign in to comment.