Merge branch 'main' into design-fix
This commit is contained in:
		
						commit
						461e1557c5
					
				
					 16 changed files with 335 additions and 21 deletions
				
			
		
							
								
								
									
										150
									
								
								test/argsparser_test.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										150
									
								
								test/argsparser_test.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,150 @@ | |||
| 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 | ||||
| }) | ||||
							
								
								
									
										2
									
								
								test/deps.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								test/deps.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| export * from 'https://deno.land/std@0.95.0/testing/asserts.ts' | ||||
| export * from 'https://deno.land/std@0.95.0/http/server.ts' | ||||
|  | @ -254,6 +254,13 @@ client.on('messageCreate', async (msg: Message) => { | |||
|       buf += `\n${role.name === '@everyone' ? 'everyone' : role.name}` | ||||
|     } | ||||
|     msg.reply(buf) | ||||
|   } else if (msg.content === '!addrole') { | ||||
|     msg.member?.roles.add('837255383759716362') | ||||
|   } else if (msg.content === '!dm') { | ||||
|     console.log('wtf') | ||||
|     msg.author.send('UwU').then((m) => { | ||||
|       msg.reply(`Done, ${m.id}`) | ||||
|     }) | ||||
|   } else if (msg.content === '!timer') { | ||||
|     msg.channel.send('3...').then((msg) => { | ||||
|       setTimeout(() => { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| import { SlashClient } from '../mod.ts' | ||||
| import { SLASH_ID, SLASH_PUB_KEY, SLASH_TOKEN } from './config.ts' | ||||
| import { listenAndServe } from 'https://deno.land/std@0.90.0/http/server.ts' | ||||
| import { listenAndServe } from './deps.ts' | ||||
| 
 | ||||
| const slash = new SlashClient({ | ||||
|   id: SLASH_ID, | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ import { TOKEN } from '../src/test/config.ts' | |||
| import { | ||||
|   assertEquals, | ||||
|   assertExists | ||||
| } from 'https://deno.land/std@0.84.0/testing/asserts.ts' | ||||
| } from './deps.ts' | ||||
| 
 | ||||
| //#region Lib Tests
 | ||||
| Deno.test({ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue