From e883c561f47d9266e5d30c57a309eafca8243540 Mon Sep 17 00:00:00 2001 From: takayama Date: Mon, 26 Apr 2021 23:42:52 +0900 Subject: [PATCH] update package.json for npm update logger label --- README.md | 3 ++- lib/client.js | 20 ++++++++++++++------ lib/device.js | 2 +- lib/message/music.js | 17 +++++++++++------ lib/troop.js | 3 +-- package.json | 4 ++-- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 9621836d..47a79b62 100644 --- a/README.md +++ b/README.md @@ -61,4 +61,5 @@ bot.login("password"); // your password or password_md5 [JavaScript语言基础](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript) [Node.js入门教程](http://nodejs.cn/learn) [5分钟上手TypeScript](https://www.tslang.cn/docs/handbook/typescript-in-5-minutes.html) -[![问题交流反馈群](https://img.shields.io/badge/问题交流反馈群-236172566-red)](https://qm.qq.com/cgi-bin/qm/qr?k=NXw3NEA5lzPjkRhyEpjVBqMpdg1WHRKJ&jump_from=webapi) +[![Gitter](https://badges.gitter.im/takayama-lily/oicq.svg)](https://gitter.im/takayama-lily/oicq?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![group:236172566](https://img.shields.io/badge/group-236172566-blue)](https://qm.qq.com/cgi-bin/qm/qr?k=NXw3NEA5lzPjkRhyEpjVBqMpdg1WHRKJ&jump_from=webapi) diff --git a/lib/client.js b/lib/client.js index eae227e2..3dacecb8 100644 --- a/lib/client.js +++ b/lib/client.js @@ -34,6 +34,14 @@ function buildApiRet(retcode, data = null, error = null) { }; } +const platforms = { + 1: "Android", + 2: "aPad", + 3: "Watch", + 4: "MacOS", + 5: "iPad", +}; + class Client extends net.Socket { static OFFLINE = Symbol("OFFLINE"); static INIT = Symbol("INIT"); @@ -114,7 +122,7 @@ class Client extends net.Socket { }; this.config = config; this.dir = createDataDir(config.data_dir, uin); - this.logger = log4js.getLogger(`[BOT:${uin}]`); + this.logger = log4js.getLogger(`[${platforms[config.platform]||"Android"}:${uin}]`); this.logger.level = config.log_level; this.logger.mark("----------"); @@ -233,7 +241,7 @@ class Client extends net.Socket { this.handlers.delete(seq_id); ++this.stat.lost_pkt_cnt; reject(new TimeoutError()); - this.emit("internal.timeout", { seq_id }); + this.emit("internal.timeout", { seq_id, packet }); }, timeout); this.handlers.set(seq_id, (data) => { clearTimeout(id); @@ -326,7 +334,7 @@ class Client extends net.Socket { */ async useProtocol(fn, params) { if (!this.isOnline() || !this.sync_finished) - return buildApiRet(104, null, { code: -1, message: "bot not online" }); + return buildApiRet(104, null, { code: -1, message: "client not online" }); try { const rsp = await fn.apply(this, params); if (!rsp) @@ -678,9 +686,9 @@ class Client extends net.Socket { setGroupPortrait(group_id, file) { return this.useProtocol(troop.setGroupPortrait, arguments); } - async getLevelInfo(user_id) { - return await this.useProtocol(troop.getLevelInfo, arguments); - } + // getLevelInfo(user_id) { + // return this.useProtocol(troop.getLevelInfo, arguments); + // } getRoamingStamp(no_cache = false) { return this.useProtocol(chat.getRoamingStamp, arguments); diff --git a/lib/device.js b/lib/device.js index 87f8ed5e..61a2bf8c 100644 --- a/lib/device.js +++ b/lib/device.js @@ -173,7 +173,7 @@ apk[5].subid = 537065739; * @param {number} platform */ function getApkInfo(platform) { - return apk[platform] ? apk[platform] : apk[2]; + return apk[platform] ? apk[platform] : apk[1]; } module.exports = { diff --git a/lib/message/music.js b/lib/message/music.js index e7b69b18..d54d46ab 100644 --- a/lib/message/music.js +++ b/lib/message/music.js @@ -23,13 +23,13 @@ function parse(o) { return data; } -async function fetch(url, options = {}) { - url = new URL(url); +function fetch(address, options = {}) { + const url = new URL(address); return new Promise((resolve, reject) => { const protocol = url.protocol.startsWith("https") ? https : http; protocol.get(url, options, (res) => { if (res.statusCode !== 200) { - return reject(); + return reject("url: " + address + "\nstatusCode: " + res.statusCode); } let data = ""; res.setEncoding("utf8"); @@ -37,7 +37,9 @@ async function fetch(url, options = {}) { res.on("end", () => { resolve(data); }); - }).on("error", reject); + }).on("error", (err) => { + reject("url: " + address + "\nerror: " + err.message); + }); }); } @@ -74,8 +76,11 @@ async function get163SongInfo(id) { async function getMiGuSongInfo(id) { let rsp = await fetch(`https://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do?copyrightId=${id}&resourceType=2`); rsp = JSON.parse(rsp).resource[0]; - let previewUrl = await fetch(`https://music.migu.cn/v3/api/music/audioPlayer/getSongPic?songId=${rsp.songId}`, { headers: { referer: "https://music.migu.cn/v3/music/player/audio" } }); - let preview = JSON.parse(previewUrl).smallPic || ""; + let preview = ""; + try { + let previewUrl = await fetch(`https://music.migu.cn/v3/api/music/audioPlayer/getSongPic?songId=${rsp.songId}`, { headers: { referer: "https://music.migu.cn/v3/music/player/audio" } }); + preview = JSON.parse(previewUrl).smallPic || ""; + } catch { } let getJumpUrl = await fetch(`https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/shareInfo.do?contentId=${rsp.contentId}&contentName=${rsp.songName}&resourceType=2&targetUserName=${rsp.singer}`); let jumpUrl = JSON.parse(getJumpUrl).url || "http://c.migu.cn/"; return { diff --git a/lib/troop.js b/lib/troop.js index 1d097a45..f76e9c8c 100644 --- a/lib/troop.js +++ b/lib/troop.js @@ -644,13 +644,12 @@ async function getGroupNotice(group_id) { } catch { reject("response error"); } - }); }).on("error", (e) => reject(e.message)); }); return { result: 0, data }; } catch (e) { - return { result: 102, emsg: e }; + return { result: -1, emsg: e }; } } diff --git a/package.json b/package.json index 673d8833..bdf4bbca 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "oicq", - "version": "1.16.0", - "upday": "2021/4/21", + "version": "1.16.1", + "upday": "2021/4/27", "description": "QQ protocol!", "main": "index.js", "types": "index.d.ts",