-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
29 lines (28 loc) · 948 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var _ = require('underscore')
var csv = require('fast-csv')
var config = require(__dirname + '/../.' + require('./package').name)
module.exports = () => {
var range = []
csv.parseFile(__dirname + '/../binlistData/ranges.csv', {headers: true, ignoreEmpty: true, discardUnmappedColumns: true}).
on('data', d => range.push(d))
return (req, res) => {
console.log(req.body)
if (req.body.message) {
var text = 'Not found'
var n = +req.body.message.text
var r = _.find(range, range => {
if (n < +range.iin_start)
return
if (+range.iin_end && (n > +range.iin_end))
return
if (!+range.iin_end && (n != +range.iin_start))
return
return true
})
if (r)
text = _.values(_.pick(r, ['scheme', 'type', 'country'])).join(' ')
return res.json({method: 'sendMessage', chat_id: req.body.message.chat.id, text: text})
}
res.end()
}
}