fix: potential version display fix when not using git

This commit is contained in:
草师傅 2025-08-02 22:19:22 +08:00
parent 7920ee0567
commit a6a50252a6

View file

@ -62,9 +62,12 @@ async def handle_about_command(message: Message) -> None:
import time import time
bot_time_start = time.time() bot_time_start = time.time()
about_message = await message.reply('Loading...') about_message = await message.reply('Loading...')
try:
from dulwich.repo import Repo from dulwich.repo import Repo
git_commit_hash = Repo('.').head().decode('utf-8')[:7] # Get the first 7 characters of the commit hash git_commit_hash = f"g{Repo('.').head().decode('utf-8')[:7]}" # Get the first 7 characters of the commit hash
response = f"realbot@g{git_commit_hash}\n\n" except Exception:
git_commit_hash = 'v20250802' # Fallback when git operations fail
response = f"realbot@{git_commit_hash}\n\n"
response += "孩子不懂随便写的 bot\n" response += "孩子不懂随便写的 bot\n"
if message.chat.id == config.config.get_admin_id(): if message.chat.id == config.config.get_admin_id():
response += '\nDebug Info:\n' response += '\nDebug Info:\n'