Dev watch button
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { ActionRowBuilder, ButtonInteraction, Client, ModalBuilder, TextInputBuilder, TextInputStyle, MessageFlags } from 'discord.js';
|
||||
import { ticketCooldownMap } from '../shared/ticket-cooldown';
|
||||
import { Database } from '../shared/Database';
|
||||
|
||||
export default {
|
||||
name: 'dev-watch',
|
||||
handler: async function (client: Client, interaction: ButtonInteraction) {
|
||||
const member = await interaction.guild!.members.fetch(interaction.user.id);
|
||||
|
||||
if (!member) return await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'There was an error. Please try again later.' });
|
||||
|
||||
const settings = await Database.getGuildSettings(interaction.guild!.id);
|
||||
|
||||
if (!settings || !settings.devwatch_role_id) return await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'There was an error. Please try again later.' });
|
||||
|
||||
if (member.roles.cache.has(settings.devwatch_role_id)) {
|
||||
await member.roles.remove(settings.devwatch_role_id);
|
||||
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Removed role.' });
|
||||
} else {
|
||||
await member.roles.add(settings.devwatch_role_id);
|
||||
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Added role.' });
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
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.' });
|
||||
}
|
||||
};
|
||||
@@ -58,6 +58,12 @@ 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')
|
||||
@@ -175,6 +181,14 @@ export default {
|
||||
response += `Private helper role set to ${privateHelperRole}.\n`;
|
||||
}
|
||||
|
||||
const devWatchRole = interaction.options.getRole('devwatch-role');
|
||||
|
||||
if (devWatchRole) {
|
||||
await Database.setGuildDevWatchRole(interaction.guildId!, devWatchRole.id);
|
||||
|
||||
response += `DevWatch role set to ${devWatchRole}.\n`;
|
||||
}
|
||||
|
||||
const addCategory = interaction.options.getChannel('add-staff-category');
|
||||
if (addCategory) {
|
||||
if (addCategory.type == ChannelType.GuildCategory) {
|
||||
|
||||
@@ -25,6 +25,7 @@ const DB_SCHEMA = `
|
||||
voice_logs_channel_id TEXT,
|
||||
admin_role_id TEXT,
|
||||
private_help_role_id TEXT,
|
||||
devwatch_role_id TEXT,
|
||||
staff_categories TEXT,
|
||||
safe_channels TEXT,
|
||||
link_skip_channels TEXT,
|
||||
@@ -183,6 +184,10 @@ export class Database {
|
||||
await Database.db.run('UPDATE settings SET private_help_role_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildDevWatchRole(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET devwatch_role_id = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
static async setGuildGithubReleaseChannel(guildId: string, id: string) {
|
||||
await Database.db.run('UPDATE settings SET github_release_channel = ? WHERE guild_id = ?', id, guildId);
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -18,6 +18,7 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user