适配icqq0.4.12的转发消息、checkCode增加mysApi参数,方便处理验证码。 (#211)

* 适配icqq0.4.12的转发消息。

* 优化 转发消息全部调用 common.makeForwardMsg

* checkCode增加mysApi参数,方便处理验证码。

* fix

* 。。。

* 。

---------

Co-authored-by: 🌌 <Time.Rain.Star.Sky@Gmail.com>
Co-authored-by: Kokomi <102026640+yoimiya-kokomi@users.noreply.github.com>
This commit is contained in:
小飞 2023-07-26 05:23:14 +08:00 committed by GitHub
parent 43430b077a
commit f34240511b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 97 additions and 233 deletions

View File

@ -61,19 +61,19 @@ function mkdirs (dirname) {
/** /**
* 制作转发消息 * 制作转发消息
* @param e icqq消息e * @param e 消息事件
* @param msg 消息数组 * @param msg 消息数组
* @param dec 转发描述 * @param dec 转发描述
* @param msgsscr 转发信息是否为Bot * @param msgsscr 转发信息是否为Bot
*/ */
async function makeForwardMsg(e, msg = [], dec = '', msgsscr = false) { async function makeForwardMsg(e, msg = [], dec = '', msgsscr = false) {
// 是频道直接返回 join
if (e.isGuild) return msg.join('\n')
let name = msgsscr ? this.e.sender.card || this.e.user_id : Bot.nickname let name = msgsscr ? this.e.sender.card || this.e.user_id : Bot.nickname
let id = msgsscr ? this.e.user_id : Bot.uin let id = msgsscr ? this.e.user_id : Bot.uin
if (e.isGroup) { if (e.isGroup) {
let info = await e.bot.getGroupMemberInfo(e.group_id, e.bot.uin) let info = await e.bot.getGroupMemberInfo(e.group_id, id)
name = info.card || info.nickname
} }
let userInfo = { let userInfo = {
@ -82,29 +82,35 @@ async function makeForwardMsg (e, msg = [], dec = '', msgsscr = false) {
} }
let forwardMsg = [] let forwardMsg = []
msg.forEach(msg => { for (const message of msg)
forwardMsg.push({ forwardMsg.push({
...userInfo, ...userInfo,
message: msg message
})
}) })
/** 制作转发内容 */ /** 制作转发内容 */
if (e.isGroup) { if (e?.group?.makeForwardMsg) {
forwardMsg = await e.group.makeForwardMsg(forwardMsg) forwardMsg = await e.group.makeForwardMsg(forwardMsg)
} else if (e.friend) { } else if (e?.friend?.makeForwardMsg) {
forwardMsg = await e.friend.makeForwardMsg(forwardMsg) forwardMsg = await e.friend.makeForwardMsg(forwardMsg)
} else { } else {
return false return msg.join('\n')
} }
if (dec) { if (dec) {
/** 处理描述 */ /** 处理描述 */
if (typeof (forwardMsg.data) === 'object') {
let detail = forwardMsg.data?.meta?.detail
if (detail) {
detail.news = [{ text: dec }]
}
} else {
forwardMsg.data = forwardMsg.data forwardMsg.data = forwardMsg.data
.replace(/\n/g, '') .replace(/\n/g, '')
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___') .replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
.replace(/___+/, `<title color="#777777" size="26">${dec}</title>`) .replace(/___+/, `<title color="#777777" size="26">${dec}</title>`)
} }
}
return forwardMsg return forwardMsg
} }

View File

@ -1,4 +1,5 @@
import plugin from '../../../lib/plugins/plugin.js' import plugin from '../../../lib/plugins/plugin.js'
import common from '../../../lib/common/common.js'
import fs from 'node:fs' import fs from 'node:fs'
import gsCfg from '../model/gsCfg.js' import gsCfg from '../model/gsCfg.js'
import YAML from 'yaml' import YAML from 'yaml'
@ -125,8 +126,7 @@ export class abbrSet extends plugin {
} }
async delAbbr() { async delAbbr() {
let role = gsCfg.getRole(this.e.msg, '#|星铁|删除|别名|昵称', this.e.isSr) let role = gsCfg.getRole(this.e.msg, '#|删除|别名|昵称')
if (!role) return false if (!role) return false
let nameArr = gsCfg.getConfig('role', 'name') let nameArr = gsCfg.getConfig('role', 'name')
@ -164,7 +164,7 @@ export class abbrSet extends plugin {
let title = `${role.name}别名,${list.length}` let title = `${role.name}别名,${list.length}`
msg = await this.makeForwardMsg(this.e.bot.uin, title, msg) msg = await common.makeForwardMsg(this.e, msg, title)
await this.e.reply(msg) await this.e.reply(msg)
} }

View File

@ -64,11 +64,6 @@ export default class GachaLog extends base {
MakeMsg.push(tmpMsg) MakeMsg.push(tmpMsg)
MakeMsg.push(`抽卡记录更新完成,您还可回复\n【#${this?.e?.isSr?'星铁光锥':'武器'}记录】统计${this?.e?.isSr?'星铁光锥':'武器'}池数据\n【#${this?.e?.isSr?'星铁':''}角色统计】按卡池统计数据\n【#导出记录】导出记录数据`) MakeMsg.push(`抽卡记录更新完成,您还可回复\n【#${this?.e?.isSr?'星铁光锥':'武器'}记录】统计${this?.e?.isSr?'星铁光锥':'武器'}池数据\n【#${this?.e?.isSr?'星铁':''}角色统计】按卡池统计数据\n【#导出记录】导出记录数据`)
let Msg = await common.makeForwardMsg(this.e, MakeMsg, tmpMsg) let Msg = await common.makeForwardMsg(this.e, MakeMsg, tmpMsg)
Msg.data=Msg.data
.replace(/\n/g, '')
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
.replace(/___+/, `<title color="#777777" size="26">${tmpMsg}</title>`)
await this.e.reply(Msg) await this.e.reply(Msg)
this.isLogUrl = true this.isLogUrl = true

View File

@ -177,7 +177,7 @@ export default class MysInfo {
} }
for (let i in res) { for (let i in res) {
res[i] = await mysInfo.checkCode(res[i], res[i].api) res[i] = await mysInfo.checkCode(res[i], res[i].api, mysApi)
if (res[i]?.retcode === 0) continue if (res[i]?.retcode === 0) continue
@ -185,7 +185,7 @@ export default class MysInfo {
} }
} else { } else {
res = await mysApi.getData(api, data) res = await mysApi.getData(api, data)
res = await mysInfo.checkCode(res, api) res = await mysInfo.checkCode(res, api, mysApi)
} }
return res return res
@ -335,7 +335,7 @@ export default class MysInfo {
return this.ckUser?.ck return this.ckUser?.ck
} }
async checkCode(res, type) { async checkCode(res, type, mysApi = {}) {
if (!res) { if (!res) {
this.e.reply('米游社接口请求失败,暂时无法查询') this.e.reply('米游社接口请求失败,暂时无法查询')
return false return false

View File

@ -264,9 +264,7 @@ export default class MysNews extends base {
return img[0] return img[0]
} else { } else {
let msg = [titile, ...img] let msg = [titile, ...img]
return await common.makeForwardMsg(this.e, msg, titile).catch((err) => { return await common.makeForwardMsg(this.e, msg, titile)
logger.error(err)
})
} }
} }

View File

@ -186,9 +186,7 @@ export default class MysSrNews extends base {
return img[0] return img[0]
} else { } else {
let msg = [titile, ...img] let msg = [titile, ...img]
return await common.makeForwardMsg(this.e, msg, titile).catch((err) => { return await common.makeForwardMsg(this.e, msg, titile)
logger.error(err)
})
} }
} }

