Compare commits

..

5 commits

7 changed files with 245 additions and 37 deletions

View file

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

View file

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

View file

@ -0,0 +1,46 @@
import { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
import db from '../../models/index.js';
export default {
data: new SlashCommandBuilder()
.setName('optout')
.setDescription('Opt out of the quotation command.'),
category: 'utility',
async execute(interaction, args, client) {
const isOptOut = await db.optout.findOne({ where: { userID: interaction.user.id } });
if (!isOptOut) {
const body = { userID: interaction.user.id };
await db.optout.create(body);
return await interaction.reply({ content: 'You have successfully been opt out.' });
}
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('yes')
.setLabel('Yes')
.setStyle(ButtonStyle.Primary),
)
.addComponents(
new ButtonBuilder()
.setCustomId('no')
.setLabel('No')
.setStyle(ButtonStyle.Danger),
);
await interaction.reply({ content: 'You are already opt out, do you wish to opt in?', components: [row] });
client.once('interactionCreate', async (interactionMenu) => {
if (!interactionMenu.isButton) return;
interactionMenu.update({ components: [] });
if (interactionMenu.customId === 'yes') {
await db.optout.destroy({ where: { userID: interaction.user.id } });
return interaction.editReply('You have successfully been opt in');
}
else {
return interaction.editReply('Nothing has been changed.');
}
});
},
};

View file

@ -205,6 +205,8 @@ export default {
* This section will contain the code for the quotation feature, it will detect link for it and send it as embed * This section will contain the code for the quotation feature, it will detect link for it and send it as embed
* *
*/ */
const isOptOut = await db.optout.findOne({ where: { userID: message.author.id } });
if (!isOptOut) {
const quotationstat = await db.quotationStat.findOne({ where: { serverID: message.guild.id, stat: 'enable' } }); const quotationstat = await db.quotationStat.findOne({ where: { serverID: message.guild.id, stat: 'enable' } });
if (quotationstat && (message.content.includes('discordapp.com/channels/') || message.content.includes('discord.com/channels/'))) { if (quotationstat && (message.content.includes('discordapp.com/channels/') || message.content.includes('discord.com/channels/'))) {
@ -247,6 +249,7 @@ export default {
return message.channel.send({ embeds: [Embed] }); return message.channel.send({ embeds: [Embed] });
} }
} }
}
// Command handling from message // Command handling from message
@ -260,9 +263,22 @@ export default {
if (!hasPrefix) return; if (!hasPrefix) return;
const messageArray = message.content.match(/"[^"]*"|\S+/g).map(m => m.slice(0, 1) === '"' ? m.slice(1, -1) : m); const messageArray = message.content.match(/"[^"]*"|\S+/g).map(m => m.slice(0, 1) === '"' ? m.slice(1, -1) : m);
const commandName = messageArray[1].toLowerCase(); let commandName = messageArray[1].toLowerCase();
let messageArgs = messageArray.splice(2, messageArray.length); let messageArgs = messageArray.splice(2, messageArray.length);
// Search for alias
client.commands.find(c => {
if (c.alias) {
if (c.alias.includes(commandName)) {
commandName = c.data.name;
}
}
});
const command = client.commands.get(commandName);
if (!command) return;
const globalBlacklist = await db.Blacklists.findOne({ where: { type:'global', uid:message.author.id } }); const globalBlacklist = await db.Blacklists.findOne({ where: { type:'global', uid:message.author.id } });
const commandBlacklist = await db.Blacklists.findOne({ where: { type:commandName, uid:message.author.id } }); const commandBlacklist = await db.Blacklists.findOne({ where: { type:commandName, uid:message.author.id } });
@ -276,10 +292,6 @@ export default {
const userTag = message.author.tag; const userTag = message.author.tag;
const userID = message.author.id; const userID = message.author.id;
const command = client.commands.get(commandName);
if (!command) return;
console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m`); console.log(`\x1b[33m${userTag} (${userID})\x1b[0m launched command \x1b[33m${commandName}\x1b[0m`);
// Owner only check // Owner only check

View file

@ -0,0 +1,27 @@
'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('optouts', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
userID: {
type: Sequelize.BIGINT
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('optouts');
}
};

23
models/optout.js Normal file
View file

@ -0,0 +1,23 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class optout extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
}
}
optout.init({
userID: DataTypes.BIGINT
}, {
sequelize,
modelName: 'optout',
});
return optout;
};

View file

@ -114,6 +114,10 @@ const commands = [
.setDescription('🤫') .setDescription('🤫')
.setRequired(true)), .setRequired(true)),
new SlashCommandBuilder()
.setName('autoresponse')
.setDescription('Enable or disable autoresponse'),
new SlashCommandBuilder() new SlashCommandBuilder()
.setName('die') .setName('die')
.setDescription('Kill the bot'), .setDescription('Kill the bot'),