适配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:
		
							parent
							
								
									43430b077a
								
							
						
					
					
						commit
						f34240511b
					
				|  | @ -61,19 +61,19 @@ function mkdirs (dirname) { | |||
| 
 | ||||
| /** | ||||
|  * 制作转发消息 | ||||
|  * @param e icqq消息e | ||||
|  * @param e 消息事件 | ||||
|  * @param msg 消息数组 | ||||
|  * @param dec 转发描述 | ||||
|  * @param msgsscr 转发信息是否为Bot | ||||
|  */ | ||||
| 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 id = msgsscr ? this.e.user_id : Bot.uin | ||||
| 
 | ||||
|   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 = { | ||||
|  | @ -82,29 +82,35 @@ async function makeForwardMsg (e, msg = [], dec = '', msgsscr = false) { | |||
|   } | ||||
| 
 | ||||
|   let forwardMsg = [] | ||||
|   msg.forEach(msg => { | ||||
|   for (const message of msg) | ||||
|     forwardMsg.push({ | ||||
|       ...userInfo, | ||||
|       message: msg | ||||
|     }) | ||||
|       message | ||||
|     }) | ||||
| 
 | ||||
|   /** 制作转发内容 */ | ||||
|   if (e.isGroup) { | ||||
|   if (e?.group?.makeForwardMsg) { | ||||
|     forwardMsg = await e.group.makeForwardMsg(forwardMsg) | ||||
|   } else if (e.friend) { | ||||
|   } else if (e?.friend?.makeForwardMsg) { | ||||
|     forwardMsg = await e.friend.makeForwardMsg(forwardMsg) | ||||
|   } else { | ||||
|     return false | ||||
|     return msg.join('\n') | ||||
|   } | ||||
| 
 | ||||
|   if (dec) { | ||||
|     /** 处理描述 */ | ||||
|     if (typeof (forwardMsg.data) === 'object') { | ||||
|       let detail = forwardMsg.data?.meta?.detail | ||||
|       if (detail) { | ||||
|         detail.news = [{ text: dec }] | ||||
|       } | ||||
|     } else { | ||||
|       forwardMsg.data = forwardMsg.data | ||||
|         .replace(/\n/g, '') | ||||
|         .replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___') | ||||
|         .replace(/___+/, `<title color="#777777" size="26">${dec}</title>`) | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   return forwardMsg | ||||
| } | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| import plugin from '../../../lib/plugins/plugin.js' | ||||
| import common from '../../../lib/common/common.js' | ||||
| import fs from 'node:fs' | ||||
| import gsCfg from '../model/gsCfg.js' | ||||
| import YAML from 'yaml' | ||||
|  | @ -125,8 +126,7 @@ export class abbrSet extends plugin { | |||
|   } | ||||
| 
 | ||||
|   async delAbbr() { | ||||
|     let role = gsCfg.getRole(this.e.msg, '#|星铁|删除|别名|昵称', this.e.isSr) | ||||
| 
 | ||||
|     let role = gsCfg.getRole(this.e.msg, '#|删除|别名|昵称') | ||||
|     if (!role) return false | ||||
| 
 | ||||
|     let nameArr = gsCfg.getConfig('role', 'name') | ||||
|  | @ -164,7 +164,7 @@ export class abbrSet extends plugin { | |||
| 
 | ||||
|     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) | ||||
|   } | ||||
|  |  | |||
|  | @ -64,11 +64,6 @@ export default class GachaLog extends base { | |||
|     MakeMsg.push(tmpMsg) | ||||
|     MakeMsg.push(`抽卡记录更新完成,您还可回复\n【#${this?.e?.isSr?'星铁光锥':'武器'}记录】统计${this?.e?.isSr?'星铁光锥':'武器'}池数据\n【#${this?.e?.isSr?'星铁':''}角色统计】按卡池统计数据\n【#导出记录】导出记录数据`) | ||||
|     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) | ||||
| 
 | ||||
|     this.isLogUrl = true | ||||
|  |  | |||
|  | @ -177,7 +177,7 @@ export default class MysInfo { | |||
|       } | ||||
| 
 | ||||
|       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 | ||||
| 
 | ||||
|  | @ -185,7 +185,7 @@ export default class MysInfo { | |||
|       } | ||||
|     } else { | ||||
|       res = await mysApi.getData(api, data) | ||||
|       res = await mysInfo.checkCode(res, api) | ||||
|       res = await mysInfo.checkCode(res, api, mysApi) | ||||
|     } | ||||
| 
 | ||||
|     return res | ||||
|  | @ -335,7 +335,7 @@ export default class MysInfo { | |||
|     return this.ckUser?.ck | ||||
|   } | ||||
| 
 | ||||
|   async checkCode(res, type) { | ||||
|   async checkCode(res, type, mysApi = {}) { | ||||
|     if (!res) { | ||||
|       this.e.reply('米游社接口请求失败,暂时无法查询') | ||||
|       return false | ||||
|  |  | |||
|  | @ -264,9 +264,7 @@ export default class MysNews extends base { | |||
|       return img[0] | ||||
|     } else { | ||||
|       let msg = [titile, ...img] | ||||
|       return await common.makeForwardMsg(this.e, msg, titile).catch((err) => { | ||||
|         logger.error(err) | ||||
|       }) | ||||
|       return await common.makeForwardMsg(this.e, msg, titile) | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -186,9 +186,7 @@ export default class MysSrNews extends base { | |||
|       return img[0] | ||||
|     } else { | ||||
|       let msg = [titile, ...img] | ||||
|       return await common.makeForwardMsg(this.e, msg, titile).catch((err) => { | ||||
|         logger.error(err) | ||||
|       }) | ||||
|       return await common.makeForwardMsg(this.e, msg, titile) | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| import plugin from '../../lib/plugins/plugin.js' | ||||
| import common from '../../lib/common/common.js' | ||||
| import fs from 'node:fs' | ||||
| import lodash from 'lodash' | ||||
| import moment from 'moment' | ||||
|  | @ -49,7 +50,7 @@ export class sendLog extends plugin { | |||
|       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) | ||||
|   } | ||||
|  | @ -78,42 +79,4 @@ export class sendLog extends plugin { | |||
| 
 | ||||
|     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 | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -80,9 +80,7 @@ export class update extends plugin { | |||
|       if (!plugin) return '' | ||||
|     } | ||||
| 
 | ||||
|     let path = `./plugins/${plugin}/.git` | ||||
| 
 | ||||
|     if (!fs.existsSync(path)) return false | ||||
|     if (!fs.existsSync(`plugins/${plugin}/.git`)) return false | ||||
| 
 | ||||
|     this.typeName = plugin | ||||
|     return plugin | ||||
|  | @ -104,16 +102,14 @@ export class update extends plugin { | |||
|     let type = '更新' | ||||
|     if (this.e.msg.includes('强制')) { | ||||
|       type = '强制更新' | ||||
|       cm = `git fetch --all && git reset --hard && ${cm}` | ||||
|       cm = `git reset --hard && git pull --rebase --allow-unrelated-histories` | ||||
|     } | ||||
| 
 | ||||
|     if (plugin) { | ||||
|       if (this.e.msg.includes('强制')) { | ||||
|         type = '强制更新' | ||||
|         cm = `git -C ./plugins/${plugin}/ fetch --all && git -C ./plugins/${plugin}/ reset --hard && git -C ./plugins/${plugin}/ pull` | ||||
|       }else{ | ||||
|         cm =  `git -C ./plugins/${plugin}/ pull --no-rebase` | ||||
|       } | ||||
|       if (type == '强制更新') | ||||
|         cm = `cd "plugins/${plugin}" && git reset --hard && git pull --rebase --allow-unrelated-histories` | ||||
|       else | ||||
|         cm = `cd "plugins/${plugin}" && git pull --no-rebase` | ||||
|     } | ||||
| 
 | ||||
|     this.oldCommitId = await this.getcommitId(plugin) | ||||
|  | @ -150,7 +146,7 @@ export class update extends plugin { | |||
|   async getcommitId(plugin = '') { | ||||
|     let cm = 'git rev-parse --short HEAD' | ||||
|     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' }) | ||||
|  | @ -160,9 +156,9 @@ export class update extends 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) { | ||||
|       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 = '' | ||||
|  | @ -230,9 +226,9 @@ export class update extends 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) { | ||||
|       cm = `cd ./plugins/${plugin}/ && ${cm}` | ||||
|       cm = `cd "plugins/${plugin}" && ${cm}` | ||||
|     } | ||||
| 
 | ||||
|     let logAll | ||||
|  | @ -261,56 +257,11 @@ export class update extends plugin { | |||
| 
 | ||||
|     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 | ||||
|   } | ||||
| 
 | ||||
|   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() { | ||||
|     let log = await this.getLog() | ||||
|     await this.reply(log) | ||||
|  |  | |||
|  | @ -1,9 +1,8 @@ | |||
| 
 | ||||
| import cfg from '../../lib/config/config.js' | ||||
| import plugin from '../../lib/plugins/plugin.js' | ||||
| import common from '../../lib/common/common.js' | ||||
| import fs from 'node:fs' | ||||
| import lodash from 'lodash' | ||||
| import { segment } from 'icqq' | ||||
| import { pipeline } from 'stream' | ||||
| import { promisify } from 'util' | ||||
| import fetch from 'node-fetch' | ||||
|  | @ -96,7 +95,6 @@ export class add extends plugin { | |||
| 
 | ||||
|   /** 获取群号 */ | ||||
|   async getGroupId() { | ||||
|      | ||||
|     /** 添加全局表情,存入到机器人qq文件中 */ | ||||
|     if (this.isGlobal) { | ||||
|       this.group_id = this.e.bot.uin; | ||||
|  | @ -727,9 +725,8 @@ export class add extends plugin { | |||
|       num++ | ||||
|     } | ||||
| 
 | ||||
|     let end = '' | ||||
|     if (type == 'list' && count > 100) { | ||||
|       end = `更多内容请翻页查看\n如:#表情列表${Number(page) + 1}` | ||||
|       msg.push(`更多内容请翻页查看\n如:#表情列表${Number(page) + 1}`) | ||||
|     } | ||||
| 
 | ||||
|     let title = `表情列表,第${page}页,共${count}条` | ||||
|  | @ -737,55 +734,11 @@ export class add extends plugin { | |||
|       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) | ||||
|   } | ||||
| 
 | ||||
|   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) { | ||||
|     let offset = (pageNo - 1) * pageSize | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue