From 2e975d2e8cc52355d7b1720a8a887552d1741987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=80=BB=E5=8A=A8=E5=91=98?= <73592731+devourbots@users.noreply.github.com> Date: Wed, 5 May 2021 11:41:27 +0800 Subject: [PATCH] None --- connector.py | 21 +++++++++++++++++++++ func.py | 17 ++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 connector.py diff --git a/connector.py b/connector.py new file mode 100644 index 0000000..7d49ae1 --- /dev/null +++ b/connector.py @@ -0,0 +1,21 @@ +import redis + +# 连接 redis +# 指定主机地址,port与服务器连接,redis默认数据库有16个,默认db是0 +# r = redis.Redis(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True) # password='**' +# print(r.get('foo')) +# r.set('foo', '[1,2,3]') +# print(r.get('foo')) +# print(r.keys()) +# r.delete('foo') +# print(r.keys()) + +pool = redis.ConnectionPool(host='127.0.0.1', port=6379, encoding='utf8', decode_responses=True) + + +# r = redis.Redis(connection_pool=pool) +# r.set('foo', 'Bar') +# print(r.get('foo')) + +def get_connection(): + return redis.StrictRedis(connection_pool=pool) diff --git a/func.py b/func.py index 7b6c9fd..b8150ab 100644 --- a/func.py +++ b/func.py @@ -1,5 +1,6 @@ import datetime import threading +import connector import telegram from telegram import InlineKeyboardMarkup, InlineKeyboardButton, ForceReply @@ -22,8 +23,22 @@ def start(update, context): def chat_content_exec(update, context): + r = connector.get_connection() + text = update.message.text + chat_type = update.effective_chat.type + user_id = update.effective_user.id chat_id = update.effective_message.chat_id - print(chat_id) + print("\n---------------------------") + print("内容: " + text) + if "/" in text: + print("这是一条指令信息") + print("群组类型: " + str(chat_type)) + print("用户ID: " + str(user_id)) + print("chat_id: " + str(chat_id)) + r.append("{}_chat_content".format(chat_id), text) + r.incrby("{}_user_message_amount", user_id) + print("---------------------------") + start_handler = CommandHandler('start', start)