word_cloud_bot/func.py
机器人总动员 206ae3f94d 添加 /start 检测功能
更新使用说明
2021-05-05 18:28:26 +08:00

65 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import time
import connector
import telegram
from telegram.ext import CommandHandler, MessageHandler, Filters
from config import TOKEN
import schedule
bot = telegram.Bot(token=TOKEN)
def start(update, context):
try:
connector.get_connection()
print('进入start函数')
update.message.reply_text(
'在呢!系统运行正常~',
)
except Exception as e:
print(e)
print('进入start函数')
update.message.reply_text("系统故障Redis连接失败请检查")
update.message.reply_text("错误信息:" + str(e))
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
if chat_type != "supergroup":
return
# if chat_id not in ["1231242141"]:
# return
try:
username = update.effective_user.username
except Exception as e:
username = update.effective_user.id
print("\n---------------------------")
print("内容: " + text[:10])
print("群组类型: " + str(chat_type))
print("用户ID: " + str(user_id))
print("chat_id: " + str(chat_id))
if "/" in text:
print("这是一条指令信息,跳过")
return
else:
if text[-1] not in ["", "", "", "", "", "!", "?", ",", ":", "."]:
r.append("{}_chat_content".format(chat_id), text + "")
else:
r.append("{}_chat_content".format(chat_id), text)
r.incrby("{}_total_message_amount".format(chat_id))
r.hincrby("{}_user_message_amount".format(chat_id), username)
print("---------------------------")
def check_schedule():
while True:
schedule.run_pending()
time.sleep(1)
start_handler = CommandHandler('start', start)
chat_content_handler = MessageHandler(Filters.text, chat_content_exec)