feat: 持久记忆和代码优化、函数工具筛选
125
plugins/SignInPlugin/README.md
Normal file
@@ -0,0 +1,125 @@
|
||||
# 签到插件 (SignIn Plugin)
|
||||
|
||||
## 功能介绍
|
||||
|
||||
- 用户发送签到关键词即可进行签到
|
||||
- 随机获得 3-10 积分奖励
|
||||
- 每天只能签到一次
|
||||
- 支持连续签到奖励(每7天额外获得5积分)
|
||||
- 记录用户昵称和签到历史
|
||||
- 使用 MySQL 数据库存储
|
||||
|
||||
## 安装步骤
|
||||
|
||||
### 1. 安装依赖
|
||||
|
||||
```bash
|
||||
pip install pymysql
|
||||
```
|
||||
|
||||
### 2. 创建数据库
|
||||
|
||||
执行 `database.sql` 文件中的 SQL 语句创建数据库表:
|
||||
|
||||
```sql
|
||||
-- 在你的 MySQL 数据库中执行
|
||||
source /path/to/database.sql
|
||||
```
|
||||
|
||||
### 3. 配置数据库连接
|
||||
|
||||
编辑 `config.toml` 文件,修改数据库连接信息:
|
||||
|
||||
```toml
|
||||
[database]
|
||||
host = "your_mysql_host"
|
||||
port = 3306
|
||||
user = "your_username"
|
||||
password = "your_password"
|
||||
database = "your_database_name"
|
||||
charset = "utf8mb4"
|
||||
```
|
||||
|
||||
### 4. 自定义配置(可选)
|
||||
|
||||
你可以在 `config.toml` 中自定义:
|
||||
|
||||
- 积分奖励范围 (`min_points`, `max_points`)
|
||||
- 连续签到奖励设置 (`bonus_streak_days`, `bonus_points`)
|
||||
- 签到触发关键词 (`keywords`)
|
||||
- 回复消息模板 (`messages`)
|
||||
|
||||
## 使用方法
|
||||
|
||||
用户在微信中发送以下任意关键词即可签到:
|
||||
- 签到
|
||||
- 打卡
|
||||
- checkin
|
||||
- sign
|
||||
|
||||
## 功能特性
|
||||
|
||||
### 签到奖励
|
||||
- 基础积分:3-10 随机积分
|
||||
- 连续签到奖励:每连续签到7天额外获得5积分
|
||||
|
||||
### 数据记录
|
||||
- 用户基本信息(wxid、昵称、总积分)
|
||||
- 签到统计(最后签到日期、连续签到天数、总签到天数)
|
||||
- 详细签到记录(每次签到的时间、获得积分等)
|
||||
|
||||
### 防重复签到
|
||||
- 每天只能签到一次
|
||||
- 自动检测签到状态并提示
|
||||
|
||||
## 数据库表结构
|
||||
|
||||
### user_signin 表
|
||||
- 存储用户基本信息和签到统计
|
||||
- 包含积分、连续签到天数等字段
|
||||
|
||||
### signin_records 表
|
||||
- 存储详细的签到历史记录
|
||||
- 可用于统计分析和历史查询
|
||||
|
||||
## 回复消息示例
|
||||
|
||||
### 签到成功
|
||||
```
|
||||
✅ 签到成功!
|
||||
🎁 获得积分:7
|
||||
💰 当前积分:127
|
||||
🔥 连续签到:5天
|
||||
```
|
||||
|
||||
### 连续签到奖励
|
||||
```
|
||||
✅ 签到成功!
|
||||
🎁 获得积分:8
|
||||
💰 当前积分:200
|
||||
🔥 连续签到:7天
|
||||
🎉 连续签到7天奖励:+5积分!
|
||||
```
|
||||
|
||||
### 重复签到
|
||||
```
|
||||
❌ 今天已经签到过了!
|
||||
💰 当前积分:127
|
||||
🔥 连续签到:5天
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保 MySQL 数据库服务正常运行
|
||||
2. 数据库连接信息配置正确
|
||||
3. 插件会自动创建用户记录,无需手动添加
|
||||
4. 连续签到以自然日为准,中断后重新计算
|
||||
|
||||
## 扩展功能
|
||||
|
||||
你可以基于此插件扩展更多功能:
|
||||
- 签到排行榜
|
||||
- 积分商城
|
||||
- 签到提醒
|
||||
- 更复杂的奖励机制
|
||||
- 群组签到统计
|
||||
1
plugins/SignInPlugin/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# SignIn Plugin - 签到插件
|
||||
67
plugins/SignInPlugin/database.sql
Normal file
@@ -0,0 +1,67 @@
|
||||
-- 签到插件数据库表结构
|
||||
-- MySQL 5.7+ 兼容
|
||||
|
||||
-- 创建数据库(可选)
|
||||
-- CREATE DATABASE IF NOT EXISTS wechat_bot DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
-- USE wechat_bot;
|
||||
|
||||
-- 用户签到表
|
||||
CREATE TABLE IF NOT EXISTS `user_signin` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '自增ID',
|
||||
`wxid` VARCHAR(50) NOT NULL COMMENT '用户微信ID',
|
||||
`nickname` VARCHAR(100) DEFAULT '' COMMENT '用户昵称',
|
||||
`city` VARCHAR(50) DEFAULT '' COMMENT '用户城市',
|
||||
`points` INT DEFAULT 0 COMMENT '用户积分',
|
||||
`last_signin_date` DATE DEFAULT NULL COMMENT '最后签到日期',
|
||||
`signin_streak` INT DEFAULT 0 COMMENT '连续签到天数',
|
||||
`total_signin_days` INT DEFAULT 0 COMMENT '总签到天数',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
UNIQUE KEY `uk_wxid` (`wxid`),
|
||||
INDEX `idx_points` (`points` DESC),
|
||||
INDEX `idx_signin_date` (`last_signin_date`),
|
||||
INDEX `idx_city` (`city`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户签到表';
|
||||
|
||||
-- 签到记录表(可选,用于记录详细的签到历史)
|
||||
CREATE TABLE IF NOT EXISTS `signin_records` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '自增ID',
|
||||
`wxid` VARCHAR(50) NOT NULL COMMENT '用户微信ID',
|
||||
`nickname` VARCHAR(100) DEFAULT '' COMMENT '用户昵称',
|
||||
`signin_date` DATE NOT NULL COMMENT '签到日期',
|
||||
`points_earned` INT NOT NULL COMMENT '获得积分',
|
||||
`signin_streak` INT DEFAULT 1 COMMENT '当时的连续签到天数',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '签到时间',
|
||||
UNIQUE KEY `uk_wxid_date` (`wxid`, `signin_date`),
|
||||
INDEX `idx_signin_date` (`signin_date`),
|
||||
INDEX `idx_wxid` (`wxid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='签到记录表';
|
||||
|
||||
-- 积分变动记录表(记录所有积分增减)
|
||||
CREATE TABLE IF NOT EXISTS `points_history` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '自增ID',
|
||||
`wxid` VARCHAR(50) NOT NULL COMMENT '用户微信ID',
|
||||
`nickname` VARCHAR(100) DEFAULT '' COMMENT '用户昵称',
|
||||
`change_type` VARCHAR(20) NOT NULL COMMENT '变动类型: signin(签到), bonus(奖励), consume(消费), admin(管理员调整), other(其他)',
|
||||
`points_change` INT NOT NULL COMMENT '积分变动数量(正数增加,负数减少)',
|
||||
`points_before` INT NOT NULL COMMENT '变动前积分',
|
||||
`points_after` INT NOT NULL COMMENT '变动后积分',
|
||||
`description` VARCHAR(200) DEFAULT '' COMMENT '变动说明',
|
||||
`related_id` VARCHAR(50) DEFAULT '' COMMENT '关联ID(如订单号、签到记录ID等)',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '变动时间',
|
||||
INDEX `idx_wxid` (`wxid`),
|
||||
INDEX `idx_change_type` (`change_type`),
|
||||
INDEX `idx_created_at` (`created_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='积分变动记录表';
|
||||
|
||||
-- 积分统计视图(方便查询用户积分汇总)
|
||||
CREATE OR REPLACE VIEW `v_points_summary` AS
|
||||
SELECT
|
||||
wxid,
|
||||
nickname,
|
||||
points as current_points,
|
||||
total_signin_days,
|
||||
signin_streak,
|
||||
(SELECT COALESCE(SUM(points_change), 0) FROM points_history ph WHERE ph.wxid = us.wxid AND points_change > 0) as total_earned,
|
||||
(SELECT COALESCE(SUM(ABS(points_change)), 0) FROM points_history ph WHERE ph.wxid = us.wxid AND points_change < 0) as total_spent
|
||||
FROM user_signin us;
|
||||
BIN
plugins/SignInPlugin/images/1.png
Normal file
|
After Width: | Height: | Size: 2.1 MiB |
BIN
plugins/SignInPlugin/images/10.png
Normal file
|
After Width: | Height: | Size: 4.4 MiB |
BIN
plugins/SignInPlugin/images/11.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
plugins/SignInPlugin/images/12.png
Normal file
|
After Width: | Height: | Size: 2.5 MiB |
BIN
plugins/SignInPlugin/images/13.png
Normal file
|
After Width: | Height: | Size: 3.8 MiB |
BIN
plugins/SignInPlugin/images/14.png
Normal file
|
After Width: | Height: | Size: 2.7 MiB |
BIN
plugins/SignInPlugin/images/15.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
plugins/SignInPlugin/images/16.png
Normal file
|
After Width: | Height: | Size: 2.8 MiB |
BIN
plugins/SignInPlugin/images/17.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
plugins/SignInPlugin/images/18.png
Normal file
|
After Width: | Height: | Size: 488 KiB |
BIN
plugins/SignInPlugin/images/19.png
Normal file
|
After Width: | Height: | Size: 575 KiB |
BIN
plugins/SignInPlugin/images/2.png
Normal file
|
After Width: | Height: | Size: 5.1 MiB |
BIN
plugins/SignInPlugin/images/20.png
Normal file
|
After Width: | Height: | Size: 2.8 MiB |
BIN
plugins/SignInPlugin/images/21.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
plugins/SignInPlugin/images/22.png
Normal file
|
After Width: | Height: | Size: 5.4 MiB |
BIN
plugins/SignInPlugin/images/23.png
Normal file
|
After Width: | Height: | Size: 8.4 MiB |
BIN
plugins/SignInPlugin/images/24.png
Normal file
|
After Width: | Height: | Size: 2.6 MiB |
BIN
plugins/SignInPlugin/images/25.png
Normal file
|
After Width: | Height: | Size: 5.1 MiB |
BIN
plugins/SignInPlugin/images/26.png
Normal file
|
After Width: | Height: | Size: 3.3 MiB |
BIN
plugins/SignInPlugin/images/27.png
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
plugins/SignInPlugin/images/28.png
Normal file
|
After Width: | Height: | Size: 11 MiB |
BIN
plugins/SignInPlugin/images/29.png
Normal file
|
After Width: | Height: | Size: 3.4 MiB |
BIN
plugins/SignInPlugin/images/3.png
Normal file
|
After Width: | Height: | Size: 2.5 MiB |
BIN
plugins/SignInPlugin/images/30.png
Normal file
|
After Width: | Height: | Size: 3.8 MiB |
BIN
plugins/SignInPlugin/images/31.png
Normal file
|
After Width: | Height: | Size: 760 KiB |
BIN
plugins/SignInPlugin/images/32.png
Normal file
|
After Width: | Height: | Size: 724 KiB |
BIN
plugins/SignInPlugin/images/33.png
Normal file
|
After Width: | Height: | Size: 1.9 MiB |
BIN
plugins/SignInPlugin/images/34.png
Normal file
|
After Width: | Height: | Size: 1.8 MiB |
BIN
plugins/SignInPlugin/images/4.png
Normal file
|
After Width: | Height: | Size: 3.1 MiB |
BIN
plugins/SignInPlugin/images/5.png
Normal file
|
After Width: | Height: | Size: 1.5 MiB |
BIN
plugins/SignInPlugin/images/6.png
Normal file
|
After Width: | Height: | Size: 3.3 MiB |
BIN
plugins/SignInPlugin/images/7.png
Normal file
|
After Width: | Height: | Size: 4.2 MiB |
BIN
plugins/SignInPlugin/images/8.png
Normal file
|
After Width: | Height: | Size: 1.5 MiB |
BIN
plugins/SignInPlugin/images/9.png
Normal file
|
After Width: | Height: | Size: 820 KiB |
1614
plugins/SignInPlugin/main.py
Normal file
BIN
plugins/SignInPlugin/temp/avatar_kanweiting.jpg
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
plugins/SignInPlugin/temp/avatar_wxid_2fc15j0k7v6922.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
plugins/SignInPlugin/temp/avatar_wxid_43lhklsm0j4k22.jpg
Normal file
|
After Width: | Height: | Size: 59 KiB |
BIN
plugins/SignInPlugin/temp/avatar_wxid_8szghkl8ii3l12.jpg
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
plugins/SignInPlugin/temp/avatar_wxid_agyvm1pvbkj722.jpg
Normal file
|
After Width: | Height: | Size: 64 KiB |
BIN
plugins/SignInPlugin/temp/avatar_wxid_b8leztfi7o2v22.jpg
Normal file
|
After Width: | Height: | Size: 186 KiB |
BIN
plugins/SignInPlugin/temp/avatar_wxid_fkk3f2khf05k21.jpg
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
plugins/SignInPlugin/temp/avatar_wxid_pylrull4awqm22.jpg
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
plugins/SignInPlugin/temp/avatar_wxid_rm8cr2qjf45n12.jpg
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
plugins/SignInPlugin/temp/avatar_wxid_sidlglgli5e122.jpg
Normal file
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 223 KiB |
|
After Width: | Height: | Size: 197 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 62 KiB |
BIN
plugins/SignInPlugin/temp/signin_kanweiting_1763082828.jpg
Normal file
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 248 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 106 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 69 KiB |
74
plugins/SignInPlugin/update_database.sql
Normal file
@@ -0,0 +1,74 @@
|
||||
-- 签到插件数据库升级脚本
|
||||
-- 版本: 1.1.0
|
||||
-- 更新内容:
|
||||
-- v1.0.0: 添加城市字段
|
||||
-- v1.1.0: 添加积分变动记录表
|
||||
|
||||
-- ============================================
|
||||
-- v1.0.0 - 添加城市字段(如果已执行可跳过)
|
||||
-- ============================================
|
||||
|
||||
-- 添加城市字段到 user_signin 表(如果不存在)
|
||||
-- ALTER TABLE `user_signin`
|
||||
-- ADD COLUMN `city` VARCHAR(50) DEFAULT '' COMMENT '用户城市'
|
||||
-- AFTER `nickname`;
|
||||
|
||||
-- 添加城市字段的索引
|
||||
-- ALTER TABLE `user_signin`
|
||||
-- ADD INDEX `idx_city` (`city`);
|
||||
|
||||
-- ============================================
|
||||
-- v1.1.0 - 添加积分变动记录表
|
||||
-- ============================================
|
||||
|
||||
-- 创建积分变动记录表
|
||||
CREATE TABLE IF NOT EXISTS `points_history` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY COMMENT '自增ID',
|
||||
`wxid` VARCHAR(50) NOT NULL COMMENT '用户微信ID',
|
||||
`nickname` VARCHAR(100) DEFAULT '' COMMENT '用户昵称',
|
||||
`change_type` VARCHAR(20) NOT NULL COMMENT '变动类型: signin(签到), bonus(奖励), consume(消费), admin(管理员调整), other(其他)',
|
||||
`points_change` INT NOT NULL COMMENT '积分变动数量(正数增加,负数减少)',
|
||||
`points_before` INT NOT NULL COMMENT '变动前积分',
|
||||
`points_after` INT NOT NULL COMMENT '变动后积分',
|
||||
`description` VARCHAR(200) DEFAULT '' COMMENT '变动说明',
|
||||
`related_id` VARCHAR(50) DEFAULT '' COMMENT '关联ID(如订单号、签到记录ID等)',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '变动时间',
|
||||
INDEX `idx_wxid` (`wxid`),
|
||||
INDEX `idx_change_type` (`change_type`),
|
||||
INDEX `idx_created_at` (`created_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='积分变动记录表';
|
||||
|
||||
-- 创建积分统计视图
|
||||
CREATE OR REPLACE VIEW `v_points_summary` AS
|
||||
SELECT
|
||||
wxid,
|
||||
nickname,
|
||||
points as current_points,
|
||||
total_signin_days,
|
||||
signin_streak,
|
||||
(SELECT COALESCE(SUM(points_change), 0) FROM points_history ph WHERE ph.wxid = us.wxid AND points_change > 0) as total_earned,
|
||||
(SELECT COALESCE(SUM(ABS(points_change)), 0) FROM points_history ph WHERE ph.wxid = us.wxid AND points_change < 0) as total_spent
|
||||
FROM user_signin us;
|
||||
|
||||
-- ============================================
|
||||
-- 可选:从历史签到记录迁移数据(仅首次升级时执行一次)
|
||||
-- ============================================
|
||||
-- INSERT INTO points_history (wxid, nickname, change_type, points_change, points_before, points_after, description, related_id, created_at)
|
||||
-- SELECT
|
||||
-- sr.wxid,
|
||||
-- sr.nickname,
|
||||
-- 'signin' as change_type,
|
||||
-- sr.points_earned as points_change,
|
||||
-- 0 as points_before,
|
||||
-- 0 as points_after,
|
||||
-- CONCAT('签到获得 ', sr.points_earned, ' 积分(连续', sr.signin_streak, '天)') as description,
|
||||
-- sr.signin_date as related_id,
|
||||
-- sr.created_at
|
||||
-- FROM signin_records sr
|
||||
-- WHERE NOT EXISTS (
|
||||
-- SELECT 1 FROM points_history ph
|
||||
-- WHERE ph.wxid = sr.wxid AND ph.related_id = sr.signin_date AND ph.change_type = 'signin'
|
||||
-- );
|
||||
|
||||
-- 验证升级结果
|
||||
-- SELECT '积分变动记录表' as table_name, COUNT(*) as record_count FROM points_history;
|
||||