bot commited on
Commit
006b713
·
1 Parent(s): bc27f7f
Files changed (1) hide show
  1. main.py +40 -12
main.py CHANGED
@@ -10,6 +10,7 @@ from telegram.ext import (
10
  MessageHandler,
11
  CallbackQueryHandler,
12
  CallbackContext,
 
13
  )
14
  import httpx
15
 
@@ -149,18 +150,44 @@ TG_BASE_URL = "https://tg.alist.dpdns.org/bot"
149
 
150
  ###################TG机器人功能区###################
151
  # 定义命令处理函数
152
- async def start(update: Update, context):
153
- commands = (
154
- "🚀欢迎使用我的机器人!\n\n"
155
- "📋可用命令:\n"
156
- "•直接发送magent:开的关磁力将直接离线下载\n"
157
- "•/tasks - 查看下载任务\n"
158
- "•/files - 查看文件列表\n"
159
- "•/quota - 查看存储空间\n"
160
- "•/emptytrash - 清空回收站\n"
161
- "•/help - 获取帮助信息\n"
162
- )
163
- await update.message.reply_text(commands)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
 
166
  async def help(update: Update, context):
@@ -406,6 +433,7 @@ async def init_client():
406
  TG_BOT_APPLICATION.add_handler(
407
  CallbackQueryHandler(handle_task_confirmation, pattern="^confirm_task")
408
  )
 
409
  TG_BOT_APPLICATION.add_handler(CommandHandler("start", start))
410
  TG_BOT_APPLICATION.add_handler(CommandHandler("help", help))
411
  TG_BOT_APPLICATION.add_handler(CommandHandler("quota", quota))
 
10
  MessageHandler,
11
  CallbackQueryHandler,
12
  CallbackContext,
13
+ ContextTypes,
14
  )
15
  import httpx
16
 
 
150
 
151
  ###################TG机器人功能区###################
152
  # 定义命令处理函数
153
+ # async def start(update: Update, context):
154
+ # commands = (
155
+ # "🚀欢迎使用我的机器人!\n\n"
156
+ # "📋可用命令:\n"
157
+ # "•直接发送magent:开的关磁力将直接离线下载\n"
158
+ # "•/tasks - 查看下载任务\n"
159
+ # "•/files - 查看文件列表\n"
160
+ # "•/quota - 查看存储空间\n"
161
+ # "•/emptytrash - 清空回收站\n"
162
+ # "•/help - 获取帮助信息\n"
163
+ # )
164
+ # await update.message.reply_text(commands)
165
+
166
+
167
+ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
168
+ """Sends a message with three inline buttons attached."""
169
+ keyboard = [
170
+ [
171
+ InlineKeyboardButton("Option 1", callback_data="1"),
172
+ InlineKeyboardButton("Option 2", callback_data="2"),
173
+ ],
174
+ [InlineKeyboardButton("Option 3", callback_data="3")],
175
+ ]
176
+
177
+ reply_markup = InlineKeyboardMarkup(keyboard)
178
+
179
+ await update.message.reply_text("Please choose:", reply_markup=reply_markup)
180
+
181
+
182
+ async def button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
183
+ """Parses the CallbackQuery and updates the message text."""
184
+ query = update.callback_query
185
+
186
+ # CallbackQueries need to be answered, even if no notification to the user is needed
187
+ # Some clients may have trouble otherwise. See https://core.telegram.org/bots/api#callbackquery
188
+ await query.answer()
189
+
190
+ await query.edit_message_text(text=f"Selected option: {query.data}")
191
 
192
 
193
  async def help(update: Update, context):
 
433
  TG_BOT_APPLICATION.add_handler(
434
  CallbackQueryHandler(handle_task_confirmation, pattern="^confirm_task")
435
  )
436
+ TG_BOT_APPLICATION.add_handler(CallbackQueryHandler(button))
437
  TG_BOT_APPLICATION.add_handler(CommandHandler("start", start))
438
  TG_BOT_APPLICATION.add_handler(CommandHandler("help", help))
439
  TG_BOT_APPLICATION.add_handler(CommandHandler("quota", quota))