Skip to content

Commit 327ea13

Browse files
committed
feat: handle args with interactions
1 parent 37496f9 commit 327ea13

31 files changed

+146
-91
lines changed

src/arguments/CoreBoolean.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { container } from '@sapphire/pieces';
22
import { resolveBoolean } from '../lib/resolvers/boolean';
33
import { Argument } from '../lib/structures/Argument';
44
import type { BooleanArgumentContext } from '../lib/types/ArgumentContexts';
5+
import { ApplicationCommandOptionType, type CommandInteractionOption } from 'discord.js';
56

67
export class CoreArgument extends Argument<boolean> {
78
public constructor(context: Argument.LoaderContext) {
8-
super(context, { name: 'boolean' });
9+
super(context, { name: 'boolean', optionType: ApplicationCommandOptionType.Boolean });
910
}
1011

11-
public run(parameter: string, context: BooleanArgumentContext): Argument.Result<boolean> {
12+
public run(parameter: string | CommandInteractionOption, context: BooleanArgumentContext): Argument.Result<boolean> {
13+
if (typeof parameter !== 'string') return this.ok(parameter.value as boolean);
1214
const resolved = resolveBoolean(parameter, { truths: context.truths, falses: context.falses });
1315
return resolved.mapErrInto((identifier) =>
1416
this.error({

src/arguments/CoreChannel.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import type { ChannelTypes } from '@sapphire/discord.js-utilities';
22
import { container } from '@sapphire/pieces';
33
import { resolveChannel } from '../lib/resolvers/channel';
44
import { Argument } from '../lib/structures/Argument';
5+
import { ApplicationCommandOptionType, type CommandInteractionOption } from 'discord.js';
56

67
export class CoreArgument extends Argument<ChannelTypes> {
78
public constructor(context: Argument.LoaderContext) {
8-
super(context, { name: 'channel' });
9+
super(context, { name: 'channel', optionType: ApplicationCommandOptionType.Channel });
910
}
1011

11-
public run(parameter: string, context: Argument.Context): Argument.Result<ChannelTypes> {
12+
public override run(parameter: string | CommandInteractionOption, context: Argument.Context): Argument.Result<ChannelTypes> {
13+
if (typeof parameter !== 'string') parameter = parameter.channel!.id;
1214
const resolved = resolveChannel(parameter, context.messageOrInteraction);
1315
return resolved.mapErrInto((identifier) =>
1416
this.error({

src/arguments/CoreDMChannel.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { container } from '@sapphire/pieces';
2-
import type { DMChannel } from 'discord.js';
2+
import { ApplicationCommandOptionType, type CommandInteractionOption, type DMChannel } from 'discord.js';
33
import { resolveDMChannel } from '../lib/resolvers/dmChannel';
44
import { Argument } from '../lib/structures/Argument';
55

66
export class CoreArgument extends Argument<DMChannel> {
77
public constructor(context: Argument.LoaderContext) {
8-
super(context, { name: 'dmChannel' });
8+
super(context, { name: 'dmChannel', optionType: ApplicationCommandOptionType.Channel });
99
}
1010

11-
public run(parameter: string, context: Argument.Context): Argument.Result<DMChannel> {
11+
public run(parameter: string | CommandInteractionOption, context: Argument.Context): Argument.Result<DMChannel> {
12+
if (typeof parameter !== 'string') parameter = parameter.channel!.id;
1213
const resolved = resolveDMChannel(parameter, context.messageOrInteraction);
1314
return resolved.mapErrInto((identifier) =>
1415
this.error({

src/arguments/CoreDate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { container } from '@sapphire/pieces';
2+
import { ApplicationCommandOptionType, type CommandInteractionOption } from 'discord.js';
23
import { Identifiers } from '../lib/errors/Identifiers';
34
import { resolveDate } from '../lib/resolvers/date';
45
import { Argument } from '../lib/structures/Argument';
@@ -11,10 +12,11 @@ export class CoreArgument extends Argument<Date> {
1112
} as const;
1213

1314
public constructor(context: Argument.LoaderContext) {
14-
super(context, { name: 'date' });
15+
super(context, { name: 'date', optionType: ApplicationCommandOptionType.String });
1516
}
1617

17-
public run(parameter: string, context: Argument.Context): Argument.Result<Date> {
18+
public run(parameter: string | CommandInteractionOption, context: Argument.Context): Argument.Result<Date> {
19+
if (typeof parameter !== 'string') parameter = parameter.value as string;
1820
const resolved = resolveDate(parameter, { minimum: context.minimum, maximum: context.maximum });
1921
return resolved.mapErrInto((identifier) =>
2022
this.error({

src/arguments/CoreEmoji.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { container } from '@sapphire/pieces';
2+
import { ApplicationCommandOptionType, type CommandInteractionOption } from 'discord.js';
23
import { resolveEmoji, type EmojiObject } from '../lib/resolvers/emoji';
34
import { Argument } from '../lib/structures/Argument';
45

56
export class CoreArgument extends Argument<EmojiObject> {
67
public constructor(context: Argument.LoaderContext) {
7-
super(context, { name: 'emoji' });
8+
super(context, { name: 'emoji', optionType: ApplicationCommandOptionType.String });
89
}
910

10-
public run(parameter: string, context: Argument.Context): Argument.Result<EmojiObject> {
11+
public run(parameter: string | CommandInteractionOption, context: Argument.Context): Argument.Result<EmojiObject> {
12+
if (typeof parameter !== 'string') parameter = parameter.value as string;
1113
const resolved = resolveEmoji(parameter);
1214
return resolved.mapErrInto((identifier) =>
1315
this.error({

src/arguments/CoreEnum.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { container } from '@sapphire/pieces';
2+
import { ApplicationCommandOptionType, type CommandInteractionOption } from 'discord.js';
23
import { resolveEnum } from '../lib/resolvers/enum';
34
import { Argument } from '../lib/structures/Argument';
45
import type { EnumArgumentContext } from '../lib/types/ArgumentContexts';
56

67
export class CoreArgument extends Argument<string> {
78
public constructor(context: Argument.LoaderContext) {
8-
super(context, { name: 'enum' });
9+
super(context, { name: 'enum', optionType: ApplicationCommandOptionType.String });
910
}
1011

11-
public run(parameter: string, context: EnumArgumentContext): Argument.Result<string> {
12+
public run(parameter: string | CommandInteractionOption, context: EnumArgumentContext): Argument.Result<string> {
13+
if (typeof parameter !== 'string') parameter = parameter.value as string;
1214
const resolved = resolveEnum(parameter, { enum: context.enum, caseInsensitive: context.caseInsensitive });
1315
return resolved.mapErrInto((identifier) =>
1416
this.error({

src/arguments/CoreFloat.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { container } from '@sapphire/pieces';
2+
import { ApplicationCommandOptionType, type CommandInteractionOption } from 'discord.js';
23
import { Identifiers } from '../lib/errors/Identifiers';
34
import { resolveFloat } from '../lib/resolvers/float';
45
import { Argument } from '../lib/structures/Argument';
@@ -11,10 +12,11 @@ export class CoreArgument extends Argument<number> {
1112
} as const;
1213

1314
public constructor(context: Argument.LoaderContext) {
14-
super(context, { name: 'float' });
15+
super(context, { name: 'float', optionType: ApplicationCommandOptionType.Number });
1516
}
1617

17-
public run(parameter: string, context: Argument.Context): Argument.Result<number> {
18+
public run(parameter: string | CommandInteractionOption, context: Argument.Context): Argument.Result<number> {
19+
if (typeof parameter !== 'string') return this.ok(parameter.value as number);
1820
const resolved = resolveFloat(parameter, { minimum: context.minimum, maximum: context.maximum });
1921
return resolved.mapErrInto((identifier) =>
2022
this.error({

src/arguments/CoreGuild.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { container } from '@sapphire/pieces';
2-
import type { Guild } from 'discord.js';
2+
import { ApplicationCommandOptionType, type CommandInteractionOption, type Guild } from 'discord.js';
33
import { resolveGuild } from '../lib/resolvers/guild';
44
import { Argument } from '../lib/structures/Argument';
55

66
export class CoreArgument extends Argument<Guild> {
77
public constructor(context: Argument.LoaderContext) {
8-
super(context, { name: 'guild' });
8+
super(context, { name: 'guild', optionType: ApplicationCommandOptionType.String });
99
}
1010

11-
public async run(parameter: string, context: Argument.Context): Argument.AsyncResult<Guild> {
11+
public async run(parameter: string | CommandInteractionOption, context: Argument.Context): Argument.AsyncResult<Guild> {
12+
if (typeof parameter !== 'string') parameter = parameter.value as string;
1213
const resolved = await resolveGuild(parameter);
1314
return resolved.mapErrInto((identifier) =>
1415
this.error({

src/arguments/CoreGuildCategoryChannel.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { container } from '@sapphire/pieces';
2-
import type { CategoryChannel } from 'discord.js';
2+
import { ApplicationCommandOptionType, type CategoryChannel, type CommandInteractionOption } from 'discord.js';
33
import { Identifiers } from '../lib/errors/Identifiers';
44
import { resolveGuildCategoryChannel } from '../lib/resolvers/guildCategoryChannel';
55
import { Argument } from '../lib/structures/Argument';
66

77
export class CoreArgument extends Argument<CategoryChannel> {
88
public constructor(context: Argument.LoaderContext) {
9-
super(context, { name: 'guildCategoryChannel' });
9+
super(context, { name: 'guildCategoryChannel', optionType: ApplicationCommandOptionType.Channel });
1010
}
1111

12-
public run(parameter: string, context: Argument.Context): Argument.Result<CategoryChannel> {
12+
public run(parameter: string | CommandInteractionOption, context: Argument.Context): Argument.Result<CategoryChannel> {
13+
if (typeof parameter !== 'string') parameter = parameter.channel!.id;
1314
const { guild } = context.messageOrInteraction;
1415
if (!guild) {
1516
return this.error({

src/arguments/CoreGuildChannel.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import type { GuildBasedChannelTypes } from '@sapphire/discord.js-utilities';
22
import { container } from '@sapphire/pieces';
3+
import { ApplicationCommandOptionType, type CommandInteractionOption } from 'discord.js';
34
import { Identifiers } from '../lib/errors/Identifiers';
45
import { resolveGuildChannel } from '../lib/resolvers/guildChannel';
56
import { Argument } from '../lib/structures/Argument';
67

78
export class CoreArgument extends Argument<GuildBasedChannelTypes> {
89
public constructor(context: Argument.LoaderContext) {
9-
super(context, { name: 'guildChannel' });
10+
super(context, { name: 'guildChannel', optionType: ApplicationCommandOptionType.Channel });
1011
}
1112

12-
public run(parameter: string, context: Argument.Context): Argument.Result<GuildBasedChannelTypes> {
13+
public run(parameter: string | CommandInteractionOption, context: Argument.Context): Argument.Result<GuildBasedChannelTypes> {
14+
if (typeof parameter !== 'string') parameter = parameter.channel!.id;
1315
const { guild } = context.messageOrInteraction;
1416
if (!guild) {
1517
return this.error({

0 commit comments

Comments
 (0)