Skip to main content

⚡ Volt-Toy 电击群友 ⚡

用指令电群友的群聊玩具:电压、电量、度数记账,带连击、暴击与供电局文案。

python nonebot astrbot license

📖 介绍

群里发一句 /电 @某人,对方就被电一下:一次同时掷出电压(V)与电量(Ah),按 度(kWh) 累计,顺手折算电费。被电的人有次数、失败数、单次峰值与总用电量,群里有四张榜单。

  • 一次电击三个数:电压、电量、功率;统计只认度数
  • 档位:静电 → 家用 → 工业 → 高压 → 雷击,连击与暴击会升档
  • 特效头像:成功电击后可附带原头像电击滤镜;雷击档可发动态 GIF,特效可在配置中关闭
  • 风控:单目标每日上限、施电过载跳闸、免电名单、群内启停
  • 失败也记账:超出每日上限不拒绝,只记一次「失败」,电量不再增加
  • 两套框架:NoneBot2 与 AstrBot 共用同一份数据格式与文案

💿 安装

NoneBot2

推荐用 nb-cli 安装,插件已上架 NoneBot 商店:

nb plugin install nonebot-plugin-volt-toy

或者直接用包管理器:

pip install nonebot-plugin-volt-toy

然后在 pyproject.toml 中确认插件已启用:

[tool.nonebot]
plugins = ["nonebot_plugin_volt_toy"]

依赖 nonebot-plugin-alconna、nonebot-plugin-uninfo、nonebot-plugin-localstore 与 Pillow,会随插件自动安装。

AstrBot

仓库根目录同时是 AstrBot 插件,二选一:

  • 在 AstrBot WebUI 的插件市场搜索「Volt-Toy」安装
  • 或把仓库克隆到 data/plugins/:
cd AstrBot/data/plugins
git clone https://github.com/Funny1Potato/Volt-Toy

无需手动安装依赖;插件依赖在 requirements.txt 中声明,由 AstrBot 安装流程处理。

🎉 使用

指令 别名 说明
zap [@目标] 电 电击 雷 电目标;引用回复时电被回复的人;都没有则电自己(0.8 倍)
zapkwh 度数榜 电费榜 累计度数 TOP5,附折算电费
zaptop 被电榜 被电次数 TOP5,括号里是失败数
zapmax 峰值榜 单次最高度数 TOP5
zapking 电王榜 施电次数 + 首电加权
zapinfo [@目标] 电档 个人用电档案
zapclear [@目标] — 清除记录(管理员)
zapnodo [@目标] 绝缘 免电名单开关(管理员)
zapon / zapoff — 群内启停(管理员)

NoneBot 默认只响应 / 开头的消息;AstrBot 的前缀以它自己的配置为准。

电击是群里的虚拟玩法,数值与电费都是文案效果,不涉及任何真实惩罚。

⚙️ 配置

NoneBot 在 .env 或 .env.prod 中配置(均可选,默认值即可开箱使用);AstrBot 在 WebUI 的插件配置页调整,字段一一对应。

VOLT_RECEIVE_CAP=25        # 单目标每日受电上限,0 = 不限;超出只记失败不加电量
VOLT_OVERLOAD_WINDOW=60    # 过载统计窗口(秒)
VOLT_OVERLOAD_THRESHOLD=10 # 窗口内最多施电次数,达到即跳闸
VOLT_OVERLOAD_BAN=300      # 跳闸时长(秒)

VOLT_DAILY_QUOTA=0         # 每日施电额度,0 = 不限
VOLT_COOLDOWN=0            # 同一目标冷却秒数,0 = 关闭

VOLT_CRIT_PROB=0.15        # 暴击概率
VOLT_SELF_EFFICIENCY=0.8   # 电自己的效率倍率
VOLT_PRICE_PER_KWH=0.55    # 电价(元/度),只影响展示

VOLT_IS_LOG=false          # 是否写逐条审计日志
VOLT_GROUP_DEFAULT=true    # 新群默认启用
VOLT_WHITELIST=[]          # 免电名单初始值
VOLT_SHOW_AVATAR=true      # 成功施电后附被电者头像(仅 QQ 系平台)
VOLT_AVATAR_CACHE=true     # 缓存头像原图,减少下载并容忍临时网络失败
VOLT_AVATAR_EFFECT=true    # 给头像添加电击特效
VOLT_AVATAR_EFFECT_GIF=true # 雷击档使用动态 GIF;关闭后雷击档仍发静态特效图

档位与数值

档位 度数 电压 大致相当于
静电 0.01–0.05 120–180V 手机充电 1%
家用 0.05–0.15 180–240V 电饭煲保温一小时
工业 0.15–0.35 240–380V 洗衣机洗一桶
高压 0.35–0.80 380–800V 空调开一小时
雷击 0.80–2.60 800–1000V 电动车充满一次

