From 2f870350b00460f554aa2099a14aa60f7a2d8b82 Mon Sep 17 00:00:00 2001 From: Huan LI Date: Sun, 10 Jun 2018 03:04:09 +0800 Subject: [PATCH] code clean --- package.json | 1 - src/puppet-padchat/padchat-rpc.ts | 121 +++++++++++++++--------------- 2 files changed, 60 insertions(+), 62 deletions(-) diff --git a/package.json b/package.json index 6cff32b9..77fed9cf 100644 --- a/package.json +++ b/package.json @@ -133,7 +133,6 @@ "@types/fluent-ffmpeg": "^2.1.0", "@types/fs-extra": "^5.0.3", "@types/glob": "^5.0.0p", - "@types/jimp": "^0.2.28", "@types/lru-cache": "^4.1.0", "@types/mime": "^2.0.0", "@types/node": "^10.3.0", diff --git a/src/puppet-padchat/padchat-rpc.ts b/src/puppet-padchat/padchat-rpc.ts index 6dc25d81..c9c8e480 100644 --- a/src/puppet-padchat/padchat-rpc.ts +++ b/src/puppet-padchat/padchat-rpc.ts @@ -53,7 +53,7 @@ import { WXSendMsgType, WXLoadWxDatType, WXQRCodeLoginType, - WXCheckQRCodeStatus, + // WXCheckQRCodeStatus, StandardType, WXAddChatRoomMemberType, WXLogoutType, @@ -335,22 +335,21 @@ export class PadchatRpc extends EventEmitter { } public async WXGetQRCode(): Promise { - let result = await this.rpcCall('WXGetQRCode') - if (!result || !(result.qr_code)) { - result = await this.WXGetQRCodeTwice() - } - + const result = await this.rpcCall('WXGetQRCode') + // if (!result || !(result.qr_code)) { + // result = await this.WXGetQRCodeTwice() + // } return result } - private async WXGetQRCodeTwice(): Promise { - await this.WXInitialize() - const resultTwice = await this.rpcCall('WXGetQRCode') - if (!resultTwice || !(resultTwice.qr_code)) { - throw Error('WXGetQRCodeTwice error! canot get result from websocket server when calling WXGetQRCode after WXInitialize') - } - return resultTwice - } + // private async WXGetQRCodeTwice(): Promise { + // await this.WXInitialize() + // const resultTwice = await this.rpcCall('WXGetQRCode') + // if (!resultTwice || !(resultTwice.qr_code)) { + // throw Error('WXGetQRCodeTwice error! canot get result from websocket server when calling WXGetQRCode after WXInitialize') + // } + // return resultTwice + // } public async WXCheckQRCode(): Promise { // this.checkQrcode() @@ -439,14 +438,14 @@ export class PadchatRpc extends EventEmitter { // TODO: should show result here const result = await this.rpcCall('WXLoginRequest', token) log.silly('PadchatRpc', 'WXLoginRequest result: %s, type: %s', JSON.stringify(result), typeof result) - if (!result || result.status !== 0) { - await this.WXGetQRCode() - return - } else { - // check qrcode status - log.silly('PadchatRpc', 'WXLoginRequest begin to check whether user has clicked confirm login') - this.checkQrcode() - } + // if (!result || result.status !== 0) { + // await this.WXGetQRCode() + // return + // } else { + // // check qrcode status + // log.silly('PadchatRpc', 'WXLoginRequest begin to check whether user has clicked confirm login') + // this.checkQrcode() + // } return result } @@ -635,58 +634,58 @@ export class PadchatRpc extends EventEmitter { throw Error('PadchatRpc, WXQRCodeLogin, unknown status: ' + result.status) } - public async checkQrcode(): Promise { - log.verbose('PadchatRpc', 'checkQrcode') - const result = await this.WXCheckQRCode() + // public async checkQrcode(): Promise { + // log.verbose('PadchatRpc', 'checkQrcode') + // const result = await this.WXCheckQRCode() - if (result && result.status === WXCheckQRCodeStatus.WaitScan) { - log.verbose('PadchatRpc', 'checkQrcode: Please scan the Qrcode!') + // if (result && result.status === WXCheckQRCodeStatus.WaitScan) { + // log.verbose('PadchatRpc', 'checkQrcode: Please scan the Qrcode!') - setTimeout(() => { - this.checkQrcode() - }, 1000) + // setTimeout(() => { + // this.checkQrcode() + // }, 1000) - return - } + // return + // } - if (result && result.status === WXCheckQRCodeStatus.WaitConfirm) { - log.silly('PadchatRpc', 'checkQrcode: Had scan the Qrcode, but not Login!') + // if (result && result.status === WXCheckQRCodeStatus.WaitConfirm) { + // log.silly('PadchatRpc', 'checkQrcode: Had scan the Qrcode, but not Login!') - setTimeout(() => { - this.checkQrcode() - }, 1000) + // setTimeout(() => { + // this.checkQrcode() + // }, 1000) - return - } + // return + // } - if (result && result.status === WXCheckQRCodeStatus.Confirmed) { - log.silly('PadchatRpc', 'checkQrcode: Trying to login... please wait') + // if (result && result.status === WXCheckQRCodeStatus.Confirmed) { + // log.silly('PadchatRpc', 'checkQrcode: Trying to login... please wait') - if (!result.user_name || !result.password) { - throw Error('PadchatRpc, checkQrcode, cannot get username or password here, return!') - } + // if (!result.user_name || !result.password) { + // throw Error('PadchatRpc, checkQrcode, cannot get username or password here, return!') + // } - // this.username = result.user_name - // this.nickname = result.nick_name - // this.password = result.password + // // this.username = result.user_name + // // this.nickname = result.nick_name + // // this.password = result.password - // this.WXQRCodeLogin(this.username, this.password) - return - } + // // this.WXQRCodeLogin(this.username, this.password) + // return + // } - if (result && result.status === WXCheckQRCodeStatus.Timeout) { - log.silly('PadchatRpc', 'checkQrcode: Timeout') - return - } + // if (result && result.status === WXCheckQRCodeStatus.Timeout) { + // log.silly('PadchatRpc', 'checkQrcode: Timeout') + // return + // } - if (result && result.status === WXCheckQRCodeStatus.Cancel) { - log.silly('PadchatRpc', 'checkQrcode: Cancel by user') - return - } + // if (result && result.status === WXCheckQRCodeStatus.Cancel) { + // log.silly('PadchatRpc', 'checkQrcode: Cancel by user') + // return + // } - log.warn('PadchatRpc', 'checkQrcode: not know the reason, return data: %s', JSON.stringify(result)) - return - } + // log.warn('PadchatRpc', 'checkQrcode: not know the reason, return data: %s', JSON.stringify(result)) + // return + // } public async WXSetUserRemark(id: string, remark: string): Promise { const result = await this.rpcCall('WXSetUserRemark', id, remark) -- GitLab