克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

wechat-bot-plugins

介绍

微信机器人插件合集

软件架构

此模块以wechat-bot-plugin-base作为父模块,该模块依赖wechat-bot-core核心模块,同时依赖maven-shade插件进行打包操作。

插件说明

AI插件

wechat-bot-plugin-ai模块,监听文本消息事件,基于ai接口对接大模型,实现对微信消息的回复及聊天记录总结等功能。

今日新闻插件

wechat-bot-plugin-daily_news模块,监听文本消息事件,基于第三方api,使用hutool-http下载每日新闻或每日吃瓜图片并进行回复。

关键词今日新闻今日吃瓜

表情包插件

wechat-bot-plugin-emoticon模块,监听文本消息事件,通过消息中存在的关键词触发,回复表情包。 该插件包括命令执行器,可通过命令动态添加、删除表情包及关键词,亦可手动管理配置文件。

命令

  • /emoticon list
  • /emoticon add <name> <emoticon_md5> <kerwords>
  • /emoticon remove <name>
  • /emoticon black <keywords>

邀请入群插件

wechat-bot-plugin-invite模块通过监听好友请求事件或私聊消息事件,通过关键词触发,添加机器人好友时的验证信息或私聊机器人相应关键词,自动邀请好友进群。 通过配置文件配置关键词、对应群名称。

keyword: group_name
# 例如通过`wechat-bot`关键词邀请好友加入`协议版机器人催更群`
wechat-bot: 协议版机器人催更群

kfc插件

wechat-bot-plugin-kfc模块,监听消息事件,通过关键词触发,回复kfc文案。插件优先从api获取文案,失败后会从本地json文件中获取。

关键词kfcKFC肯德基疯狂星期四v我50

内存插件

wechat-bot-plugin-memory模块,监听消息事件,通过命令执行器,查看bot程序当前占用内存及清理内存。

命令

  • /memory [-s|--show] 查看内存使用情况
  • /memory [-c|--clear] 清理内存

复读机插件

wechat-bot-plugin-reread模块,人类的本质就是复读机RereadListener监听群组文本消息事件, 如果同一个群组中的文本消息与上次的相同,那么进行复读,发送同一条消息给群组。

定时任务插件

wechat-bot-plugin-schedule模块,通过命令执行器或手动配置,添加、删除定时任务。

命令

  • /scheduler list 查看定时任务列表
  • scheduler add [-n|--name]=<name> [-c|--cron]=<cron> [-k|--kerword]=<keyword> [-t|--targets]=<targets...> 添加定时任务,name为任务名称,cron为cron表达式(因命令行解析原因,空格需要使用[-+|.]代替) ,keyword为触发关键词,targets为目标群组名称(使用空格分隔)
  • /scheduler remove <name> 删除定时任务
  • /scheduler edit [-n|--name]=<name> [-c|--cron]=<cron> [-k|--kerword]=<keyword> [-t|--targets]=<targets...> 编辑定时任务,参考add命令

配置文件示例

daily-news:
  name: 今日新闻
  cron: 30 8 * * *
  keyword: 每日新闻
  targets:
    - 协议版机器人催更群

色图插件

wechat-bot-plugin-setu模块,监听文本消息事件,通过关键词触发,回复相应图片。 发送图片频率太高会被微信限制,请不要频繁使用。(考虑后续添加间隔限制)

关键词

  • 来点黑丝 回复黑丝图片
  • 来点白丝 回复白丝图片
  • 看看腿 随机回复黑丝或白丝图片
  • plmm漂亮妹妹来点美女 回复美女图片或视频
  • 来点帅哥 回复帅哥图片
  • 来点** 通过360图片搜索**,随机获取其中一张回复

群消息统计分析插件

