feat: customizable message for required params #36
							
								
								
									
										19
									
								
								src/index.js
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/index.js
									
									
									
									
									
								
							| @@ -117,7 +117,12 @@ export default class Bot extends EventEmitter { | |||||||
|    *                           gets the update |    *                           gets the update | ||||||
|    * @return {object} returns the bot object |    * @return {object} returns the bot object | ||||||
|    */ |    */ | ||||||
|   command(command, listener) { |   command(command, customMessage, listener) { | ||||||
|  |     if (!listener) { | ||||||
|  |       listener = customMessage; | ||||||
|  |       customMessage = {}; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     const regex = /[^\s]+/; |     const regex = /[^\s]+/; | ||||||
|  |  | ||||||
|     const cmd = command.match(regex)[0].trim(); |     const cmd = command.match(regex)[0].trim(); | ||||||
| @@ -125,6 +130,7 @@ export default class Bot extends EventEmitter { | |||||||
|     this._userEvents.push({ |     this._userEvents.push({ | ||||||
|       pattern: new RegExp(`^/${cmd}`), |       pattern: new RegExp(`^/${cmd}`), | ||||||
|       parse: argumentParser.bind(null, command), |       parse: argumentParser.bind(null, command), | ||||||
|  |       customMessage, | ||||||
|       listener |       listener | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
| @@ -211,9 +217,16 @@ export default class Bot extends EventEmitter { | |||||||
|  |  | ||||||
|       const bot = this; |       const bot = this; | ||||||
|       function* getAnswer() { |       function* getAnswer() { | ||||||
|  |         const customMessage = ev.customMessage; | ||||||
|  |  | ||||||
|         for (const param of requiredParams) { |         for (const param of requiredParams) { | ||||||
|           const ga = new Message().to(msg.chat.id) |           let ga; | ||||||
|                                    .text(`Enter value for ${param}`); |           if (customMessage[param]) { | ||||||
|  |             ga = new Message().to(msg.chat.id).text(customMessage[param]); | ||||||
|  |           } else { | ||||||
|  |             ga = new Message().to(msg.chat.id) | ||||||
|  |                                     .text(`Enter value for ${param}`); | ||||||
|  |           } | ||||||
|           yield bot.send(ga).then(answer => { |           yield bot.send(ga).then(answer => { | ||||||
|             args[param] = answer.text; |             args[param] = answer.text; | ||||||
|           }); |           }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user