mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
[Buttons] Remove separate devwatch button. (#29)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
--------------------------------------------------------------------------------
|
||||
-- Up
|
||||
--------------------------------------------------------------------------------
|
||||
ALTER TABLE settings DROP COLUMN devwatch_role_id;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Down
|
||||
--------------------------------------------------------------------------------
|
||||
ALTER TABLE settings ADD devwatch_role_id TEXT;
|
||||
+1
-1
@@ -107,4 +107,4 @@ CREATE TABLE
|
||||
timestamp datetime NOT NULL DEFAULT (datetime ('now', 'localtime'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS index_timestamp ON private_help_tickets (timestamp);
|
||||
CREATE INDEX IF NOT EXISTS index_timestamp ON private_help_tickets (timestamp);
|
||||
|
||||
+8
-25
@@ -1,37 +1,20 @@
|
||||
import { ButtonInteraction, Client, MessageFlags } from 'discord.js';
|
||||
import { Database } from '../shared/Database';
|
||||
import { Button } from '../types';
|
||||
import { SetSeverity } from '../utils';
|
||||
|
||||
class DevWatchButton implements Button<Client> {
|
||||
id = 'dev-watch';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ButtonInteraction): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
||||
await interaction.reply({
|
||||
embeds: [{
|
||||
...SetSeverity('warning'),
|
||||
description: 'DevWatch roles have been deprecated in favour of the `/role-buttons create` command. Please notify an administrator to setup a new role-button.'
|
||||
}],
|
||||
|
||||
try {
|
||||
const settings = await Database.getOrCreateSettings(interaction.guildId);
|
||||
if (!settings.devwatch_role_id) throw new Error('`devwatch_role_id` was not configured. Please configure a role then try again.');
|
||||
|
||||
const guild = await context.guilds.fetch(interaction.guildId);
|
||||
const member = await guild.members.fetch(interaction.user.id);
|
||||
if (!member) throw new Error('Unable to fetch the member executing this command.');
|
||||
|
||||
const bot = await guild.members.fetchMe();
|
||||
const role = await guild.roles.fetch(settings.devwatch_role_id);
|
||||
if (!role) throw new Error('The configured `devwatch_role_id` does not exist.');
|
||||
if (role.position > bot.roles.highest.position) throw new Error('The configured `devwatch_role_id` is higher than my highest role.');
|
||||
|
||||
if (member.roles.cache.has(settings.devwatch_role_id)) {
|
||||
await member.roles.remove(settings.devwatch_role_id);
|
||||
await interaction.editReply({ content: 'Removed role.' });
|
||||
} else {
|
||||
await member.roles.add(settings.devwatch_role_id);
|
||||
await interaction.editReply({ content: 'Added role.' });
|
||||
}
|
||||
} catch (error: Error | any) {
|
||||
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||
}
|
||||
flags: MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
import { ActionRowBuilder, ApplicationIntegrationType, ButtonBuilder, ButtonStyle, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||
|
||||
export default {
|
||||
name: 'devwatch',
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('devwatch')
|
||||
.setDescription('Sends a dev watch role toggle button.')
|
||||
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
||||
.setContexts(InteractionContextType.Guild)
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName('content')
|
||||
.setDescription('The content of the message.')
|
||||
.setRequired(false)
|
||||
)
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName('button-label')
|
||||
.setDescription('The button label.')
|
||||
.setRequired(false)
|
||||
),
|
||||
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
||||
if (!interaction.channel || !interaction.channel.isSendable())
|
||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Missing permissions to send to channel.' });
|
||||
|
||||
const content = interaction.options.getString('content') ?? '';
|
||||
const label = interaction.options.getString('button-label') ?? 'Toggle DevWatch Role';
|
||||
|
||||
const button = new ButtonBuilder()
|
||||
.setCustomId('dev-watch')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setLabel(label);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(button);
|
||||
|
||||
await interaction.channel.send({ components: [row], content });
|
||||
|
||||
interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Sent.' });
|
||||
}
|
||||
};
|
||||
@@ -75,12 +75,7 @@ export default {
|
||||
.setDescription('Set the private helper role.')
|
||||
.setRequired(false)
|
||||
)
|
||||
.addRoleOption(option =>
|
||||
option
|
||||
.setName('devwatch-role')
|
||||
.setDescription('Set the DevWatch role.')
|
||||
.setRequired(false)
|
||||
)
|
||||
|
||||
.addChannelOption(option =>
|
||||
option
|
||||
.setName('add-staff-category')
|
||||
@@ -204,12 +199,6 @@ export default {
|
||||
response.push(`**private_help_role_id** has been set to: ${privateHelperRole}.`);
|
||||
}
|
||||
|
||||
const devWatchRole = interaction.options.getRole('devwatch-role');
|
||||
if (devWatchRole) {
|
||||
await Database.updateSettings(interaction.guildId, 'devwatch_role_id', devWatchRole.id);
|
||||
response.push(`**devwatch_role_id** has been set to ${devWatchRole}.`);
|
||||
}
|
||||
|
||||
const addCategory = interaction.options.getChannel('add-staff-category');
|
||||
if (addCategory) {
|
||||
if (addCategory.type == ChannelType.GuildCategory) {
|
||||
|
||||
Vendored
+1
-2
@@ -22,7 +22,6 @@ export type GuildSettings = {
|
||||
voice_logs_channel_id?: string
|
||||
admin_role_id?: string
|
||||
private_help_role_id?: string
|
||||
devwatch_role_id?: string
|
||||
staff_categories?: string
|
||||
safe_channels?: string
|
||||
link_skip_channels?: string
|
||||
@@ -97,4 +96,4 @@ export type RoleButton = {
|
||||
id: number
|
||||
message_id: string
|
||||
role_id: string
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user