Skip to content

Commit 1a4fa21

Browse files
committed
Mark e2p as nsfw
1 parent cb3d797 commit 1a4fa21

File tree

7 files changed

+101
-26
lines changed

7 files changed

+101
-26
lines changed

src/commands/interactions/basecommand.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { DefaultParameters, Parameters, editOrReply } from '../../utils';
1717

1818
export interface InteractionCommandMetadata {
1919
id: string,
20+
nsfw?: boolean,
2021
};
2122

2223
export class BaseInteractionCommand<ParsedArgsFinished = Interaction.ParsedArgs> extends Interaction.InteractionCommand<ParsedArgsFinished> {
@@ -32,7 +33,9 @@ export class BaseInteractionCommand<ParsedArgsFinished = Interaction.ParsedArgs>
3233
}
3334

3435
if (this.triggerLoadingAsEphemeral) {
35-
return context.respond(InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE, {flags: MessageFlags.EPHEMERAL});
36+
return context.respond(InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE, {
37+
flags: MessageFlags.EPHEMERAL,
38+
});
3639
}
3740
// check perms to maybe force as ephemeral, just in case
3841
return context.respond(InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE);
@@ -46,6 +49,29 @@ export class BaseInteractionCommand<ParsedArgsFinished = Interaction.ParsedArgs>
4649
});
4750
}
4851

52+
onBefore(context: Interaction.InteractionContext) {
53+
const metadata = context.invoker.metadata;
54+
if (metadata && metadata.nsfw) {
55+
if (context.channel) {
56+
return context.channel.isDm || context.channel.nsfw;
57+
}
58+
return context.inDm;
59+
}
60+
return true;
61+
}
62+
63+
onCancel(context: Interaction.InteractionContext) {
64+
const metadata = context.invoker.metadata;
65+
if (metadata && metadata.nsfw) {
66+
if (!context.inDm && (context.channel && (!context.channel.isDm || !context.channel.nsfw))) {
67+
return editOrReply(context, {
68+
content: '⚠ Not a NSFW channel.',
69+
flags: MessageFlags.EPHEMERAL,
70+
});
71+
}
72+
}
73+
}
74+
4975
onCancelRun(context: Interaction.InteractionContext, args: Record<string, any>) {
5076
const command = Markup.codestring(context.name);
5177
return context.editOrRespond({
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Interaction } from 'detritus-client';
2+
3+
import { Formatter } from '../../../../../utils';
4+
5+
import { BaseInteractionImageCommandOption } from '../../../basecommand';
6+
7+
8+
export const COMMAND_NAME = 'e2e';
9+
10+
export class ImageE2ECommand extends BaseInteractionImageCommandOption {
11+
description = 'Edges to Emoji an Image';
12+
metadata = {
13+
id: Formatter.Commands.ImageManipulationE2E.COMMAND_ID,
14+
};
15+
name = COMMAND_NAME;
16+
17+
async run(context: Interaction.InteractionContext, args: Formatter.Commands.ImageManipulationE2E.CommandArgs) {
18+
return Formatter.Commands.ImageManipulationE2E.createMessage(context, args);
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Interaction } from 'detritus-client';
2+
3+
import { Formatter } from '../../../../../utils';
4+
5+
import { BaseInteractionImageCommandOption } from '../../../basecommand';
6+
7+
8+
export const COMMAND_NAME = 'e2p';
9+
10+
export class ImageE2PCommand extends BaseInteractionImageCommandOption {
11+
description = 'Edges to NSFW an Image';
12+
metadata = {
13+
id: Formatter.Commands.ImageManipulationE2P.COMMAND_ID,
14+
nsfw: true,
15+
};
16+
name = COMMAND_NAME;
17+
18+
async run(context: Interaction.InteractionContext, args: Formatter.Commands.ImageManipulationE2P.CommandArgs) {
19+
return Formatter.Commands.ImageManipulationE2P.createMessage(context, args);
20+
}
21+
}

src/commands/interactions/slash/image/fun/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { BaseInteractionCommandOptionGroup } from '../../../basecommand';
33
import { ImageBlurCommand } from './blur';
44
import { ImageCircleCommand } from './circle';
55
import { ImageDeepfryCommand } from './deepfry';
6+
import { ImageE2ECommand } from './e2e';
7+
import { ImageE2PCommand } from './e2p';
68
import { ImageExplodeCommand } from './explode';
79
import { ImageGlitchCommand } from './glitch';
810
import { ImageImplodeCommand } from './implode';
@@ -24,6 +26,8 @@ export class ImageFunGroupCommand extends BaseInteractionCommandOptionGroup {
2426
new ImageBlurCommand(),
2527
new ImageCircleCommand(),
2628
new ImageDeepfryCommand(),
29+
new ImageE2ECommand(),
30+
new ImageE2PCommand(),
2731
new ImageExplodeCommand(),
2832
new ImageGlitchCommand(),
2933
new ImageImplodeCommand(),

src/commands/interactions/slash/search/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ export default class SearchGroupCommand extends BaseSlashCommand {
2727
}
2828

2929
if (context.member && !context.member.can([Permissions.EMBED_LINKS])) {
30-
return context.respond(InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE, {flags: MessageFlags.EPHEMERAL});
30+
return context.respond(InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE, {
31+
flags: MessageFlags.EPHEMERAL,
32+
});
3133
}
34+
3235
return super.onLoadingTrigger(context);
3336
}
3437
}

src/commands/prefixed/basecommand.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ export interface CommandMetadata {
2121
usage?: string,
2222
}
2323

24-
export interface ContextMetadata {
25-
contentUrl?: string,
26-
responseUrl?: string,
27-
}
28-
2924
export class BaseCommand<ParsedArgsFinished = Command.ParsedArgs> extends Command.Command<ParsedArgsFinished> {
25+
nsfw = false;
26+
3027
permissionsIgnoreClientOwner = true;
3128
triggerTypingAfter = 2000;
3229

@@ -38,6 +35,10 @@ export class BaseCommand<ParsedArgsFinished = Command.ParsedArgs> extends Comman
3835
{duration: 500, limit: 1, type: 'channel'},
3936
],
4037
}, options));
38+
if (this.metadata) {
39+
this.nsfw = this.metadata.nsfw || this.nsfw;
40+
this.metadata.nsfw = this.nsfw;
41+
}
4142
}
4243

