-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
12 changed files
with
135 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
export class BooleanType { | ||
validate() { | ||
|
||
import { Argument, ArgumentType } from '../Argument'; | ||
import { MessageArgumentTypeBase } from './base'; | ||
|
||
const truthy = new Set(['true', 't', 'yes', 'y', 'on', 'enable', 'enabled', '1', '+']); | ||
const falsy = new Set(['false', 'f', 'no', 'n', 'off', 'disable', 'disabled', '0', '-']); | ||
|
||
export class BooleanType extends MessageArgumentTypeBase { | ||
value; | ||
|
||
validate(content: string): boolean { | ||
const yes = truthy.has(content.toLowerCase()); | ||
const no = falsy.has(content.toLowerCase()); | ||
|
||
if (!yes && !no) return false; | ||
else { | ||
this.value = yes ? true : false; | ||
return true; | ||
}; | ||
} | ||
|
||
resolve(argument: Argument) { | ||
return { | ||
...argument.toJSON(), | ||
type: ArgumentType[argument.type], | ||
value: this.value | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export class ChannelType { | ||
import { MessageArgumentTypeBase } from './base'; | ||
|
||
export class ChannelType extends MessageArgumentTypeBase { | ||
validate() { | ||
|
||
return true; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export class MentionableType { | ||
import { MessageArgumentTypeBase } from './base'; | ||
|
||
export class MentionableType extends MessageArgumentTypeBase { | ||
validate() { | ||
|
||
return true; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export class RoleType { | ||
import { MessageArgumentTypeBase } from './base'; | ||
|
||
export class RoleType extends MessageArgumentTypeBase { | ||
validate() { | ||
|
||
return true; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Util } from '../../util/Util'; | ||
import { Argument, ArgumentType } from '../Argument'; | ||
import type { BooleanType } from './Boolean'; | ||
import type { ChannelType } from './Channel'; | ||
import type { IntegerType } from './Integer'; | ||
import type { MentionableType } from './Mentionable'; | ||
import type { NumberType } from './Number'; | ||
import type { RoleType } from './Role'; | ||
import type { StringType } from './String'; | ||
import type { UserType } from './User'; | ||
|
||
export type MessageArgumentTypes = BooleanType | ChannelType | IntegerType | MentionableType | NumberType | RoleType | StringType | UserType; | ||
|
||
export class MessageArgumentTypeBase { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
validate(content: string): boolean { | ||
Util.throwError('Validate method is not implemented!', this.constructor.name); | ||
return true; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
resolve(argument: Argument, ...args) { | ||
Util.throwError('Resolve method is not implemented!', this.constructor.name); | ||
} | ||
|
||
static async createArgument(type: ArgumentType | keyof typeof ArgumentType) { | ||
switch(type) { | ||
case ArgumentType.BOOLEAN: | ||
const { BooleanType } = await import('./Boolean'); | ||
return new BooleanType(); | ||
case ArgumentType.CHANNEL: | ||
const { ChannelType } = await import('./Channel'); | ||
return new ChannelType(); | ||
case ArgumentType.INTEGER: | ||
const { IntegerType } = await import('./Integer'); | ||
return new IntegerType(); | ||
case ArgumentType.MENTIONABLE: | ||
const { MentionableType } = await import('./Mentionable'); | ||
return new MentionableType(); | ||
case ArgumentType.NUMBER: | ||
const { NumberType } = await import('./Number'); | ||
return new NumberType(); | ||
case ArgumentType.ROLE: | ||
const { RoleType } = await import('./Role'); | ||
return new RoleType(); | ||
case ArgumentType.STRING: | ||
const { StringType } = await import('./String'); | ||
return new StringType(); | ||
case ArgumentType.USER: | ||
const { UserType } = await import('./User'); | ||
return new UserType(); | ||
} | ||
} | ||
} |
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