merge
This commit is contained in:
commit
7570dfffbe
26 changed files with 922 additions and 482 deletions
174
test/argsparser_test.ts
Normal file
174
test/argsparser_test.ts
Normal file
|
@ -0,0 +1,174 @@
|
|||
import { Args, parseArgs } from '../src/utils/command.ts'
|
||||
import {
|
||||
assertEquals,
|
||||
assertNotEquals
|
||||
} from 'https://deno.land/std@0.95.0/testing/asserts.ts'
|
||||
|
||||
const commandArgs: Args[] = [
|
||||
{
|
||||
name: 'originalMessage',
|
||||
match: 'content'
|
||||
},
|
||||
{
|
||||
name: 'permaban',
|
||||
match: 'flag',
|
||||
flag: '--permanent',
|
||||
defaultValue: true
|
||||
},
|
||||
{
|
||||
name: 'user',
|
||||
match: 'mentionUser'
|
||||
},
|
||||
{
|
||||
name: 'reason',
|
||||
match: 'rest',
|
||||
defaultValue: 'ree'
|
||||
}
|
||||
]
|
||||
|
||||
const messageArgs1: string[] = [
|
||||
'<@!708544768342229012>',
|
||||
'--permanent',
|
||||
'bye',
|
||||
'bye',
|
||||
'Skyler'
|
||||
]
|
||||
const expectedResult1 = {
|
||||
originalMessage: [
|
||||
'<@!708544768342229012>',
|
||||
'--permanent',
|
||||
'bye',
|
||||
'bye',
|
||||
'Skyler'
|
||||
],
|
||||
permaban: true,
|
||||
user: '708544768342229012',
|
||||
reason: 'bye bye Skyler'
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
only: false,
|
||||
name: 'parse command arguments 1 (assertEquals)',
|
||||
fn: () => {
|
||||
const result = parseArgs(commandArgs, messageArgs1)
|
||||
assertEquals(result, expectedResult1)
|
||||
},
|
||||
sanitizeOps: true,
|
||||
sanitizeResources: true,
|
||||
sanitizeExit: true
|
||||
})
|
||||
|
||||
const messageArgs2: string[] = [
|
||||
'<@!708544768342229012>',
|
||||
'bye',
|
||||
'bye',
|
||||
'Skyler'
|
||||
]
|
||||
const expectedResult2 = {
|
||||
originalMessage: ['<@!708544768342229012>', 'bye', 'bye', 'Skyler'],
|
||||
permaban: true,
|
||||
user: '708544768342229012',
|
||||
reason: 'bye bye Skyler'
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: 'parse command arguments 2 (assertEquals)',
|
||||
fn: () => {
|
||||
const result = parseArgs(commandArgs, messageArgs2)
|
||||
assertEquals(result, expectedResult2)
|
||||
},
|
||||
sanitizeOps: true,
|
||||
sanitizeResources: true,
|
||||
sanitizeExit: true
|
||||
})
|
||||
|
||||
const messageArgs3: string[] = [
|
||||
'<@!708544768342229012>',
|
||||
'bye',
|
||||
'bye',
|
||||
'Skyler'
|
||||
]
|
||||
const expectedResult3 = {
|
||||
permaban: false,
|
||||
user: '708544768342229012',
|
||||
reason: 'bye bye Skyler'
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: 'parse command arguments default value (assertNotEquals)',
|
||||
fn: () => {
|
||||
const result = parseArgs(commandArgs, messageArgs3)
|
||||
assertNotEquals(result, expectedResult3)
|
||||
},
|
||||
sanitizeOps: true,
|
||||
sanitizeResources: true,
|
||||
sanitizeExit: true
|
||||
})
|
||||
|
||||
const commandArgs2: Args[] = [
|
||||
{
|
||||
name: 'user',
|
||||
match: 'mentionUser'
|
||||
},
|
||||
{
|
||||
name: 'channel',
|
||||
match: 'mentionChannel'
|
||||
},
|
||||
{
|
||||
name: 'role',
|
||||
match: 'mentionRole'
|
||||
},
|
||||
{
|
||||
name: 'reason',
|
||||
match: 'rest',
|
||||
defaultValue: 'ree'
|
||||
}
|
||||
]
|
||||
|
||||
const messageArgs4: string[] = [
|
||||
'<@!708544768342229012>',
|
||||
'bye',
|
||||
'<#783319033730564098>',
|
||||
'<@&836715188690092032>'
|
||||
]
|
||||
const expectedResult4 = {
|
||||
channel: '783319033730564098',
|
||||
role: '836715188690092032',
|
||||
user: '708544768342229012',
|
||||
reason: 'bye'
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: 'parse command arguments mentions (assertEquals)',
|
||||
fn: () => {
|
||||
const result = parseArgs(commandArgs2, messageArgs4)
|
||||
assertEquals(result, expectedResult4)
|
||||
},
|
||||
sanitizeOps: true,
|
||||
sanitizeResources: true,
|
||||
sanitizeExit: true
|
||||
})
|
||||
|
||||
const messageArgs5: string[] = ['<@!708544768342229012>']
|
||||
const expectedResult5 = {
|
||||
user: '708544768342229012',
|
||||
reason: 'No reason provided'
|
||||
}
|
||||
const commandArgs5: Args[] = [
|
||||
{
|
||||
name: 'user',
|
||||
match: 'mentionUser'
|
||||
},
|
||||
{
|
||||
name: 'reason',
|
||||
match: 'rest',
|
||||
defaultValue: 'No reason provided'
|
||||
}
|
||||
]
|
||||
Deno.test({
|
||||
name: 'parse command arguments, rest match default',
|
||||
fn: () => {
|
||||
const result = parseArgs(commandArgs5, messageArgs5)
|
||||
assertEquals(result, expectedResult5)
|
||||
}
|
||||
})
|
|
@ -9,8 +9,8 @@ import {
|
|||
Extension,
|
||||
Collection,
|
||||
GuildTextChannel,
|
||||
Interaction,
|
||||
slash
|
||||
slash,
|
||||
SlashCommandInteraction
|
||||
} from '../mod.ts'
|
||||
import { LL_IP, LL_PASS, LL_PORT, TOKEN } from './config.ts'
|
||||
import { Manager, Player } from 'https://deno.land/x/lavadeno/mod.ts'
|
||||
|
@ -58,12 +58,12 @@ class MyClient extends CommandClient {
|
|||
}
|
||||
|
||||
@subslash('cmd', 'sub-cmd-no-grp')
|
||||
subCmdNoGroup(d: Interaction): void {
|
||||
subCmdNoGroup(d: SlashCommandInteraction): void {
|
||||
d.respond({ content: 'sub-cmd-no-group worked' })
|
||||
}
|
||||
|
||||
@groupslash('cmd', 'sub-cmd-group', 'sub-cmd')
|
||||
subCmdGroup(d: Interaction): void {
|
||||
subCmdGroup(d: SlashCommandInteraction): void {
|
||||
d.respond({ content: 'sub-cmd-group worked' })
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ class MyClient extends CommandClient {
|
|||
}
|
||||
|
||||
@slash()
|
||||
run(d: Interaction): void {
|
||||
run(d: SlashCommandInteraction): void {
|
||||
console.log(d.name)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue