32 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| const request = require("request");
 | |
| 
 | |
| module.exports = {
 | |
|     tellMe: (bot, msg, logger, name) => {
 | |
|         const joke = name.toLowerCase() + " tell me a joke";
 | |
|         if (msg.text && msg.text.toString().toLowerCase().includes(joke)) {
 | |
|             logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " asked for a joke");
 | |
| 
 | |
|             var options = {
 | |
|                 method: 'GET',
 | |
|                 url: 'https://joke3.p.rapidapi.com/v1/joke',
 | |
|                 // qs: { tz: 'Europe/London', leagues: '8', include: 'localTeam,visitorTeam' },
 | |
|                 headers: {
 | |
|                     'x-rapidapi-host': 'joke3.p.rapidapi.com',
 | |
|                     'x-rapidapi-key': process.env.RAPIDAPI_API_KEY,
 | |
|                     useQueryString: true
 | |
|                 },
 | |
|                 // ttl: 18000 //5 hours
 | |
|             };
 | |
| 
 | |
|             request(options, function (error, response, body) {
 | |
|                 // console.log(response)
 | |
| 
 | |
|                 if (error) throw new Error(error);
 | |
|                 let jsonBody = JSON.parse(body)
 | |
|                 bot.sendMessage(msg.chat.id, jsonBody.content)
 | |
|             }
 | |
|             )
 | |
|         }
 | |
| 
 | |
|     }
 | |
| } |