mirror of
				https://github.com/keanuplayz/TravBot-v3.git
				synced 2024-08-15 02:33:12 +00:00 
			
		
		
		
	Modularized finding members by their username
This commit is contained in:
		
							parent
							
								
									8ca171e924
								
							
						
					
					
						commit
						3767a10829
					
				
					 2 changed files with 30 additions and 13 deletions
				
			
		|  | @ -223,19 +223,9 @@ export default new Command({ | ||||||
| 		description: "See how much money someone else has by using their username.", | 		description: "See how much money someone else has by using their username.", | ||||||
| 		async run($: CommonLibrary): Promise<any> | 		async run($: CommonLibrary): Promise<any> | ||||||
| 		{ | 		{ | ||||||
| 			if($.guild) | 			$.callMemberByUsername($.message, $.args.join(" "), member => { | ||||||
| 			{ | 				$.channel.send(getMoneyEmbed(member.user)); | ||||||
| 				const username = $.args.join(" "); | 			}); | ||||||
| 				const member = (await $.guild.members.fetch({ |  | ||||||
| 					query: username, |  | ||||||
| 					limit: 1 |  | ||||||
| 				})).first(); |  | ||||||
| 				 |  | ||||||
| 				if(member) |  | ||||||
| 					$.channel.send(getMoneyEmbed(member.user)); |  | ||||||
| 				else |  | ||||||
| 					$.channel.send(`Couldn't find a user by the name of \`${username}\`!`); |  | ||||||
| 			} |  | ||||||
| 		} | 		} | ||||||
| 	}) | 	}) | ||||||
| }); | }); | ||||||
|  | @ -25,6 +25,8 @@ export interface CommonLibrary | ||||||
| 	ready: (...args: any[]) => void; | 	ready: (...args: any[]) => void; | ||||||
| 	paginate: (message: Message, senderID: string, total: number, callback: (page: number) => void, duration?: number) => void; | 	paginate: (message: Message, senderID: string, total: number, callback: (page: number) => void, duration?: number) => void; | ||||||
| 	prompt: (message: Message, senderID: string, onConfirm: () => void, duration?: number) => void; | 	prompt: (message: Message, senderID: string, onConfirm: () => void, duration?: number) => void; | ||||||
|  | 	getMemberByUsername: (guild: Guild, username: string) => Promise<GuildMember|undefined>; | ||||||
|  | 	callMemberByUsername: (message: Message, username: string, onSuccess: (member: GuildMember) => void) => Promise<void>; | ||||||
| 	 | 	 | ||||||
| 	// Dynamic Properties //
 | 	// Dynamic Properties //
 | ||||||
| 	args: any[]; | 	args: any[]; | ||||||
|  | @ -216,6 +218,31 @@ $.prompt = async(message: Message, senderID: string, onConfirm: () => void, dura | ||||||
| 		message.delete(); | 		message.delete(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | $.getMemberByUsername = async(guild: Guild, username: string) => { | ||||||
|  | 	return (await guild.members.fetch({ | ||||||
|  | 		query: username, | ||||||
|  | 		limit: 1 | ||||||
|  | 	})).first(); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | /** Convenience function to handle false cases automatically. */ | ||||||
|  | $.callMemberByUsername = async(message: Message, username: string, onSuccess: (member: GuildMember) => void) => { | ||||||
|  | 	const guild = message.guild; | ||||||
|  | 	const send = message.channel.send; | ||||||
|  | 	 | ||||||
|  | 	if(guild) | ||||||
|  | 	{ | ||||||
|  | 		const member = await $.getMemberByUsername(guild, username); | ||||||
|  | 		 | ||||||
|  | 		if(member) | ||||||
|  | 			onSuccess(member); | ||||||
|  | 		else | ||||||
|  | 			send(`Couldn't find a user by the name of \`${username}\`!`); | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 		send("You must execute this command in a server!"); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Splits a command by spaces while accounting for quotes which capture string arguments. |  * Splits a command by spaces while accounting for quotes which capture string arguments. | ||||||
|  * - `\"` = `"` |  * - `\"` = `"` | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue