80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
|
/* eslint-disable max-classes-per-file */
|
||
|
import { CommandOption, IResolver } from '@navy.gif/commandparser';
|
||
|
|
||
|
class Resolver implements IResolver
|
||
|
{
|
||
|
resolveMember<Member, Guild> (_resolveable: string, _strict: boolean, _guild: Guild): Promise<Member | null>
|
||
|
{
|
||
|
throw new Error('Method not implemented.');
|
||
|
}
|
||
|
resolveRole<Role, Guild> (_resolveable: string, _strict: boolean, _guild: Guild): Promise<Role | null>
|
||
|
{
|
||
|
throw new Error('Method not implemented.');
|
||
|
}
|
||
|
resolveBoolean (_resolveable: string): boolean | null
|
||
|
{
|
||
|
throw new Error('Method not implemented.');
|
||
|
}
|
||
|
resolveTime (_resolveable: string): number | null
|
||
|
{
|
||
|
throw new Error('Method not implemented.');
|
||
|
}
|
||
|
resolveUsers<User> (_rawValue: string[], _strict: boolean)
|
||
|
{
|
||
|
const users: User[] = [];
|
||
|
return users;
|
||
|
}
|
||
|
async resolveUser<User> (arg0: string, strict: boolean)
|
||
|
{
|
||
|
const users = await this.resolveUsers<User>([ arg0 ], strict);
|
||
|
return users[0] ?? null;
|
||
|
}
|
||
|
resolveChannel<Channel> (_arg0: string)
|
||
|
{
|
||
|
return {} as Channel;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// These functions are called by the command option class
|
||
|
// All you need to do is implement them as you need
|
||
|
class ExtendedCommandOption extends CommandOption
|
||
|
{
|
||
|
declare options: ExtendedCommandOption[];
|
||
|
declare protected resolver: Resolver;
|
||
|
protected async USERS ()
|
||
|
{
|
||
|
if (!this.resolver)
|
||
|
throw new Error('Missing resolver');
|
||
|
if (!this.rawValue)
|
||
|
throw new Error('Missing raw value');
|
||
|
const member = await this.resolver.resolveUsers(this.rawValue, this.strict);
|
||
|
if (!member)
|
||
|
return { error: true };
|
||
|
return { value: member, removed: this.rawValue };
|
||
|
}
|
||
|
protected async USER ()
|
||
|
{
|
||
|
if (!this.resolver)
|
||
|
throw new Error('Missing resolver');
|
||
|
if (!this.rawValue)
|
||
|
throw new Error('Missing raw value');
|
||
|
const member = await this.resolver.resolveUser(this.rawValue[0], this.strict);
|
||
|
if (!member)
|
||
|
return { error: true };
|
||
|
return { value: member, removed: [ this.rawValue[0] ] };
|
||
|
}
|
||
|
protected async TEXT_CHANNEL ()
|
||
|
{
|
||
|
if (!this.resolver)
|
||
|
throw new Error('Missing resolver');
|
||
|
if (!this.rawValue)
|
||
|
throw new Error('Missing raw value');
|
||
|
const channel = await this.resolver.resolveChannel < {isTextBased:() => boolean}>(this.rawValue[0]);
|
||
|
if (!channel || !channel.isTextBased())
|
||
|
return { error: true };
|
||
|
return { value: channel, removed: [ this.rawValue[0] ] };
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default ExtendedCommandOption;
|