Skip to content

Commit

Permalink
feat: review
Browse files Browse the repository at this point in the history
  • Loading branch information
Lain. committed May 18, 2024
1 parent 3245258 commit ddc80eb
Show file tree
Hide file tree
Showing 14 changed files with 756 additions and 582 deletions.
18 changes: 9 additions & 9 deletions config/defSet/App.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# 黑名单相关
black_list:
BlackList:
# 黑名单用户
users: false
# 黑名单群聊
groups: false
# 消息日志黑名单群聊 设置后不会打印该群的消息日志 暂未实现
msg_groups: false
# 消息日志黑名单群聊 设置后不会打印该群的消息日志
GroupMsgLog: false

# 白名单相关
white_list:
WhiteList:
# 白名单用户
users: false
# 白名单群聊
groups: false
# 消息日志白名单群聊 设置后只会打印该群的消息日志 暂未实现
msg_groups: false
# 消息日志白名单群聊 设置后只会打印该群的消息日志
GroupMsgLog: false

# 群聊
group_config:
GroupConfig:
# 群聊中所有消息冷却时间
global_cd: false
GroupCD: false

# 群聊中 每个人的消息冷却时间
personal_cd: false
GroupUserCD: true

# 机器人响应模式
mode: false
Expand Down
14 changes: 7 additions & 7 deletions config/defSet/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ master: []
# 管理员列表 子权限
admin: []

# 超时时间
# Api请求超时时间
timeout:
grpc: 30
ws: 30
grpc: 60
ws: 60

# 黑名单相关
black_list:
BlackList:
# 黑名单用户
users: []
# 黑名单群聊
groups: []
# 消息日志黑名单群聊 设置后不会打印该群的消息日志
msg_groups: []
GroupMsgLog: []

# 白名单相关
white_list:
WhiteList:
# 白名单用户
users: []
# 白名单群聊
groups: []
# 消息日志白名单群聊 设置后只会打印该群的消息日志
msg_groups: []
GroupMsgLog: []

# ffmpeg配置 用于音视频处理
ffmpeg_path: ""
Expand Down
4 changes: 2 additions & 2 deletions config/defSet/group.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 默认配置
default:
# 群聊中所有消息冷却时间,单位秒,0则无限制
global_cd: 0
GroupCD: 0
# 群聊中 每个人的消息冷却时间,单位秒,0则无限制。注意,开启后所有消息,无论是否触发插件。
personal_cd: 0
GroupUserCD: 1
# 机器人响应模式,0-所有 1-仅@机器人 2-仅回应主人 3-仅回应前缀 4-前缀或@机器人 5-主人无前缀,群员前缀或@机器人
mode: 0

Expand Down
18 changes: 16 additions & 2 deletions lib/Renderer/puppeteer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs'
import path from 'path'
import { randomUUID } from 'crypto'
import RenderClass from './RenderClass.js'
Expand All @@ -8,6 +9,7 @@ class Puppeteer extends RenderClass {
super()
this.socket = socket
this.request = request
this._path = process.cwd()
this.#start()
}

Expand All @@ -23,6 +25,14 @@ class Puppeteer extends RenderClass {
/** 监听上报事件 */
this.socket.on('message', data => {
data = JSON.parse(data)
if (data.action === 'static') {
data.status = 'ok'
data.data = decodeURIComponent(data.data)
const file = process.cwd() + `/${data.data}`
data.data = fs.readFileSync(file).toString('base64')
console.log(file)
return this.socket.send(JSON.stringify(data))
}
if (data.echo) {
Bot.emit(data.echo, data)
} else {
Expand Down Expand Up @@ -81,9 +91,13 @@ class Puppeteer extends RenderClass {
async render (name, data = {}) {
/** 渲染模板 并获取模板绝对路径 */
data.savePath = data.tplFile.includes('http') ? data.tplFile : path.resolve(this.dealTpl(name, data))
if (!data.savePath) return false

const content = fs.readFileSync(data.savePath, 'utf-8')
/** 处理所有绝对路径、相对路径 */
const html = content.replace(new RegExp(`(${this._path}|${this._path.replace(/\\/g, '/')})`, 'g'), '')
const echo = randomUUID()
this.socket.send(JSON.stringify({ echo, name, data }))
const action = 'renderHtml'
this.socket.send(JSON.stringify({ echo, action, data: { name, data, html } }))

return new Promise((resolve, reject) => {
Bot.once(echo, data => {
Expand Down
2 changes: 1 addition & 1 deletion lib/bot/KarinNotice.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Contacts, SendersNotice } from './UserInfo.js'
/**
* @class KarinNotice
*/
class KarinNotice extends KarinEvent {
export class KarinNotice extends KarinEvent {
/**
* 构造一个通知
* @param {{
Expand Down
12 changes: 6 additions & 6 deletions lib/bot/bot.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '../adapter/kritor/index.js'
import { EventEmitter } from 'events'
import message from '../event/message.js'
import notice from '../event/notice.js'
import request from '../event/request.js'
import KarinMessage from '../event/message.js'
import KarinNotice from '../event/notice.js'
import KarinRequest from '../event/request.js'
import { segment, common, logger } from '#Karin'

class Bot extends EventEmitter {
Expand All @@ -20,11 +20,11 @@ class Bot extends EventEmitter {
/** 错误事件 */
this.on('error', data => logger.error(data))
/** 消息事件 */
this.on('message', data => message.deal(data))
this.on('message', data => new KarinMessage(data))
/** 通知事件 */
this.on('notice', data => notice.deal(data))
this.on('notice', data => new KarinNotice(data))
/** 请求事件 */
this.on('request', data => request.deal(data))
this.on('request', data => new KarinRequest(data))
/** 注册bot */
this.on('bot', data => {
/** {uin: '1234...', adapter: class } */
Expand Down
20 changes: 10 additions & 10 deletions lib/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import logger from './log.js'
class Cfg {
constructor () {
this.config = {}
this.other_status = false
this.review = false
/** 监听文件 */
this.watcher = { config: {}, defSet: {} }
this.initCfg()
Expand Down Expand Up @@ -146,13 +146,13 @@ class Cfg {
}

async change_App () {
await this.#other()
await this.#review()
}

async change_config () {
/** 修改日志等级 */
logger.level = this.Config.log_level
await this.#other()
await this.#review()
if (this.Config.hot_update) {
const { Bot } = await import('../index.js')
Bot.emit('restart_http', {})
Expand All @@ -161,15 +161,15 @@ class Cfg {
}

async change_group () {
await this.#other()
await this.#review()
}

async #other () {
if (this.other_status) return
this.other_status = true
const other = await import('./other.js')
other.default.main()
this.other_status = false
async #review () {
if (this.review) return
this.review = true
const review = await import('../event/review.js')
review.default.main()
this.review = false
}
}

Expand Down
21 changes: 21 additions & 0 deletions lib/config/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ log4js.configure({
}
})

/**
* @description 日志模块
* @type {log4js.Logger & {
* bot: logger,
* chalk: import('chalk').default,
* red: (text: string) => string,
* green: (text: string) => string,
* yellow: (text: string) => string,
* blue: (text: string) => string,
* magenta: (text: string) => string,
* cyan: (text: string) => string,
* white: (text: string) => string,
* gray: (text: string) => string,
* violet: (text: string) => string
* }}
*/
const logger = log4js.getLogger('default')
logger.chalk = chalk
logger.red = chalk.red
Expand All @@ -63,3 +79,8 @@ logger.violet = chalk.hex('#868ECC')
logger.bot = (level, id, ...args) => logger[level](logger.violet(`[Bot:${id}] `) + args.join(' '))

export default Object.freeze(logger)

/**
* bot专用日志
* @typedef {(level: 'trace'|'debug'|'mark'|'info'|'warn'|'error'|'fatal', id: string, ...args: any[]) => void} logger
*/
Loading

0 comments on commit ddc80eb

Please sign in to comment.