import fetch from "node-fetch" import { Cfg } from './index.js'; import lodash from 'lodash' import moment from 'moment' import { segment } from "oicq"; /**获取gtk */ const gtk = function (t) { for (var e = t || "", n = 5381, r = 0, o = e.length; r < o; ++r) n += (n << 5) + e.charAt(r).charCodeAt(0); return 2147483647 & n } /**QQ接口 */ export default new class assistant { constructor() { this.headers = { "Content-type": "application/json;charset=UTF-8", "Cookie": Bot.cookies['qun.qq.com'], "qname-service": "976321:131072", "qname-space": "Production", } } /** * @description: 取说说列表 * @param {*} e oicq * @param {Number} pos 偏移量 * @param {Number} num 数量 * @return {Object} QQ空间数据 */ async getQzone(pos = 0, num = 20) { let url = `https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin=${Bot.uin}&ftype=0&sort=0&pos=${pos}&num=${num}&replynum=100&g_tk=${Bot.bkn}&code_version=1&format=json&need_private_comment=1` return await fetch(url, { headers: { "Cookie": Bot.cookies["qzone.qq.com"], } }).then(res => res.json()).catch(err => console.log(err)) } /** * @description: 删除说说 * @param {String} tid tid参数 * @param {String} t1_source t1_source参数 */ async delQzone(tid, t1_source) { let url = `https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?&g_tk=${Bot.bkn}` //发送请求 return await fetch(url, { method: 'POST', body: `hostuin=${Bot.uin}&tid=${tid}&t1_source=${t1_source}&code_version=1&format=json`, headers: { "Cookie": Bot.cookies["qzone.qq.com"], } }).then(res => res.json()).catch(err => console.log(err)) } /**删除全部说说 */ async delQzoneAll() { let list = await this.getQzone(0, -1) if (list.total == 0) return `❎ 说说列表空空` for (let item of list.msglist) { let res = await this.delQzone(item.tid, item.t1_source) if (res.code != 0) return `❎ 遇到错误 ${JSON.stringify(res)}` } return `✅ 已清空全部说说` } /**发送说说 */ async setQzone(con, img) { let ck = Cfg.getck('qzone.qq.com') if (img) { let url = `http://xiaobai.klizi.cn/API/qqgn/ss_sendimg.php?uin=${Bot.uin}&skey=${ck.skey}&pskey=${ck.p_skey}&url=${img[0]}&msg=${con}` return await fetch(url).then(res => res.json()).catch(err => console.log(err)) } else { let url = `https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_publish_v6?&g_tk=${Bot.bkn}` return await fetch(url, { method: 'POST', body: `syn_tweet_verson=1¶mstr=1&con=${con}&feedversion=1&ver=1&ugc_right=1&to_sign=1&hostuin=${Bot.uin}&code_version=1&format=json`, headers: { "Cookie": Bot.cookies["qzone.qq.com"], } }).then(res => res.json()).catch(err => console.log(err)) } } /** * @description: 获取留言 * @param {Number} num 数量为0时返回为全部 * @param {Number} start 偏移量/开始的位置 * @return {*} */ async getQzoneMsgb(num = 0, start = 0) { let url = `https://user.qzone.qq.com/proxy/domain/m.qzone.qq.com/cgi-bin/new/get_msgb?uin=${Bot.uin}&hostUin=${Bot.uin}&start=${start}&s=0.45779069937151884&format=json&num=${num}&inCharset=utf-8&outCharset=utf-8&g_tk=${Bot.bkn}` return await fetch(url, { "headers": { "cookie": Bot.cookies["qzone.qq.com"], }, }).then(res => res.json()); } /** * @description: 删除留言 * @param {*} id 留言id * @param {*} uinId * @return {*} */ async delQzoneMsgb(id, uinId) { let delurl = `https://h5.qzone.qq.com/proxy/domain/m.qzone.qq.com/cgi-bin/new/del_msgb?&g_tk=${Bot.bkn}` return await fetch(delurl, { method: "POST", headers: { "Cookie": Bot.cookies['qzone.qq.com'], }, body: `hostUin=${Bot.uin}&idList=${id}&uinList=${uinId}&format=json&iNotice=1&inCharset=utf-8&outCharset=utf-8&ref=qzone&json=1&g_tk=${Bot.bkn}` }).then(res => res.json()); } /**删除全部留言 */ async delQzoneMsgbAll() { let list = await this.getQzoneMsgb() if (list.code != 0) return `❎ 获取列表错误 ${JSON.stringify(list)}` if (list.data.total == 0) return `❎ 留言列表空空` for (let item of list.data.commentList) { let res = await this.delQzoneMsgb(item.id, item.uin) if (res.code != 0) return `❎ 遇到错误 ${JSON.stringify(res)}` } return `✅ 已清空全部留言` } // ----------------------------------------------------公告--------------------------------------------- /** * @description: 获取群公告 * @param {String} group 群号 * @param {String} item 序号 * @return {Object} */ async getAnnouncelist(group_id, s = 0) { let n = s ? 1 : 20; let url = `https://web.qun.qq.com/cgi-bin/announce/get_t_list?bkn=${Bot.bkn}&qid=${group_id}&ft=23&s=${s - 1}&n=${n}` let res = await fetch(url, { headers: { "Cookie": Bot.cookies["qun.qq.com"], } }).then(res => res.json()).catch(err => console.error(err)) if (!res) return false; if (s) { return { text: res.feeds[0].msg.text, fid: res.feeds[0].fid } } else { return res.feeds.map((item, index) => `${index + 1}、${lodash.truncate(item.msg.text)}`).join('\n') } } /** * @description: 发送群公告 * @param {Number} group_id 发送群号 * @param {String} msg 发送内容 */ async setAnnounce(group_id, msg) { let url = `https://web.qun.qq.com/cgi-bin/announce/add_qun_notice?bkn=${Bot.bkn}` return await fetch(url, { method: 'POST', body: `qid=${group_id}&bkn=${Bot.bkn}&text=${msg}&pinned=0&type=1&settings={"is_show_edit_card":1,"tip_window_type":1,"confirm_required":1}`, headers: { "Cookie": Bot.cookies["qun.qq.com"], } }).then(res => res.json()).catch(err => console.error(err)) } /** * @description: 删群公告 * @param {Number} group_id 群号 * @param {Number} num 序号 */ async delAnnounce(group_id, num) { let fid = await this.getAnnouncelist(group_id, num) if (!fid) return false; let url = `https://web.qun.qq.com/cgi-bin/announce/del_feed?bkn=${Bot.bkn}` let res = await fetch(url, { method: 'POST', body: `bkn=${Bot.bkn}&fid=${fid.fid}&qid=${group_id}`, headers: { "Cookie": Bot.cookies["qun.qq.com"], } }).then(res => res.json()).catch(err => console.error(err)) return { ...res, text: lodash.truncate(fid.text) } } /**群星级 */ async getCreditLevelInfo(group_id) { let url = `https://qqweb.qq.com/c/activedata/get_credit_level_info?bkn=${Bot.bkn}&uin=${Bot.uin}&gc=${group_id}` return await fetch(url, { headers: { "Cookie": Bot.cookies["qqweb.qq.com"], "Referer": `https://qqweb.qq.com/m/business/qunlevel/index.html?gc=${group_id}&from=0&_wv=1027`, "User-agent": "Mozilla/5.0 (Linux; Android 12; M2012K11AC Build/SKQ1.220303.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.72 MQQBrowser/6.2 TBS/046141 Mobile Safari/537.36 V1_AND_SQ_8.3.9_350_TIM_D QQ/3.5.0.3148 NetType/WIFI WebP/0.3.0 Pixel/1080 StatusBarHeight/81 SimpleUISwitch/0 QQTheme/1015712" } }).then(res => res.json()).catch(err => console.error(err)) } /**查看本群龙王 */ async dragon(group_id) { let url = `https://qun.qq.com/interactive/honorlist?gc=${group_id}&type=1&_wv=3&_wwv=129` let res = await fetch(url, { headers: { "Cookie": Bot.cookies['qun.qq.com'] } }) .then(res => res.text()).catch(err => console.error(err)); let data = res.match(/