From 931531b21e7ca38e87fc759a75cffc5e50c28f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E8=A1=A8=E4=BC=9F?= Date: Thu, 19 Dec 2019 17:14:48 +0800 Subject: [PATCH 1/2] Update start-web.ts --- src/start-web.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/start-web.ts b/src/start-web.ts index 7cb7a98..ace2852 100644 --- a/src/start-web.ts +++ b/src/start-web.ts @@ -43,7 +43,7 @@ export async function startWeb (bot: Wechaty): Promise { ` - const handler = () => { + const handler = async () => { let html if (qrcodeValue) { @@ -61,12 +61,20 @@ export async function startWeb (bot: Wechaty): Promise { ].join('') } else if (userName) { + // zhuangbiaowei add code begin + let rooms = await bot.Room.findAll() + let room_html : string = `` + for(let room in rooms){ + const topic = await room.topic() + room_html = room_html + topic + `
/n` + } + // zhuangbiaowei add code end html = [ `

OSS Bot v${VERSION} User ${userName} logined.

`, FORM_HTML, + room_html, ].join('') - } else { html = `OSS Bot v${VERSION} Hello, come back later please.` @@ -101,4 +109,4 @@ export async function startWeb (bot: Wechaty): Promise { await server.start() log.info('startWeb', 'startWeb() listening to http://localhost:%d', PORT) -} +} From 8bc5a8f2b695e2eeeace94d8fd4996ab6f2aa50d Mon Sep 17 00:00:00 2001 From: zhuangbiaowei Date: Fri, 20 Dec 2019 21:45:12 +0800 Subject: [PATCH 2/2] feat: list robot joined rooms --- src/start-web.ts | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/start-web.ts b/src/start-web.ts index ace2852..8ed38d1 100644 --- a/src/start-web.ts +++ b/src/start-web.ts @@ -1,13 +1,13 @@ -import Hapi, { Request, ResponseToolkit } from '@hapi/hapi' +import Hapi, { Request, ResponseToolkit } from '@hapi/hapi' import { Wechaty, -} from 'wechaty' +} from 'wechaty' import { log, PORT, VERSION, -} from './config' +} from './config' import { chatops } from './chatops' let wechaty: Wechaty @@ -27,12 +27,12 @@ async function chatopsHandler (request: Request, response: ResponseToolkit) { export async function startWeb (bot: Wechaty): Promise { log.verbose('startWeb', 'startWeb(%s)', bot) - let qrcodeValue : undefined | string - let userName : undefined | string + let qrcodeValue: undefined | string + let userName: undefined | string wechaty = bot - const server = new Hapi.Server({ + const server = new Hapi.Server({ port: PORT, }) @@ -61,19 +61,18 @@ export async function startWeb (bot: Wechaty): Promise { ].join('') } else if (userName) { - // zhuangbiaowei add code begin let rooms = await bot.Room.findAll() - let room_html : string = `` - for(let room in rooms){ + let roomHtml = `The rooms I have joined are as follows:
    ` + for (let room of rooms) { const topic = await room.topic() - room_html = room_html + topic + `
    /n` + roomHtml = roomHtml + `
  1. ` + topic + `
  2. \n` } - // zhuangbiaowei add code end + roomHtml = roomHtml + `
` html = [ `

OSS Bot v${VERSION} User ${userName} logined.

`, FORM_HTML, - room_html, + roomHtml, ].join('') } else { @@ -85,23 +84,23 @@ export async function startWeb (bot: Wechaty): Promise { server.route({ handler, - method : 'GET', - path : '/', + method: 'GET', + path: '/', }) server.route({ handler: chatopsHandler, - method : 'POST', - path : '/chatops/', + method: 'POST', + path: '/chatops/', }) bot.on('scan', qrcode => { qrcodeValue = qrcode - userName = undefined + userName = undefined }) bot.on('login', user => { qrcodeValue = undefined - userName = user.name() + userName = user.name() }) bot.on('logout', () => { userName = undefined @@ -109,4 +108,4 @@ export async function startWeb (bot: Wechaty): Promise { await server.start() log.info('startWeb', 'startWeb() listening to http://localhost:%d', PORT) -} +}