word_cloud_bot/func.py
机器人总动员 722ecfef28 None
2021-05-05 15:35:04 +08:00

45 lines
1.5 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 connector
import telegram
from telegram.ext import CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackQueryHandler
from config import TOKEN
bot = telegram.Bot(token=TOKEN)
def start(update, context):
print('进入start函数')
update.message.reply_text(
'您好!',
)
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
try:
username = update.effective_user.username
except Exception as e:
username = update.effective_user.id
print("\n---------------------------")
print("内容: " + text)
print("群组类型: " + str(chat_type))
print("用户ID: " + str(user_id))
print("chat_id: " + str(chat_id))
if "/" in text:
print("这是一条指令信息,跳过")
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("---------------------------")
start_handler = CommandHandler('start', start)
chat_content_handler = MessageHandler(Filters.text, chat_content_exec)