mirror of
				https://github.com/cdryzun/tg_bot_collections.git
				synced 2025-11-04 16:56:43 +08:00 
			
		
		
		
	feat: create telegraph account
- feat: create and store the telegraph token locally - check and use if there exist token in json - feat: auto generate telegraph token for cohere.py and answer_it - fix: optional delete other answer_it message and only leave a telegraph link messsage for clean view Co-Authored-By: yihong <zouzou0208@gmail.com>
This commit is contained in:
		@ -21,6 +21,11 @@ COHERE_MODEL = "command-r-plus"
 | 
			
		||||
TELEGRA_PH_TOKEN = environ.get("TELEGRA_PH_TOKEN")
 | 
			
		||||
if TELEGRA_PH_TOKEN:
 | 
			
		||||
    ph = TelegraphAPI(TELEGRA_PH_TOKEN)
 | 
			
		||||
else:
 | 
			
		||||
    TELEGRA_PH_TOKEN = create_ph_account(
 | 
			
		||||
        short_name="cohere", author_name="A Telegram Bot"
 | 
			
		||||
    )
 | 
			
		||||
    ph = TelegraphAPI(TELEGRA_PH_TOKEN)
 | 
			
		||||
 | 
			
		||||
if COHERE_API_KEY:
 | 
			
		||||
    co = cohere.Client(api_key=COHERE_API_KEY)
 | 
			
		||||
@ -219,22 +224,15 @@ def cohere_handler(message: Message, bot: TeleBot) -> None:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if COHERE_API_KEY:
 | 
			
		||||
    if not TELEGRA_PH_TOKEN:
 | 
			
		||||
 | 
			
		||||
        def register(bot: TeleBot) -> None:
 | 
			
		||||
            bot.register_message_handler(
 | 
			
		||||
                cohere_handler_direct, commands=["cohere"], pass_bot=True
 | 
			
		||||
            )
 | 
			
		||||
            bot.register_message_handler(
 | 
			
		||||
                cohere_handler_direct, regexp="^cohere:", pass_bot=True
 | 
			
		||||
            )
 | 
			
		||||
    def register(bot: TeleBot) -> None:
 | 
			
		||||
        bot.register_message_handler(
 | 
			
		||||
            cohere_handler_direct, commands=["cohere_no_ph"], pass_bot=True
 | 
			
		||||
        )
 | 
			
		||||
        bot.register_message_handler(
 | 
			
		||||
            cohere_handler_direct, regexp="^cohere_no_ph:", pass_bot=True
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    else:
 | 
			
		||||
 | 
			
		||||
        def register(bot: TeleBot) -> None:
 | 
			
		||||
            bot.register_message_handler(
 | 
			
		||||
                cohere_handler, commands=["cohere"], pass_bot=True
 | 
			
		||||
            )
 | 
			
		||||
            bot.register_message_handler(
 | 
			
		||||
                cohere_handler, regexp="^cohere:", pass_bot=True
 | 
			
		||||
            )
 | 
			
		||||
    def register(bot: TeleBot) -> None:
 | 
			
		||||
        bot.register_message_handler(cohere_handler, commands=["cohere"], pass_bot=True)
 | 
			
		||||
        bot.register_message_handler(cohere_handler, regexp="^cohere:", pass_bot=True)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user