Compare commits

...

4 commits

7 changed files with 270 additions and 21 deletions

View file

@ -4,16 +4,16 @@ import db from '../../models/index.js';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('autoresponse') .setName('autoresponse')
.setDescription('Enable or disable autoresponse'), .setDescription('Enable or disable autoresponse')
category: 'utility', .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages),
userPermissions: [PermissionFlagsBits.ManageMessages], category: 'admin',
async execute(interaction, args, client) { async execute(interaction, args, client) {
const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } }); const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } });
if (autoresponseStat.stat !== 'enable') { if (autoresponseStat.stat !== 'enable') {
const body = { serverID: interaction.guild.id, stat: 'enable' }; const body = { serverID: interaction.guild.id, stat: 'enable' };
await db.autoresponseStat.create(body); await db.autoresponseStat.create(body);
return await interaction.reply({ content: 'Autoresponse has been enabled.' }); return await interaction.reply({ content: 'Autoresponse has been enabled.', ephemeral: true });
} }
const row = new ActionRowBuilder() const row = new ActionRowBuilder()
@ -30,7 +30,7 @@ export default {
.setStyle(ButtonStyle.Danger), .setStyle(ButtonStyle.Danger),
); );
await interaction.reply({ content: 'Autoresponse is already enabled, do you wish to disable it?', components: [row] }); await interaction.reply({ content: 'Autoresponse is already enabled, do you wish to disable it?', components: [row], ephemeral: true });
client.once('interactionCreate', async (interactionMenu) => { client.once('interactionCreate', async (interactionMenu) => {
if (!interactionMenu.isButton) return; if (!interactionMenu.isButton) return;
@ -38,10 +38,10 @@ export default {
if (interactionMenu.customId === 'yes') { if (interactionMenu.customId === 'yes') {
const body = { serverID: interaction.guild.id, stat: 'disable' }; const body = { serverID: interaction.guild.id, stat: 'disable' };
await db.autoresponseStat.update(body, { where: { serverID: interaction.guild.id } }); await db.autoresponseStat.update(body, { where: { serverID: interaction.guild.id } });
return interaction.editReply('Auto response has been disabled.'); return interaction.editReply({ content: 'Auto response has been disabled.', ephemeral: true });
} }
else { else {
return interaction.editReply('Nothing has been changed.'); return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true });
} }
}); });
}, },

67
commands/admin/bye.js Normal file
View file

@ -0,0 +1,67 @@
import { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, PermissionFlagsBits } from 'discord.js';
import db from '../../models/index.js';
export default {
data: new SlashCommandBuilder()
.setName('bye')
.setDescription('Set a leave message')
.addStringOption(option =>
option.setName('message')
.setDescription('The message you want the bot to say when someone leave in the current channel.')),
category: 'admin',
userPermissions: [PermissionFlagsBits.ManageChannels],
async execute(interaction, args, client) {
const leave = await db.leaveChannel.findOne({ where: { guildID: interaction.guild.id } });
if (!leave && !args[0]) {
return interaction.reply({ content: 'You need a message for me to say anything!', ephemeral: true });
}
else if (!leave) {
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
await db.leaveChannel.create(body);
return interaction.reply({ content: `The leave message have been set with ${args.message}`, ephemeral: true });
}
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('edit')
.setLabel('Edit')
.setStyle(ButtonStyle.Primary),
)
.addComponents(
new ButtonBuilder()
.setCustomId('remove')
.setLabel('Remove')
.setStyle(ButtonStyle.Danger),
)
.addComponents(
new ButtonBuilder()
.setCustomId('nothing')
.setLabel('Do nothing')
.setStyle(ButtonStyle.Secondary),
);
await interaction.reply({ content: 'The server already has a message set, do you want to edit it or remove it?', components: [row], ephemeral: true });
client.once('interactionCreate', async (interactionMenu) => {
if (!interactionMenu.isButton) return;
interactionMenu.update({ components: [] });
if (interactionMenu.customId === 'edit') {
if (!args[0]) {
return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true });
}
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
await db.leaveChannel.update(body, { where: { guildID: interaction.guild.id } });
return interaction.editReply({ content: `The leave message has been set to ${args[0]}`, ephemeral: true });
}
else if (interactionMenu.customId === 'remove') {
db.leaveChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } });
return interaction.editReply({ content: 'The leave message has been deleted.', ephemeral: true });
}
else {
return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true });
}
});
},
};

View file

@ -4,16 +4,16 @@ import db from '../../models/index.js';
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('quotation') .setName('quotation')
.setDescription('Enable or disable quotations'), .setDescription('Enable or disable quotations')
category: 'utility', .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages),
userPermissions: [PermissionFlagsBits.ManageMessages], category: 'admin',
async execute(interaction, args, client) { async execute(interaction, args, client) {
const quotationstat = await db.quotationstat.findOne({ where: { serverID: interaction.guild.id } }); const quotationstat = await db.quotationstat.findOne({ where: { serverID: interaction.guild.id } });
if (quotationstat.stat !== 'enable') { if (quotationstat.stat !== 'enable') {
const body = { serverID: interaction.guild.id, stat: 'enable' }; const body = { serverID: interaction.guild.id, stat: 'enable' };
await db.quotationstat.create(body); await db.quotationstat.create(body);
return await interaction.reply({ content: 'Quotation has been enabled.' }); return await interaction.reply({ content: 'Quotation has been enabled.', ephemeral: true });
} }
const row = new ActionRowBuilder() const row = new ActionRowBuilder()
@ -30,7 +30,7 @@ export default {
.setStyle(ButtonStyle.Danger), .setStyle(ButtonStyle.Danger),
); );
await interaction.reply({ content: 'Quotation is already enabled, do you wish to disable it?', components: [row] }); await interaction.reply({ content: 'Quotation is already enabled, do you wish to disable it?', components: [row], ephemeral: true });
client.once('interactionCreate', async (interactionMenu) => { client.once('interactionCreate', async (interactionMenu) => {
if (!interactionMenu.isButton) return; if (!interactionMenu.isButton) return;
@ -38,10 +38,10 @@ export default {
if (interactionMenu.customId === 'yes') { if (interactionMenu.customId === 'yes') {
const body = { serverID: interaction.guild.id, stat: 'disable' }; const body = { serverID: interaction.guild.id, stat: 'disable' };
await db.quotationstat.update(body, { where: { serverID: interaction.guild.id } }); await db.quotationstat.update(body, { where: { serverID: interaction.guild.id } });
return interaction.editReply('Quotation has been disabled.'); return interaction.editReply({ content: 'Quotation has been disabled.', ephemeral: true });
} }
else { else {
return interaction.editReply('Nothing has been changed.'); return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true });
} }
}); });
}, },

68
commands/admin/welcome.js Normal file
View file

@ -0,0 +1,68 @@
import { SlashCommandBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, PermissionFlagsBits } from 'discord.js';
import db from '../../models/index.js';
export default {
data: new SlashCommandBuilder()
.setName('welcome')
.setDescription('Set a join message')
.addStringOption(option =>
option.setName('message')
.setDescription('The message you want the bot to say when someone join in the current channel.')),
category: 'admin',
userPermissions: [PermissionFlagsBits.ManageChannels],
async execute(interaction, args, client) {
const join = await db.joinChannel.findOne({ where: { guildID: interaction.guild.id } });
if (!join && !args[0]) {
return interaction.reply({ content: 'You need a message for me to say anything!', ephemeral: true });
}
else if (!join) {
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
await db.joinChannel.create(body);
return interaction.reply({ content: `The join message have been set with ${args[0]}`, ephemeral: true });
}
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('edit')
.setLabel('Edit')
.setStyle(ButtonStyle.Primary),
)
.addComponents(
new ButtonBuilder()
.setCustomId('remove')
.setLabel('Remove')
.setStyle(ButtonStyle.Danger),
)
.addComponents(
new ButtonBuilder()
.setCustomId('nothing')
.setLabel('Do nothing')
.setStyle(ButtonStyle.Secondary),
);
await interaction.reply({ content: 'The server already has a message set, do you want to edit it or remove it?', components: [row], ephemeral: true });
client.once('interactionCreate', async (interactionMenu) => {
if (!interactionMenu.isButton) return;
interactionMenu.update({ components: [] });
if (interactionMenu.customId === 'edit') {
if (!args[0]) {
return interaction.reply({ content: 'You need to input a message for me to edit!', ephemeral: true });
}
const body = { guildID: interaction.guild.id, channelID: interaction.channel.id, message: args[0] };
await db.joinChannel.update(body, { where: { guildID: interaction.guild.id } });
return interaction.editReply({ content: `The join message has been set to ${args[0]}`, ephemeral: true });
}
else if (interactionMenu.customId === 'remove') {
db.joinChannel.destroy({ where: { guildID: interaction.guild.id, channelID: interaction.channel.id } });
return interaction.editReply({ content: 'The join message has been deleted.', ephemeral: true });
}
else {
return interaction.editReply({ content: 'Nothing has been changed.', ephemeral: true });
}
});
},
};

115
commands/utility/help.js Normal file
View file

@ -0,0 +1,115 @@
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import fs from 'node:fs';
const { ownerId, prefix } = process.env;
const prefixs = prefix.split(',');
export default {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Displays a list of commands or information about a command.'),
category: 'utility',
async execute(interaction, args, client) {
if (args[0]) {
const command = client.commands.get(args[0]);
const description = Object.assign({
content: 'No description available.',
usage: '',
examples: [],
fields: [],
}, command.data);
const usage = command.data.options.map(cmd => {
console.log(cmd);
let type = 'String';
const constructorName = cmd.constructor.name.toLowerCase();
console.log(constructorName);
if (constructorName.includes('boolean')) {
type = 'True/False';
}
else if (constructorName.includes('mentionable')) {
type = 'User';
}
else if (constructorName.includes('attachment')) {
type = 'Attachment';
}
return `[${cmd.name}: ${type}]`;
});
const embed = new EmbedBuilder()
.setColor(interaction.member ? interaction.member.displayHexColor : 'NAVY')
.setTitle(`\`${prefixs[0]}${command.data.name} ${usage.join(' ')}\``)
.addFields(
{ name: 'Description', value: description.description },
)
.setFooter({ text: `All the available prefix: ${prefixs.join(' | ')}` });
for (const field of description.fields) embed.addFields({ name: field.name, value: field.value });
if (description.examples.length) {
const text = `${prefixs[0]}${command.alias[0]}`;
embed.addFields({ name: 'Examples', value: `\`${text} ${description.examples.join(`\`\n\`${text} `)}\``, inline: true });
}
if (command.alias) {
if (command.alias.length > 1) {
embed.addField({ name: 'Aliases', value: `\`${command.alias.join('` `')}\``, inline: true });
}
}
if (command.userPermissions) {
embed.addField({ name: 'User permission', value: `\`${command.userPermissions.join('` `')}\``, inline: true });
}
if (command.clientPermissions) {
embed.addField({ name: 'Bot permission', value: `\`${command.clientPermissions.join('` `')}\``, inline: true });
}
if (fs.existsSync(`./asset/img/command/${command.category}/${command.data.name}.png`)) {
embed.attachFiles(`./asset/img/command/${command.category}/${command.data.name}.png`);
embed.setImage(`attachment://${command.data.name}.png`);
}
return interaction.reply({ embeds: [embed] });
}
else {
const embed = new EmbedBuilder()
.setColor(interaction.member ? interaction.member.displayHexColor : 'NAVY')
.addFields({ name: 'Command List', value: `This is a list of commands.\nTo view details for a command, do \`${prefixs[0]}help <command>\`.` })
.setFooter({ text: `All the available prefix: ${prefixs.join('| ')}` });
const object = { };
for (const command of client.commands.values()) {
if (object[command.category]) {
object[command.category].push(command.data.name);
}
else {
object[command.category] = [ command.data.name ];
}
}
for (const category in object) {
console.log(category);
let title;
if (interaction.user.id == ownerId) {
title = {
fun: '🎉\u2000Fun',
utility: '🔩\u2000Utility',
admin: '⚡\u2000Admin',
owner: '🛠️\u2000Owner',
}[category];
}
else {
title = {
fun: '🎉\u2000Fun',
utility: '🔩\u2000Utility',
admin: '⚡\u2000Admin',
}[category];
}
embed.addFields({ name: title, value: `\`${object[category].join('` `')}\`` });
}
return interaction.reply({ embeds: [embed] });
}
},
};