View File

@ -1,4 +1,5 @@
import plugin from '../../lib/plugins/plugin.js' import plugin from '../../lib/plugins/plugin.js'
import common from '../../lib/common/common.js'
import fs from 'node:fs' import fs from 'node:fs'
import lodash from 'lodash' import lodash from 'lodash'
import moment from 'moment' import moment from 'moment'
@ -49,7 +50,7 @@ export class sendLog extends plugin {
return return
} }
let forwardMsg = await this.makeForwardMsg(`最近${log.length}${type}日志`, log) let forwardMsg = await common.makeForwardMsg(this.e, log, `最近${log.length}${type}日志`)
await this.reply(forwardMsg) await this.reply(forwardMsg)
} }
@ -78,42 +79,4 @@ export class sendLog extends plugin {
return tmp return tmp
} }
async makeForwardMsg (title, msg) {
let nickname = this.e.bot.nickname
if (this.e.isGroup) {
let info = await this.e.bot.getGroupMemberInfo(this.e.group_id, this.e.bot.uin)
nickname = info.card ?? info.nickname
}
let userInfo = {
user_id: this.e.bot.uin,
nickname
}
let forwardMsg = [
{
...userInfo,
message: title
},
{
...userInfo,
message: msg
}
]
/** 制作转发内容 */
if (this.e.isGroup) {
forwardMsg = await this.e.group.makeForwardMsg(forwardMsg)
} else {
forwardMsg = await this.e.friend.makeForwardMsg(forwardMsg)
}
/** 处理描述 */
forwardMsg.data = forwardMsg.data
.replace(/\n/g, '')
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
.replace(/___+/, `<title color="#777777" size="26">${title}</title>`)
return forwardMsg
}
} }

