From a0c48d505ea0f309c717bc0e62d2728cd1803770 Mon Sep 17 00:00:00 2001 From: BennyThink Date: Fri, 24 Jun 2022 19:26:07 +0800 Subject: [PATCH] set bot command #124 --- README.md | 2 +- requirements.txt | 4 ++-- ytdlbot/constant.py | 6 ++++++ ytdlbot/ytdl_bot.py | 14 ++++++++++++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2bda341..1e1cd37 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ docker-compose -f worker.yml up -d # Command -``` +```cmd start - Let's start about - What's this bot? ping - Bot running status diff --git a/requirements.txt b/requirements.txt index a27a974..3cad522 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ pyrogram==1.4.16 tgcrypto==1.2.3 -yt-dlp==2022.5.18 +yt-dlp==2022.6.22.1 APScheduler==3.9.1 beautifultable==1.1.0 ffmpeg-python==0.2.0 @@ -19,4 +19,4 @@ requests==2.28.0 tqdm==4.64.0 requests-toolbelt==0.9.1 ffpb==0.4.1 -youtube-search-python==1.6.5 +youtube-search-python==1.6.6 diff --git a/ytdlbot/constant.py b/ytdlbot/constant.py index bc8ceec..9ad45d2 100644 --- a/ytdlbot/constant.py +++ b/ytdlbot/constant.py @@ -8,6 +8,8 @@ __author__ = "Benny " import os +import pathlib +import re import time from config import (AFD_LINK, COFFEE_LINK, ENABLE_CELERY, ENABLE_VIP, EX, @@ -149,3 +151,7 @@ Sending format: **{1}** text += f"{status}{hostname} **{active}** {load} {rev}\n" return text + + +with open(pathlib.Path(__file__).parent.parent.joinpath("README.md"), encoding="u8") as f: + COMMANDS = re.findall(r"```cmd([\s|\S]*)```", f.read())[0].strip() diff --git a/ytdlbot/ytdl_bot.py b/ytdlbot/ytdl_bot.py index 5797687..f241548 100644 --- a/ytdlbot/ytdl_bot.py +++ b/ytdlbot/ytdl_bot.py @@ -15,18 +15,19 @@ import time import traceback import typing from io import BytesIO -from youtubesearchpython import VideosSearch + import pyrogram.errors from apscheduler.schedulers.background import BackgroundScheduler from pyrogram import Client, filters, types from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from tgbot_ping import get_runtime +from youtubesearchpython import VideosSearch from client_init import create_app from config import (AUTHORIZED_USER, ENABLE_CELERY, ENABLE_VIP, OWNER, REQUIRED_MEMBERSHIP) -from constant import BotText +from constant import COMMANDS, BotText from db import InfluxDB, MySQL, Redis from limit import VIP, verify_payment from tasks import app as celery_app @@ -387,4 +388,13 @@ By @BennyThink, VIP mode: {ENABLE_VIP}, Distribution: {ENABLE_CELERY} Version: {get_revision()} """ print(banner) + + with app: + commands = [i for i in COMMANDS.split("\n") if i] + command_list = [] + for cmd in commands: + split = cmd.split("-") + command_list.append(pyrogram.types.BotCommand(split[0].strip(), split[1].strip())) + app.set_bot_commands(command_list) + app.run()