代码拉取完成,页面将自动刷新
const readline = require('readline')
const { bot } = require('./bot')
const config = require('./config')
const cli = readline.createInterface({
input: process.stdin,
output: process.stdout
})
cli.on('close', () => {
console.log('\ncli closed. ctrl-c again to exit') // 正确换行
})
const getGroupId = index => Object.keys(config.groups)[index]
let currentGroup = getGroupId(0)
const commands = [
[/^\/ls/, () => console.log(config.groups)],
[/^\/cd/, input => console.log(
config.groups[currentGroup = getGroupId(input || 0)]
)
],
[/^/, input => input && bot.sendMessage({
group: currentGroup,
message: buildMsg(input)
}).catch(console.error)
]
]
// 处理消息中的 qq 表情. 如, 滑稽的代码是 \178
function buildMsg(input) {
let match = input.match(/\\(\d+)/)
const msg = []
while (match) {
if (match.index) {
msg.push({ type: 'Plain', text: input.slice(0, match.index) })
}
msg.push({ type: 'Face', faceId: parseInt(match[1]) })
input = input.slice(match.index + match[0].length)
match = input.match(/\\(\d+)/)
}
if (input) {
msg.push({ type: 'Plain', text: input })
}
return msg
}
function processCli (text) {
// 寻找第一个匹配的命令, 并执行
for ([key, method] of commands) {
if (!key.test(text)) continue
return method(text.replace(key, '').trim())
}
}
module.exports = function interact () {
cli.question('> ', input => {
processCli(input)
interact()
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。