2
2
import os
3
3
import config
4
4
import logging
5
+ import decorators
5
6
from md2tgmd import escape
6
7
from runasync import run_async
7
8
from chatgpt2api .V3 import Chatbot as GPT
26
27
botNicKLength = len (botNick ) if botNick else 0
27
28
print ("nick:" , botNick )
28
29
translator_prompt = "You are a translation engine, you can only translate text and cannot interpret it, and do not explain. Translate the text to {}, please do not explain any sentences, just translate or leave them as they are. this is the content you need to translate: "
30
+ @decorators .Authorization
29
31
async def command_bot (update , context , language = None , prompt = translator_prompt , title = "" , robot = None , has_command = True ):
30
32
if config .SEARCH_USE_GPT and not has_command :
31
33
title = f"`🤖️ { config .DEFAULT_SEARCH_MODEL } `\n \n "
@@ -40,7 +42,7 @@ async def command_bot(update, context, language=None, prompt=translator_prompt,
40
42
message = prompt + message
41
43
if config .API and message :
42
44
await context .bot .send_chat_action (chat_id = update .message .chat_id , action = ChatAction .TYPING )
43
- await getChatGPT (update , context , title , robot , message , config .SEARCH_USE_GPT , has_command = True )
45
+ await getChatGPT (update , context , title , robot , message , config .SEARCH_USE_GPT , has_command )
44
46
else :
45
47
message = await context .bot .send_message (
46
48
chat_id = update .message .chat_id ,
@@ -75,6 +77,7 @@ async def command_bot(update, context, language=None, prompt=translator_prompt,
75
77
print (result )
76
78
await context .bot .send_message (chat_id = update .message .chat_id , text = escape (result ), parse_mode = 'MarkdownV2' , disable_web_page_preview = True )
77
79
80
+ @decorators .Authorization
78
81
async def reset_chat (update , context ):
79
82
if config .API :
80
83
config .ChatGPTbot .reset (convo_id = str (update .message .chat_id ), system_prompt = config .systemprompt )
@@ -351,7 +354,7 @@ async def button_press(update, context):
351
354
parse_mode = 'MarkdownV2'
352
355
)
353
356
354
-
357
+ @ decorators . Authorization
355
358
async def info (update , context ):
356
359
info_message = (
357
360
f"`Hi, { update .effective_user .username } !`\n \n "
@@ -368,6 +371,7 @@ async def info(update, context):
368
371
await context .bot .delete_message (chat_id = update .effective_chat .id , message_id = update .message .message_id )
369
372
370
373
from agent import pdfQA , getmd5 , persist_emdedding_pdf
374
+ @decorators .Authorization
371
375
async def handle_pdf (update , context ):
372
376
# 获取接收到的文件
373
377
pdf_file = update .message .document
@@ -397,6 +401,7 @@ async def handle_pdf(update, context):
397
401
print (result )
398
402
await context .bot .send_message (chat_id = update .message .chat_id , text = escape (result ), parse_mode = 'MarkdownV2' , disable_web_page_preview = True )
399
403
404
+ @decorators .Authorization
400
405
async def qa (update , context ):
401
406
if (len (context .args ) != 2 ):
402
407
message = (
@@ -439,6 +444,7 @@ async def error(update, context):
439
444
logger .warning ('Update "%s" caused error "%s"' , update , context .error )
440
445
await context .bot .send_message (chat_id = update .message .chat_id , text = "出错啦!请重试。" , parse_mode = 'MarkdownV2' )
441
446
447
+ @decorators .Authorization
442
448
async def unknown (update , context ): # 当用户输入未知命令时,返回文本
443
449
await context .bot .send_message (chat_id = update .effective_chat .id , text = "Sorry, I didn't understand that command." )
444
450
@@ -452,9 +458,6 @@ def setup(token):
452
458
BotCommand ('zh2en' , 'translate to English' ),
453
459
BotCommand ('start' , 'Start the bot' ),
454
460
BotCommand ('reset' , 'Reset the bot' ),
455
- # BotCommand('gpt_use_search', 'open or close gpt use search'),
456
- # BotCommand('history', 'open or close chat history'),
457
- # BotCommand('google', 'open or close google search'),
458
461
]))
459
462
460
463
application .add_handler (CommandHandler ("start" , start ))
0 commit comments