This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sergejmueller/1.1.0
v1.1.0
- Loading branch information
Showing
3 changed files
with
113 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
/** | ||
* Required modules | ||
*/ | ||
|
||
const ip2countrify = require( 'ip2countrify' ) | ||
|
||
|
||
module.exports = { | ||
|
||
|
||
/** | ||
* Handle requests with a invalid IP address | ||
* | ||
* @param {String} msg Incoming message | ||
* @param {Function} reply Bot instance function | ||
* @return void | ||
*/ | ||
|
||
handleInvalidIP( msg, reply ) { | ||
|
||
if ( msg.toLowerCase().includes( 'thank' ) ) { | ||
return reply( { | ||
'text': "👍\n\nYou are welcome." | ||
} ) | ||
} | ||
|
||
return reply( { | ||
'text': "👋\n\nTell me a valid IP,\nI will map the right country." | ||
} ) | ||
|
||
}, | ||
|
||
|
||
/** | ||
* Handle requests with a private IP address | ||
* | ||
* @param {String} ip Incoming IP address | ||
* @param {Function} reply Bot instance function | ||
* @return void | ||
*/ | ||
|
||
handlePrivateIP( ip, reply ) { | ||
|
||
return reply( { | ||
'text': "😝\n\nReserved IP address?\nYou are kidding me." | ||
} ) | ||
|
||
}, | ||
|
||
|
||
/** | ||
* Start lookup for a valid IP address | ||
* | ||
* @param {String} ip Incoming IP address | ||
* @param {Function} reply Bot instance function | ||
* @return void | ||
*/ | ||
|
||
lookupValidIP( ip, reply ) { | ||
|
||
ip2countrify.lookup( ip, ( ip, result, error ) => { | ||
|
||
if ( error ) { | ||
return reply( { | ||
'text': "😢\n\nNothing found for this IP." | ||
} ) | ||
} | ||
|
||
const countryName = result.countryName | ||
const countryCode = result.countryCode.toLowerCase() | ||
|
||
return reply( { | ||
'attachment': { | ||
'type': 'template', | ||
'payload': { | ||
'template_type': 'generic', | ||
'elements': [ { | ||
'title': countryName, | ||
'image_url': `https://raw.githubusercontent.com/hjnilsson/country-flags/master/png1000px/${countryCode}.png` | ||
} ] | ||
} | ||
} | ||
} ) | ||
|
||
} ) | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters