parent
099d0d75e4
commit
c24520dd24
4 changed files with 139 additions and 40 deletions
@ -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.'); |
||||
} |
||||
}); |
||||
}, |
||||
}; |
@ -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'); |
||||
} |
||||
}; |
@ -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; |
||||
}; |
Loading…
Reference in new issue