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

Commit

Permalink
add mark
Browse files Browse the repository at this point in the history
add comments
remove slider option
  • Loading branch information
takayama-lily committed Feb 28, 2021
1 parent b39d5b4 commit 543ed04
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 44 deletions.
27 changes: 19 additions & 8 deletions client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ export type Uin = number;

// 大多数情况下你无需关心这些配置项,因为默认配置就是最常用的,除非你需要一些与默认不同的规则
export interface ConfBot {
log_level?: "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "off", //默认info
platform?: number, //1:安卓手机(默认) 2:aPad 3:安卓手表 4:MacOS(实验性) 5:iPad(实验性)
kickoff?: boolean, //被踢下线是否在3秒后重新登陆,默认false
ignore_self?: boolean,//群聊是否无视自己的发言,默认true
resend?: boolean, //被风控时是否尝试用分片发送,默认true
data_dir?: string, //数据存储文件夹,需要可写权限,默认主目录下的data文件夹

slider?: boolean, //启用滑动验证码,默认true
//日志等级,默认info,若消息量巨大可设置为"warn"屏蔽一般消息日志
log_level?: "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "mark" | "off",

//1:安卓手机(默认) 2:aPad 3:安卓手表 4:MacOS(实验性) 5:iPad(实验性)
platform?: number,

//被踢下线是否在3秒后重新登陆,默认false
kickoff?: boolean,

//群聊是否无视自己的发言,默认true
ignore_self?: boolean,

//被风控时是否尝试用分片发送,默认true
resend?: boolean,

//数据存储文件夹,需要可写权限,默认主目录下的data文件夹
data_dir?: string,

//触发system.offline.network事件后的重连间隔秒数,默认5(秒),不建议设置低于3(秒)
//瞬间的断线重连不会触发此事件,通常你的机器真的没有网络或登陆无响应时才会触发
Expand Down Expand Up @@ -542,11 +552,12 @@ export class Client extends events.EventEmitter {
setGroupPortrait(group_id: number, file: Buffer | string): Promise<RetCommon>;

// getFile(fileid: string, busid?: string): Promise<RetCommon<FileElem["data"]>>; //用于下载链接失效后重新获取
// getHistoryMsgs(message_id: string, num?: number): Promise<RetCommon<PrivateMessageEventData[] | GroupMessageEventData[]>>; //获取msgid往前的num条消息
// getChatHistory(message_id: string, num?: number): Promise<RetCommon<PrivateMessageEventData[] | GroupMessageEventData[]>>; //获取msgid往前的num条消息
// uploadC2CImages(user_id: number, images: ImgPttElem["data"][]): Promise<RetCommon<ImgPttElem["data"][]>>; //上传好友图以备发送
// uploadGroupImages(group_id: number, images: ImgPttElem["data"][]): Promise<RetCommon<ImgPttElem["data"][]>>; //上传群图以备发送
// getSummaryCard(user_id: number): Promise<RetCommon<unknown>>; //查看用户资料
// getForwardMsg(resid: string): Promise<RetCommon<unknown>>;
// getSystemMsg(): Promise<RetCommon<Array<FriendAddEventData | GroupAddEventData | GroupInviteEventData>>>;

getCookies(domain?: string): Promise<RetCommon<{ cookies: string }>>;
getCsrfToken(): Promise<RetCommon<{ token: number }>>;
Expand Down
23 changes: 11 additions & 12 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class AndroidClient extends Client {
ignore_self: true,
resend: true,
reconn_interval: 5,
slider: true,
data_dir: path.join(process.mainModule.path, "data"),
...config
};
Expand All @@ -110,14 +109,14 @@ class AndroidClient extends Client {
this.logger = log4js.getLogger(`[BOT:${uin}]`);
this.logger.level = config.log_level;

this.logger.info("----------");
this.logger.info(`Package Version: oicq@${version.version} (Released on ${version.upday})`);
this.logger.info("View Changelogs:https://github.com/takayama-lily/oicq/releases");
this.logger.info("----------");
this.logger.mark("----------");
this.logger.mark(`Package Version: oicq@${version.version} (Released on ${version.upday})`);
this.logger.mark("View Changelogs:https://github.com/takayama-lily/oicq/releases");
this.logger.mark("----------");

const filepath = path.join(this.dir, `device-${uin}.json`);
if (!fs.existsSync(filepath))
this.logger.info("创建了新的设备文件:" + filepath);
this.logger.mark("创建了新的设备文件:" + filepath);
this.device = getDeviceInfo(filepath);
this.apk = getApkInfo(config.platform);
this.ksid = Buffer.from(`|${this.device.imei}|` + this.apk.name);
Expand All @@ -128,7 +127,7 @@ class AndroidClient extends Client {
this.on("close", () => {
this.read();
if (this.remoteAddress)
this.logger.info(`${this.remoteAddress}:${this.remotePort} closed`);
this.logger.mark(`${this.remoteAddress}:${this.remotePort} closed`);
this.stopHeartbeat();
if (this.status === Client.OFFLINE) {
return this.emit("internal.wt.failed", "网络不通畅。");
Expand Down Expand Up @@ -162,7 +161,7 @@ class AndroidClient extends Client {
});

this.on("internal.login", async () => {
this.logger.info(`Welcome, ${this.nickname} ! 开始初始化资源...`);
this.logger.mark(`Welcome, ${this.nickname} ! 初始化资源...`);
this.sync_finished = false;
await this.register();
if (!this.isOnline())
Expand All @@ -171,9 +170,9 @@ class AndroidClient extends Client {
frdlst.initFL.call(this),
frdlst.initGL.call(this)
]);
this.logger.info(`加载了${this.fl.size}个好友,${this.gl.size}个群。`);
this.logger.mark(`加载了${this.fl.size}个好友,${this.gl.size}个群。`);
this.sync_finished = true;
this.logger.info("初始化完毕,开始处理消息。");
this.logger.mark("初始化完毕,开始处理消息。");
core.getMsg.call(this);
this.em("system.online");
});
Expand All @@ -200,11 +199,11 @@ class AndroidClient extends Client {
ip = this.config.remote_ip;
if (this.config.remote_port > 0 && this.config.remote_port < 65536)
port = this.config.remote_port;
this.logger.info(`connecting to ${ip}:${port}`);
this.logger.mark(`connecting to ${ip}:${port}`);
this.removeAllListeners("connect");
this.connect(port, ip, () => {
this.status = Client.INIT;
this.logger.info(`${this.remoteAddress}:${this.remotePort} connected`);
this.logger.mark(`${this.remoteAddress}:${this.remotePort} connected`);
this.resume();
callback();
});
Expand Down
4 changes: 0 additions & 4 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ function onPushNotify(blob) {
case 84:
case 87:
case 525:
if (parent[5] === 525) {
this.lock525 = !this.lock525;
if (this.lock525) return;
}
return sysmsg.getNewGroup.call(this, parent[5]);
case 187:
return sysmsg.getNewFriend.call(this);
Expand Down
6 changes: 3 additions & 3 deletions lib/friendlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ async function initGL() {
this.gl = new Map;
for (let v of parent[5]) {
v = jce.decode(v);
var last_sent_time = 0, create_time = 0, grade = 0, max_admin_count = 0, active_member_count = 0, update_time = 0;
var last_sent_time = 0, create_time = 0, grade = 0, max_admin_count = 0, active_member_count = 0;
if (tmp.has(v[1])) {
const g = tmp.get(v[1]);
var { last_sent_time, create_time, grade, max_admin_count, active_member_count, update_time } = g;
var { last_sent_time, create_time, grade, max_admin_count, active_member_count } = g;
}
this.gl.set(v[1], {
group_id: v[1],
Expand All @@ -128,7 +128,7 @@ async function initGL() {
shutup_time_me: v[10] * 1000 > Date.now() ? v[10] : 0,
create_time, grade,
max_admin_count, active_member_count,
update_time,
update_time: 0,
});
}
} catch (e) {
Expand Down
2 changes: 2 additions & 0 deletions lib/message/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ async function getHistoryMsg(message_id) {
const msg = await getOneGroupMsg.call(this, message_id);
try {
const data = await parseGroupMsg.call(this, msg);
data.post_type = "message";
data.message_type = "group";
data.message_id = message_id;
data.real_id = message_id;
Expand All @@ -458,6 +459,7 @@ async function getHistoryMsg(message_id) {
const msg = await getOneC2CMsg.call(this, message_id);
try {
const data = await parseC2CMsg.call(this, msg);
data.post_type = "message";
data.message_type = "private";
data.message_id = message_id;
data.real_id = message_id;
Expand Down
19 changes: 17 additions & 2 deletions lib/message/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const img_exts = {
};

/**
* 生成CQ码file字段
* @param {Buffer} md5
* @param {number} size
* @param {number} width
Expand All @@ -43,16 +44,19 @@ function buildImageFileParam(md5, size, width, height, type) {
class ImageBuilder {

/**
* 图片protobuf节点
* @type {import("../ref").Proto}
*/
nested;

/**
* 图片bytes
* @type {Buffer}
*/
buf;

/**
* 服务端返回的fileid
* @type {Buffer}
*/
fid;
Expand All @@ -64,11 +68,13 @@ class ImageBuilder {
type = 1000;

/**
* 网络图片下载任务
* @type {Promise}
*/
task;

/**
* 缓存文件路径
* @type {string}
*/
filepath;
Expand All @@ -87,6 +93,7 @@ class ImageBuilder {
}

/**
* 计算图片md5, size, 长宽
* @private
*/
calcSizeOf() {
Expand All @@ -102,6 +109,7 @@ class ImageBuilder {
}

/**
* 从缓存文件中获取md5, size, 长宽
* @private
* @param {string} file
*/
Expand All @@ -126,6 +134,7 @@ class ImageBuilder {
}

/**
* 构造图片protobuf节点
* @private
*/
setNested() {
Expand Down Expand Up @@ -171,6 +180,7 @@ class ImageBuilder {
}

/**
* 下载网络图片并生成缓存文件
* @private
*/
async download() {
Expand Down Expand Up @@ -202,6 +212,7 @@ class ImageBuilder {
}

/**
* 删除缓存文件
* @public
*/
deleteCache() {
Expand All @@ -210,6 +221,7 @@ class ImageBuilder {
}

/**
* 服务端返回的fid(fileid)写入图片节点
* @public
* @param {Buffer} fid
*/
Expand Down Expand Up @@ -305,11 +317,12 @@ class ImageBuilder {
}

/**
* 上传群图(最多20张)
* @this {import("../ref").Client}
* @param {number} group_id
* @param {ImageBuilder[]} imgs
*/
async function imageStore(group_id, imgs) {
async function groupPicUp(group_id, imgs) {
const req = [];
for (const v of imgs) {
req.push({
Expand Down Expand Up @@ -339,6 +352,7 @@ async function imageStore(group_id, imgs) {
}

/**
* 上传私聊图(最多20张)
* @this {import("../ref").Client}
* @param {number} user_id
* @param {ImageBuilder[]} imgs
Expand Down Expand Up @@ -372,6 +386,7 @@ async function offPicUp(user_id, imgs) {
}

/**
* 最多同时上传20张
* @this {import("../ref").Client}
* @param {number} target
* @param {ImageBuilder[]} imgs
Expand All @@ -383,7 +398,7 @@ async function uploadImages(target, imgs, c2c) {
while (imgs.length > n) {
try {
this.logger.debug("开始请求上传图片到tx服务器");
let rsp = await (c2c ? offPicUp : imageStore).call(this, target, imgs.slice(n, n + 20));
let rsp = await (c2c ? offPicUp : groupPicUp).call(this, target, imgs.slice(n, n + 20));
rsp = Array.isArray(rsp) ? rsp : [rsp];
const tasks = [];
for (let i = n; i < imgs.length; ++i) {
Expand Down
3 changes: 3 additions & 0 deletions lib/pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ function _encode(writer, tag, value) {
}
}

/**
* @param {import("./ref").Proto} o
*/
function encode(o) {
const writer = new pb.Writer();
for (let tag in o) {
Expand Down
25 changes: 10 additions & 15 deletions lib/wtlogin/wt.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function build0x0BPacket(cmd, body, seq = 0) {
/**
* @this {import("../ref").Client}
*/
async function passwordLogin(slider = true) {
async function passwordLogin() {
this.logining = true;
try {
this.t106 = await fs.promises.readFile(path.join(this.dir, "t106"));
Expand All @@ -151,7 +151,7 @@ async function passwordLogin(slider = true) {
const t = tlv.getPacker(this);
let body = new Writer()
.writeU16(9)
.writeU16(slider ? 24 : 23)
.writeU16(24)
.writeBytes(t(0x18))
.writeBytes(t(0x1))
.writeBytes(t(0x106))
Expand All @@ -169,10 +169,9 @@ async function passwordLogin(slider = true) {
.writeBytes(t(0x511))
.writeBytes(t(0x187))
.writeBytes(t(0x188))
.writeBytes(t(0x194));
if (slider)
body = body.writeBytes(t(0x191));
body = body.writeBytes(t(0x202))
.writeBytes(t(0x194))
.writeBytes(t(0x191))
.writeBytes(t(0x202))
.writeBytes(t(0x177))
.writeBytes(t(0x516))
.writeBytes(t(0x521))
Expand Down Expand Up @@ -551,14 +550,10 @@ function decodeLoginResponse(blob, token = false) {
if (type === 2) {
this.t104 = t[0x104];
if (t[0x192]) {
if (this.config.slider) {
const url = String(t[0x192]);
this.logger.info(`收到滑动验证码,请访问以下地址完成滑动:${url}
const url = String(t[0x192]);
this.logger.mark(`收到滑动验证码,请访问以下地址完成滑动:${url}
注意:请提前打开浏览器F12->Network(网络),从滑动的返回结果中取出ticket并输入`);
return this.em("system.login.slider", { url });
} else {
return passwordLogin.call(this, false);
}
return this.em("system.login.slider", { url });
}
if (t[0x165]) {
const stream = Readable.from(t[0x105], { objectMode: false });
Expand All @@ -568,7 +563,7 @@ function decodeLoginResponse(blob, token = false) {
const image = stream.read();
const filepath = path.join(this.dir, "captcha.jpg");
fs.writeFileSync(filepath, image);
this.logger.info(`收到图片验证码,已保存到文件(${filepath}),请查看并输入: `);
this.logger.mark(`收到图片验证码,已保存到文件(${filepath}),请查看并输入: `);
return this.em("system.login.captcha", { image });
}
const message = "[登陆失败]未知格式的验证码。";
Expand All @@ -580,7 +575,7 @@ function decodeLoginResponse(blob, token = false) {

if (type === 160) {
const url = String(t[0x204]);
this.logger.info("需要扫码完成设备锁验证,验证地址:" + url);
this.logger.mark("需要扫码完成设备锁验证,验证地址:" + url);
return this.em("system.login.device", { url });
}

Expand Down

0 comments on commit 543ed04

Please sign in to comment.