npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

koishi-plugin-haruki-activity

v0.2.2

Published

基于 haruki.db 统计近7日命令命中量并生成表格图片的 Koishi 插件

Readme

koishi-plugin-haruki-activity

生成近 N 日命令使用量表格(16:9 PNG)。支持背景图、中文字体、趋势线、额外窗口统计。内置零点定时与并发安全的计数写入。

快速开始

  • 安装:npm i(依赖:koishi@^4.15sql.jspureimage)。
  • 启用:在 Koishi 控制台勾选插件。
  • 配置:设置 sourceDbPath 指向你的 haruki.db;如需自定义统计库路径,填写 countDbPath
  • 使用:在会话发送 daily,收到 16:9 图片。

配置项

  • sourceDbPath:命令命中数据库路径。
  • countDbPath:统计库路径,默认与源库同目录 count.db
  • bgPath:背景图路径(可选)。
  • backgroundStrategycontain | cover,默认 contain
  • imageWidth / imageHeight:图片尺寸,默认 1920x1080。
  • title:标题文本。
  • fontPath / fontFamily:自定义字体(建议 TTF)。
  • windowDays:主统计窗口,默认 7。
  • extraWindows:额外窗口数组(如 [14, 30])。
  • showTrend:是否绘制趋势线,默认 false。
  • style:配色覆盖(bgColortitleColorheaderBgheaderColortextColorseparatorColor)。

提供的命令

  • daily:刷新今日计数、补齐窗口缺失日,渲染并发送图片。
  • daily.fix:修正并固定近 7 日计数(默认仅 authority ≥ 4 可用)。

工作流与一致性

  • 零点任务:按本地时区每天 00:00 记录“昨日”计数到 count.db
  • 命中刷新:daily 触发时实时更新“今日”计数,并回填窗口内缺失日期。
  • 并发安全:对 count.db 的读写已串行化,避免命令与定时器互相覆盖。
  • 数据源:分日与额外窗口统计均基于 haruki.dbcommand_usage(本地时区)。
  • 锁定机制:daily.fix 将近 7 日写入并设置 locked=1,后续零点/命中不会覆盖。

生成结果

  • 输出文件:count.db(表 daily_counts(day TEXT PRIMARY KEY, count INTEGER, updated_at DATETIME, locked INTEGER DEFAULT 0))。
  • 输出消息:16:9 PNG 图片,包含标题、日期-计数表格,可选趋势线与额外窗口汇总。

配置示例(JSON 片段)

{
  "plugins": {
    "haruki-activity": {
      "sourceDbPath": "/data/haruki/haruki.db",
      "countDbPath": "/data/haruki/count.db",
      "bgPath": "/data/assets/bg.jpg",
      "backgroundStrategy": "cover",
      "imageWidth": 1920,
      "imageHeight": 1080,
      "title": "阳子萝卜每日活跃度",
      "fontPath": "/usr/share/fonts/truetype/noto/NotoSansSC-Regular.ttf",
      "fontFamily": "NotoSansSC",
      "windowDays": 7,
      "extraWindows": [14, 30],
      "showTrend": true
    }
  }
}

测试与验证

  • 聚合测试脚本:npm run test:aggregate -- <sourceDbPath> [windowDays] [extraWindows]
  • 运行验证:在会话发送 daily,应收到图片,并在 count.db 看到最新计数。

常见问题

  • 字体显示异常:确认提供 TTF,并确保 fontFamily 与字体内部名称一致。
  • 未生成 count.db:检查路径是否可写;留空 countDbPath 时默认写入 sourceDbPath 同目录。
  • 时区偏差:依赖宿主本地时区,请确保主机时区即业务时区。