mirror of
https://github.com/cdryzun/tg_bot_collections.git
synced 2025-04-29 00:27:09 +08:00
fix: no reply message
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
parent
e5838d7876
commit
2e52fa58cb
@ -4,7 +4,12 @@ from pathlib import Path
|
|||||||
from anthropic import Anthropic, APITimeoutError
|
from anthropic import Anthropic, APITimeoutError
|
||||||
from telebot import TeleBot
|
from telebot import TeleBot
|
||||||
from telebot.types import Message
|
from telebot.types import Message
|
||||||
from md2tgmd import escape
|
|
||||||
|
import telegramify_markdown
|
||||||
|
from telegramify_markdown.customize import markdown_symbol
|
||||||
|
|
||||||
|
markdown_symbol.head_level_1 = "📌" # If you want, Customizing the head level 1 symbol
|
||||||
|
markdown_symbol.link = "🔗" # If you want, Customizing the link symbol
|
||||||
|
|
||||||
ANTHROPIC_API_KEY = environ.get("ANTHROPIC_API_KEY")
|
ANTHROPIC_API_KEY = environ.get("ANTHROPIC_API_KEY")
|
||||||
ANTHROPIC_BASE_URL = environ.get("ANTHROPIC_BASE_URL")
|
ANTHROPIC_BASE_URL = environ.get("ANTHROPIC_BASE_URL")
|
||||||
@ -18,10 +23,6 @@ claude_player_dict = {}
|
|||||||
|
|
||||||
def claude_handler(message: Message, bot: TeleBot) -> None:
|
def claude_handler(message: Message, bot: TeleBot) -> None:
|
||||||
"""claude : /claude <question>"""
|
"""claude : /claude <question>"""
|
||||||
reply_message = bot.reply_to(
|
|
||||||
message,
|
|
||||||
"Generating Anthropic claude answer please wait, note, will only keep the last five messages:",
|
|
||||||
)
|
|
||||||
m = message.text.strip()
|
m = message.text.strip()
|
||||||
player_message = []
|
player_message = []
|
||||||
# restart will lose all TODO
|
# restart will lose all TODO
|
||||||
@ -71,7 +72,7 @@ def claude_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
try:
|
try:
|
||||||
bot.reply_to(
|
bot.reply_to(
|
||||||
message,
|
message,
|
||||||
"claude answer:\n" + escape(claude_reply_text),
|
"Claude answer:\n" + telegramify_markdown.convert(claude_reply_text),
|
||||||
parse_mode="MarkdownV2",
|
parse_mode="MarkdownV2",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@ -82,9 +83,6 @@ def claude_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
"claude answer:\n\n" + claude_reply_text,
|
"claude answer:\n\n" + claude_reply_text,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
finally:
|
|
||||||
bot.delete_message(reply_message.chat.id, reply_message.message_id)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def claude_photo_handler(message: Message, bot: TeleBot) -> None:
|
def claude_photo_handler(message: Message, bot: TeleBot) -> None:
|
||||||
|
@ -5,7 +5,11 @@ import google.generativeai as genai
|
|||||||
from google.generativeai.types.generation_types import StopCandidateException
|
from google.generativeai.types.generation_types import StopCandidateException
|
||||||
from telebot import TeleBot
|
from telebot import TeleBot
|
||||||
from telebot.types import Message
|
from telebot.types import Message
|
||||||
from md2tgmd import escape
|
import telegramify_markdown
|
||||||
|
from telegramify_markdown.customize import markdown_symbol
|
||||||
|
|
||||||
|
markdown_symbol.head_level_1 = "📌" # If you want, Customizing the head level 1 symbol
|
||||||
|
markdown_symbol.link = "🔗" # If you want, Customizing the link symbol
|
||||||
|
|
||||||
GOOGLE_GEMINI_KEY = environ.get("GOOGLE_GEMINI_KEY")
|
GOOGLE_GEMINI_KEY = environ.get("GOOGLE_GEMINI_KEY")
|
||||||
|
|
||||||
@ -46,10 +50,6 @@ def make_new_gemini_convo():
|
|||||||
|
|
||||||
def gemini_handler(message: Message, bot: TeleBot) -> None:
|
def gemini_handler(message: Message, bot: TeleBot) -> None:
|
||||||
"""Gemini : /gemini <question>"""
|
"""Gemini : /gemini <question>"""
|
||||||
reply_message = bot.reply_to(
|
|
||||||
message,
|
|
||||||
"Generating google gemini answer please wait, note, will only keep the last five messages:",
|
|
||||||
)
|
|
||||||
m = message.text.strip()
|
m = message.text.strip()
|
||||||
player = None
|
player = None
|
||||||
# restart will lose all TODO
|
# restart will lose all TODO
|
||||||
@ -81,7 +81,7 @@ def gemini_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
try:
|
try:
|
||||||
bot.reply_to(
|
bot.reply_to(
|
||||||
message,
|
message,
|
||||||
"Gemini answer:\n" + escape(gemini_reply_text),
|
"Gemini answer:\n" + telegramify_markdown.convert(gemini_reply_text),
|
||||||
parse_mode="MarkdownV2",
|
parse_mode="MarkdownV2",
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
@ -90,8 +90,6 @@ def gemini_handler(message: Message, bot: TeleBot) -> None:
|
|||||||
message,
|
message,
|
||||||
"Gemini answer:\n\n" + gemini_reply_text,
|
"Gemini answer:\n\n" + gemini_reply_text,
|
||||||
)
|
)
|
||||||
finally:
|
|
||||||
bot.delete_message(reply_message.chat.id, reply_message.message_id)
|
|
||||||
|
|
||||||
|
|
||||||
def gemini_photo_handler(message: Message, bot: TeleBot) -> None:
|
def gemini_photo_handler(message: Message, bot: TeleBot) -> None:
|
||||||
|
@ -6,7 +6,6 @@ from telebot.types import Message
|
|||||||
|
|
||||||
def github_poster_handler(message: Message, bot: TeleBot):
|
def github_poster_handler(message: Message, bot: TeleBot):
|
||||||
"""github poster: /github <github_user_name> [<start>-<end>]"""
|
"""github poster: /github <github_user_name> [<start>-<end>]"""
|
||||||
reply_message = bot.reply_to(message, "Generating poster please wait:")
|
|
||||||
m = message.text.strip()
|
m = message.text.strip()
|
||||||
message_list = m.split(",")
|
message_list = m.split(",")
|
||||||
name = message_list[0].strip()
|
name = message_list[0].strip()
|
||||||
@ -26,8 +25,8 @@ def github_poster_handler(message: Message, bot: TeleBot):
|
|||||||
bot.send_photo(
|
bot.send_photo(
|
||||||
message.chat.id, photo, reply_to_message_id=message.message_id
|
message.chat.id, photo, reply_to_message_id=message.message_id
|
||||||
)
|
)
|
||||||
finally:
|
except:
|
||||||
bot.delete_message(reply_message.chat.id, reply_message.message_id)
|
bot.reply_to(message, "github poster error")
|
||||||
|
|
||||||
|
|
||||||
def register(bot: TeleBot) -> None:
|
def register(bot: TeleBot) -> None:
|
||||||
|
@ -86,9 +86,7 @@ def draw_pretty_map(location, style, output_file):
|
|||||||
|
|
||||||
def map_handler(message: Message, bot: TeleBot):
|
def map_handler(message: Message, bot: TeleBot):
|
||||||
"""pretty map: /map <address>"""
|
"""pretty map: /map <address>"""
|
||||||
reply_message = bot.reply_to(
|
bot.reply_to(message, "Generating pretty map may take some time please wait:")
|
||||||
message, "Generating pretty map may take some time please wait:"
|
|
||||||
)
|
|
||||||
m = message.text.strip()
|
m = message.text.strip()
|
||||||
location = m.strip()
|
location = m.strip()
|
||||||
styles_list = list(STYLES.keys())
|
styles_list = list(STYLES.keys())
|
||||||
@ -104,16 +102,11 @@ def map_handler(message: Message, bot: TeleBot):
|
|||||||
message.chat.id, out_image, reply_to_message_id=message.message_id
|
message.chat.id, out_image, reply_to_message_id=message.message_id
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
bot.delete_message(reply_message.chat.id, reply_message.message_id)
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
def map_location_handler(message: Message, bot: TeleBot):
|
def map_location_handler(message: Message, bot: TeleBot):
|
||||||
# TODO refactor the function
|
# TODO refactor the function
|
||||||
reply_message = bot.reply_to(
|
|
||||||
message,
|
|
||||||
"Generating pretty map using location now, may take some time please wait:",
|
|
||||||
)
|
|
||||||
location = "{0}, {1}".format(message.location.latitude, message.location.longitude)
|
location = "{0}, {1}".format(message.location.latitude, message.location.longitude)
|
||||||
styles_list = list(STYLES.keys())
|
styles_list = list(STYLES.keys())
|
||||||
style = random.choice(styles_list)
|
style = random.choice(styles_list)
|
||||||
@ -129,7 +122,6 @@ def map_location_handler(message: Message, bot: TeleBot):
|
|||||||
)
|
)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
bot.delete_message(reply_message.chat.id, reply_message.message_id)
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,4 +4,4 @@ github_poster
|
|||||||
prettymapp
|
prettymapp
|
||||||
google-generativeai==0.3.1
|
google-generativeai==0.3.1
|
||||||
anthropic
|
anthropic
|
||||||
md2tgmd
|
telegramify-markdown
|
||||||
|
Loading…
x
Reference in New Issue
Block a user