View file

@ -37,7 +37,7 @@ export default {
} }
// Check if the bot has the needed permissions // Check if the bot has the needed permissions
if (command.clientPermissions) { if (command.default_permission) {
const clientMember = await interaction.guild.members.fetch(client.user.id); const clientMember = await interaction.guild.members.fetch(client.user.id);
if (!clientMember.permissions.has(command.clientPermissions)) { if (!clientMember.permissions.has(command.clientPermissions)) {
return interaction.reply({ content: `❌ I am missing one of the following permission(s): \`${new PermissionFlagsBits(command.clientPermissions).toArray()}\``, ephemeral: true }); return interaction.reply({ content: `❌ I am missing one of the following permission(s): \`${new PermissionFlagsBits(command.clientPermissions).toArray()}\``, ephemeral: true });
@ -45,11 +45,13 @@ export default {
} }
// Check if the user has the needed permissions // Check if the user has the needed permissions
if (command.userPermissions) { /*
if (command.default_member_permissions) {
if (!interaction.member.permissions.has(command.userPermissions)) { if (!interaction.member.permissions.has(command.userPermissions)) {
return interaction.reply({ content: `❌ You are missing one of the following permission(s): \`${new PermissionFlagsBits(command.userPermissions).toArray()}\``, ephemeral: true }); return interaction.reply({ content: `❌ You are missing one of the following permission(s): \`${new PermissionFlagsBits(command.userPermissions).toArray()}\``, ephemeral: true });
} }
} }
*/
try { try {
const date = new Date(); const date = new Date();
@ -77,7 +79,6 @@ export default {
const args = []; const args = [];
interaction.options.data.forEach(arg => { interaction.options.data.forEach(arg => {
console.log(arg);
if (arg.type === 'MENTIONABLE') { if (arg.type === 'MENTIONABLE') {
return args.push(arg.member); return args.push(arg.member);
} }

View file

@ -7,8 +7,6 @@ import db from '../../models/index.js';
import { rand } from '../../utils/rand.js'; import { rand } from '../../utils/rand.js';
const ratelimit = {}; const ratelimit = {};
import dotenv from 'dotenv';
dotenv.config();
const { ownerId, prefix } = process.env; const { ownerId, prefix } = process.env;
const prefixs = prefix.split(','); const prefixs = prefix.split(',');
@ -308,8 +306,8 @@ export default {
} }
// Check if the user has the needed permissions // Check if the user has the needed permissions
if (command.userPermissions) { if (command.default_member_permissions) {
if (!message.member.permissions.has(command.userPermissions)) { if (!message.member.permissions.has(command.default_member_permissions)) {
return message.reply({ content: `❌ You are missing one of the following permission(s): \`${new PermissionFlagsBits(command.userPermissions).toArray()}\``, ephemeral: true }); return message.reply({ content: `❌ You are missing one of the following permission(s): \`${new PermissionFlagsBits(command.userPermissions).toArray()}\``, ephemeral: true });
} }
} }