make it simple

This commit is contained in:
Huan LI
2018-07-03 01:36:12 +08:00
parent 20d00c5159
commit 4cd633588f
5 changed files with 42 additions and 61 deletions
+41
View File
@@ -0,0 +1,41 @@
const qrTerm = require('qrcode-terminal')
const {
Wechaty,
Room
} = require('wechaty')
const bot = new Wechaty()
bot.on('scan', onScan)
bot.on('login', onLogin)
bot.on('logout', onLogout)
bot.on('message', onMessage)
bot.start()
.catch(console.error)
function onScan (qrcode, status) {
qrTerm.generate(qrcode, { small: true }) // show qrcode on console
const qrcodeImageUrl = [
'https://api.qrserver.com/v1/create-qr-code/?data=',
encodeURIComponent(qrcode),
'&size=220x220&margin=20',
].join('')
console.log(qrcodeImageUrl)
}
function onLogin (user) {
console.log(`${user} login`)
}
function onLogout(user) {
console.log(`${user} logout`)
}
async function onMessage (msg) {
console.log(msg.toString())
}
-26
View File
@@ -1,26 +0,0 @@
const { Wechaty, Room } = require('wechaty')
const qrTerm = require('qrcode-terminal')
const bot = new Wechaty()
bot.on('scan', (qrcode, status) => {
qrTerm.generate(qrcode, { small: true }) // show qrcode on console
const qrcodeImageUrl = [
'https://api.qrserver.com/v1/create-qr-code/?data=',
encodeURIComponent(qrcode),
'&size=220x220&margin=20',
].join('')
console.log(qrcodeImageUrl)
})
bot.on('login', user => {
console.log(`${user} login`)
})
bot.on('message', async function (msg) {
console.log(msg.toString())
})
bot.start()
-27
View File
@@ -1,27 +0,0 @@
import { Wechaty, Room } from 'wechaty'
const qrTerm = require('qrcode-terminal')
const bot = new Wechaty()
bot.on('scan', (qrcode, status) => {
qrTerm.generate(qrcode, { small: true }) // show qrcode on console
const qrcodeImageUrl = [
'https://api.qrserver.com/v1/create-qr-code/?data=',
encodeURIComponent(qrcode),
'&size=220x220&margin=20',
].join('')
console.log(qrcodeImageUrl)
})
bot.on('login', user => {
console.log(`${user} login`)
})
bot.on('message', async function (msg) {
console.log(msg.toString())
})
bot.start()
-6
View File
@@ -1,6 +0,0 @@
const { Wechaty } = require('wechaty') // import { Wechaty } from 'wechaty'
Wechaty.instance() // Global Instance
.on('scan', (qrcode, status) => console.log(`Scan QR Code to login: ${status}\n${qrcode}`))
.on('login', user => console.log(`User ${user} logined`))
.on('message', message => console.log(`Message: ${message}`))
.start()
+1 -2
View File
@@ -4,8 +4,7 @@
"description": "Wechaty is an easy to use Wechat Chat Bot SDK. This repo contains the code about the video tutorial.",
"main": "index.js",
"scripts": {
"start": "ts-node examples/simplest-bot/bot.ts",
"six-lines-bot": "node examples/six-lines-bot.js",
"start": "ts-node examples/basic-bot.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {