Move role menu setup and allow everyone to send it
This commit is contained in:
parent
f03314af80
commit
fdfc2fc88a
@ -59,7 +59,8 @@
|
|||||||
"missingTreeMessage": "There was a problem finding the Tree message. Please make sure the ``/tree`` and ``/top trees`` messages are this channel, or run </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.",
|
"missingTreeMessage": "There was a problem finding the Tree message. Please make sure the ``/tree`` and ``/top trees`` messages are this channel, or run </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.",
|
||||||
"missingTreeChannel": "There was a problem finding the Tree channel, was it deleted? Please make sure the ``/tree`` and ``/top trees`` messages are in this channel, or run </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.",
|
"missingTreeChannel": "There was a problem finding the Tree channel, was it deleted? Please make sure the ``/tree`` and ``/top trees`` messages are in this channel, or run </setup:1065407649363005561> to set the ``/tree`` and ``/top trees`` channels.",
|
||||||
"reset": "All guild configuration information has been removed from the database.",
|
"reset": "All guild configuration information has been removed from the database.",
|
||||||
"resetError": "There was a problem deleting your guild information, contact @voidf1sh#0420 for help."
|
"resetError": "There was a problem deleting your guild information, contact @voidf1sh#0420 for help.",
|
||||||
|
"noRoleMenu": "A role menu has not been created for this guild yet. Run </setup rolemenu:0> to create a role menu."
|
||||||
},
|
},
|
||||||
"notifications": {
|
"notifications": {
|
||||||
"water": "is ready to be watered again!",
|
"water": "is ready to be watered again!",
|
||||||
|
@ -54,9 +54,9 @@ module.exports = {
|
|||||||
this.watchChannelId = watchChannelId;
|
this.watchChannelId = watchChannelId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
setRoles(waterRole, fruitRole) {
|
setRoles(waterRoleId, fruitRoleId) {
|
||||||
this.waterRoleId = waterRole.id;
|
this.waterRoleId = waterRoleId;
|
||||||
if (fruitRole) this.fruitRoleId = fruitRole.id;
|
if (fruitRoleId) this.fruitRoleId = fruitRoleId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
queryBuilder(query) {
|
queryBuilder(query) {
|
||||||
@ -134,9 +134,12 @@ module.exports = {
|
|||||||
case "setRoles":
|
case "setRoles":
|
||||||
if (this.fruitRoleId != "") {
|
if (this.fruitRoleId != "") {
|
||||||
queryParts = [
|
queryParts = [
|
||||||
`UPDATE guild_info SET water_role_id = ${db.escape(this.waterRoleId)}, `,
|
`INSERT INTO guild_info (`,
|
||||||
`fruit_role_id = ${db.escape(this.fruitRoleId)} `,
|
`guild_id, water_role_id, fruit_role_id`,
|
||||||
`WHERE guild_id = ${db.escape(this.guildId)}`
|
`) VALUES (`,
|
||||||
|
`${db.escape(this.guildId)}, ${db.escape(this.waterRoleId)}, ${db.escape(this.fruitRoleId)}`,
|
||||||
|
`) ON DUPLICATE KEY UPDATE water_role_id = ${db.escape(this.waterRoleId)}, `,
|
||||||
|
`fruit_role_id = ${db.escape(this.fruitRoleId)}`
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
queryParts = [
|
queryParts = [
|
||||||
|
@ -543,7 +543,7 @@ const functions = {
|
|||||||
const comparedRankings = await this.rankings.compare(interaction, guildInfo);
|
const comparedRankings = await this.rankings.compare(interaction, guildInfo);
|
||||||
|
|
||||||
const embed = this.builders.comparisonEmbed(comparedRankings, guildInfo);
|
const embed = this.builders.comparisonEmbed(comparedRankings, guildInfo);
|
||||||
await interaction.update(embed).catch(err => console.error(err));
|
await interaction.update(embed).catch(e => console.error(e));
|
||||||
} else {
|
} else {
|
||||||
await interaction.update(this.builders.errorEmbed(findMessagesResponse.status));
|
await interaction.update(this.builders.errorEmbed(findMessagesResponse.status));
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,18 @@
|
|||||||
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const dbfn = require('../modules/dbfn.js');
|
|
||||||
const fn = require('../modules/functions.js');
|
const fn = require('../modules/functions.js');
|
||||||
|
const strings = require('../data/strings.json');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('rolemenu')
|
.setName('rolemenu')
|
||||||
.setDescription('Send a self-assignable role selection menu')
|
.setDescription('Send a self-assignable role selection menu'),
|
||||||
.addRoleOption(o =>
|
|
||||||
o.setName('waterrole')
|
|
||||||
.setDescription('The role for water reminder pings')
|
|
||||||
.setRequired(true))
|
|
||||||
.addRoleOption(o =>
|
|
||||||
o.setName('fruitrole')
|
|
||||||
.setDescription('The role for fruit alert pings')
|
|
||||||
.setRequired(false))
|
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles),
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
await interaction.deferReply().catch(err => console.error(err));
|
await interaction.deferReply().catch(e => console.error(e));
|
||||||
if (interaction.client.guildInfos.has(interaction.guildId)) {
|
if (interaction.client.guildInfos.has(interaction.guildId)) {
|
||||||
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
||||||
guildInfo.setRoles(interaction.options.getRole('waterrole'), interaction.options.getRole('fruitrole'));
|
await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(e => console.error(e));
|
||||||
await dbfn.setGuildInfo(guildInfo.queryBuilder("setRoles"));
|
|
||||||
await fn.collectionBuilders.guildInfos(interaction.client);
|
|
||||||
await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(err => console.error(err));
|
|
||||||
} else {
|
} else {
|
||||||
await interaction.editReply(fn.builders.errorEmbed("No information is known about your server yet, please run /setup or /compare")).catch(err => console.error(err));
|
await interaction.editReply(fn.builders.errorEmbed(strings.status.noRoleMenu)).catch(e => console.error(e));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
@ -2,37 +2,77 @@ const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
|
|||||||
const fn = require('../modules/functions.js');
|
const fn = require('../modules/functions.js');
|
||||||
const strings = require('../data/strings.json');
|
const strings = require('../data/strings.json');
|
||||||
const dbfn = require('../modules/dbfn.js');
|
const dbfn = require('../modules/dbfn.js');
|
||||||
|
const { GuildInfo } = require('../modules/CustomClasses.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('setup')
|
.setName('setup')
|
||||||
.setDescription('Attempt automatic configuration of the bot.')
|
.setDescription('Attempt automatic configuration of the bot.')
|
||||||
|
.addSubcommand(sc =>
|
||||||
|
sc.setName('compare')
|
||||||
|
.setDescription('Set up the channels to be used with /compare')
|
||||||
.addChannelOption(o =>
|
.addChannelOption(o =>
|
||||||
o.setName('treechannel')
|
o.setName('treechannel')
|
||||||
.setDescription('What channel is your tree in?')
|
.setDescription('What channel is your tree in?')
|
||||||
.setRequired(true))
|
.setRequired(true)
|
||||||
|
)
|
||||||
.addChannelOption(o =>
|
.addChannelOption(o =>
|
||||||
o.setName('leaderboardchannel')
|
o.setName('leaderboardchannel')
|
||||||
.setDescription('If your leaderboard isn\'t in the same channel, where is it?')
|
.setDescription('If your leaderboard isn\'t in the same channel, where is it?')
|
||||||
.setRequired(false))
|
.setRequired(false)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addSubcommand(sc =>
|
||||||
|
sc.setName('rolemenu')
|
||||||
|
.setDescription('Setup the roles to be used with /rolemenu')
|
||||||
|
.addRoleOption(o =>
|
||||||
|
o.setName('waterrole')
|
||||||
|
.setDescription('The role for water reminder pings')
|
||||||
|
.setRequired(true)
|
||||||
|
)
|
||||||
|
.addRoleOption(o =>
|
||||||
|
o.setName('fruitrole')
|
||||||
|
.setDescription('The role for fruit alert pings')
|
||||||
|
.setRequired(false)
|
||||||
|
)
|
||||||
|
)
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
await interaction.deferReply({ ephemeral: true });
|
await interaction.deferReply({ ephemeral: true });
|
||||||
/**/
|
const subcommand = interaction.options.getSubcommand();
|
||||||
let guildInfo = {
|
switch (subcommand) {
|
||||||
"guildId": interaction.guildId,
|
case "compare":
|
||||||
"treeName": "",
|
if (interaction.client.guildInfos.has(interaction.guildId)) {
|
||||||
"treeHeight": 0,
|
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
||||||
"treeMessageId": "",
|
|
||||||
"treeChannelId": `${interaction.options.getChannel('treechannel').id }`,
|
|
||||||
"leaderboardMessageId": "",
|
|
||||||
"leaderboardChannelId": `${interaction.options.getChannel('leaderboardchannel').id || interaction.options.getChannel('treechannel').id }`,
|
|
||||||
"reminderMessage": "",
|
|
||||||
"reminderChannelId": "",
|
|
||||||
"remindedStatus": 0,
|
|
||||||
"reminderOptIn": 0,
|
|
||||||
};
|
|
||||||
const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
|
const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
|
||||||
interaction.editReply(findMessagesResponse.status);
|
await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e));
|
||||||
|
} else {
|
||||||
|
let guildInfo = new GuildInfo()
|
||||||
|
.setId(interaction.guildId);
|
||||||
|
const findMessagesResponse = await fn.messages.find(interaction, guildInfo);
|
||||||
|
await interaction.editReply(findMessagesResponse.status).catch(e => console.error(e));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "rolemenu":
|
||||||
|
let waterRoleId = interaction.options.getRole('waterrole').id;
|
||||||
|
let fruitRoleId = interaction.options.getRole('fruitrole') ? interaction.options.getRole('fruitrole').id : undefined;
|
||||||
|
if (interaction.client.guildInfos.has(interaction.guildId)) {
|
||||||
|
let guildInfo = interaction.client.guildInfos.get(interaction.guildId);
|
||||||
|
guildInfo.setRoles(waterRoleId, fruitRoleId);
|
||||||
|
await dbfn.setGuildInfo(guildInfo.queryBuilder("setRoles"));
|
||||||
|
await fn.collectionBuilders.guildInfos(interaction.client);
|
||||||
|
await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(e => console.error(e));
|
||||||
|
} else {
|
||||||
|
let guildInfo = new GuildInfo()
|
||||||
|
.setId(interaction.guildId);
|
||||||
|
guildInfo.setRoles(waterRoleId, fruitRoleId);
|
||||||
|
await dbfn.setGuildInfo(guildInfo.queryBuilder("setRoles"));
|
||||||
|
await fn.collectionBuilders.guildInfos(interaction.client);
|
||||||
|
await interaction.editReply(fn.builders.embeds.treeRoleMenu(guildInfo)).catch(e => console.error(e));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user