同一目标 10 分钟内连续受电会累积连击并升档;暴击再升一档,最高到雷击。

电击特效

成功施电后,被电者的头像会被套上一层电击滤镜:电弧带白芯、多层光晕,档位越高电弧越粗越密,高压与雷击档还有 RGB 色散。雷击档默认发三帧动态 GIF,其余档位为静态图。

点开看五个档位的实际效果
静电
静电
家用
家用
工业
工业
高压
高压
雷击
雷击(静态帧)
雷击 GIF
雷击(动态 GIF)

渲染在本地完成,不依赖外部服务;取头像失败且无可用缓存时回退纯文本,特效渲染失败时回退原头像,不会吞掉结算结果。想关掉特效:VOLT_AVATAR_EFFECT=false;只关 GIF 保留静态图:VOLT_AVATAR_EFFECT_GIF=false。

双端默认缓存头像原图:1 小时内直接复用,之后按需刷新;刷新失败时允许沿用下载时间距今不超过 24 小时的旧图,30 秒内不重复请求失败的头像。同一头像的并发下载会合并,缓存最多 128 项、原图总计 32 MiB、单图 5 MiB,按 LRU 淘汰;只接受可校验的图片。缓存同时保留在内存与平台规定的目录中,重启后可继续复用;不缓存电击特效成品,磁盘读写在线程中完成,写入采用临时文件原子替换,过期文件在访问/写入缓存时惰性清理。缓存目录不可读写时退回内存缓存,不影响结算。首次下载失败仍可能只有文字;正常刷新成功时,换头像最多延迟 1 小时更新。设置 VOLT_AVATAR_CACHE=false 可禁用缓存(AstrBot 在插件配置中关闭 volt_avatar_cache)。

🗃 数据

文件 内容
zap.json 群用电账本(原子写)
zap_log.jsonl 逐条审计日志(VOLT_IS_LOG=true 时)
zap_whitelist.json 免电名单

NoneBot 账本存于 localstore 插件数据目录,头像缓存使用 get_plugin_cache_dir() / "avatars"(遵循 localstore 的路径配置,不硬编码根目录);AstrBot 账本存于 data/plugin_data/astrbot_plugin_volt_toy/,头像缓存存于其下的 cache/avatars/。两边账本格式一致,可对拷迁移;缓存可直接删除,随后自动重新下载。

💡 说明

  • 电自己按 0.8 倍结算,且不占每日额度。
  • 榜单只统计成功施电;失败记录保留在账本与日志里,不进电王榜。

开发与回归测试

python -m pip install -e ".[dev]"
python -m pytest

测试不联网,账本和持久缓存均使用临时目录,不会修改实际群数据。覆盖五档渲染、GIF/特效开关、原图与文本回退、缓存过期/刷新失败/并发合并/容量淘汰/重启恢复。NoneBot 使用独立子进程运行真实 OneBot 指令事件链;AstrBot 使用 SDK 边界桩验证适配逻辑,不替代真实 AstrBot 环境的上线验证。CI 构建前自动运行这些测试。

📄 许可

MIT © Funny1Potato

Metadata

Release files for nonebot-plugin-volt-toy 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-plugin-volt-toy 0.2.1
File Size Uploaded Provenance Actions
nonebot_plugin_volt_toy-0.2.1.tar.gz 2.3 MB With provenance Details for nonebot_plugin_volt_toy-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-volt-toy 0.2.1
File Interpreter ABI Platform Actions
nonebot_plugin_volt_toy-0.2.1-py3-none-any.whl Python 3 none any Details for nonebot_plugin_volt_toy-0.2.1-py3-none-any.whl

Total release size: 2.4 MB

Release files / nonebot_plugin_volt_toy-0.2.1.tar.gz

Download URL nonebot_plugin_volt_toy-0.2.1.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
c1c1ab3a2241cdaf019880cdfae4b967e82d959e56db5f3514fde07d942d6d0e
BLAKE2b-256 checksum
How to use checksums
e65498cc214edd14ba7f8150baa3f3b118db4142460e71fb6a16de981700bb0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / nonebot_plugin_volt_toy-0.2.1-py3-none-any.whl

Download URL nonebot_plugin_volt_toy-0.2.1-py3-none-any.whl
Size 44.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1b487c3710c39eb596da29c9d96e91606578a10e2a9bf3f5edc6884dca68182
BLAKE2b-256 checksum
How to use checksums
ebe40b92e4168c830c184f794865cbdedb358417b526c9d972531342fc7a0fc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for nonebot-plugin-volt-toy 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nonebot_plugin_volt_toy-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page