Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
update package.json for npm
Browse files Browse the repository at this point in the history
update logger label
  • Loading branch information
takayama-lily committed Apr 26, 2021
1 parent b383c4a commit e883c56
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 14 additions & 6 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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("----------");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
17 changes: 11 additions & 6 deletions lib/message/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ 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");
res.on("data", chunk => data += chunk);
res.on("end", () => {
resolve(data);
});
}).on("error", reject);
}).on("error", (err) => {
reject("url: " + address + "\nerror: " + err.message);
});
});
}

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions lib/troop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit e883c56

Please sign in to comment.