4344
get commandDescription(): string {
@@ -48,6 +49,24 @@ export class BaseCommand<ParsedArgsFinished = Command.ParsedArgs> extends Comman
4849
return '';
4950
}
5051

52+
onBefore(context: Command.Context) {
53+
if (this.nsfw) {
54+
if (context.channel) {
55+
return context.channel.isDm || context.channel.nsfw;
56+
}
57+
return context.inDm;
58+
}
59+
return true;
60+
}
61+
62+
onCancel(context: Command.Context) {
63+
if (this.nsfw) {
64+
if (!context.inDm && (context.channel && (!context.channel.isDm || !context.channel.nsfw))) {
65+
return editOrReply(context, '⚠ Not a NSFW channel.');
66+
}
67+
}
68+
}
69+
5170
onCancelRun(context: Command.Context, args: unknown) {
5271
const description = this.commandDescription;
5372
if (description) {
@@ -399,8 +418,6 @@ export class BaseImageCommand<ParsedArgsFinished = Command.ParsedArgs> extends B
399418

400419

401420
export class BaseSearchCommand<ParsedArgsFinished = Command.ParsedArgs> extends BaseCommand<ParsedArgsFinished> {
402-
nsfw = false;
403-
404421
constructor(commandClient: CommandClient, options: Partial<Command.CommandOptions>) {
405422
super(commandClient, {
406423
label: 'query',
@@ -411,23 +428,6 @@ export class BaseSearchCommand<ParsedArgsFinished = Command.ParsedArgs> extends
411428
],
412429
...options,
413430
});
414-
if (this.metadata) {
415-
this.metadata.nsfw = this.nsfw;
416-
}
417-
}
418-
419-
onBefore(context: Command.Context) {
420-
if (this.nsfw) {
421-
if (context.channel) {
422-
return context.channel.isDm || context.channel.nsfw;
423-
}
424-
return context.inDm;
425-
}
426-
return true;
427-
}
428-
429-
onCancel(context: Command.Context) {
430-
return editOrReply(context, '⚠ Not a NSFW channel.');
431431
}
432432

433433
onBeforeRun(context: Command.Context, args: {query: string}) {

src/commands/prefixed/image/e2p.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class E2PCommand extends BaseImageCommand {
2222
`${COMMAND_NAME} notsobot`,
2323
],
2424
id: Formatter.Commands.ImageManipulationE2P.COMMAND_ID,
25+
nsfw: true,
2526
usage: '?<emoji,user:id|mention|name,url>',
2627
},
2728
});

0 commit comments

Comments
 (0)