koishi-plugin-chat-analyse 1.6.13 → 1.7.0
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/index.js +20 -13
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1605,7 +1605,7 @@ var Renderer = class {
|
|
|
1605
1605
|
*/
|
|
1606
1606
|
async *renderList(data, headers) {
|
|
1607
1607
|
const { title, time, list } = data;
|
|
1608
|
-
const CHUNK_SIZE =
|
|
1608
|
+
const CHUNK_SIZE = 200;
|
|
1609
1609
|
const totalItems = list.length;
|
|
1610
1610
|
const countHeaderIndex = headers?.findIndex((h7) => ["总计发言", "条数", "次数", "数量"].includes(h7)) ?? -1;
|
|
1611
1611
|
const totalCount = data.total || (countHeaderIndex > -1 ? list.reduce((sum, row) => sum + (Number(row[countHeaderIndex]) || 0), 0) : totalItems);
|
|
@@ -1907,7 +1907,7 @@ var Stat = class {
|
|
|
1907
1907
|
}
|
|
1908
1908
|
}, "handleAction");
|
|
1909
1909
|
if (this.config.enableCmdStat) {
|
|
1910
|
-
cmd.subcommand("cmdstat", "命令统计").usage("查询命令统计,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("separate", "-p 分离子命令").option("sortByTime", "-s 以时间排序").option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
1910
|
+
cmd.subcommand("cmdstat", "命令统计").usage("查询命令统计,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("limit", "-l <count:number> 限制数量").option("separate", "-p 分离子命令").option("sortByTime", "-s 以时间排序").option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
1911
1911
|
const scope = await this.parseScope(session, options);
|
|
1912
1912
|
if (scope.error) return scope.error;
|
|
1913
1913
|
const query = scope.uids ? { uid: { $in: scope.uids } } : {};
|
|
@@ -1932,14 +1932,15 @@ var Stat = class {
|
|
|
1932
1932
|
} else {
|
|
1933
1933
|
processedStats.sort((a, b) => b.count - a.count);
|
|
1934
1934
|
}
|
|
1935
|
+
const limitedStats = options.limit > 0 ? processedStats.slice(0, options.limit) : processedStats;
|
|
1935
1936
|
const total = processedStats.reduce((sum, r) => sum + r.count, 0);
|
|
1936
|
-
const list =
|
|
1937
|
+
const list = limitedStats.map((item) => [item.command, item.count, item.lastUsed]);
|
|
1937
1938
|
const title = await generateTitle(this.ctx, scope.scopeDesc, { main: "命令" });
|
|
1938
1939
|
return this.renderer.renderList({ title, time: /* @__PURE__ */ new Date(), total, list }, ["命令", "次数", "最后使用"]);
|
|
1939
1940
|
})()));
|
|
1940
1941
|
}
|
|
1941
1942
|
if (this.config.enableMsgStat) {
|
|
1942
|
-
cmd.subcommand("msgstat", "发言统计").usage("查询发言统计,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("type", "-t <type:string> 指定类型").option("sortByTime", "-s 以时间排序").option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
1943
|
+
cmd.subcommand("msgstat", "发言统计").usage("查询发言统计,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("type", "-t <type:string> 指定类型").option("limit", "-l <count:number> 限制数量").option("sortByTime", "-s 以时间排序").option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
1943
1944
|
const scope = await this.parseScope(session, options);
|
|
1944
1945
|
if (scope.error) return scope.error;
|
|
1945
1946
|
const query = scope.uids ? { uid: { $in: scope.uids } } : {};
|
|
@@ -1956,8 +1957,9 @@ var Stat = class {
|
|
|
1956
1957
|
const stats2 = await this.ctx.database.select("analyse_msg").where(query).groupBy("type", { count: /* @__PURE__ */ __name((row) => import_koishi3.$.sum(row.count), "count"), lastUsed: /* @__PURE__ */ __name((row) => import_koishi3.$.max(row.timestamp), "lastUsed") }).execute();
|
|
1957
1958
|
if (stats2.length === 0) return "暂无统计数据";
|
|
1958
1959
|
applySort(stats2);
|
|
1960
|
+
const limitedStats2 = options.limit > 0 ? stats2.slice(0, options.limit) : stats2;
|
|
1959
1961
|
const total2 = stats2.reduce((sum, r) => sum + r.count, 0);
|
|
1960
|
-
const list2 =
|
|
1962
|
+
const list2 = limitedStats2.map((item) => [item.type, item.count, item.lastUsed]);
|
|
1961
1963
|
return this.renderer.renderList({ title, time: /* @__PURE__ */ new Date(), total: total2, list: list2 }, ["类型", "条数", "最后发言"]);
|
|
1962
1964
|
}
|
|
1963
1965
|
if (options.user) {
|
|
@@ -1966,14 +1968,16 @@ var Stat = class {
|
|
|
1966
1968
|
const stats2 = await this.ctx.database.select("analyse_msg").where(query).groupBy("uid", { count: /* @__PURE__ */ __name((row) => import_koishi3.$.sum(row.count), "count"), lastUsed: /* @__PURE__ */ __name((row) => import_koishi3.$.max(row.timestamp), "lastUsed") }).execute();
|
|
1967
1969
|
if (stats2.length === 0) return "暂无统计数据";
|
|
1968
1970
|
applySort(stats2);
|
|
1971
|
+
const limitedStats2 = options.limit > 0 ? stats2.slice(0, options.limit) : stats2;
|
|
1969
1972
|
const total2 = stats2.reduce((sum, r) => sum + r.count, 0);
|
|
1970
|
-
const list2 =
|
|
1973
|
+
const list2 = limitedStats2.map((item) => [uidToChannelMap.get(item.uid) || `未知群组`, item.count, item.lastUsed]);
|
|
1971
1974
|
return this.renderer.renderList({ title, time: /* @__PURE__ */ new Date(), total: total2, list: list2 }, ["群组", "条数", "最后发言"]);
|
|
1972
1975
|
}
|
|
1973
1976
|
const stats = await this.ctx.database.select("analyse_msg").where(query).groupBy("uid", { count: /* @__PURE__ */ __name((row) => import_koishi3.$.sum(row.count), "count"), lastUsed: /* @__PURE__ */ __name((row) => import_koishi3.$.max(row.timestamp), "lastUsed") }).execute();
|
|
1974
1977
|
if (stats.length === 0) return "暂无统计数据";
|
|
1975
1978
|
applySort(stats);
|
|
1976
|
-
const
|
|
1979
|
+
const limitedStats = options.limit > 0 ? stats.slice(0, options.limit) : stats;
|
|
1980
|
+
const allUids = limitedStats.map((s) => s.uid);
|
|
1977
1981
|
const userNameMap = /* @__PURE__ */ new Map();
|
|
1978
1982
|
const BATCH_SIZE2 = 4096;
|
|
1979
1983
|
for (let i = 0; i < allUids.length; i += BATCH_SIZE2) {
|
|
@@ -1984,12 +1988,12 @@ var Stat = class {
|
|
|
1984
1988
|
}
|
|
1985
1989
|
}
|
|
1986
1990
|
const total = stats.reduce((sum, r) => sum + r.count, 0);
|
|
1987
|
-
const list =
|
|
1991
|
+
const list = limitedStats.map((item) => [userNameMap.get(item.uid) || `UID ${item.uid}`, item.count, item.lastUsed]);
|
|
1988
1992
|
return this.renderer.renderList({ title, time: /* @__PURE__ */ new Date(), total, list }, ["用户", "条数", "最后发言"]);
|
|
1989
1993
|
})()));
|
|
1990
1994
|
}
|
|
1991
1995
|
if (this.config.enableRankStat) {
|
|
1992
|
-
cmd.subcommand("rankstat", "发言排行").usage("查询发言排行,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("type", "-t <type:string> 指定类型").option("duration", "-n <hours:number> 指定时长", { fallback: 24 }).option("offset", "-o <hours:number> 指定偏移", { fallback: 0 }).option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
1996
|
+
cmd.subcommand("rankstat", "发言排行").usage("查询发言排行,可指定查询范围,默认当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("type", "-t <type:string> 指定类型").option("duration", "-n <hours:number> 指定时长", { fallback: 24 }).option("offset", "-o <hours:number> 指定偏移", { fallback: 0 }).option("limit", "-l <count:number> 限制数量").option("all", "-a 全局统计").action(({ session, options }) => handleAction(session, (async () => {
|
|
1993
1997
|
const scope = await this.parseScope(session, options);
|
|
1994
1998
|
if (scope.error) return scope.error;
|
|
1995
1999
|
const until = new Date(Date.now() - options.offset * import_koishi3.Time.hour);
|
|
@@ -2001,8 +2005,9 @@ var Stat = class {
|
|
|
2001
2005
|
if (options.user && options.guild) {
|
|
2002
2006
|
const stats2 = await this.ctx.database.select("analyse_rank").where(query).groupBy("type", { count: /* @__PURE__ */ __name((row) => import_koishi3.$.sum(row.count), "count") }).orderBy("count", "desc").execute();
|
|
2003
2007
|
if (stats2.length === 0) return "暂无统计数据";
|
|
2008
|
+
const limitedStats2 = options.limit > 0 ? stats2.slice(0, options.limit) : stats2;
|
|
2004
2009
|
const total2 = stats2.reduce((sum, r) => sum + r.count, 0);
|
|
2005
|
-
const list2 =
|
|
2010
|
+
const list2 = limitedStats2.map((r) => [r.type, r.count, total2 > 0 ? `${(r.count / total2 * 100).toFixed(2)}%` : "0.00%"]);
|
|
2006
2011
|
return this.renderer.renderList({ title, time: /* @__PURE__ */ new Date(), total: total2, list: list2 }, ["类型", "条数", "占比"]);
|
|
2007
2012
|
}
|
|
2008
2013
|
if (options.user) {
|
|
@@ -2010,13 +2015,15 @@ var Stat = class {
|
|
|
2010
2015
|
const uidToChannelMap = new Map(userRecords.map((u) => [u.uid, u.channelName || u.channelId]));
|
|
2011
2016
|
const stats2 = await this.ctx.database.select("analyse_rank").where(query).groupBy("uid", { count: /* @__PURE__ */ __name((row) => import_koishi3.$.sum(row.count), "count") }).orderBy("count", "desc").execute();
|
|
2012
2017
|
if (stats2.length === 0) return "暂无统计数据";
|
|
2018
|
+
const limitedStats2 = options.limit > 0 ? stats2.slice(0, options.limit) : stats2;
|
|
2013
2019
|
const total2 = stats2.reduce((sum, r) => sum + r.count, 0);
|
|
2014
|
-
const list2 =
|
|
2020
|
+
const list2 = limitedStats2.map((r) => [uidToChannelMap.get(r.uid) || "未知群组", r.count, total2 > 0 ? `${(r.count / total2 * 100).toFixed(2)}%` : "0.00%"]);
|
|
2015
2021
|
return this.renderer.renderList({ title, time: /* @__PURE__ */ new Date(), total: total2, list: list2 }, ["群组", "条数", "占比"]);
|
|
2016
2022
|
}
|
|
2017
2023
|
const stats = await this.ctx.database.select("analyse_rank").where(query).groupBy("uid", { count: /* @__PURE__ */ __name((row) => import_koishi3.$.sum(row.count), "count") }).orderBy("count", "desc").execute();
|
|
2018
2024
|
if (stats.length === 0) return "暂无统计数据";
|
|
2019
|
-
const
|
|
2025
|
+
const limitedStats = options.limit > 0 ? stats.slice(0, options.limit) : stats;
|
|
2026
|
+
const allUids = limitedStats.map((s) => s.uid);
|
|
2020
2027
|
const userNameMap = /* @__PURE__ */ new Map();
|
|
2021
2028
|
const BATCH_SIZE2 = 4096;
|
|
2022
2029
|
for (let i = 0; i < allUids.length; i += BATCH_SIZE2) {
|
|
@@ -2027,7 +2034,7 @@ var Stat = class {
|
|
|
2027
2034
|
}
|
|
2028
2035
|
}
|
|
2029
2036
|
const total = stats.reduce((sum, r) => sum + r.count, 0);
|
|
2030
|
-
const list =
|
|
2037
|
+
const list = limitedStats.map((r) => [userNameMap.get(r.uid) || `UID ${r.uid}`, r.count, total > 0 ? `${(r.count / total * 100).toFixed(2)}%` : "0.00%"]);
|
|
2031
2038
|
return this.renderer.renderList({ title, time: /* @__PURE__ */ new Date(), total, list }, ["用户", "条数", "占比"]);
|
|
2032
2039
|
})()));
|
|
2033
2040
|
}
|