Editprofile: Add buttons to toggle ping user-settings
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const { SlashCommandBuilder, ComponentType, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder } = require("discord.js");
|
const { SlashCommandBuilder, ComponentType, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalBuilder } = require("discord.js");
|
||||||
const { Card, User, Character } = require("../models");
|
const { Card, User, Character } = require("../models");
|
||||||
const UserUtils = require("../util/users");
|
const { UserUtils, ReplyUtils } = require("../util");
|
||||||
|
|
||||||
const pageSize = 8;
|
const pageSize = 8;
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@ module.exports = {
|
|||||||
.setDescription("Edit your profile"),
|
.setDescription("Edit your profile"),
|
||||||
permissionLevel: 0,
|
permissionLevel: 0,
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
await interaction.deferReply();
|
||||||
let user = await UserUtils.getUserByDiscordId(interaction.member.id);
|
let user = await UserUtils.getUserByDiscordId(interaction.member.id);
|
||||||
|
|
||||||
let profile = await user.getProfile();
|
let profile = await user.getProfile();
|
||||||
@@ -18,8 +19,8 @@ module.exports = {
|
|||||||
|
|
||||||
|
|
||||||
//row of button components to select what property to edit
|
//row of button components to select what property to edit
|
||||||
const row = new ActionRowBuilder();
|
const mainRow = new ActionRowBuilder();
|
||||||
row.addComponents(
|
mainRow.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setLabel('Edit Status')
|
.setLabel('Edit Status')
|
||||||
.setCustomId('editStatus')
|
.setCustomId('editStatus')
|
||||||
@@ -30,25 +31,66 @@ module.exports = {
|
|||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Primary)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const pingRow = new ActionRowBuilder();
|
||||||
|
pingRow.addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setLabel('Wishlist Ping')
|
||||||
|
.setCustomId('toggle-wishlist-ping')
|
||||||
|
.setStyle(user.wishlistPing ? ButtonStyle.Success : ButtonStyle.Primary),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setLabel('Drop Ping')
|
||||||
|
.setCustomId('toggle-drop-ping')
|
||||||
|
.setStyle(user.dropPing ? ButtonStyle.Success : ButtonStyle.Primary),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setLabel('Daily Ping')
|
||||||
|
.setCustomId('toggle-daily-ping')
|
||||||
|
.setStyle(user.dailyPing ? ButtonStyle.Success : ButtonStyle.Primary)
|
||||||
|
);
|
||||||
|
|
||||||
//show buttons
|
//show buttons
|
||||||
let message = await interaction.reply({ content: "", components: [row], fetchReply: true });
|
let message = await interaction.editReply({ content: "", components: [mainRow, pingRow], fetchReply: true });
|
||||||
|
|
||||||
//filter only events from the user who triggered the command
|
//filter only events from the user who triggered the command
|
||||||
const filter = (m) => m.author.id === interaction.author.id;
|
const filter = (m) => m.author.id === interaction.author.id;
|
||||||
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button, time: 25000 })
|
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button, time: 25000 })
|
||||||
|
|
||||||
collector.on('collect', async (m) => {
|
collector.on('collect', async (i) => {
|
||||||
switch (m.customId) {
|
await i.deferReply();
|
||||||
|
switch (i.customId) {
|
||||||
case 'editStatus':
|
case 'editStatus':
|
||||||
await this.openStatusModal(m, user, profile);
|
await this.openStatusModal(i, user, profile);
|
||||||
break;
|
break;
|
||||||
case 'editShowcase':
|
case 'editShowcase':
|
||||||
await this.openShowcaseModal(m, user, profile);
|
await this.openShowcaseModal(i, user, profile);
|
||||||
|
break;
|
||||||
|
case 'toggle-wishlist-ping':
|
||||||
|
user.wishlistPing = !user.wishlistPing;
|
||||||
|
user.save();
|
||||||
|
break;
|
||||||
|
case 'toggle-drop-ping':
|
||||||
|
user.dropPing = !user.dropPing;
|
||||||
|
user.save();
|
||||||
|
break;
|
||||||
|
case 'toggle-daily-ping':
|
||||||
|
user.dailyPing = !user.dailyPing;
|
||||||
|
user.save();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
m.reply({ content: "Invalid selection" });
|
i.editReply({ content: "Invalid selection" });
|
||||||
|
return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let newComponents= ReplyUtils.recreateComponents(message.components);
|
||||||
|
newComponents[1].components.forEach(component => {
|
||||||
|
if(component.data.custom_id == i.customId) {
|
||||||
|
component.setStyle((component.data.style == 1) ? 3 : 1);
|
||||||
|
console.log(`Changed style of ${component.data.custom_id} is now ${component.data.style}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await message.edit({ components: newComponents });
|
||||||
|
let msg = await i.editReply({content: '...'});
|
||||||
|
await msg.delete();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async openShowcaseModal(interaction, user, profile) {
|
async openShowcaseModal(interaction, user, profile) {
|
||||||
|
|||||||
Reference in New Issue
Block a user