static isValidNameHint(nameHint, userName) { const pinyinRaw = pinyin(userName, { style: pinyin.STYLE_FIRST_LETTER, }); let pinyinName = ''; for (const py of pinyinRaw) { if (py[0] && py[0] !== ' ') { pinyinName += py[0]; } } const nameRe = new RegExp(nameHint[1], 'ig'); return nameRe.test(userName) || nameRe.test(pinyinName); }
bot.onText(/\/aqi (.+)/, (msg, match) => { let city = match[1]; const re = /[^\u4e00-\u9fa5]|[\uFE30-\uFFA0]/; if (!re.test(city)) { city = pinyin(city, { segment: true, style: pinyin.STYLE_NORMAL, }); city = city.join(''); } console.log(`query ${city} city`); request(`http://aqicn.org/aqicn/json/android/${city}/json`, (error, response, body) => { if (!error && response.statusCode === 200) { const res = JSON.parse(body); if (res.wgt) { console.log(res.wgt); bot.sendPhoto(msg.chat.id, res.wgt); } } else { console.error(error); } }); });