From 47aff191b107b0b2d590eaefe6e2ee5f132c1ca0 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 20 Jun 2021 18:51:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=B8=AE=E5=8A=A9=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.gen.py | 4 ++++ func.py | 22 +++++++++++++++++++--- main.py | 3 ++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/config.gen.py b/config.gen.py index 3219eb0..1f3030f 100644 --- a/config.gen.py +++ b/config.gen.py @@ -23,3 +23,7 @@ OWNER = 0 # 日志频道 id 0 为不启用 CHANNEL = 0 + +# 帮助信息 +HELP = '**Group Word Cloud Bot**\n\n/start - 查看此帮助信息\n/ping - 我还活着吗?\n/rank - 手动生成词云(绒布球)\n\n' \ + '此项目开源于:https://git.io/JnrvH' diff --git a/func.py b/func.py index 8655a27..872d211 100644 --- a/func.py +++ b/func.py @@ -3,7 +3,7 @@ import time import connector import telegram from telegram.ext import CommandHandler, MessageHandler, Filters -from config import TOKEN, LIMIT_COUNT, EXCLUSIVE_MODE, RANK_COMMAND_MODE, OWNER, EXCLUSIVE_LIST, CHANNEL +from config import TOKEN, LIMIT_COUNT, EXCLUSIVE_MODE, RANK_COMMAND_MODE, OWNER, EXCLUSIVE_LIST, CHANNEL, HELP import schedule from task import add_task @@ -17,9 +17,9 @@ def start(update, context): return try: connector.get_connection().keys() - print('进入start函数') + print('进入 start 函数') update.message.reply_text( - 'pong~', + HELP, ) except Exception as e: print(e) @@ -28,6 +28,21 @@ def start(update, context): update.message.reply_text(f"系统故障,Redis连接失败,错误信息:\n{e}") +def ping(update, context): + # 限制不为群组 + chat_type = update.effective_chat.type + if chat_type == "supergroup": + return + try: + connector.get_connection().keys() + print('进入 ping 函数') + update.message.reply_text( + 'pong~', + ) + except Exception as e: + print(e) + + def rank(update, context): try: r = connector.get_connection() @@ -134,5 +149,6 @@ def check_schedule(): start_handler = CommandHandler('start', start) +ping_handler = CommandHandler('ping', ping) rank_handler = CommandHandler('rank', rank) chat_content_handler = MessageHandler(Filters.text, chat_content_exec) diff --git a/main.py b/main.py index e3cfbcd..90b30c5 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ from telegram.ext import Updater from config import TOKEN -from func import start_handler, chat_content_handler, check_schedule, rank_handler +from func import start_handler, ping_handler, chat_content_handler, check_schedule, rank_handler import schedule from task import schedule_task, flush_redis, do_task import threading @@ -23,6 +23,7 @@ updater = Updater(token=TOKEN, use_context=True) dispatcher = updater.dispatcher dispatcher.add_handler(start_handler) +dispatcher.add_handler(ping_handler) dispatcher.add_handler(rank_handler) dispatcher.add_handler(chat_content_handler)