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-revoke-image

v0.0.6

Published

通过图片对比撤回某些图片消息

Downloads

52

Readme

koishi-plugin-revoke-image

npm

通过图片对比撤回某些图片消息

功能特性

  • ✅ 自动监听QQ群组中的图片消息
  • ✅ 使用感知哈希算法(dHash)进行图片相似度对比
  • ✅ 当相似度达到95%以上时自动撤回消息
  • ✅ 支持黑名单图片管理(添加、删除、列表、清空)
  • ✅ 提供命令行和Web界面两种管理方式
  • ✅ 可配置相似度阈值和启用/禁用功能

安装

npm install koishi-plugin-revoke-image

配置

在 Koishi 配置文件中添加:

plugins:
  revoke-image:
    similarityThreshold: 0.95  # 相似度阈值(0-1之间,默认0.95)
    enabled: true               # 是否启用自动撤回功能(默认true)
    allowedUserIds:             # 允许使用插件命令的QQ号列表(必填)
      - '283213563'
      # - '另一个QQ号'  # 可以添加多个QQ号

使用方法

命令行管理

查看黑名单统计

revoke-image
# 或简写
ri

添加图片到黑名单

# 方式1:提供图片URL
revoke-image.add <图片URL> [-d 描述]
# 或简写
ri.add <图片URL> [-d 描述]

# 方式2:发送图片消息后使用命令(不带参数)
ri.add [-d 描述]

# 示例
ri.add https://example.com/image.jpg -d "违规图片"
# 或者:发送图片消息,然后输入 "ri.add -d 违规图片"

列出所有黑名单图片

revoke-image.list
# 或简写
ri.list

从黑名单移除图片

revoke-image.remove <图片ID>
# 或简写
ri.remove <图片ID>

清空黑名单

revoke-image.clear
# 或简写
ri.clear

Web界面管理

  1. 启动 Koishi 后,访问控制台
  2. 在侧边栏找到"图片撤回黑名单"页面
  3. 在Web界面中可以:
    • 查看所有黑名单图片(带预览)
    • 添加新图片到黑名单
    • 删除黑名单中的图片
    • 清空整个黑名单

工作原理

  1. 图片监听:插件监听所有QQ群组消息,检测是否包含图片
  2. 图片下载:下载用户发送的图片
  3. 哈希计算:使用差异哈希(dHash)算法计算图片的感知哈希值
  4. 相似度对比:将用户图片的哈希值与黑名单中所有图片的哈希值进行对比
  5. 自动撤回:如果相似度达到配置的阈值(默认95%),自动撤回该消息

技术细节

  • 图片哈希算法:使用差异哈希(dHash)算法,将图片调整为9x8大小,计算相邻像素的差异
  • 相似度计算:使用汉明距离计算两个哈希值的差异,相似度 = 1 - 汉明距离 / 哈希长度
  • 数据存储:黑名单数据存储在 data/revoke-image/blacklist.json 文件中

注意事项

  1. 确保机器人具有撤回消息的权限
  2. 图片下载和处理可能需要一些时间,建议在网络良好的环境下使用
  3. 相似度阈值设置过高可能导致误判,设置过低可能漏检
  4. 黑名单图片数量过多可能影响处理速度

开发

# 安装依赖
npm install

# 构建
npm run build

# 开发模式
npm run dev

License

MIT