2021-05-05 08:13:28 +00:00
|
|
|
|
import time
|
|
|
|
|
|
2021-05-05 03:41:27 +00:00
|
|
|
|
import connector
|
2021-05-05 03:10:01 +00:00
|
|
|
|
import telegram
|
|
|
|
|
from telegram.ext import CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackQueryHandler
|
|
|
|
|
from config import TOKEN
|
2021-05-05 08:13:28 +00:00
|
|
|
|
import schedule
|
2021-05-05 03:10:01 +00:00
|
|
|
|
|
|
|
|
|
bot = telegram.Bot(token=TOKEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start(update, context):
|
|
|
|
|
print('进入start函数')
|
|
|
|
|
update.message.reply_text(
|
|
|
|
|
'您好!',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chat_content_exec(update, context):
|
2021-05-05 03:41:27 +00:00
|
|
|
|
r = connector.get_connection()
|
|
|
|
|
text = update.message.text
|
|
|
|
|
chat_type = update.effective_chat.type
|
|
|
|
|
user_id = update.effective_user.id
|
2021-05-05 03:10:01 +00:00
|
|
|
|
chat_id = update.effective_message.chat_id
|
2021-05-05 10:17:21 +00:00
|
|
|
|
if chat_type != "supergroup":
|
|
|
|
|
return
|
|
|
|
|
# if chat_id not in ["1231242141"]:
|
|
|
|
|
# return
|
2021-05-05 07:35:04 +00:00
|
|
|
|
try:
|
|
|
|
|
username = update.effective_user.username
|
|
|
|
|
except Exception as e:
|
|
|
|
|
username = update.effective_user.id
|
2021-05-05 03:41:27 +00:00
|
|
|
|
print("\n---------------------------")
|
2021-05-05 08:27:21 +00:00
|
|
|
|
print("内容: " + text[:10])
|
2021-05-05 03:41:27 +00:00
|
|
|
|
print("群组类型: " + str(chat_type))
|
|
|
|
|
print("用户ID: " + str(user_id))
|
|
|
|
|
print("chat_id: " + str(chat_id))
|
2021-05-05 06:50:25 +00:00
|
|
|
|
if "/" in text:
|
|
|
|
|
print("这是一条指令信息,跳过")
|
2021-05-05 08:27:21 +00:00
|
|
|
|
return
|
2021-05-05 06:50:25 +00:00
|
|
|
|
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))
|
2021-05-05 07:35:04 +00:00
|
|
|
|
r.hincrby("{}_user_message_amount".format(chat_id), username)
|
2021-05-05 03:41:27 +00:00
|
|
|
|
print("---------------------------")
|
|
|
|
|
|
2021-05-05 03:10:01 +00:00
|
|
|
|
|
2021-05-05 08:13:28 +00:00
|
|
|
|
def check_schedule():
|
|
|
|
|
while True:
|
|
|
|
|
schedule.run_pending()
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
2021-05-05 03:10:01 +00:00
|
|
|
|
start_handler = CommandHandler('start', start)
|
2021-05-05 03:12:17 +00:00
|
|
|
|
chat_content_handler = MessageHandler(Filters.text, chat_content_exec)
|