-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70bc6a0
commit b52070c
Showing
4 changed files
with
148 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* This file is part of SudoBot. | ||
* | ||
* Copyright (C) 2021-2023 OSN Developers. | ||
* | ||
* SudoBot is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* SudoBot 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 Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { | ||
Channel, | ||
ChatInputCommandInteraction, | ||
GuildChannel, | ||
Message, | ||
PermissionsBitField, | ||
TextChannel, | ||
User | ||
} from "discord.js"; | ||
import Command, { | ||
AnyCommandContext, | ||
ArgumentType, | ||
CommandMessage, | ||
CommandReturn, | ||
ValidationRule | ||
} from "../../core/Command"; | ||
import { isTextableChannel } from "../../utils/utils"; | ||
import { logError } from "../../utils/logger"; | ||
|
||
export default class ClearCommand extends Command { | ||
public readonly name = "clear"; | ||
public readonly validationRules: ValidationRule[] = [ | ||
{ | ||
types: [ArgumentType.User, ArgumentType.Integer], | ||
entityNotNull: true, | ||
entityNotNullErrorMessage: "This user does not exist! If it's an ID, make sure it's correct!", | ||
name: "countOrUser", | ||
requiredErrorMessage: "You must specify the count of messages to delete or a user to delete messages from!", | ||
typeErrorMessage: "Please either specify a message count or user at position 1!", | ||
minValue: 0, | ||
maxValue: 100, | ||
minMaxErrorMessage: "The message count must be a number between 0 to 100" | ||
}, | ||
{ | ||
types: [ArgumentType.Integer], | ||
optional: true, | ||
name: "count", | ||
typeErrorMessage: "Please specify a valid message count at position 2!", | ||
minValue: 0, | ||
maxValue: 100, | ||
minMaxErrorMessage: "The message count must be a number between 0 to 100" | ||
}, | ||
{ | ||
types: [ArgumentType.Channel], | ||
optional: true, | ||
entityNotNull: true, | ||
entityNotNullErrorMessage: "This channel does not exist! If it's an ID, make sure it's correct!", | ||
name: "channel", | ||
typeErrorMessage: "Please specify a valid text channel at position 3!", | ||
} | ||
]; | ||
public readonly permissions = [PermissionsBitField.Flags.ManageMessages]; | ||
|
||
async execute(message: CommandMessage, context: AnyCommandContext): Promise<CommandReturn> { | ||
const count: number | undefined = !context.isLegacy ? context.options.getInteger('count') ?? undefined : ( | ||
typeof context.parsedNamedArgs.countOrUser === 'number' ? context.parsedNamedArgs.countOrUser : context.parsedNamedArgs.count | ||
); | ||
|
||
const user: User | undefined = !context.isLegacy ? context.options.getUser('user') ?? undefined : ( | ||
typeof context.parsedNamedArgs.countOrUser !== 'number' ? context.parsedNamedArgs.countOrUser : undefined | ||
); | ||
|
||
const channel: Channel | undefined = !context.isLegacy ? context.options.getChannel('channel') ?? undefined : context.parsedNamedArgs.channel ?? undefined; | ||
|
||
if (channel && !isTextableChannel(channel)) { | ||
return { | ||
__reply: true, | ||
content: `${this.emoji('error')} The given channel is not a text channel` | ||
}; | ||
} | ||
|
||
if ((!count && count !== 0) && !user) { | ||
return { | ||
__reply: true, | ||
content: `${this.emoji('error')} Please specify a user or message count, otherwise the system cannot determine how many messages to delete!` | ||
}; | ||
} | ||
|
||
if (message instanceof Message) { | ||
await message.delete().catch(logError); | ||
} | ||
|
||
await this.deferIfInteraction(message); | ||
|
||
await this.client.infractionManager.bulkDeleteMessages({ | ||
user, | ||
guild: message.guild!, | ||
reason: undefined, | ||
sendLog: true, | ||
moderator: message.member!.user as User, | ||
notifyUser: false, | ||
messageChannel: message.channel! as TextChannel, | ||
count | ||
}); | ||
|
||
if (message instanceof ChatInputCommandInteraction) | ||
await message.editReply(`${this.emoji('check')} Operation completed.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b52070c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
sudobot – ./
sudobot-osn.vercel.app
sudobot-git-main-osn.vercel.app
docs.sudobot.onesoftnet.eu.org
sudobot.vercel.app