Skip to content

Commit 2f65f75

Browse files
committed
fix: bugs
1 parent b876303 commit 2f65f75

4 files changed

Lines changed: 44 additions & 26 deletions

File tree

‎hiddify_support_bot/modules/user/reply_handler.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
import copy
1414

1515

16-
@bot.message_handler(func=lambda msg: msg.sender_chat)
16+
# @bot.message_handler(func=lambda msg: msg.sender_chat and not((msg.text or "").startswith("/")))
17+
@bot.message_handler(func=lambda msg: msg.sender_chat and " SSH Site" in ((msg.text or "")))
1718
async def main_message_from_channel(msg: HMessage):
1819
# print(msg)
1920
newmsg = copy.deepcopy(msg)
2021
newmsg.reply_to_message = msg
2122
newmsg.main_message = msg
22-
# newmsg.text = ""
23+
newmsg.text = ""
2324
await is_reply_to_user_condition(newmsg)
24-
await reply_to_user(newmsg, add_reply_text=True)
25+
await reply_to_user(newmsg, False)
2526
from .ssh import check
2627
await check(newmsg)
2728

@@ -121,7 +122,7 @@ async def reply_to_user(msg: HMessage, add_reply_text=True):
121122
return
122123
user_data = await bot.get_user_data(reply_to_chat_data['user_id'], reply_to_chat_data['chat_id'])
123124
target_chat_lang = user_data.get('lang', 'en')
124-
125+
125126
caption = f"""[ ](https://hiddify.com/reply_to_us/?chat={msg.chat_id}&msg={msg.message_id})
126127
{_("chat.reply_insrtuction",target_chat_lang)}
127128
=====

‎hiddify_support_bot/modules/user/ssh_utils.py‎

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,47 @@ def get_public_key():
1212
SSH_PUB_PATH = SSH_PK_PATH+".pub"
1313
SSH_PUB_STR = get_public_key()
1414

15-
ansi_escape_pattern = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]')
1615

17-
# Remove ANSI escape sequences
1816

17+
ansi_escape_pattern = re.compile(r"\x1B[@-_][0-?]*[ -/]*[@-~]")
18+
19+
20+
def _text(stream: bytes | str | None) -> str:
21+
if stream is None:
22+
return ""
23+
if isinstance(stream, bytes):
24+
return stream.decode(errors="replace")
25+
return str(stream)
26+
27+
28+
def _format_result(result: asyncssh.SSHCompletedProcess) -> str:
29+
return f"{_text(result.stdout)} {_text(result.stderr)}".strip()
30+
31+
32+
async def test_ssh(host: str,port: int,username: str, key_path: str) -> str:
33+
async with asyncssh.connect(host,port=port,username=username,client_keys=[key_path],known_hosts=None,connect_timeout=10,encoding="utf-8") as conn:
34+
result = await conn.run("cat /opt/hiddify-manager/VERSION", check=False)
35+
out = _format_result(result)
36+
print(f"VERSION (exit {result.exit_status}):\n{out}\n")
37+
38+
try:
39+
status = await conn.run("/opt/hiddify-manager/status.sh", check=False)
40+
cleaned = ansi_escape_pattern.sub("", _text(status.stdout))
41+
cleaned = cleaned.replace(" ", " ")
42+
cleaned = cleaned.replace("-----------------------------------", " ")
43+
out += f"\n```bash\n{cleaned}\n{_text(status.stderr)}```"
44+
print(f"status.sh (exit {status.exit_status}):\n{cleaned}\n")
45+
except Exception as e:
46+
out += f"\nError running status.sh: {e}"
47+
print(f"status.sh failed: {e}")
48+
49+
return out
1950

2051
async def test_ssh_connection(ssh_info):
2152
if not ssh_info:
2253
return False
23-
print("TEST")
2454
try:
25-
async with asyncssh.connect(
26-
ssh_info["host"], port=ssh_info["port"], username=ssh_info["user"], client_keys=[SSH_PK_PATH], known_hosts=None, connect_timeout=2
27-
) as conn:
28-
# result = await conn.run("pip3 freeze | grep hiddifypanel | awk -F ' == ' '{ print $2 }'")
29-
result = await conn.run("cat /opt/hiddify-manager/VERSION")
30-
out = f"{result.stdout} {result.stderr}".strip()
31-
try:
32-
status = await conn.run("/opt/hiddify-manager/status.sh")
33-
out += f"\n```bash\n{ansi_escape_pattern.sub('', status.stdout)}\n{status.stderr}```"
34-
except Exception as e:
35-
out += (f"Error: {e}")
36-
print("SUCCESS")
37-
return f'{out}'
38-
return "WTF?"
55+
return await test_ssh(ssh_info["host"], ssh_info["port"], ssh_info["user"], SSH_PK_PATH)
3956
except Exception as e:
4057
print(f"Error: {e}")
4158
return False

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies = [
1212
"pyTelegramBotAPI==4.21.0",
1313
"aiohttp==3.13.5",
1414
"python-dotenv==1.0.1",
15-
"asyncssh==2.15.0",
15+
"asyncssh==2.23.0",
1616
"cryptography==42.0",
1717
]
1818

‎uv.lock‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)