mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 08:24:16 +02:00
feat(arabot): add soft mute basics
This commit is contained in:
parent
a44c804097
commit
8d1276ab2c
105
src/commands/mod/softMute.ts
Normal file
105
src/commands/mod/softMute.ts
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
/*
|
||||||
|
Animal Rights Advocates Discord Bot
|
||||||
|
Copyright (C) 2023 Anthony Berg
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Args, Command, RegisterBehavior } from '@sapphire/framework';
|
||||||
|
import type { GuildMember, Message } from 'discord.js';
|
||||||
|
import IDs from '#utils/ids';
|
||||||
|
|
||||||
|
export class SoftMuteCommand extends Command {
|
||||||
|
public constructor(context: Command.Context, options: Command.Options) {
|
||||||
|
super(context, {
|
||||||
|
...options,
|
||||||
|
name: 'softmute',
|
||||||
|
aliases: ['sm'],
|
||||||
|
description: 'Prevent a user from reacting to a message by giving '
|
||||||
|
+ 'the soft mute role',
|
||||||
|
preconditions: ['ModOnly'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Registers that this is a slash command
|
||||||
|
public override registerApplicationCommands(registry: Command.Registry) {
|
||||||
|
registry.registerChatInputCommand(
|
||||||
|
(builder) => builder
|
||||||
|
.setName(this.name)
|
||||||
|
.setDescription(this.description)
|
||||||
|
.addUserOption((option) => option.setName('user')
|
||||||
|
.setDescription('User to soft mute')
|
||||||
|
.setRequired(true)),
|
||||||
|
{
|
||||||
|
behaviorWhenNotIdentical: RegisterBehavior.Overwrite,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command run
|
||||||
|
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
|
||||||
|
// TODO add database updates
|
||||||
|
// Get the arguments
|
||||||
|
const user = interaction.options.getUser('user', true);
|
||||||
|
const { guild } = interaction;
|
||||||
|
|
||||||
|
// Checks if all the variables are of the right type
|
||||||
|
if (guild === null) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: 'Error fetching the guild!',
|
||||||
|
ephemeral: true,
|
||||||
|
fetchReply: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets guildMember whilst removing the ability of each other variables being null
|
||||||
|
const guildMember = guild.members.cache.get(user.id);
|
||||||
|
|
||||||
|
// Checks if guildMember is null
|
||||||
|
if (guildMember === undefined) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: 'Error fetching user!',
|
||||||
|
ephemeral: true,
|
||||||
|
fetchReply: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await guildMember.roles.add(IDs.roles.restrictions.softMute);
|
||||||
|
|
||||||
|
await interaction.reply({
|
||||||
|
content: `Soft muted ${user}`,
|
||||||
|
fetchReply: true,
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async messageRun(message: Message, args: Args) {
|
||||||
|
// Get arguments
|
||||||
|
let user: GuildMember;
|
||||||
|
try {
|
||||||
|
user = await args.pick('member');
|
||||||
|
} catch {
|
||||||
|
await message.react('❌');
|
||||||
|
await message.reply('User was not provided!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await user.roles.add(IDs.roles.restrictions.softMute);
|
||||||
|
|
||||||
|
await message.react('✅');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user