This commit is contained in:
机器人总动员 2021-05-05 11:41:27 +08:00
parent babc67df93
commit 2e975d2e8c
2 changed files with 37 additions and 1 deletions

21
connector.py Normal file
View File

@ -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)

17
func.py
View File

@ -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)