1
This commit is contained in:
@@ -67,12 +67,20 @@ def admin_only(func):
|
|||||||
async def wrapper(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def wrapper(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
user_id = update.effective_user.id
|
user_id = update.effective_user.id
|
||||||
if user_id not in TELEGRAM_ADMIN_CHAT_IDS:
|
if user_id not in TELEGRAM_ADMIN_CHAT_IDS:
|
||||||
await update.message.reply_text("⛔ 无权限,你的 ID 不在管理员列表中")
|
# 兼容 message 和 callback_query
|
||||||
|
message = update.message or (update.callback_query.message if update.callback_query else None)
|
||||||
|
if message:
|
||||||
|
await message.reply_text("⛔ 无权限,你的 ID 不在管理员列表中")
|
||||||
return
|
return
|
||||||
return await func(self, update, context)
|
return await func(self, update, context)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def get_message(update: Update):
|
||||||
|
"""获取可用于回复的 message 对象,兼容普通消息和 callback_query"""
|
||||||
|
return update.message or (update.callback_query.message if update.callback_query else None)
|
||||||
|
|
||||||
|
|
||||||
class ProvisionerBot:
|
class ProvisionerBot:
|
||||||
"""OpenAI Team Provisioner Telegram Bot"""
|
"""OpenAI Team Provisioner Telegram Bot"""
|
||||||
|
|
||||||
@@ -2362,8 +2370,12 @@ class ProvisionerBot:
|
|||||||
@admin_only
|
@admin_only
|
||||||
async def cmd_gptmail_add(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def cmd_gptmail_add(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
"""添加 GPTMail API Key (支持批量导入)"""
|
"""添加 GPTMail API Key (支持批量导入)"""
|
||||||
|
message = get_message(update)
|
||||||
|
if not message:
|
||||||
|
return
|
||||||
|
|
||||||
if not context.args:
|
if not context.args:
|
||||||
await update.message.reply_text(
|
await message.reply_text(
|
||||||
"<b>📧 添加 GPTMail API Key</b>\n\n"
|
"<b>📧 添加 GPTMail API Key</b>\n\n"
|
||||||
"<b>单个添加:</b>\n"
|
"<b>单个添加:</b>\n"
|
||||||
"<code>/gptmail_add gpt-xxx</code>\n\n"
|
"<code>/gptmail_add gpt-xxx</code>\n\n"
|
||||||
@@ -2385,7 +2397,7 @@ class ProvisionerBot:
|
|||||||
keys.append(key)
|
keys.append(key)
|
||||||
|
|
||||||
if not keys:
|
if not keys:
|
||||||
await update.message.reply_text("❌ Key 不能为空")
|
await message.reply_text("❌ Key 不能为空")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 获取现有 keys
|
# 获取现有 keys
|
||||||
@@ -2396,7 +2408,7 @@ class ProvisionerBot:
|
|||||||
skipped = []
|
skipped = []
|
||||||
invalid = []
|
invalid = []
|
||||||
|
|
||||||
await update.message.reply_text(f"⏳ 正在验证 {len(keys)} 个 Key...")
|
await message.reply_text(f"⏳ 正在验证 {len(keys)} 个 Key...")
|
||||||
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
# 检查是否已存在
|
# 检查是否已存在
|
||||||
@@ -2405,7 +2417,7 @@ class ProvisionerBot:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# 测试 Key 是否有效
|
# 测试 Key 是否有效
|
||||||
success, message = gptmail_service.test_api_key(key)
|
success, msg = gptmail_service.test_api_key(key)
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
invalid.append(key)
|
invalid.append(key)
|
||||||
@@ -2438,7 +2450,7 @@ class ProvisionerBot:
|
|||||||
|
|
||||||
lines.append(f"\n<b>当前 Key 总数:</b> {len(get_gptmail_keys())}")
|
lines.append(f"\n<b>当前 Key 总数:</b> {len(get_gptmail_keys())}")
|
||||||
|
|
||||||
await update.message.reply_text("\n".join(lines), parse_mode="HTML")
|
await message.reply_text("\n".join(lines), parse_mode="HTML")
|
||||||
|
|
||||||
@admin_only
|
@admin_only
|
||||||
async def cmd_gptmail_del(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def cmd_gptmail_del(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
|
|||||||
Reference in New Issue
Block a user