koishi-plugin-chat-analyse 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Renderer.d.ts +1 -1
- package/lib/index.d.ts +10 -0
- package/lib/index.js +58 -23
- package/package.json +1 -2
- package/readme.md +15 -0
package/lib/Renderer.d.ts
CHANGED
|
@@ -83,7 +83,7 @@ export declare class Renderer {
|
|
|
83
83
|
* @public
|
|
84
84
|
* @method renderWordCloud
|
|
85
85
|
* @description 将词频数据渲染成一张词云图片,使用 Puppeteer 和 wordcloud2.js。
|
|
86
|
-
* @param {WordCloudData} data -
|
|
86
|
+
* @param {WordCloudData} data - 包含标题、时间和词汇列表,以及从config传入的options。
|
|
87
87
|
* @returns {AsyncGenerator<Buffer>} - 一个异步生成器,产出渲染后的图片 Buffer。
|
|
88
88
|
*/
|
|
89
89
|
renderWordCloud(data: WordCloudData): AsyncGenerator<Buffer>;
|
package/lib/index.d.ts
CHANGED
|
@@ -22,6 +22,16 @@ export interface Config {
|
|
|
22
22
|
cacheRetentionDays: number;
|
|
23
23
|
enableSimilarActivity: boolean;
|
|
24
24
|
enableAutoBackup: boolean;
|
|
25
|
+
fontFamily: string;
|
|
26
|
+
minFontSize: number;
|
|
27
|
+
maxFontSize: number;
|
|
28
|
+
shape: string;
|
|
29
|
+
gridSize: number;
|
|
30
|
+
rotateRatio: number;
|
|
31
|
+
minRotation: number;
|
|
32
|
+
maxRotation: number;
|
|
33
|
+
ellipticity: number;
|
|
34
|
+
maskImage: string;
|
|
25
35
|
}
|
|
26
36
|
/** @description 插件的配置项定义 */
|
|
27
37
|
export declare const Config: Schema<Config>;
|
package/lib/index.js
CHANGED
|
@@ -1775,19 +1775,18 @@ var Renderer = class {
|
|
|
1775
1775
|
* @public
|
|
1776
1776
|
* @method renderWordCloud
|
|
1777
1777
|
* @description 将词频数据渲染成一张词云图片,使用 Puppeteer 和 wordcloud2.js。
|
|
1778
|
-
* @param {WordCloudData} data -
|
|
1778
|
+
* @param {WordCloudData} data - 包含标题、时间和词汇列表,以及从config传入的options。
|
|
1779
1779
|
* @returns {AsyncGenerator<Buffer>} - 一个异步生成器,产出渲染后的图片 Buffer。
|
|
1780
1780
|
*/
|
|
1781
1781
|
async *renderWordCloud(data) {
|
|
1782
1782
|
const { title, time, words } = data;
|
|
1783
|
-
|
|
1783
|
+
const options = data.options;
|
|
1784
|
+
if (!words?.length || !options) return;
|
|
1784
1785
|
const wordsJson = JSON.stringify(words);
|
|
1785
1786
|
const selectedPalette = this.COLOR_PALETTES[Math.floor(Math.random() * this.COLOR_PALETTES.length)];
|
|
1786
1787
|
const weights = words.map((w) => w[1]);
|
|
1787
1788
|
const maxWeight = Math.max(...weights, 1);
|
|
1788
1789
|
const minWeight = Math.min(...weights);
|
|
1789
|
-
const MAX_FONT_SIZE = 64;
|
|
1790
|
-
const MIN_FONT_SIZE = 4;
|
|
1791
1790
|
const cardHtml = `
|
|
1792
1791
|
<div class="container">
|
|
1793
1792
|
<div class="header">
|
|
@@ -1795,31 +1794,55 @@ var Renderer = class {
|
|
|
1795
1794
|
<h1 class="title-text">${title}</h1>
|
|
1796
1795
|
<div class="time-label">${time.toLocaleString("zh-CN", { hour12: false })}</div>
|
|
1797
1796
|
</div>
|
|
1798
|
-
<div
|
|
1797
|
+
<div style="width: 512px; height: 512px; margin: auto; position: relative;">
|
|
1798
|
+
<canvas id="wordcloud-canvas" width="512" height="512"></canvas>
|
|
1799
|
+
</div>
|
|
1799
1800
|
<script>${wordCloudScript}</script>
|
|
1800
1801
|
<script>
|
|
1802
|
+
const canvas = document.getElementById('wordcloud-canvas');
|
|
1803
|
+
const maskImageUrl = ${JSON.stringify(options.maskImage)};
|
|
1801
1804
|
const palette = ${JSON.stringify(selectedPalette)};
|
|
1802
|
-
|
|
1803
|
-
|
|
1805
|
+
|
|
1806
|
+
const wordCloudOptions = {
|
|
1807
|
+
list: ${wordsJson},
|
|
1808
|
+
fontFamily: ${JSON.stringify(options.fontFamily)},
|
|
1804
1809
|
weightFactor: (size) => {
|
|
1805
|
-
if (${maxWeight} === ${minWeight}) return (${
|
|
1810
|
+
if (${maxWeight} === ${minWeight}) return (${options.minFontSize} + ${options.maxFontSize}) / 2;
|
|
1806
1811
|
const normalizedWeight = (size - ${minWeight}) / (${maxWeight} - ${minWeight});
|
|
1807
|
-
return ${
|
|
1808
|
-
},
|
|
1809
|
-
color: (word, weight, fontSize, distance, theta) => {
|
|
1810
|
-
return palette[Math.floor(Math.random() * palette.length)];
|
|
1812
|
+
return ${options.minFontSize} + normalizedWeight * (${options.maxFontSize} - ${options.minFontSize});
|
|
1811
1813
|
},
|
|
1812
|
-
|
|
1813
|
-
shape:
|
|
1814
|
-
gridSize:
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
backgroundColor: 'transparent',
|
|
1820
|
-
clearCanvas: true,
|
|
1814
|
+
color: () => palette[Math.floor(Math.random() * palette.length)],
|
|
1815
|
+
shape: ${JSON.stringify(options.shape)},
|
|
1816
|
+
gridSize: ${options.gridSize},
|
|
1817
|
+
rotateRatio: ${options.rotateRatio},
|
|
1818
|
+
minRotation: ${options.minRotation},
|
|
1819
|
+
maxRotation: ${options.maxRotation},
|
|
1820
|
+
ellipticity: ${options.ellipticity},
|
|
1821
1821
|
shuffle: true,
|
|
1822
|
-
|
|
1822
|
+
drawOutOfBoundWords: false,
|
|
1823
|
+
backgroundColor: 'transparent',
|
|
1824
|
+
};
|
|
1825
|
+
|
|
1826
|
+
function drawWordCloud(isMasked) {
|
|
1827
|
+
const finalOptions = { ...wordCloudOptions, clearCanvas: !isMasked };
|
|
1828
|
+
WordCloud(canvas, finalOptions);
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
if (maskImageUrl) {
|
|
1832
|
+
const img = new Image();
|
|
1833
|
+
img.crossOrigin = "anonymous";
|
|
1834
|
+
img.onload = () => {
|
|
1835
|
+
const ctx = canvas.getContext('2d');
|
|
1836
|
+
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
1837
|
+
drawWordCloud(true);
|
|
1838
|
+
};
|
|
1839
|
+
img.onerror = () => {
|
|
1840
|
+
drawWordCloud(false);
|
|
1841
|
+
};
|
|
1842
|
+
img.src = maskImageUrl;
|
|
1843
|
+
} else {
|
|
1844
|
+
drawWordCloud(false);
|
|
1845
|
+
}
|
|
1823
1846
|
</script>
|
|
1824
1847
|
</div>`;
|
|
1825
1848
|
const fullHtml = `<!DOCTYPE html>
|
|
@@ -2527,7 +2550,19 @@ var Config3 = import_koishi7.Schema.intersect([
|
|
|
2527
2550
|
enableAutoBackup: import_koishi7.Schema.boolean().default(false).description("启用自动备份"),
|
|
2528
2551
|
enableWordCloud: import_koishi7.Schema.boolean().default(true).description("启用词云生成"),
|
|
2529
2552
|
enableSimilarActivity: import_koishi7.Schema.boolean().default(true).description("启用相似活跃分析")
|
|
2530
|
-
}).description("高级分析配置")
|
|
2553
|
+
}).description("高级分析配置"),
|
|
2554
|
+
import_koishi7.Schema.object({
|
|
2555
|
+
ellipticity: import_koishi7.Schema.number().min(0).max(1).default(1).description("长宽比"),
|
|
2556
|
+
rotateRatio: import_koishi7.Schema.number().min(0).max(1).default(0.5).description("旋转比"),
|
|
2557
|
+
minRotation: import_koishi7.Schema.number().default(Math.PI / 2).description("最小旋转角"),
|
|
2558
|
+
maxRotation: import_koishi7.Schema.number().default(Math.PI / 2).description("最大旋转角"),
|
|
2559
|
+
minFontSize: import_koishi7.Schema.number().min(1).default(4).description("最小字号"),
|
|
2560
|
+
maxFontSize: import_koishi7.Schema.number().min(1).default(64).description("最大字号"),
|
|
2561
|
+
gridSize: import_koishi7.Schema.number().min(0).default(1).description("词云间距"),
|
|
2562
|
+
fontFamily: import_koishi7.Schema.string().default('"Noto Sans CJK SC", "Arial", sans-serif').description("词云字体"),
|
|
2563
|
+
shape: import_koishi7.Schema.union(["square", "circle", "cardioid", "diamond", "triangle-forward", "triangle", "pentagon", "star"]).default("square").description("词云形状"),
|
|
2564
|
+
maskImage: import_koishi7.Schema.string().role("link").description("词云蒙版")
|
|
2565
|
+
}).description("词云生成配置")
|
|
2531
2566
|
]);
|
|
2532
2567
|
async function parseQueryScope(ctx, session, options) {
|
|
2533
2568
|
const scopeDesc = { guildId: options.guild, userId: void 0 };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-chat-analyse",
|
|
3
3
|
"description": "强大而全面的聊天数据分析插件。支持多维度统计(命令、发言、消息类型、活跃度),可生成发言排行、词云图,并提供完善的数据管理。",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.4",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Yis_Rime <yis_rime@outlook.com>"
|
|
7
7
|
],
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"license": "AGPL-3.0-only",
|
|
20
|
-
"scripts": {},
|
|
21
20
|
"keywords": [
|
|
22
21
|
"chatbot",
|
|
23
22
|
"koishi",
|
package/readme.md
CHANGED
|
@@ -156,6 +156,21 @@
|
|
|
156
156
|
`enableSimilarActivity`: **启用相似活跃分析**。
|
|
157
157
|
> **!** 此功能依赖 **`启用发言排行`** 或 **`启用活跃统计`**。 (默认: `true`)
|
|
158
158
|
|
|
159
|
+
### 词云生成配置
|
|
160
|
+
|
|
161
|
+
| 配置项 | 描述 | 默认值 |
|
|
162
|
+
| :--- | :--- | :--- |
|
|
163
|
+
| `maskImage` | **词云蒙版**:提供一个图片的URL作为词云的形状蒙版。**注意:这会覆盖“基础形状”选项。** | (空) |
|
|
164
|
+
| `fontFamily` | **词云字体**:用于渲染词云的字体列表。 | `"Noto Sans CJK SC", "Arial", sans-serif` |
|
|
165
|
+
| `minFontSize` | **最小字号**:权重最小的单词所使用的字号。 | `4` |
|
|
166
|
+
| `maxFontSize` | **最大字号**:权重最大的单词所使用的字号。 | `64` |
|
|
167
|
+
| `gridSize` | **词云间距**:用于分隔单词的网格大小(像素)。值越大,单词间距越大。 | `1` |
|
|
168
|
+
| `shape` | **基础形状**:选择词云的整体轮廓(无蒙版时生效)。 | `square` |
|
|
169
|
+
| `ellipticity` | **长宽比**:当形状为“椭圆”时,定义其扁平程度。值越小越扁。 | `1` |
|
|
170
|
+
| `rotateRatio` | **旋转比**:随机旋转的单词所占的比例(0 到 1)。 | `0.5` |
|
|
171
|
+
| `minRotation` | **最小旋转角**:单词随机旋转的最小角度(弧度)。 | `1.570796` (π/2) |
|
|
172
|
+
| `maxRotation` | **最大旋转角**:单词随机旋转的最大角度(弧度)。 | `1.570796` (π/2) |
|
|
173
|
+
|
|
159
174
|
## 📌 注意事项
|
|
160
175
|
|
|
161
176
|
1. **Puppeteer 配置**:本插件的图片渲染强依赖 `puppeteer` 服务。请确保您已正确安装并配置了该服务,包括正确设置了可执行文件路径(如有需要)。渲染失败通常与此有关。
|