|
|
import { makeSendMsg, makeForwardMsg, msgToOneBotMsg } from './makeMsg.js' |
|
|
import { getMsgMap, setMsgMap, getGuildLatestMsgId, getLatestMsg } from './msgMap.js' |
|
|
import { MsgToCQ, CQToMsg } from './CQCode.js' |
|
|
import { Version } from '../components/index.js' |
|
|
import fetch from 'node-fetch' |
|
|
|
|
|
async function getApiData(api, params = {}, name, uin) { |
|
|
const bot = Bot[uin] || Bot |
|
|
let sendRet = null |
|
|
let ResponseData = null |
|
|
let publicApi = { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'get_login_info': async params => { |
|
|
ResponseData = { |
|
|
user_id: bot.uin, |
|
|
nickname: bot.nickname |
|
|
} |
|
|
}, |
|
|
|
|
|
'set_qq_profile': async params => { |
|
|
|
|
|
if (params.nickname) { |
|
|
await bot.setNickname?.(params.nickname) |
|
|
} |
|
|
if (params.personal_note) { |
|
|
await bot.setDescription?.(params.personal_note) |
|
|
} |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'_set_model_show': async params => { |
|
|
|
|
|
}, |
|
|
|
|
|
'get_online_clients': async params => { |
|
|
|
|
|
ResponseData = { |
|
|
clients: [] |
|
|
} |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'get_stranger_info': async (params) => { |
|
|
ResponseData = await bot.getStrangerInfo?.(params.user_id) |
|
|
}, |
|
|
|
|
|
'get_friend_list': async params => { |
|
|
let list = await bot.getFriendList?.() |
|
|
if (Array.isArray(list)) { |
|
|
ResponseData = list |
|
|
} else if (list instanceof Map) { |
|
|
ResponseData = Array.from(list.values()) |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_unidirectional_friend_list': async params => { |
|
|
|
|
|
|
|
|
ResponseData = [] |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'delete_friend': async params => { |
|
|
await bot.deleteFriend?.(params.user_id) |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'send_private_msg': async (params) => { |
|
|
let { sendMsg, quote } = await makeSendMsg(params, uin) |
|
|
if (sendMsg.length > 0) sendRet = await bot.pickFriend?.(params.user_id).sendMsg?.(sendMsg, quote) |
|
|
logger.mark(`[ws-plugin] 连接名字:${name} 处理完成`) |
|
|
}, |
|
|
|
|
|
'send_group_msg': async (params) => { |
|
|
let { sendMsg, quote } = await makeSendMsg(params, uin) |
|
|
if (sendMsg.length > 0) sendRet = await bot.pickGroup?.(params.group_id).sendMsg?.(sendMsg, quote) |
|
|
logger.mark(`[ws-plugin] 连接名字:${name} 处理完成`) |
|
|
}, |
|
|
|
|
|
'send_msg': async (params) => { |
|
|
let { sendMsg, quote } = await makeSendMsg(params, uin) |
|
|
if (params.message_type == 'group' || params.group_id) { |
|
|
if (sendMsg.length > 0) sendRet = await bot.pickGroup?.(params.group_id).sendMsg?.(sendMsg, quote) |
|
|
} else if (params.message_type == 'private' || params.user_id) { |
|
|
if (sendMsg.length > 0) sendRet = await bot.pickFriend?.(params.user_id).sendMsg?.(sendMsg, quote) |
|
|
} |
|
|
logger.mark(`[ws-plugin] 连接名字:${name} 处理完成`) |
|
|
}, |
|
|
|
|
|
'get_msg': async (params) => { |
|
|
ResponseData = await getMsgMap({ onebot_id: params.message_id }) |
|
|
if (ResponseData) { |
|
|
ResponseData = await bot.getMsg?.(ResponseData.message_id) |
|
|
if (ResponseData) { |
|
|
if (ResponseData.bot) delete ResponseData.bot |
|
|
if (ResponseData.friend) delete ResponseData.friend |
|
|
if (ResponseData.group) delete ResponseData.group |
|
|
if (ResponseData.member) delete ResponseData.member |
|
|
ResponseData.group = ResponseData.message_type == 'group' ? true : false |
|
|
ResponseData.real_id = Number(ResponseData.seq) |
|
|
ResponseData.message_id = Number(ResponseData.rand) |
|
|
ResponseData.message = await msgToOneBotMsg(ResponseData.message) |
|
|
ResponseData.raw_message = MsgToCQ(ResponseData.message) |
|
|
} else { |
|
|
throw { message: 'get_msg API error', noLog: true } |
|
|
} |
|
|
} else { |
|
|
throw { message: 'get_msg API error', noLog: true } |
|
|
} |
|
|
}, |
|
|
|
|
|
'delete_msg': async (params) => { |
|
|
let msg = await getMsgMap({ onebot_id: params.message_id }) |
|
|
if (msg) { |
|
|
await bot.deleteMsg?.(msg.message_id) |
|
|
} |
|
|
}, |
|
|
|
|
|
'mark_msg_as_read': async params => { |
|
|
|
|
|
}, |
|
|
|
|
|
'get_forward_msg': async params => { |
|
|
let result = await bot.getForwardMsg?.(params.message_id) || [] |
|
|
let messages = [] |
|
|
for (const item of result) { |
|
|
messages.push({ |
|
|
content: MsgToCQ(await msgToOneBotMsg(item.message)), |
|
|
sender: { |
|
|
nickname: item.nickname, |
|
|
user_id: item.user_id |
|
|
}, |
|
|
time: item.time |
|
|
}) |
|
|
} |
|
|
ResponseData = { |
|
|
messages |
|
|
} |
|
|
}, |
|
|
|
|
|
'send_group_forward_msg': async (params) => { |
|
|
let forwardMsg = await makeForwardMsg(params, uin) |
|
|
let forward_id |
|
|
if (typeof (forwardMsg.data) === 'object') { |
|
|
let detail = forwardMsg.data?.meta?.detail |
|
|
if (detail) forward_id = detail.resid |
|
|
} else { |
|
|
let match = forwardMsg.data.match(/m_resid="(.*?)"/); |
|
|
if (match) forward_id = match[1]; |
|
|
} |
|
|
sendRet = await bot.pickGroup(params.group_id).sendMsg(forwardMsg) |
|
|
sendRet.forward_id = forward_id |
|
|
logger.mark(`[ws-plugin] 连接名字:${name} 处理完成`) |
|
|
}, |
|
|
|
|
|
'send_private_forward_msg': async (params) => { |
|
|
let forwardMsg = await makeForwardMsg(params, uin) |
|
|
let forward_id |
|
|
if (typeof (forwardMsg.data) === 'object') { |
|
|
let detail = forwardMsg.data?.meta?.detail |
|
|
if (detail) forward_id = detail.resid |
|
|
} else { |
|
|
let match = forwardMsg.data.match(/m_resid="(.*?)"/); |
|
|
if (match) forward_id = match[1]; |
|
|
} |
|
|
sendRet = await bot.pickFriend(params.group_id).sendMsg(forwardMsg) |
|
|
sendRet.forward_id = forward_id |
|
|
logger.mark(`[ws-plugin] 连接名字:${name} 处理完成`) |
|
|
}, |
|
|
|
|
|
'get_group_msg_history': async params => { |
|
|
let messages, flag = true |
|
|
if (params.message_seq) { |
|
|
let message_id = (await getMsgMap({ onebot_id: params.message_id }))?.message_id |
|
|
if (message_id) { |
|
|
messages = await bot.getChatHistory?.(message_id) |
|
|
flag = false |
|
|
} |
|
|
} |
|
|
if (flag) { |
|
|
messages = await bot.pickGroup(params.group_id).getChatHistory?.() |
|
|
} |
|
|
if (messages) { |
|
|
for (let i = 0; i < messages.length; i++) { |
|
|
messages[i] = await msgToOneBotMsg(messages[i]) |
|
|
} |
|
|
} |
|
|
ResponseData = { |
|
|
messages |
|
|
} |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'set_friend_add_request': async params => { |
|
|
let ret = (await bot.getSystemMsg?.() || []).filter(i => i.request_type == 'friend' && i.flag == params.flag) |
|
|
if (ret.length > 0) { |
|
|
ret = ret[0] |
|
|
if (ret.approve(params.approve)) { |
|
|
if (params.remark) { |
|
|
bot.pickFriend(ret.user_id).setRemark(params.remark) |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
|
|
|
'set_group_add_request': async params => { |
|
|
let type = params.sub_type || params.type |
|
|
let ret = (await bot.getSystemMsg?.() || []).filter(i => i.request_type == 'group' && i.sub_type == type && i.flag == params.flag) |
|
|
if (ret.length > 0) { |
|
|
ret = ret[0] |
|
|
ret.approve(params.approve) |
|
|
|
|
|
} |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'get_group_info': async params => { |
|
|
const group = await bot.pickGroup(params.group_id) |
|
|
ResponseData = group.info || group.info?.() || group.getInfo?.() |
|
|
if (ResponseData.group_name) { |
|
|
ResponseData.group_memo = ResponseData.group_name |
|
|
} |
|
|
if (ResponseData.create_time) { |
|
|
ResponseData.group_create_time = ResponseData.create_time |
|
|
} |
|
|
if (ResponseData.grade) { |
|
|
ResponseData.group_level = ResponseData.grade |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_group_list': async params => { |
|
|
let list = await bot.getGroupList?.() |
|
|
if (list instanceof Map) { |
|
|
list = Array.from(list.values()) |
|
|
} |
|
|
list.map(item => { |
|
|
if (item.group_name) { |
|
|
item.group_memo = item.group_name |
|
|
} |
|
|
if (item.create_time) { |
|
|
item.group_create_time = item.create_time |
|
|
} |
|
|
if (item.grade) { |
|
|
item.group_level = item.grade |
|
|
} |
|
|
}) |
|
|
ResponseData = list |
|
|
}, |
|
|
|
|
|
'get_group_member_info': async (params) => { |
|
|
const group = await bot.pickGroup(params.group_id).pickMember(params.user_id) |
|
|
ResponseData = group?.info || group.info?.() || group.getInfo?.() || await bot.getGroupMemberInfo?.(params.group_id, params.user_id); |
|
|
if (ResponseData.shutup_time) { |
|
|
ResponseData.shut_up_timestamp = ResponseData.shutup_time |
|
|
} |
|
|
if (!ResponseData.last_sent_time) { |
|
|
ResponseData.last_sent_time = Date.now() |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_group_member_list': async (params) => { |
|
|
const group = await bot.pickGroup(params.group_id) |
|
|
let list = await group.getMemberMap?.() || await group.getMemberList?.() || [] |
|
|
if (list instanceof Map) { |
|
|
list = Array.from(list.values()) |
|
|
} |
|
|
list.map(item => { |
|
|
if (item.shutup_time) { |
|
|
item.shut_up_timestamp = item.shutup_time |
|
|
} |
|
|
if (!item.last_sent_time) { |
|
|
item.last_sent_time = Date.now() |
|
|
} |
|
|
}) |
|
|
ResponseData = list |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
'get_group_system_msg': async params => { |
|
|
let invited_requests = [] |
|
|
let join_requests = [] |
|
|
for (const i of (await bot.getSystemMsg?.() || [])) { |
|
|
if (i.request_type == 'group') { |
|
|
switch (i.sub_type) { |
|
|
case 'add': |
|
|
join_requests.push({ |
|
|
request_id: i.seq, |
|
|
requester_uin: i.user_id, |
|
|
requester_nick: i.nickname, |
|
|
message: i.comment, |
|
|
group_id: i.group_id, |
|
|
group_name: i.group_name, |
|
|
checked: false, |
|
|
actor: 0 |
|
|
}) |
|
|
break; |
|
|
case 'invite': |
|
|
invited_requests.push({ |
|
|
request_id: i.seq, |
|
|
invitor_uin: i.user_id, |
|
|
invitor_nick: i.nickname, |
|
|
group_id: i.group_id, |
|
|
group_name: i.group_name, |
|
|
checked: false, |
|
|
actor: 0 |
|
|
}) |
|
|
break; |
|
|
default: |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
ResponseData = { |
|
|
invited_requests, |
|
|
join_requests |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_essence_msg_list': async params => { |
|
|
ResponseData = [] |
|
|
let is_end = false, page_start = 0, page_limit = 50 |
|
|
while (!is_end && !Version.isTrss) { |
|
|
let res = await fetch(`https://qun.qq.com/cgi-bin/group_digest/digest_list?bkn=${bot.bkn}&group_code=${params.group_id}&page_start=${page_start}&page_limit=${page_limit}`, { |
|
|
headers: { |
|
|
Cookie: bot.cookies['qun.qq.com'] |
|
|
} |
|
|
}).then(r => r.json()) |
|
|
if (res.retcode !== 0) return |
|
|
if (res.data?.is_end === false) { |
|
|
page_start++ |
|
|
} else if (res.data?.is_end === true) { |
|
|
is_end = true |
|
|
} |
|
|
for (const i of res.data.msg_list) { |
|
|
ResponseData.push({ |
|
|
sender_id: i.sender_uin, |
|
|
sender_nick: i.sender_nick, |
|
|
sender_time: i.sender_time, |
|
|
operator_id: i.add_digest_uin, |
|
|
operator_nick: i.add_digest_nick, |
|
|
operator_time: add_digest_time, |
|
|
message_id: i.msg_random |
|
|
}) |
|
|
} |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_group_at_all_remain': async params => { |
|
|
let ret = await bot.pickGroup(params.group_id) |
|
|
ResponseData = { |
|
|
can_at_all: ret?.is_admin || false, |
|
|
|
|
|
remain_at_all_count_for_group: ret.getAtAllRemainder?.() || 0, |
|
|
remain_at_all_count_for_uin: ret.getAtAllRemainder?.() || 0 |
|
|
} |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'set_group_name': async params => { |
|
|
await bot.setGroupName?.(params.group_id, params.group_name) |
|
|
}, |
|
|
|
|
|
'set_group_portrait': async params => { |
|
|
await bot.setGroupPortrait?.(params.group_id, params.file) |
|
|
}, |
|
|
|
|
|
'set_group_admin': async params => { |
|
|
await bot.setGroupAdmin?.(params.group_id, params.user_id, params.enable) |
|
|
}, |
|
|
|
|
|
'set_group_card': async params => { |
|
|
await bot.setGroupCard?.(params.group_id, params.user_id, params.card) |
|
|
}, |
|
|
|
|
|
'set_group_special_title': async params => { |
|
|
await bot.setGroupSpecialTitle?.(params.group_id, params.user_id, params.special_title, params.duration || -1) |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'set_group_ban': async (params) => { |
|
|
await bot.setGroupBan?.(params.group_id, params.user_id, params.duration) |
|
|
}, |
|
|
|
|
|
'set_group_whole_ban': async params => { |
|
|
await bot.setGroupWholeBan?.(params.group_id, params.enable) |
|
|
}, |
|
|
|
|
|
'set_group_anonymous_ban': async params => { |
|
|
let flag = params.anonymous?.flag || params.anonymous_flag || params.flag |
|
|
await bot.setGroupAnonymousBan?.(params.group_id, flag, params.duration) |
|
|
}, |
|
|
|
|
|
'set_essence_msg': async params => { |
|
|
let message_id = (await getMsgMap({ onebot_id: params.message_id }))?.message_id |
|
|
if (message_id) await bot.setEssenceMessage?.(message_id) |
|
|
}, |
|
|
|
|
|
'delete_essence_msg': async params => { |
|
|
let message_id = (await getMsgMap({ onebot_id: params.message_id }))?.message_id |
|
|
if (message_id) await bot.removeEssenceMessage?.(message_id) |
|
|
}, |
|
|
|
|
|
'send_group_sign': async params => { |
|
|
await bot.sendGroupSign?.(params.group_id) |
|
|
}, |
|
|
|
|
|
'set_group_anonymous': async params => { |
|
|
await bot.setGroupAnonymous?.(params.group_id, params.enable) |
|
|
}, |
|
|
|
|
|
'_send_group_notice': async params => { |
|
|
|
|
|
if (!Version.isTrss) { |
|
|
await fetch(`https://web.qun.qq.com/cgi-bin/announce/add_qun_notice?bkn=${bot.bkn}`, { |
|
|
method: 'POST', |
|
|
body: `qid=${params.group_id}&bkn=${bot.bkn}&text=${params.content}&pinned=0&type=1&settings={"is_show_edit_card":1,"tip_window_type":1,"confirm_required":1}`, |
|
|
headers: { |
|
|
Cookie: bot.cookies['qun.qq.com'] |
|
|
} |
|
|
}) |
|
|
} |
|
|
}, |
|
|
|
|
|
'_get_group_notice': async params => { |
|
|
if (!Version.isTrss) { |
|
|
let res = await fetch(`https://web.qun.qq.com/cgi-bin/announce/get_t_list?bkn=${bot.bkn}&qid=${params.group_id}&ft=23&s=-1&n=20`, { |
|
|
headers: { |
|
|
Cookie: bot.cookies['qun.qq.com'] |
|
|
} |
|
|
}).then(r => r.json()) |
|
|
ResponseData = [] |
|
|
if (res.feeds) { |
|
|
for (const i of res.feeds) { |
|
|
let item = { |
|
|
sender_id: i.u, |
|
|
publish_time: i.pubt, |
|
|
message: { |
|
|
text: i.msg.text |
|
|
}, |
|
|
images: [] |
|
|
} |
|
|
if (i.pics) { |
|
|
for (const pic of i.pics) { |
|
|
item.images.push({ |
|
|
height: pic.h, |
|
|
width: pic.w, |
|
|
id: pic.id |
|
|
}) |
|
|
} |
|
|
} |
|
|
ResponseData.push(item) |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
|
|
|
'set_group_kick': async params => { |
|
|
await bot.setGroupKick?.(params.group_id, params.user_id, params.reject_add_request || false) |
|
|
}, |
|
|
|
|
|
'set_group_leave': async params => { |
|
|
await bot.setGroupLeave?.(params.group_id) |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'upload_group_file': async params => { |
|
|
await bot.pickGroup(params.group_id).fs?.upload?.(params.file, params.folder || '/', params.name) |
|
|
}, |
|
|
|
|
|
'delete_group_file': async params => { |
|
|
await bot.pickGroup(params.group_id).fs?.rm?.(params.file_id) |
|
|
}, |
|
|
|
|
|
'create_group_file_folder': async params => { |
|
|
await bot.pickGroup(params.group_id).fs?.mkdir?.(params.name) |
|
|
}, |
|
|
|
|
|
'delete_group_folder': async params => { |
|
|
await bot.pickGroup(params.group_id).fs?.rm?.(params.folder_id) |
|
|
}, |
|
|
|
|
|
'get_group_file_system_info': async params => { |
|
|
let ret = await bot.pickGroup(params.group_id).fs?.df?.() |
|
|
ResponseData = { |
|
|
file_count: ret?.file_count || 0, |
|
|
limit_count: ret?.max_file_count || 0, |
|
|
used_space: ret?.used || 0, |
|
|
total_space: ret?.total || 0 |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_group_root_files': async (params) => { |
|
|
let list = await bot.pickGroup(params.group_id).fs?.ls?.() |
|
|
let files = [] |
|
|
let folders = [] |
|
|
let nickname = {} |
|
|
if (Array.isArray(list) && list.length > 0) { |
|
|
for (const item of list) { |
|
|
let user_id = item.user_id |
|
|
if (!nickname[user_id]) { |
|
|
nickname[user_id] = (await bot.getStrangerInfo(item.user_id)).nickname |
|
|
} |
|
|
if (item.is_dir) { |
|
|
folders.push({ |
|
|
group_id: params.group_id, |
|
|
folder_id: item.fid, |
|
|
folder_name: item.name, |
|
|
create_time: item.create_time, |
|
|
creator: item.user_id, |
|
|
creator_name: nickname[user_id], |
|
|
total_file_count: item.file_count |
|
|
}) |
|
|
} else { |
|
|
files.push({ |
|
|
group_id: params.group_id, |
|
|
file_id: item.fid, |
|
|
file_name: item.name, |
|
|
busid: item.busid, |
|
|
file_size: item.size, |
|
|
upload_time: item.create_time, |
|
|
dead_time: item.duration, |
|
|
modify_time: item.create_time, |
|
|
download_times: item.download_times, |
|
|
uploader: item.user_id, |
|
|
uploader_name: nickname[user_id] |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
ResponseData = { |
|
|
files, |
|
|
folders |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_group_files_by_folder': async params => { |
|
|
let list = await bot.pickGroup(params.group_id).fs?.ls?.(params.folder_id) |
|
|
let files = [] |
|
|
let folders = [] |
|
|
let nickname = {} |
|
|
if (Array.isArray(list) && list.length > 0) { |
|
|
for (const item of list) { |
|
|
let user_id = item.user_id |
|
|
if (!nickname[user_id]) { |
|
|
nickname[user_id] = (await bot.getStrangerInfo(item.user_id)).nickname |
|
|
} |
|
|
if (item.is_dir) { |
|
|
folders.push({ |
|
|
group_id: params.group_id, |
|
|
folder_id: item.fid, |
|
|
folder_name: item.name, |
|
|
create_time: item.create_time, |
|
|
creator: item.user_id, |
|
|
creator_name: nickname[user_id], |
|
|
total_file_count: item.file_count |
|
|
}) |
|
|
} else { |
|
|
files.push({ |
|
|
group_id: params.group_id, |
|
|
file_id: item.fid, |
|
|
file_name: item.name, |
|
|
busid: item.busid, |
|
|
file_size: item.size, |
|
|
upload_time: item.create_time, |
|
|
dead_time: item.duration, |
|
|
modify_time: item.create_time, |
|
|
download_times: item.download_times, |
|
|
uploader: item.user_id, |
|
|
uploader_name: nickname[user_id] |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
ResponseData = { |
|
|
files, |
|
|
folders |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_group_file_url': async params => { |
|
|
let file = await bot.pickGroup(params.group_id).fs?.download?.(params.file_id) |
|
|
ResponseData = { |
|
|
url: file?.url |
|
|
} |
|
|
}, |
|
|
|
|
|
'upload_private_file': async params => { |
|
|
await bot.pickFriend(params.user_id).sendFile?.(params.file, params.name) |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'get_cookies': async params => { |
|
|
ResponseData = { |
|
|
cookies: await bot.getCookies?.(params.domain || null) |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_csrf_token': async params => { |
|
|
ResponseData = { |
|
|
token: await bot.getCsrfToken?.() |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_credentials': async params => { |
|
|
ResponseData = { |
|
|
cookies: await bot.getCookies?.(params.domain || null), |
|
|
token: await bot.getCsrfToken?.() |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_version_info': async params => { |
|
|
ResponseData = { |
|
|
app_name: 'ws-plugin', |
|
|
app_version: Version.version, |
|
|
protocol_version: 'v11' |
|
|
} |
|
|
}, |
|
|
|
|
|
'get_status': async params => { |
|
|
ResponseData = { |
|
|
online: bot.isOnline?.() || true, |
|
|
good: bot.isOnline?.() || true, |
|
|
app_initialized: true, |
|
|
app_enabled: true, |
|
|
plugins_good: true, |
|
|
app_good: true, |
|
|
stat: { |
|
|
packet_receivend: bot.stat?.recv_pkt_cnt || 0, |
|
|
packet_send: bot.stat?.sent_pkt_cnt || 0, |
|
|
packet_lost: bot.stat?.lost_pkt_cnt || 0, |
|
|
message_received: bot.stat?.recv_msg_cnt || 0, |
|
|
message_send: bot.stat?.sent_msg_cnt || 0, |
|
|
disconnect_times: 0, |
|
|
lost_times: bot.stat?.lost_times || 0, |
|
|
last_message_time: getLatestMsg()?.time || 0 |
|
|
} |
|
|
} |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
'clean_cache': async params => { |
|
|
await bot.cleanCache?.() |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'.handle_quick_operation': async ({ context, operation }) => { |
|
|
switch (context.post_type) { |
|
|
case 'message': |
|
|
switch (context.message_type) { |
|
|
case 'group': |
|
|
if (operation.reply) { |
|
|
if (!operation.auto_escape) { |
|
|
operation.reply = CQToMsg(operation.reply) |
|
|
} |
|
|
if (!Array.isArray(operation.reply)) { |
|
|
operation.reply = [{ type: 'text', data: { text: operation.reply } }] |
|
|
} |
|
|
let { sendMsg, quote } = await makeSendMsg({ message: operation.reply }, uin) |
|
|
if (operation.at_sender) { |
|
|
sendMsg.unshift(segment.at(context.user_id)) |
|
|
} |
|
|
await bot.pickGroup?.(context.group_id).sendMsg?.(sendMsg, quote) |
|
|
} |
|
|
if (operation.delete) { |
|
|
let msg = await getMsgMap({ onebot_id: context.message_id }) |
|
|
if (msg) { |
|
|
await bot.deleteMsg?.(msg.message_id) |
|
|
} |
|
|
} |
|
|
if (operation.kick) { |
|
|
await bot.setGroupKick?.(context.group_id, context.user_id, true) |
|
|
} |
|
|
if (operation.ban) { |
|
|
await bot.setGroupBan?.(context.group_id, context.user_id, context.ban_duration) |
|
|
} |
|
|
break; |
|
|
case 'private': |
|
|
if (operation.reply) { |
|
|
if (operation.auto_escape) { |
|
|
operation.reply = CQToMsg(operation.reply) |
|
|
} |
|
|
if (!Array.isArray(operation.reply)) { |
|
|
operation.reply = [{ type: 'text', data: { text: operation.reply } }] |
|
|
} |
|
|
let { sendMsg, quote } = await makeSendMsg({ message: operation.reply }, uin) |
|
|
await bot.pickFriend?.(context.user_id).sendMsg?.(sendMsg, quote) |
|
|
} |
|
|
break |
|
|
} |
|
|
break; |
|
|
case 'request': |
|
|
switch (context.request_type) { |
|
|
case 'friend': |
|
|
if (operation.approve) { |
|
|
let ret = (await bot.getSystemMsg?.() || []).filter(i => i.request_type == 'friend' && i.flag == context.flag) |
|
|
if (ret.length > 0) { |
|
|
ret = ret[0] |
|
|
if (ret.approve(operation.approve)) { |
|
|
if (operation.remark) { |
|
|
bot.pickFriend(ret.user_id).setRemark(operation.remark) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
break; |
|
|
case 'group': |
|
|
let type = context.sub_type |
|
|
let ret = (await bot.getSystemMsg?.() || []).filter(i => i.request_type == 'group' && i.sub_type == type && i.flag == context.flag) |
|
|
if (ret.length > 0) { |
|
|
ret = ret[0] |
|
|
ret.approve(operation.approve) |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
|
|
|
|
|
|
'send_guild_channel_msg': async params => { |
|
|
let { sendMsg } = await makeSendMsg(params, uin) |
|
|
sendMsg.unshift({ |
|
|
type: 'reply', |
|
|
data: { |
|
|
id: getGuildLatestMsgId() |
|
|
} |
|
|
}) |
|
|
await bot.pickGroup?.(`qg_${params.guild_id}-${params.channel_id}`)?.sendMsg?.(sendMsg) |
|
|
logger.mark(`[ws-plugin] 连接名字:${name} 处理完成`) |
|
|
}, |
|
|
'get_guild_service_profile': async params => { |
|
|
ResponseData = { |
|
|
avatar_url: bot.avatar, |
|
|
nickname: bot.nickname, |
|
|
tiny_id: bot.tiny_id |
|
|
} |
|
|
}, |
|
|
'get_guild_list': async params => { |
|
|
ResponseData = await bot.getGuildList?.() |
|
|
}, |
|
|
'get_guild_channel_list': async params => { |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
api = api.replace(/_async$/, '') |
|
|
if (typeof publicApi[api] === 'function') { |
|
|
await publicApi[api](params) |
|
|
if (sendRet) { |
|
|
const onebot_id = Math.floor(Math.random() * Math.pow(2, 32)) | 0 |
|
|
ResponseData = { |
|
|
...sendRet, |
|
|
message_id: onebot_id, |
|
|
} |
|
|
setMsgMap({ |
|
|
message_id: sendRet.message_id, |
|
|
time: sendRet.time, |
|
|
seq: sendRet.seq, |
|
|
rand: sendRet.rand, |
|
|
user_id: params.user_id, |
|
|
group_id: params.group_id, |
|
|
onebot_id, |
|
|
}) |
|
|
} |
|
|
return ResponseData |
|
|
} else { |
|
|
logger.warn(`[ws-plugin] 未适配的api: ${api}`); |
|
|
} |
|
|
} |
|
|
|
|
|
export { |
|
|
getApiData |
|
|
} |