ERR_PROXY_CONNECTION_FAILED
Created by: code2x14
环境是 Mac 上的 docker
14:27:09 INFO Wechaty v0.13.37 starting...
14:27:10 ERR PuppetWebBridge init() exception: Error: net::ERR_PROXY_CONNECTION_FAILED
14:27:10 ERR Bot error: Error: net::ERR_PROXY_CONNECTION_FAILED
14:27:10 ERR PuppetWeb initBridge() exception: net::ERR_PROXY_CONNECTION_FAILED
14:27:10 WARN PuppetWebBridge quit() page.close() exception: AssertionError [ERR_ASSERTION]: Protocol error: Connection closed. Most likely the page has been closed.
14:27:10 ERR Bot error: Error: net::ERR_PROXY_CONNECTION_FAILED
14:27:10 ERR PuppetWeb init() exception: Error: net::ERR_PROXY_CONNECTION_FAILED
14:27:10 ERR Bot error: Error: net::ERR_PROXY_CONNECTION_FAILED
14:27:10 WARN PuppetWeb quit() is called on a OFF puppet. return directly.
14:27:10 ERR Wechaty start() exception: net::ERR_PROXY_CONNECTION_FAILED
14:27:10 ERR Bot start() fail: Error: net::ERR_PROXY_CONNECTION_FAILED
14:27:10 WARN Wechaty stop() without this.puppet
14:27:10 INFO Bot finis(-1, exit)
14:27:10 INFO Bot finis() bot had been already stopped
____ _ _ ____ ____ _____ ____ ___ ____ _____
| __ )| | | |/ ___| | _ \| ____| _ \ / _ \| _ \_ _|
| _ \| | | | | _ | |_) | _| | |_) | | | | |_) || |
| |_) | |_| | |_| | | _ <| |___| __/| |_| | _ < | |
|____/ \___/ \____| |_| \_\_____|_| \___/|_| \_\|_|
Press ENTER to continue ...
### 1. source code of ding-dong-bot.ts
/* tslint:disable:variable-name */
const QrcodeTerminal = require('qrcode-terminal')
const finis = require('finis')
const HELPER_CONTACT_NAME = '圆桌喵'
/**
* Change `import { ... } from '../'`
* to `import { ... } from 'wechaty'`
* when you are runing with Docker or NPM instead of Git Source.
*/
import {
config,
Contact,
Wechaty,
Room,
log,
} from '../index'
const welcome = `
| __ __ _ _
| \\ \\ / /__ ___| |__ __ _| |_ _ _
| \\ \\ /\\ / / _ \\/ __| '_ \\ / _\` | __| | | |
| \\ V V / __/ (__| | | | (_| | |_| |_| |
| \\_/\\_/ \\___|\\___|_| |_|\\__,_|\\__|\\__, |
| |___/
=============== Powered by Wechaty ===============
-------- https://github.com/chatie/wechaty --------
I'm a bot, my superpower is talk in Wechat.
If you send me a 'yzm', I will reply you a 'dong'!
__________________________________________________
Hope you like it, and you are very welcome to
upgrade me to more superpowers!
Please wait... I'm trying to login in...
`
console.log(welcome)
const bot = Wechaty.instance({ profile: config.default.DEFAULT_PROFILE })
bot
.on('logout' , user => log.info('Bot', `${user.name()} logouted`))
.on('login' , user => {
log.info('Bot', `${user.name()} login`)
bot.say('Wechaty login').catch(console.error)
})
.on('scan', (url, code) => {
if (!/201|200/.test(String(code))) {
const loginUrl = url.replace(/\/qrcode\//, '/l/')
QrcodeTerminal.generate(loginUrl)
}
console.log(`${url}\n[${code}] Scan QR Code above url to log in: `)
})
/**
* 关键字回复
*/
.on('message', async m => {
try {
const room = m.room()
console.log(
(room ? `${room}` : '')
+ `${m.from()}:${m}`,
)
if (/^(报名)$/i.test(m.content()) && !m.self()) {
m.say('将文章链接转发到朋友圈,并截图给我。')
log.info('Bot', 'REPLY: 将文章链接转发到朋友圈,并截图给我。')
}
if (/^(已转发)$/i.test(m.content()) && !m.self()) {
m.say('由于报名人数众多,请耐心等待审核。')
log.info('Bot', 'REPLY: 由于报名人数众多,请耐心等待审核。')
}
} catch (e) {
log.error('Bot', 'on(message) exception: %s' , e)
}
})
/**
* 自动接受好友申请
*/
.on('friend', async (contact, request) => {
let logMsg
const fileHelper = Contact.load('filehelper')
try {
logMsg = 'received `friend` event from ' + contact.get('name')
fileHelper.say(logMsg)
console.log(logMsg)
if (request) {
/**
*
* 1. New Friend Request
*
* when request is set, we can get verify message from `request.hello`,
* and accept this request by `request.accept()`
*/
if (request.hello === 'D') {
logMsg = 'accepted because verify messsage is "D"'
request.accept()
} else {
logMsg = 'not auto accepted, because verify message is: ' + request.hello
}
} else {
/**
*
* 2. Friend Ship Confirmed
*
*/
logMsg = 'friend ship confirmed with ' + contact.get('name')
}
} catch (e) {
logMsg = e.message
}
console.log(logMsg)
fileHelper.say(logMsg)
})
/**
* Global Event: room-join 加群
*/
.on('room-join', function(this, room, inviteeList, inviter) {
log.info( 'Bot', 'EVENT: room-join - Room %s got new member %s, invited by %s',
room.topic(),
inviteeList.map(c => c.name()).join(','),
inviter.name(),
)
})
/**
* Global Event: room-leave
*/
.on('room-leave', function(this, room, leaverList) {
log.info('Bot', 'EVENT: room-leave - Room %s lost member %s',
room.topic(),
leaverList.map(c => c.name()).join(','),
)
})
/**
* Global Event: room-topic
*/
.on('room-topic', function(this, room, topic, oldTopic, changer) {
try {
log.info('Bot', 'EVENT: room-topic - Room %s change topic to %s by member %s',
oldTopic,
topic,
changer.name(),
)
} catch (e) {
log.error('Bot', 'room-topic event exception: %s', e.stack)
}
})
/**
* Global Event: message
*/
.on('message', async function(this, message) {
const room = message.room()
const sender = message.from()
const content = message.content()
console.log((room ? '[' + room.topic() + ']' : '')
+ '<' + sender.name() + '>'
+ ':' + message.toStringDigest(),
)
if (message.self()) {
return // skip self
}
/**
* `yzm` will be the magic(toggle) word:
* 1. say yzm first time, will got a room invitation
* 2. say yzm in room, will be removed out
*/
if (/^yzm$/i.test(content)) {
/**
* in-room message
*/
if (room) {
if (/^yzm/i.test(room.topic())) {
/**
* move contact out of room
*/
getOutRoom(sender, room)
}
/**
* peer to peer message
*/
} else {
/**
* find room name start with "yzm"
*/
try {
const yzmRoom = await Room.find({ topic: /^yzm/i })
if (yzmRoom) {
/**
* room found
*/
log.info('Bot', 'onMessage: got yzmRoom: %s', yzmRoom.topic())
if (yzmRoom.has(sender)) {
/**
* speaker is already in room
*/
log.info('Bot', 'onMessage: sender has already in yzmRoom')
sender.say('no need to yzm again, because you are already in yzm room')
// sendMessage({
// content: 'no need to yzm again, because you are already in yzm room'
// , to: sender
// })
} else {
/**
* put speaker into room
*/
log.info('Bot', 'onMessage: add sender(%s) to yzmRoom(%s)', sender.name(), yzmRoom.topic())
sender.say('ok, I will put you in yzm room!')
putInRoom(sender, yzmRoom)
}
} else {
/**
* room not found
*/
log.info('Bot', 'onMessage: yzmRoom not found, try to create one')
/**
* create the yzm room
*/
await createyzmRoom(sender)
/**
* listen events from yzm room
*/
manageyzmRoom()
}
} catch (e) {
log.error(e)
}
}
}
})
async function manageyzmRoom() {
log.info('Bot', 'manageyzmRoom()')
/**
* Find Room
*/
try {
const room = await Room.find({ topic: /^yzm/i })
if (!room) {
log.warn('Bot', 'there is no room topic yzm(yet)')
return
}
log.info('Bot', 'start monitor "yzm" room join/leave event')
/**
* Event: Join
*/
room.on('join', function(this, inviteeList, inviter) {
log.verbose('Bot', 'Room EVENT: join - %s, %s',
inviteeList.map(c => c.name()).join(', '),
inviter.name(),
)
checkRoomJoin.call(this, room, inviteeList, inviter)
})
/**
* Event: Leave
*/
room.on('leave', (leaver) => {
log.info('Bot', 'Room EVENT: leave - %s leave, byebye', leaver.name())
})
/**
* Event: Topic Change
*/
room.on('topic', (topic, oldTopic, changer) => {
log.info('Bot', 'Room EVENT: topic - changed from %s to %s by member %s',
oldTopic,
topic,
changer.name(),
)
})
} catch (e) {
log.warn('Bot', 'Room.find rejected: %s', e.stack)
}
}
async function checkRoomJoin(room: Room, inviteeList: Contact[], inviter: Contact) {
log.info('Bot', 'checkRoomJoin(%s, %s, %s)',
room.topic(),
inviteeList.map(c => c.name()).join(','),
inviter.name(),
)
try {
// let to, content
const user = bot.self()
if (!user) {
throw new Error('no user')
}
if (inviter.id !== user.id) {
await room.say('RULE1: Invitation is limited to me, the owner only. Please do not invit people without notify me.',
inviter,
)
await room.say('Please contact me: by send "yzm" to me, I will re-send you a invitation. Now I will remove you out, sorry.',
inviteeList,
)
room.topic('yzm - warn ' + inviter.name())
setTimeout(
_ => inviteeList.forEach(c => room.del(c)),
10 * 1000,
)
} else {
await room.say('Welcome to my room! :)')
let welcomeTopic
welcomeTopic = inviteeList.map(c => c.name()).join(', ')
await room.topic('yzm - welcome ' + welcomeTopic)
}
} catch (e) {
log.error('Bot', 'checkRoomJoin() exception: %s', e.stack)
}
}
async function putInRoom(contact, room) {
log.info('Bot', 'putInRoom(%s, %s)', contact.name(), room.topic())
try {
await room.add(contact)
setTimeout(
_ => room.say('Welcome ', contact),
10 * 1000,
)
} catch (e) {
log.error('Bot', 'putInRoom() exception: ' + e.stack)
}
}
async function getOutRoom(contact: Contact, room: Room) {
log.info('Bot', 'getOutRoom(%s, %s)', contact, room)
try {
await room.say('You said "yzm" in my room, I will remove you out.')
await room.del(contact)
} catch (e) {
log.error('Bot', 'getOutRoom() exception: ' + e.stack)
}
}
function getHelperContact() {
log.info('Bot', 'getHelperContact()')
// create a new room at least need 3 contacts
return Contact.find({ name: HELPER_CONTACT_NAME })
}
async function createyzmRoom(contact): Promise<any> {
log.info('Bot', 'createyzmRoom(%s)', contact)
try {
const helperContact = await getHelperContact()
if (!helperContact) {
log.warn('Bot', 'getHelperContact() found nobody')
return
}
log.info('Bot', 'getHelperContact() ok. got: %s', helperContact.name())
const contactList = [contact, helperContact]
log.verbose('Bot', 'contactList: %s', contactList.join(','))
const room = await Room.create(contactList, 'yzm')
log.info('Bot', 'createyzmRoom() new yzm room created: %s', room)
await room.topic('yzm - created')
await room.say('yzm - created')
return room
} catch (e) {
log.error('Bot', 'getHelperContact() exception:', e.stack)
throw e
}
}
bot.start()
.catch(e => {
log.error('Bot', 'start() fail: %s', e)
bot.stop()
process.exit(-1)
})
bot.on('error', async e => {
log.error('Bot', 'error: %s', e)
if (bot.logonoff()) {
await bot.say('Wechaty error: ' + e.message).catch(console.error)
}
// await bot.stop()
})
let quiting = false
finis(async (code, signal) => {
if (quiting) {
log.warn('Bot', 'finis(%s, %s) called when quiting... just wait...', code, signal)
return
}
quiting = true
log.info('Bot', 'finis(%s, %s)', code, signal)
const exitMsg = `Wechaty will exit ${code} because of ${signal} `
if (bot.logonoff()) {
log.info('Bot', 'finis() stoping bot')
await bot.say(exitMsg).catch(console.error)
} else {
log.info('Bot', 'finis() bot had been already stopped')
}
setTimeout(async () => {
log.info('Bot', 'finis() setTimeout() going to exit with %d', code)
try {
if (bot.logonoff()) {
await bot.stop()
}
} catch (e) {
log.error('Bot', 'finis() setTimeout() exception: %s', e)
} finally {
process.exit(code)
}
}, 3 * 1000)
})
### 2. directory structor of /bot
total 72
drwxr-xr-x 4 bot bot 128 May 18 2017 $RECYCLE.BIN
-rw-r--r-- 1 bot bot 38912 Feb 15 2017 Thumbs.db
drwx------ 5 bot bot 160 Dec 31 07:44 [ViPHD.co]引爆者 Explosion.2017.WEB-DL.1080p.H264.AAC-forlove@ViPHD.mp4
-rw-r--r-- 1 bot bot 282 Mar 3 2017 desktop.ini
-rw-r--r-- 1 bot bot 11960 Dec 31 13:57 ding-dong-bot.ts
-rw-r--r-- 1 bot bot 162 Dec 27 14:35 ~$《至爱梵高》导演问卷_c.docx
-rw-r--r-- 1 bot bot 162 Aug 30 01:07 ~$梦老人》定档参考.docx
-rw-r--r-- 1 bot bot 162 Aug 18 16:39 ~$简历 (1).docx
-rw-r--r-- 1 bot bot 162 Dec 4 11:10 ~$:腾讯视频侵权投诉反通知书.doc
### 3. package.json
cat: /bot/package.json: No such file or directory
No package.json
### 4. directory structor inside /bot/node_modules
ls: cannot access '/bot/node_modules': No such file or directory
No node_modules
### 5. wechaty doctor
#### Wechaty Doctor
1. Wechaty version: 0.13.37
2. Linux x64 version 4.9.49-moby memory 1495/1998 MB
3. Docker: true
4. Node version: v8.9.1
5. Tcp IPC TEST: PASS
____ _ _ _ ___ ____ ____ _ _ _____
/ ___| _ _| |__ _ __ ___ (_) |_ __ _ |_ _/ ___/ ___|| | | | ____|
\___ \| | | | '_ \| '_ ` _ \| | __| / _` | | |\___ \___ \| | | | _|
___) | |_| | |_) | | | | | | | |_ | (_| | | | ___) |__) | |_| | |___
|____/ \__,_|_.__/|_| |_| |_|_|\__| \__,_| |___|____/____/ \___/|_____|
_____________________________________________________________
####### please paste all the above diagnose messages #######
Wechaty Issue https://github.com/chatie/wechaty/issues