适配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
|
@ -9,7 +9,7 @@ import path from 'node:path'
|
||||||
* @param user_id qq号
|
* @param user_id qq号
|
||||||
* @param msg 消息
|
* @param msg 消息
|
||||||
*/
|
*/
|
||||||
async function relpyPrivate (userId, msg) {
|
async function relpyPrivate(userId, msg) {
|
||||||
userId = Number(userId)
|
userId = Number(userId)
|
||||||
|
|
||||||
let friend = Bot.fl.get(userId)
|
let friend = Bot.fl.get(userId)
|
||||||
|
@ -25,7 +25,7 @@ async function relpyPrivate (userId, msg) {
|
||||||
* 休眠函数
|
* 休眠函数
|
||||||
* @param ms 毫秒
|
* @param ms 毫秒
|
||||||
*/
|
*/
|
||||||
function sleep (ms) {
|
function sleep(ms) {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ function sleep (ms) {
|
||||||
* @param fileUrl 下载地址
|
* @param fileUrl 下载地址
|
||||||
* @param savePath 保存路径
|
* @param savePath 保存路径
|
||||||
*/
|
*/
|
||||||
async function downFile (fileUrl, savePath, param = {}) {
|
async function downFile(fileUrl, savePath, param = {}) {
|
||||||
try {
|
try {
|
||||||
mkdirs(path.dirname(savePath))
|
mkdirs(path.dirname(savePath))
|
||||||
logger.debug(`[下载文件] ${fileUrl}`)
|
logger.debug(`[下载文件] ${fileUrl}`)
|
||||||
|
@ -48,7 +48,7 @@ async function downFile (fileUrl, savePath, param = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mkdirs (dirname) {
|
function mkdirs(dirname) {
|
||||||
if (fs.existsSync(dirname)) {
|
if (fs.existsSync(dirname)) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
@ -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,28 +82,34 @@ 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) {
|
||||||
/** 处理描述 */
|
/** 处理描述 */
|
||||||
forwardMsg.data = forwardMsg.data
|
if (typeof (forwardMsg.data) === 'object') {
|
||||||
.replace(/\n/g, '')
|
let detail = forwardMsg.data?.meta?.detail
|
||||||
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
|
if (detail) {
|
||||||
.replace(/___+/, `<title color="#777777" size="26">${dec}</title>`)
|
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
|
return forwardMsg
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
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'
|
||||||
|
|
||||||
export class sendLog extends plugin {
|
export class sendLog extends plugin {
|
||||||
constructor () {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
name: '发送日志',
|
name: '发送日志',
|
||||||
dsc: '发送最近100条运行日志',
|
dsc: '发送最近100条运行日志',
|
||||||
|
@ -25,7 +26,7 @@ export class sendLog extends plugin {
|
||||||
this.errFile = './logs/error.log'
|
this.errFile = './logs/error.log'
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendLog () {
|
async sendLog() {
|
||||||
let lineNum = this.e.msg.match(/\d+/g)
|
let lineNum = this.e.msg.match(/\d+/g)
|
||||||
if (lineNum) {
|
if (lineNum) {
|
||||||
this.lineNum = lineNum[0]
|
this.lineNum = lineNum[0]
|
||||||
|
@ -49,12 +50,12 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
getLog (logFile) {
|
getLog(logFile) {
|
||||||
let log = fs.readFileSync(logFile, { encoding: 'utf-8' })
|
let log = fs.readFileSync(logFile, { encoding: 'utf-8' })
|
||||||
log = log.split('\n')
|
log = log.split('\n')
|
||||||
|
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ const { exec, execSync } = require('child_process')
|
||||||
let uping = false
|
let uping = false
|
||||||
|
|
||||||
export class update extends plugin {
|
export class update extends plugin {
|
||||||
constructor () {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
name: '更新',
|
name: '更新',
|
||||||
dsc: '#更新 #强制更新',
|
dsc: '#更新 #强制更新',
|
||||||
|
@ -37,7 +37,7 @@ export class update extends plugin {
|
||||||
this.typeName = 'Miao-Yunzai'
|
this.typeName = 'Miao-Yunzai'
|
||||||
}
|
}
|
||||||
|
|
||||||
async update () {
|
async update() {
|
||||||
if (!this.e.isMaster) return false
|
if (!this.e.isMaster) return false
|
||||||
if (uping) {
|
if (uping) {
|
||||||
await this.reply('已有命令更新中..请勿重复操作')
|
await this.reply('已有命令更新中..请勿重复操作')
|
||||||
|
@ -64,7 +64,7 @@ export class update extends plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkGit () {
|
async checkGit() {
|
||||||
let ret = await execSync('git --version', { encoding: 'utf-8' })
|
let ret = await execSync('git --version', { encoding: 'utf-8' })
|
||||||
if (!ret || !ret.includes('git version')) {
|
if (!ret || !ret.includes('git version')) {
|
||||||
await this.reply('请先安装git')
|
await this.reply('请先安装git')
|
||||||
|
@ -74,21 +74,19 @@ export class update extends plugin {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlugin (plugin = '') {
|
getPlugin(plugin = '') {
|
||||||
if (!plugin) {
|
if (!plugin) {
|
||||||
plugin = this.e.msg.replace(/#|更新|强制/g, '')
|
plugin = this.e.msg.replace(/#|更新|强制/g, '')
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
async execSync (cmd) {
|
async execSync(cmd) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
exec(cmd, { windowsHide: true }, (error, stdout, stderr) => {
|
exec(cmd, { windowsHide: true }, (error, stdout, stderr) => {
|
||||||
resolve({ error, stdout, stderr })
|
resolve({ error, stdout, stderr })
|
||||||
|
@ -96,7 +94,7 @@ export class update extends plugin {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async runUpdate (plugin = '') {
|
async runUpdate(plugin = '') {
|
||||||
this.isNowUp = false
|
this.isNowUp = false
|
||||||
|
|
||||||
let cm = 'git pull --no-rebase'
|
let cm = 'git pull --no-rebase'
|
||||||
|
@ -104,17 +102,15 @@ 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)
|
||||||
|
|
||||||
|
@ -147,10 +143,10 @@ export class update extends plugin {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
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' })
|
||||||
|
@ -159,10 +155,10 @@ export class update extends plugin {
|
||||||
return commitId
|
return commitId
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = ''
|
||||||
|
@ -177,7 +173,7 @@ export class update extends plugin {
|
||||||
return time
|
return time
|
||||||
}
|
}
|
||||||
|
|
||||||
async gitErr (err, stdout) {
|
async gitErr(err, stdout) {
|
||||||
let msg = '更新失败!'
|
let msg = '更新失败!'
|
||||||
let errMsg = err.toString()
|
let errMsg = err.toString()
|
||||||
stdout = stdout.toString()
|
stdout = stdout.toString()
|
||||||
|
@ -207,7 +203,7 @@ export class update extends plugin {
|
||||||
await this.reply([errMsg, stdout])
|
await this.reply([errMsg, stdout])
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateAll () {
|
async updateAll() {
|
||||||
let dirs = fs.readdirSync('./plugins/')
|
let dirs = fs.readdirSync('./plugins/')
|
||||||
|
|
||||||
await this.runUpdate()
|
await this.runUpdate()
|
||||||
|
@ -225,14 +221,14 @@ export class update extends plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
restart () {
|
restart() {
|
||||||
new Restart(this.e).restart()
|
new Restart(this.e).restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
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,57 +257,12 @@ 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) {
|
async updateLog() {
|
||||||
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()
|
let log = await this.getLog()
|
||||||
await this.reply(log)
|
await this.reply(log)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'
|
||||||
|
@ -12,7 +11,7 @@ import moment from 'moment'
|
||||||
let textArr = {}
|
let textArr = {}
|
||||||
|
|
||||||
export class add extends plugin {
|
export class add extends plugin {
|
||||||
constructor () {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
name: '添加表情',
|
name: '添加表情',
|
||||||
dsc: '添加表情,文字等',
|
dsc: '添加表情,文字等',
|
||||||
|
@ -45,7 +44,7 @@ export class add extends plugin {
|
||||||
this.isGlobal = false
|
this.isGlobal = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async init () {
|
async init() {
|
||||||
if (!fs.existsSync(this.path)) {
|
if (!fs.existsSync(this.path)) {
|
||||||
fs.mkdirSync(this.path)
|
fs.mkdirSync(this.path)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +53,7 @@ export class add extends plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async accept () {
|
async accept() {
|
||||||
/** 处理消息 */
|
/** 处理消息 */
|
||||||
if (this.e.atBot && this.e.msg && this.e?.msg.includes('添加') && !this.e?.msg.includes('#')) {
|
if (this.e.atBot && this.e.msg && this.e?.msg.includes('添加') && !this.e?.msg.includes('#')) {
|
||||||
this.e.msg = '#' + this.e.msg
|
this.e.msg = '#' + this.e.msg
|
||||||
|
@ -62,12 +61,12 @@ export class add extends plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 群号key */
|
/** 群号key */
|
||||||
get grpKey () {
|
get grpKey() {
|
||||||
return `Yz:group_id:${this.e.user_id}`
|
return `Yz:group_id:${this.e.user_id}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/** #添加 */
|
/** #添加 */
|
||||||
async add () {
|
async add() {
|
||||||
this.isGlobal = this.e?.msg.includes("全局");
|
this.isGlobal = this.e?.msg.includes("全局");
|
||||||
await this.getGroupId()
|
await this.getGroupId()
|
||||||
|
|
||||||
|
@ -95,8 +94,7 @@ 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;
|
||||||
|
@ -119,7 +117,7 @@ export class add extends plugin {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
checkAuth () {
|
checkAuth() {
|
||||||
if (this.e.isMaster) return true
|
if (this.e.isMaster) return true
|
||||||
|
|
||||||
let groupCfg = cfg.getGroup(this.group_id)
|
let groupCfg = cfg.getGroup(this.group_id)
|
||||||
|
@ -148,7 +146,7 @@ export class add extends plugin {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
checkKeyWord () {
|
checkKeyWord() {
|
||||||
if (this.e.img && this.e.img.length > 1) {
|
if (this.e.img && this.e.img.length > 1) {
|
||||||
this.e.reply('添加错误:只能发送一个表情当关键词')
|
this.e.reply('添加错误:只能发送一个表情当关键词')
|
||||||
return false
|
return false
|
||||||
|
@ -171,7 +169,7 @@ export class add extends plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 单独添加 */
|
/** 单独添加 */
|
||||||
async singleAdd () {
|
async singleAdd() {
|
||||||
if (this.e.message.length != 2) return false
|
if (this.e.message.length != 2) return false
|
||||||
let msg = lodash.keyBy(this.e.message, 'type')
|
let msg = lodash.keyBy(this.e.message, 'type')
|
||||||
if (!this.e.msg || !msg.image) return false
|
if (!this.e.msg || !msg.image) return false
|
||||||
|
@ -194,7 +192,7 @@ export class add extends plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取添加关键词 */
|
/** 获取添加关键词 */
|
||||||
getKeyWord () {
|
getKeyWord() {
|
||||||
this.e.isGlobal = this.e.msg.includes("全局");
|
this.e.isGlobal = this.e.msg.includes("全局");
|
||||||
|
|
||||||
this.keyWord = this.e.toString()
|
this.keyWord = this.e.toString()
|
||||||
|
@ -214,7 +212,7 @@ export class add extends plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 过滤别名 */
|
/** 过滤别名 */
|
||||||
trimAlias (msg) {
|
trimAlias(msg) {
|
||||||
let groupCfg = cfg.getGroup(this.group_id)
|
let groupCfg = cfg.getGroup(this.group_id)
|
||||||
let alias = groupCfg.botAlias
|
let alias = groupCfg.botAlias
|
||||||
if (!Array.isArray(alias)) {
|
if (!Array.isArray(alias)) {
|
||||||
|
@ -230,7 +228,7 @@ export class add extends plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 添加内容 */
|
/** 添加内容 */
|
||||||
async addContext () {
|
async addContext() {
|
||||||
this.isGlobal = this.e.isGlobal || this.getContext()?.addContext?.isGlobal;
|
this.isGlobal = this.e.isGlobal || this.getContext()?.addContext?.isGlobal;
|
||||||
await this.getGroupId()
|
await this.getGroupId()
|
||||||
/** 关键词 */
|
/** 关键词 */
|
||||||
|
@ -287,7 +285,7 @@ export class add extends plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 添加成功回复消息 */
|
/** 添加成功回复消息 */
|
||||||
getRetMsg () {
|
getRetMsg() {
|
||||||
let retMsg = this.getContext()
|
let retMsg = this.getContext()
|
||||||
let msg = ''
|
let msg = ''
|
||||||
if (retMsg?.addContext?.message) {
|
if (retMsg?.addContext?.message) {
|
||||||
|
@ -316,7 +314,7 @@ export class add extends plugin {
|
||||||
return lodash.compact(msg)
|
return lodash.compact(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
saveJson () {
|
saveJson() {
|
||||||
let obj = {}
|
let obj = {}
|
||||||
for (let [k, v] of textArr[this.group_id]) {
|
for (let [k, v] of textArr[this.group_id]) {
|
||||||
obj[k] = v
|
obj[k] = v
|
||||||
|
@ -337,7 +335,7 @@ export class add extends plugin {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveImg (url, keyWord) {
|
async saveImg(url, keyWord) {
|
||||||
let groupCfg = cfg.getGroup(this.group_id)
|
let groupCfg = cfg.getGroup(this.group_id)
|
||||||
let savePath = `${this.facePath}${this.group_id}/`
|
let savePath = `${this.facePath}${this.group_id}/`
|
||||||
|
|
||||||
|
@ -375,7 +373,7 @@ export class add extends plugin {
|
||||||
return savePath
|
return savePath
|
||||||
}
|
}
|
||||||
|
|
||||||
async getText () {
|
async getText() {
|
||||||
if (!this.e.message) return false
|
if (!this.e.message) return false
|
||||||
|
|
||||||
this.isGlobal = false
|
this.isGlobal = false
|
||||||
|
@ -446,7 +444,7 @@ export class add extends plugin {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
expiredMsg (keyWord, num) {
|
expiredMsg(keyWord, num) {
|
||||||
logger.mark(`[发送表情]${this.e.logText} ${keyWord} 表情已过期失效`)
|
logger.mark(`[发送表情]${this.e.logText} ${keyWord} 表情已过期失效`)
|
||||||
|
|
||||||
let arr = textArr[this.group_id].get(keyWord)
|
let arr = textArr[this.group_id].get(keyWord)
|
||||||
|
@ -462,7 +460,7 @@ export class add extends plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 初始化已添加内容 */
|
/** 初始化已添加内容 */
|
||||||
initTextArr () {
|
initTextArr() {
|
||||||
if (textArr[this.group_id]) return
|
if (textArr[this.group_id]) return
|
||||||
|
|
||||||
textArr[this.group_id] = new Map()
|
textArr[this.group_id] = new Map()
|
||||||
|
@ -568,7 +566,7 @@ export class add extends plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async del () {
|
async del() {
|
||||||
this.isGlobal = this.e?.msg.includes("全局");
|
this.isGlobal = this.e?.msg.includes("全局");
|
||||||
await this.getGroupId()
|
await this.getGroupId()
|
||||||
if (!this.group_id) return false
|
if (!this.group_id) return false
|
||||||
|
@ -652,14 +650,14 @@ export class add extends plugin {
|
||||||
img = item[0]
|
img = item[0]
|
||||||
}
|
}
|
||||||
if (img.local) {
|
if (img.local) {
|
||||||
fs.unlink(img.local, () => {})
|
fs.unlink(img.local, () => { })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.saveJson()
|
this.saveJson()
|
||||||
}
|
}
|
||||||
|
|
||||||
async list () {
|
async list() {
|
||||||
this.isGlobal = this.e?.msg.includes("全局");
|
this.isGlobal = this.e?.msg.includes("全局");
|
||||||
|
|
||||||
let page = 1
|
let page = 1
|
||||||
|
@ -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,63 +734,19 @@ 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
|
||||||
return offset + pageSize >= array.length ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize)
|
return offset + pageSize >= array.length ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 关键词转换成可发送消息 */
|
/** 关键词转换成可发送消息 */
|
||||||
async keyWordTran (msg) {
|
async keyWordTran(msg) {
|
||||||
/** 图片 */
|
/** 图片 */
|
||||||
if (msg.includes('{image')) {
|
if (msg.includes('{image')) {
|
||||||
let tmp = msg.split('{image')
|
let tmp = msg.split('{image')
|
||||||
|
|
Loading…
Reference in New Issue