Skip to content

Commit

Permalink
fix(commands:clear): bc command alias not working
Browse files Browse the repository at this point in the history
  • Loading branch information
virtual-designer committed Nov 4, 2023
1 parent 3e54e51 commit 823c8a7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 38 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:
$(MAKE) -C lib

clean:
$(MAKE) -C lib clean
48 changes: 31 additions & 17 deletions src/commands/moderation/ClearCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export default class ClearCommand extends Command {
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"
minMaxErrorMessage: "The message count must be a number between 0 to 100",
optional: true
},
{
types: [ArgumentType.Integer],
Expand Down Expand Up @@ -111,7 +112,11 @@ export default class ClearCommand extends Command {
);

async execute(message: CommandMessage, context: BasicCommandContext): Promise<CommandReturn> {
const count: number | undefined = !context.isLegacy
const isPrimaryCommand = !context.isLegacy
? !!context.options.data.find(option => option.name.startsWith("filter_"))
: context.argv[0].length > 2;

let count: number | undefined = !context.isLegacy
? context.options.getInteger("count") ?? undefined
: typeof context.parsedNamedArgs.countOrUser === "number"
? context.parsedNamedArgs.countOrUser
Expand All @@ -123,6 +128,19 @@ export default class ClearCommand extends Command {
? context.parsedNamedArgs.countOrUser
: undefined;

if (!count && count !== 0 && !user) {
if (isPrimaryCommand) {
return {
__reply: true,
content: `${this.emoji(
"error"
)} Please specify a user or message count, otherwise the system cannot determine how many messages to delete!`
};
} else {
count = 20;
}
}

const channel: Channel | undefined = !context.isLegacy
? context.options.getChannel("channel") ?? undefined
: context.parsedNamedArgs.channel ?? undefined;
Expand All @@ -134,13 +152,11 @@ export default class ClearCommand extends Command {
};
}

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 ChatInputCommandInteraction) {
if (message.options.getString("filter_pattern_flags") && !message.options.getString("filter_pattern")) {
await this.error(message, `Option \`filter_pattern\` must be present when \`filter_pattern_flags\` is set.`);
return;
}
}

if (user) {
Expand Down Expand Up @@ -193,16 +209,14 @@ export default class ClearCommand extends Command {
}
}
}
} else if (context.isLegacy) {
const aliasHandlerName = filter_aliases[context.argv[0]];

if (context.isLegacy) {
const aliasHandlerName = filter_aliases[context.argv[0]];

if (aliasHandlerName) {
const aliasHandler = filters[aliasHandlerName];
if (aliasHandlerName) {
const aliasHandler = filters[aliasHandlerName];

if (aliasHandler) {
filterHandlers.push(aliasHandler);
}
if (aliasHandler) {
filterHandlers.push(aliasHandler);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/InfractionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,11 @@ export default class InfractionManager extends Service {
.catch(logError);
}

if (!logOnly && messages && count > 0) {
if (!logOnly && messages) {
try {
await messageChannel.bulkDelete(messages);
const reply = await messageChannel.send(
`${getEmoji(this.client, "check")} Deleted ${count} messages${
`${getEmoji(this.client, "check")} Deleted ${messages.length} messages${
user ? ` from user **@${escapeMarkdown(user.username)}**` : ""
}`
);
Expand Down
40 changes: 21 additions & 19 deletions src/services/LoggerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ export default class LoggerService extends Service {
}
]
},
sendJSON
sendJSON && messages.length > 0
? {
files: [
{
Expand All @@ -1154,24 +1154,26 @@ export default class LoggerService extends Service {
: undefined
);

message
?.edit({
embeds: [
{
...(message?.embeds[0]?.data ?? {}),
fields: [
...(message?.embeds[0].data.fields ?? []),
{
name: "Messages",
value: `[Click here to view the deleted messages](${
process.env.FRONTEND_URL
}/view_deleted_messages?url=${encodeURIComponent(message.attachments.at(0)!.url)})`
}
]
}
]
})
.catch(logError);
if (messages.length > 0 && sendJSON) {
message
?.edit({
embeds: [
{
...(message?.embeds[0]?.data ?? {}),
fields: [
...(message?.embeds[0].data.fields ?? []),
{
name: "Messages",
value: `[Click here to view the deleted messages](${
process.env.FRONTEND_URL
}/view_deleted_messages?url=${encodeURIComponent(message.attachments.at(0)!.url)})`
}
]
}
]
})
.catch(logError);
}
}

async logMemberUnmute({
Expand Down

0 comments on commit 823c8a7

Please sign in to comment.