wechat-bot-plugin-statistics模块,监听所有群组的消息事件,统计群组内消息发送情况,并根据关键词生成排行榜、词云、AI分析报告(依赖于ai插件)。 该插件依赖hutool-db:5.8.29进行数据库操作(6.0去除了nosql的操作),依赖sqlite-jdbc连接sqlite数据库(存储聊天记录), 依赖jedis连接操作redis(统计发言数据、分词后的词频等),依赖hanlp进行分词,依赖kumo-core进行词云图片生成。

  1. 每个群组的消息数量存放于redis字符串中,key为statistics:total:count::{groupName},value为群组消息数量。
  2. 每个群组内每位成员发言总数存放于redis哈希表中,key为statistics:everone:count::{groupName},其中key为成员名称,value为成员发言总数。
  3. 每个群组内每位成员每天发言总数存放于redis哈希表中,key为statistics:everyday:count::{groupName} ,其中key为日期,value为成员当天发言总数。
  4. 每个群组内每位成员今日发言数量存放于redis哈希表中,key为statistics:today:count::{groupName}:{date} ,其中key为成员名称,value为成员今日发言总数,此哈希表保留31天。
  5. 群组内消息类型统计的key为statistics:analyze::{messageType},value为消息类型对应的数量。
  6. 群组消息分词词频统计数据存放于redis排序集合中,key为tokenizer::{groupName}:{date},value为关键词,score为词频。

  1. 分词词频统计仅统计词性为"n"、"v"、"a"、"g",其他词性不纳入统计,且分词后关键词长度大于1才纳入统计。
  2. 分词统计及词云生成需要在配置文件中配置启用的群组才会生效,未启用时不会进行分词,统计数据没有词云
  3. AI分析报告依赖ai插件,需要确保ai插件可以正常使用,否则将不会生成AI分析报告。
  4. AI分析报告需要在配置文件中配置启用的群组才会生效,未启用时不会生成AI分析报告。
  5. 只有今日排行会生成AI分析报告。

关键词: 今日排行昨日排行本周排行本月排行历史排行

命令

  • /statistics|stat <groupName> [-a|--add]=<members> 为群组添加可以查看排行的成员,支持添加多个成员,多个成员之间使用空格分隔。
  • /statistics|stat <groupName> [-r|--remove]=<members> 为群组移除可以查看排行的成员,支持移除多个成员,多个成员之间使用空格分隔。

配置文件示例

wordcloud: # 启用词频统计及词云生成的群
  - 机器人测试群
ai-analyze: # 启用AI分析报告的群
  - 机器人测试群

群成员发言欢迎词插件

wechat-bot-plugin-tips模块,监听群组文本消息事件,当发送消息的成员配置了欢迎词,则发送欢迎词。

命令

  • /tips add [-m|--member]=<member> [-t|--tip]=<tip> 为成员添加欢迎词,member为成员名称,tip为欢迎词。
  • /tips edit [-m|--member]=<member> [-t|--tip]=<tip> 编辑成员欢迎词,member为成员名称,tip为欢迎词。
  • /tips del [-m|--member]=<member> 移除成员欢迎词,member为成员名称。

配置文件示例

tips::timeout: 10   # 超时时间,单位分钟,当成员发言间隔大于该值时,才发送成员欢迎词
member_nick_name: tips # 成员昵称及欢迎词

常见问题

如何使用?

将打包好的jar文件拷贝到plugins目录下,重启bot或向bot发送指令/pm load <plugin-name>(前提是已经加载了PluginManager 插件)即可。

如何管理插件?

确保你已经加载了PluginManager插件,该插件提供了插件管理的相关命令:

  • /pm list 查看已加载的插件
  • /pm help 查看插件帮助信息
  • /pm load <plugin-name>... 加载插件
  • /pm unload <plugin-name>... 卸载插件
  • /pm reload <plugin-name>... 重新加载插件
  • /pm info <plugin-name>... 查看插件信息
  • /pm enable <plugin-name>... 启用插件,如果在群组中执行该命令,则是为该群组启用插件,否则为全局启用插件;
  • /pm disable <plugin-name>... 禁用插件,如果在群组中执行该命令,则是为该群组禁用插件,否则为全局禁用插件;

插件的调用权限如何设置?

  1. 对于命令执行插件,默认bot owner拥有执行权限,其他用户无权限执行;owner可用过/cm <command> [-a|--add] <user> 命令添加指定命令可执行的用户。
  2. 对于插件监听器,则需要自行在EventListener类的support方法或者onEvent方法中添加权限判断。

如何开发插件?

  1. frok本仓库或直接拉取本仓库后,创建新的插件模块进行开发,本仓库的pom.xml中已配置了插件依赖,无需手动添加依赖;
  2. 自行创建插件项目或模块,pom.xml中以x.ovo.wechat.bot:wechat-bot-plugin-base作为父模块,wechat-bot-plugin-base 中引入了核心依赖并配置了打包方式;
  3. 自行船舰插件项目或模块,pom.xml中引入x.ovo.wechat.bot:wechat-bot-core,并配置maven shade打包插件;

插件中至少需要包含以下内容:

  1. 继承Plugin类,实现onLoadgetEventListenergetCommandExcutor方法,onLoad方法为插件加载时调用,一般用于向 plugin/{plugin-name}目录下创建配置文件, getEventListener方法返回事件监听器(可返回null),getCommandExcutor方法返回命令执行器(可返回null);
  2. resources中创建plugin.yml文件,该文件为插件配置文件,插件加载时需要获取插件jar包中的该文件,必不可少:
name: plugin-manager      # 插件名称
version: 2.0.0            # 插件版本
priority: 10              # 优先级,值越小优先级越高越先执行,默认为10
main: x.ovo.wechat.bot.plugin.PmPlugin    # 插件类
description: 插件管理器,用于插件管理,启用、禁用、加载、下载、重载插件  # 插件描述
authors: # 插件作者
  - Ooops

Plugin中的getEventListener方法返回一个事件监听器,该监听器需要继承EventListener<E extends Event<S>, S>并实现 boolean support(@NonNull E event, S source)方法和boolean onEvent(@NonNull E event, S source)。 泛型E为事件类型,S为事件源类型,事件监听器用于监听事件,当监听到事件时,会调用support方法判断是否支持该事件,如果支持,则调用 onEvent方法处理事件。

onEvent方法需要返回一个boolean值,如果返回true,则表示事件监听器监听到事件并处理成功,否则表示事件处理失败。同时可自行选择是否需要重写 boolean executeNext()方法, 如果onEvent返回trueexecuteNext返回false,则表示此监听器已正常处理某事件,不再执行后续的事件监听器,否则会继续执行后续监听器。

getCommandExcutor方法返回一个命令执行器,该执行器需要继承CommandExecutorCommandExecutor中没有方法需要强制你去实现,命令行解析采用picocli,可参考官方文档进行开发。

CommandExecutor中包含两个方法,你可以根据自己需要进行重写:

  1. String noPermissionTip() 当发送命令的联系人没有执行权限时,返回的提示语,默认为“你没有权限执行此命令,请不要调皮”;
  2. boolean hasPermission(String user) 权限检查,根据发送命令的用户昵称判断该用户是否具有权限执行此命令。 默认逻辑为bot所有者和指定用户具有权限(可通过wecaht-bot-plugin-cm插件提供的/cm <command> [-a|--add] <users>... 命令添加或自行修改配置文件 command_permission.json)。

bot仓库中的wechat-bot-plugin模块下,基础插件wechat-bot-plugin-cmwechat-bot-plugin-pm中的命令执行器采用了两种不同的实现形式,你可以参考进行开发。

配置文件映射为bean异常

因为获取配置文件的getConfig方法声明于Plugin类,该类位于wechat-bot-core 模块中,bot启动时由“app”类加载器加载该类,而配置类位于插件jar中,由插件对应的ClassLoader加载。 yaml配置文件在解析时会先解析为Java基础类或Map、List等类型,而在进行类型转换时,由于跨类加载器,导致出现 ClassDefinerNotFoundException异常。本人能力有限,未能解决此问题,如有解决方案,欢迎提交PR。 因此在插件中使用配置文件时,不能自定义配置类,只能通过plugin.getConfig()方法获取Map<String, Object>类型对象后,再从map中取值。

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

微信机器人插件合集 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化