签到功能初始化
消息计数定时任务入库
This commit is contained in:
4
main.py
4
main.py
@@ -58,8 +58,10 @@ def main(chat_type: int):
|
|||||||
robot.onEveryTime("10:30", robot.sendEpicFreeGames)
|
robot.onEveryTime("10:30", robot.sendEpicFreeGames)
|
||||||
|
|
||||||
|
|
||||||
# message report
|
# message report 1:数据自动从redis 转到sqllite
|
||||||
robot.onEveryTime("00:30", robot.messageCountToDB)
|
robot.onEveryTime("00:30", robot.messageCountToDB)
|
||||||
|
# 从db中提取并发送给相关群
|
||||||
|
robot.onEveryTime("09:30", robot.generateAndSendRanking)
|
||||||
|
|
||||||
# 让机器人一直跑
|
# 让机器人一直跑
|
||||||
robot.keepRunningAndBlockProcess()
|
robot.keepRunningAndBlockProcess()
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
CREATE TABLE IF NOT EXISTS speech_counts (
|
CREATE TABLE IF NOT EXISTS speech_counts
|
||||||
|
(
|
||||||
group_id TEXT,
|
group_id TEXT,
|
||||||
wx_id TEXT,
|
wx_id TEXT,
|
||||||
date TEXT,
|
date TEXT,
|
||||||
count INTEGER,
|
count INTEGER,
|
||||||
PRIMARY KEY (group_id, wx_id, date)
|
PRIMARY KEY (group_id, wx_id, date)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -19,5 +19,3 @@ def process_message(message:WxMsg):
|
|||||||
# 设置时效为48小时
|
# 设置时效为48小时
|
||||||
r.expire(key, 86400 * 2)
|
r.expire(key, 86400 * 2)
|
||||||
# 或者使用字符串:r.incr(key) # 如果只存储一个整数值,字符串类型可能更简单
|
# 或者使用字符串:r.incr(key) # 如果只存储一个整数值,字符串类型可能更简单
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ import time
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import redis
|
import redis
|
||||||
|
|
||||||
# 连接到Redis
|
# 连接到Redis
|
||||||
r = redis.Redis(host='192.168.2.32', port=6379, db=0)
|
r = redis.Redis(host='192.168.2.32', port=6379, db=0)
|
||||||
|
|
||||||
|
|
||||||
def write_to_db():
|
def write_to_db():
|
||||||
# 连接到SQLite数据库
|
# 连接到SQLite数据库
|
||||||
conn = sqlite3.connect('message_stats.db')
|
conn = sqlite3.connect('message_stats.db')
|
||||||
@@ -63,12 +65,9 @@ def generate_and_send_ranking(groupId,allContacts: dict):
|
|||||||
ranking_str = yesterday + "发言数量前20的用户排名:\n"
|
ranking_str = yesterday + "发言数量前20的用户排名:\n"
|
||||||
for rank, (username, speech_count) in enumerate(results, start=1):
|
for rank, (username, speech_count) in enumerate(results, start=1):
|
||||||
ranking_str += f"{rank}. {allContacts[username]}: {speech_count} 次发言\n"
|
ranking_str += f"{rank}. {allContacts[username]}: {speech_count} 次发言\n"
|
||||||
|
|
||||||
# 关闭数据库连接
|
# 关闭数据库连接
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
# 这里我们没有实际“发送”排名,只是返回字符串
|
# 这里我们没有实际“发送”排名,只是返回字符串
|
||||||
# 如果需要发送,可以在此添加发送逻辑
|
# 如果需要发送,可以在此添加发送逻辑
|
||||||
return ranking_str
|
return ranking_str
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
message_sign/readme.md
Normal file
2
message_sign/readme.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# 签到功能
|
||||||
|
## 用户每日签到,可以汇报签到次数
|
||||||
Reference in New Issue
Block a user