forked from hanhan258/hanhan-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,715 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 1.1.0 | ||
* 删除了一些功能,修改了帮助图样式 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,80 @@ | ||
import plugin from '../../../lib/plugins/plugin.js' | ||
import lodash from 'lodash' | ||
import { Data } from '../components/index.js' | ||
import HelpTheme from './help/HelpTheme.js' | ||
import runtimeRender from '../common/runtimeRender.js' | ||
|
||
export class help extends plugin { | ||
constructor () { | ||
super({ | ||
/** 功能名称 */ | ||
name: '憨憨Help', | ||
/** 功能描述 */ | ||
dsc: '憨憨Help', | ||
/** https://oicqjs.github.io/oicq/#events */ | ||
name: '憨憨帮助', | ||
dsc: '憨憨帮助', | ||
event: 'message', | ||
/** 优先级,数字越小等级越高 */ | ||
priority: 6, | ||
priority: 100, | ||
rule: [ | ||
{ | ||
/** 命令正则匹配 */ | ||
reg: '#?(nav|憨憨帮助)$', | ||
/** 执行方法 */ | ||
fnc: 'hanhanHelp' | ||
fnc: 'help' | ||
}, | ||
{ | ||
/** 命令正则匹配 */ | ||
reg: '^#?搜一搜帮助$', | ||
/** 执行方法 */ | ||
fnc: 'so_help' | ||
} | ||
] | ||
}) | ||
} | ||
|
||
// 憨憨帮助 | ||
async hanhanHelp (e) { | ||
await e.runtime.render('hanhan-plugin', '/help/help.html') | ||
async help (e) { | ||
let custom = {} | ||
let help = {} | ||
let { diyCfg, sysCfg } = await Data.importCfg('help') | ||
|
||
// 兼容一下旧字段 | ||
if (lodash.isArray(help.helpCfg)) { | ||
custom = { | ||
helpList: help.helpCfg, | ||
helpCfg: {} | ||
} | ||
} else { | ||
custom = help | ||
} | ||
|
||
let helpConfig = lodash.defaults(diyCfg.helpCfg || {}, custom.helpCfg, sysCfg.helpCfg) | ||
let helpList = diyCfg.helpList || custom.helpList || sysCfg.helpList | ||
|
||
let helpGroup = [] | ||
|
||
lodash.forEach(helpList, (group) => { | ||
if (group.auth && group.auth === 'master' && !e.isMaster) { | ||
return true | ||
} | ||
|
||
lodash.forEach(group.list, (help) => { | ||
let icon = help.icon * 1 | ||
if (!icon) { | ||
help.css = 'display:none' | ||
} else { | ||
let x = (icon - 1) % 10 | ||
let y = (icon - x - 1) / 10 | ||
help.css = `background-position:-${x * 50}px -${y * 50}px` | ||
} | ||
}) | ||
|
||
helpGroup.push(group) | ||
}) | ||
let themeData = await HelpTheme.getThemeData(diyCfg.helpCfg || {}, sysCfg.helpCfg || {}) | ||
return await runtimeRender(e, 'help/index', { | ||
helpCfg: helpConfig, | ||
helpGroup, | ||
...themeData, | ||
element: 'default' | ||
}, { | ||
scale: 1.6 | ||
}) | ||
} | ||
|
||
async so_help (e) { | ||
/** e.msg 用户的命令消息 */ | ||
logger.info('[用户命令]', e.msg) | ||
await e.runtime.render('hanhan-plugin', '/help/sys.html') | ||
/** e.msg 用户的命令消息 */ | ||
logger.info('[用户命令]', e.msg) | ||
await e.runtime.render('hanhan-plugin', '/help/sys.html') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import lodash from 'lodash' | ||
import fs from 'fs' | ||
import { Data } from '../../components/index.js' | ||
|
||
let HelpTheme = { | ||
async getThemeCfg (theme, exclude) { | ||
let dirPath = './plugins/hanhan-plugin/resources/help/theme/' | ||
let ret = [] | ||
let names = [] | ||
let dirs = fs.readdirSync(dirPath) | ||
lodash.forEach(dirs, (dir) => { | ||
if (fs.existsSync(`${dirPath}${dir}/main.png`)) { | ||
names.push(dir) | ||
} | ||
}) | ||
if (lodash.isArray(theme)) { | ||
ret = lodash.intersection(theme, names) | ||
} else if (theme === 'all') { | ||
ret = names | ||
} | ||
if (exclude && lodash.isArray(exclude)) { | ||
ret = lodash.difference(ret, exclude) | ||
} | ||
if (ret.length === 0) { | ||
ret = ['default'] | ||
} | ||
let name = lodash.sample(ret) | ||
let resPath = '{{_res_path}}/help/theme/' | ||
return { | ||
main: `${resPath}${name}/main.png`, | ||
bg: fs.existsSync(`${dirPath}${name}/bg.jpg`) ? `${resPath}${name}/bg.jpg` : `${resPath}default/bg.jpg`, | ||
style: (await Data.importModule(`resources/help/theme/${name}/config.js`)).style || {} | ||
} | ||
}, | ||
async getThemeData (diyStyle, sysStyle) { | ||
let helpConfig = lodash.extend({}, sysStyle, diyStyle) | ||
let colCount = Math.min(5, Math.max(parseInt(helpConfig?.colCount) || 3, 2)) | ||
let colWidth = Math.min(500, Math.max(100, parseInt(helpConfig?.colWidth) || 265)) | ||
let width = Math.min(2500, Math.max(800, colCount * colWidth + 30)) | ||
let theme = await HelpTheme.getThemeCfg(diyStyle.theme || sysStyle.theme, diyStyle.themeExclude || sysStyle.themeExclude) | ||
let themeStyle = theme.style || {} | ||
let ret = [` | ||
body{background-image:url(${theme.bg});width:${width}px;} | ||
.container{background-image:url(${theme.main});width:${width}px;} | ||
.help-table .td,.help-table .th{width:${100 / colCount}%} | ||
`] | ||
let css = function (sel, css, key, def, fn) { | ||
let val = Data.def(themeStyle[key], diyStyle[key], sysStyle[key], def) | ||
if (fn) { | ||
val = fn(val) | ||
} | ||
ret.push(`${sel}{${css}:${val}}`) | ||
} | ||
css('.help-title,.help-group', 'color', 'fontColor', '#ceb78b') | ||
css('.help-title,.help-group', 'text-shadow', 'fontShadow', 'none') | ||
css('.help-desc', 'color', 'descColor', '#eee') | ||
css('.cont-box', 'background', 'contBgColor', 'rgba(43, 52, 61, 0.8)') | ||
css('.cont-box', 'backdrop-filter', 'contBgBlur', 3, (n) => diyStyle.bgBlur === false ? 'none' : `blur(${n}px)`) | ||
css('.help-group', 'background', 'headerBgColor', 'rgba(34, 41, 51, .4)') | ||
css('.help-table .tr:nth-child(odd)', 'background', 'rowBgColor1', 'rgba(34, 41, 51, .2)') | ||
css('.help-table .tr:nth-child(even)', 'background', 'rowBgColor2', 'rgba(34, 41, 51, .4)') | ||
return { | ||
style: `<style>${ret.join('\n')}</style>`, | ||
colCount | ||
} | ||
} | ||
} | ||
export default HelpTheme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import setting from '../utils/setting.js' | ||
import Version from '../components/Version.js' | ||
const decimalAdjust = (type, value, exp = 0) => { | ||
type = String(type) | ||
if (!['round', 'floor', 'ceil'].includes(type)) { | ||
throw new TypeError( | ||
"The type of decimal adjustment must be one of 'round', 'floor', or 'ceil'." | ||
) | ||
} | ||
exp = Number(exp) | ||
value = Number(value) | ||
if (exp % 1 !== 0 || Number.isNaN(value)) { | ||
return NaN | ||
} else if (exp === 0) { | ||
return Math[type](value) | ||
} | ||
const [magnitude, exponent = 0] = value.toString().split('e') | ||
const adjustedValue = Math[type](`${magnitude}e${exponent - exp}`) | ||
// Shift back | ||
const [newMagnitude, newExponent = 0] = adjustedValue.toString().split('e') | ||
return Number(`${newMagnitude}e${+newExponent + exp}`) | ||
} | ||
const MathPro = { | ||
floor10: function (value, exp) { | ||
return decimalAdjust('floor', value, exp) | ||
}, | ||
ceil10: function (value, exp) { | ||
return decimalAdjust('ceil', value, exp) | ||
}, | ||
round10: function (value, exp) { | ||
return decimalAdjust('round', value, exp) | ||
} | ||
} | ||
export default function runtimeRender (e, path, renderData = {}, cfg = {}) { | ||
if (!e.runtime) { | ||
console.log('未找到e.runtime,请升级至最新版Yunzai') | ||
} | ||
let scale = setting.getConfig('gachaHelp').renderScale || 100 | ||
scale = Math.min(2, Math.max(0.5, scale / 100)) | ||
scale = (cfg.scale || 1) * scale | ||
const pct = `style='transform:scale(${scale})'` | ||
const layoutPath = | ||
process.cwd() + '/plugins/hanhan-plugin/resources/common/layout/' | ||
return e.runtime.render('hanhan-plugin', path, renderData, { | ||
...cfg, | ||
beforeRender ({ data }) { | ||
let resPath = data.pluResPath | ||
return { | ||
...data, | ||
_res_path: resPath, | ||
_layout_path: layoutPath, | ||
defaultLayout: layoutPath + 'default.html', | ||
elemLayout: layoutPath + 'elem.html', | ||
sys: { | ||
scale: pct, | ||
copyright: `Created By ${Version.name}<span class="version">${Version.yunzai}</span> & hanhan-plugin<span class="version">${Version.version}</span>`, | ||
createdby: `Created By ${Version.name} & hanhan-plugin`, | ||
}, | ||
Math, | ||
MathPro, | ||
quality: 100 | ||
} | ||
} | ||
}) | ||
} |
Oops, something went wrong.