新增 ComWeChat 通知/请求事件

This commit is contained in:
🌌 2023-07-28 19:36:51 +08:00
parent ab1b270c96
commit 276d27f24c
3 changed files with 89 additions and 20 deletions

View File

@ -385,6 +385,84 @@ Bot.adapter.push(new class ComWeChatAdapter {
Bot.emit(`${data.post_type}`, data) Bot.emit(`${data.post_type}`, data)
} }
makeNotice(data) {
data.post_type = data.type
if (data.group_id)
data.notice_type = "group"
else
data.notice_type = "friend"
switch (data.detail_type) {
case "private_message_delete":
logger.info(`${logger.blue(`[${data.self_id}]`)} 好友消息撤回:[${data.user_id}] ${data.message_id}`)
data.sub_type = "recall"
break
case "group_message_delete":
logger.info(`${logger.blue(`[${data.self_id}]`)} 群消息撤回:[${data.group_id}, ${data.operator_id}=>${data.user_id}] ${data.message_id}`)
data.sub_type = "recall"
break
case "wx.get_private_file":
logger.info(`${logger.blue(`[${data.self_id}]`)} 私聊文件:[${data.user_id}] ${data.file_name} ${data.file_length} ${data.md5}`)
break
case "wx.get_group_file":
logger.info(`${logger.blue(`[${data.self_id}]`)} 群文件:[${data.group_id}, ${data.user_id}] ${data.file_name} ${data.file_length} ${data.md5}`)
break
case "wx.get_private_redbag":
logger.info(`${logger.blue(`[${data.self_id}]`)} 好友红包:[${data.user_id}]`)
break
case "wx.get_group_redbag":
logger.info(`${logger.blue(`[${data.self_id}]`)} 群红包:[${data.group_id}, ${data.user_id}]`)
break
case "wx.get_private_poke":
data.operator_id = data.from_user_id
data.target_id = data.user_id
logger.info(`${logger.blue(`[${data.self_id}]`)} 好友拍一拍:[${data.operator_id}=>${data.target_id}]`)
break
case "wx.get_group_poke":
data.operator_id = data.from_user_id
data.target_id = data.user_id
logger.info(`${logger.blue(`[${data.self_id}]`)} 群拍一拍:[${data.group_id}, ${data.operator_id}=>${data.target_id}]`)
break
case "wx.get_private_card":
logger.info(`${logger.blue(`[${data.self_id}]`)} 好友用户名片:[${data.user_id}] ${data.v3} ${data.v4} ${data.nickname} ${data.head_url} ${data.province} ${data.city} ${data.sex}`)
break
case "wx.get_group_card":
logger.info(`${logger.blue(`[${data.self_id}]`)} 群用户名片:[${data.group_id}, ${data.user_id}] ${data.v3} ${data.v4} ${data.nickname} ${data.head_url} ${data.province} ${data.city} ${data.sex}`)
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知通知:${logger.magenta(JSON.stringify(data))}`)
}
if (!data.sub_type)
data.sub_type = data.detail_type.split("_").pop()
Bot.emit(`${data.post_type}.${data.notice_type}.${data.sub_type}`, data)
Bot.emit(`${data.post_type}.${data.notice_type}`, data)
Bot.emit(`${data.post_type}`, data)
}
makeRequest(data) {
data.post_type = data.type
if (data.group_id)
data.notice_type = "group"
else
data.notice_type = "friend"
switch (data.detail_type) {
case "wx.friend_request":
logger.info(`${logger.blue(`[${data.self_id}]`)} 加好友请求:[${data.user_id}] ${data.v3} ${data.v4} ${data.nickname} ${data.content} ${data.province} ${data.city}`)
data.sub_type = "add"
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知请求:${logger.magenta(JSON.stringify(data))}`)
}
if (!data.sub_type)
data.sub_type = data.detail_type.split("_").pop()
Bot.emit(`${data.post_type}.${data.request_type}.${data.sub_type}`, data)
Bot.emit(`${data.post_type}.${data.request_type}`, data)
Bot.emit(`${data.post_type}`, data)
}
makeMeta(data) { makeMeta(data) {
switch (data.detail_type) { switch (data.detail_type) {
case "heartbeat": case "heartbeat":
@ -427,14 +505,12 @@ Bot.adapter.push(new class ComWeChatAdapter {
case "message": case "message":
this.makeMessage(data) this.makeMessage(data)
break break
/*
case "notice": case "notice":
this.makeNotice(data) this.makeNotice(data)
break break
case "request": case "request":
this.makeRequest(data) this.makeRequest(data)
break break
*/
default: default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`) logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`)
} }

View File

@ -698,11 +698,11 @@ Bot.adapter.push(new class gocqhttpAdapter {
data.notice_type = "friend" data.notice_type = "friend"
switch (data.sub_type) { switch (data.sub_type) {
case "poke": case "poke":
if (data.group_id)
logger.info(`${logger.blue(`[${data.self_id}]`)} 群戳一戳:[${data.group_id}, ${data.user_id}=>${data.target_id}]`)
else
logger.info(`${logger.blue(`[${data.self_id}]`)} 好友戳一戳:[${data.user_id}=>${data.target_id}]`)
data.operator_id = data.user_id data.operator_id = data.user_id
if (data.group_id)
logger.info(`${logger.blue(`[${data.self_id}]`)} 群戳一戳:[${data.group_id}, ${data.operator_id}=>${data.target_id}]`)
else
logger.info(`${logger.blue(`[${data.self_id}]`)} 好友戳一戳:[${data.operator_id}=>${data.target_id}]`)
break break
case "honor": case "honor":
logger.info(`${logger.blue(`[${data.self_id}]`)} 群荣誉:[${data.group_id}, ${data.user_id}] ${data.honor_type}`) logger.info(`${logger.blue(`[${data.self_id}]`)} 群荣誉:[${data.group_id}, ${data.user_id}] ${data.honor_type}`)

View File

@ -2,7 +2,7 @@ import cfg from '../../lib/config/config.js'
import moment from 'moment' import moment from 'moment'
export class status extends plugin { export class status extends plugin {
constructor () { constructor() {
super({ super({
name: '其他功能', name: '其他功能',
dsc: '#状态', dsc: '#状态',
@ -16,18 +16,13 @@ export class status extends plugin {
}) })
} }
async status () { async status() {
if (this.e.isMaster) return this.statusMaster() if (this.e.isMaster) return this.statusMaster()
if (!this.e.isGroup) return this.reply('请群聊查看')
if (!this.e.isGroup) {
this.reply('请群聊查看')
return
}
return this.statusGroup() return this.statusGroup()
} }
async statusMaster () { async statusMaster() {
let runTime = moment().diff(moment.unix(this.e.bot.stat.start_time), 'seconds') let runTime = moment().diff(moment.unix(this.e.bot.stat.start_time), 'seconds')
let Day = Math.floor(runTime / 3600 / 24) let Day = Math.floor(runTime / 3600 / 24)
let Hour = Math.floor((runTime / 3600) % 24) let Hour = Math.floor((runTime / 3600) % 24)
@ -52,22 +47,20 @@ export class status extends plugin {
await this.reply(msg) await this.reply(msg)
} }
async statusGroup () { async statusGroup() {
let msg = '-------状态-------' let msg = '-------状态-------'
msg += await this.getCount(this.e.group_id) msg += await this.getCount(this.e.group_id)
await this.reply(msg) await this.reply(msg)
} }
async getCount (groupId = '') { async getCount(groupId = '') {
this.date = moment().format('MMDD') this.date = moment().format('MMDD')
this.month = Number(moment().month()) + 1 this.month = Number(moment().month()) + 1
this.key = 'Yz:count:' this.key = 'Yz:count:'
if (groupId) { if (groupId) this.key += `group:${groupId}:`
this.key += `group:${groupId}:`
}
this.msgKey = { this.msgKey = {
day: `${this.key}sendMsg:day:`, day: `${this.key}sendMsg:day:`,