View File

@ -80,9 +80,7 @@ export class update extends plugin {
if (!plugin) return '' if (!plugin) return ''
} }
let path = `./plugins/${plugin}/.git` if (!fs.existsSync(`plugins/${plugin}/.git`)) return false
if (!fs.existsSync(path)) return false
this.typeName = plugin this.typeName = plugin
return plugin return plugin
@ -104,16 +102,14 @@ export class update extends plugin {
let type = '更新' let type = '更新'
if (this.e.msg.includes('强制')) { if (this.e.msg.includes('强制')) {
type = '强制更新' type = '强制更新'
cm = `git fetch --all && git reset --hard && ${cm}` cm = `git reset --hard && git pull --rebase --allow-unrelated-histories`
} }
if (plugin) { if (plugin) {
if (this.e.msg.includes('强制')) { if (type == '强制更新')
type = '强制更新' cm = `cd "plugins/${plugin}" && git reset --hard && git pull --rebase --allow-unrelated-histories`
cm = `git -C ./plugins/${plugin}/ fetch --all && git -C ./plugins/${plugin}/ reset --hard && git -C ./plugins/${plugin}/ pull` else
}else{ cm = `cd "plugins/${plugin}" && git pull --no-rebase`
cm = `git -C ./plugins/${plugin}/ pull --no-rebase`
}
} }
this.oldCommitId = await this.getcommitId(plugin) this.oldCommitId = await this.getcommitId(plugin)
@ -150,7 +146,7 @@ export class update extends plugin {
async getcommitId(plugin = '') { async getcommitId(plugin = '') {
let cm = 'git rev-parse --short HEAD' let cm = 'git rev-parse --short HEAD'
if (plugin) { if (plugin) {
cm = `git -C ./plugins/${plugin}/ rev-parse --short HEAD` cm = `cd "plugins/${plugin}" && git rev-parse --short HEAD`
} }
let commitId = await execSync(cm, { encoding: 'utf-8' }) let commitId = await execSync(cm, { encoding: 'utf-8' })
@ -160,9 +156,9 @@ export class update extends plugin {
} }
async getTime(plugin = '') { async getTime(plugin = '') {
let cm = 'git log -1 --oneline --pretty=format:"%cd" --date=format:"%m-%d %H:%M"' let cm = 'git log -1 --pretty=format:"%cd" --date=format:"%F %T"'
if (plugin) { if (plugin) {
cm = `cd ./plugins/${plugin}/ && git log -1 --oneline --pretty=format:"%cd" --date=format:"%m-%d %H:%M"` cm = `cd "plugins/${plugin}" && git log -1 --pretty=format:"%cd" --date=format:"%F %T"`
} }
let time = '' let time = ''
@ -230,9 +226,9 @@ export class update extends plugin {
} }
async getLog(plugin = '') { async getLog(plugin = '') {
let cm = 'git log -20 --oneline --pretty=format:"%h||[%cd] %s" --date=format:"%m-%d %H:%M"' let cm = 'git log -20 --pretty=format:"%h||[%cd] %s" --date=format:"%F %T"'
if (plugin) { if (plugin) {
cm = `cd ./plugins/${plugin}/ && ${cm}` cm = `cd "plugins/${plugin}" && ${cm}`
} }
let logAll let logAll
@ -261,56 +257,11 @@ export class update extends plugin {
let end = '' let end = ''
log = await this.makeForwardMsg(`${plugin || 'Miao-Yunzai'}更新日志,共${line}`, log, end) log = await common.makeForwardMsg(this.e, [log, end], `${plugin || 'Miao-Yunzai'}更新日志,共${line}`)
return log return log
} }
async makeForwardMsg (title, msg, end) {
let nickname = this.e.bot.nickname
if (this.e.isGroup) {
let info = await this.e.bot.getGroupMemberInfo(this.e.group_id, this.e.bot.uin)
nickname = info.card ?? info.nickname
}
let userInfo = {
user_id: this.e.bot.uin,
nickname
}
let forwardMsg = [
{
...userInfo,
message: title
},
{
...userInfo,
message: msg
}
]
if (end) {
forwardMsg.push({
...userInfo,
message: end
})
}
/** 制作转发内容 */
if (this.e.isGroup) {
forwardMsg = await this.e.group.makeForwardMsg(forwardMsg)
} else {
forwardMsg = await this.e.friend.makeForwardMsg(forwardMsg)
}
/** 处理描述 */
forwardMsg.data = forwardMsg.data
.replace(/\n/g, '')
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
.replace(/___+/, `<title color="#777777" size="26">${title}</title>`)
return forwardMsg
}
async updateLog() { async updateLog() {
let log = await this.getLog() let log = await this.getLog()
await this.reply(log) await this.reply(log)

View File

@ -1,9 +1,8 @@
import cfg from '../../lib/config/config.js' import cfg from '../../lib/config/config.js'
import plugin from '../../lib/plugins/plugin.js' import plugin from '../../lib/plugins/plugin.js'
import common from '../../lib/common/common.js'
import fs from 'node:fs' import fs from 'node:fs'
import lodash from 'lodash' import lodash from 'lodash'
import { segment } from 'icqq'
import { pipeline } from 'stream' import { pipeline } from 'stream'
import { promisify } from 'util' import { promisify } from 'util'
import fetch from 'node-fetch' import fetch from 'node-fetch'
@ -96,7 +95,6 @@ export class add extends plugin {
/** 获取群号 */ /** 获取群号 */
async getGroupId() { async getGroupId() {
/** 添加全局表情存入到机器人qq文件中 */ /** 添加全局表情存入到机器人qq文件中 */
if (this.isGlobal) { if (this.isGlobal) {
this.group_id = this.e.bot.uin; this.group_id = this.e.bot.uin;
@ -727,9 +725,8 @@ export class add extends plugin {
num++ num++
} }
let end = ''
if (type == 'list' && count > 100) { if (type == 'list' && count > 100) {
end = `更多内容请翻页查看\n如:#表情列表${Number(page) + 1}` msg.push(`更多内容请翻页查看\n如:#表情列表${Number(page) + 1}`)
} }
let title = `表情列表,第${page}页,共${count}` let title = `表情列表,第${page}页,共${count}`
@ -737,55 +734,11 @@ export class add extends plugin {
title = `表情${search}${count}` title = `表情${search}${count}`
} }
let forwardMsg = await this.makeForwardMsg(this.e.bot.uin, title, msg, end) let forwardMsg = await common.makeForwardMsg(this.e, msg, title)
this.e.reply(forwardMsg) this.e.reply(forwardMsg)
} }
async makeForwardMsg (qq, title, msg, end = '') {
let nickname = this.e.bot.nickname
if (this.e.isGroup) {
let info = await this.e.bot.getGroupMemberInfo(this.e.group_id, qq)
nickname = info.card ?? info.nickname
}
let userInfo = {
user_id: this.e.bot.uin,
nickname
}
let forwardMsg = [
{
...userInfo,
message: title
}
]
let msgArr = lodash.chunk(msg, 40)
msgArr.forEach(v => {
v[v.length - 1] = lodash.trim(v[v.length - 1], '\n')
forwardMsg.push({ ...userInfo, message: v })
})
if (end) {
forwardMsg.push({ ...userInfo, message: end })
}
/** 制作转发内容 */
if (this.e.isGroup) {
forwardMsg = await this.e.group.makeForwardMsg(forwardMsg)
} else {
forwardMsg = await this.e.friend.makeForwardMsg(forwardMsg)
}
/** 处理描述 */
forwardMsg.data = forwardMsg.data
.replace(/\n/g, '')
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
.replace(/___+/, `<title color="#777777" size="26">${title}</title>`)
return forwardMsg
}
/** 分页 */ /** 分页 */
pagination(pageNo, pageSize, array) { pagination(pageNo, pageSize, array) {
let offset = (pageNo - 1) * pageSize let offset = (pageNo - 1) * pageSize