Fix ping command by separating detailed output into a new stats command; ping now displays only the ping result. (#398)

* rewrote spdl to feel more integrated and add support for terabox.com links

* small typo fix and terabox link extraction improvement

* another tweak to improve terabox link extraction

* Update sp_downloader.py

Add progress bar to spdl Instagram downloads

* improvement on instagram download to show filename while downloading

* reformat

* Fix `ping` command by separating detailed output into a new `stats` command
This commit is contained in:
Sanuja Seneviratne 2024-06-20 00:59:15 +05:30 committed by GitHub
parent 2e458231e9
commit d1e702f111
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 3 deletions

View file

@ -294,18 +294,19 @@ refer guide here [kubernetes](k8s.md)
```
start - Let's start
about - What's this bot?
ping - Bot running status
help - Help
spdl - Use to download specific link downloader links
ytdl - Download video in group
direct - Download file directly
settings - Set your preference
buy - Buy token
direct - Download file directly
sub - Subscribe to YouTube Channel
unsub - Unsubscribe from YouTube Channel
sub_count - Check subscription status, owner only.
uncache - Delete cache for this link, owner only.
purge - Delete all tasks, owner only.
ping - Ping the Bot
stats - Bot running status
show_history - Show download history
clear_history - Clear download history
```

View file

@ -11,6 +11,7 @@ import contextlib
import json
import logging
import os
import threading
import random
import re
import tempfile
@ -201,11 +202,34 @@ def purge_handler(client: Client, message: types.Message):
@app.on_message(filters.command(["ping"]))
def ping_handler(client: Client, message: types.Message):
redis = Redis()
chat_id = message.chat.id
client.send_chat_action(chat_id, enums.ChatAction.TYPING)
message_sent = False
def send_message_and_measure_ping():
start_time = int(round(time.time() * 1000))
reply = client.send_message(chat_id, "Starting Ping...")
end_time = int(round(time.time() * 1000))
ping_time = int(round(end_time - start_time))
message_sent = True
if message_sent:
message.reply_text(f"Ping: {ping_time:.2f} ms", quote=True)
time.sleep(0.5)
client.edit_message_text(chat_id=reply.chat.id, message_id=reply.id, text="Ping Calculation Complete.")
time.sleep(1)
client.delete_messages(chat_id=reply.chat.id, message_ids=reply.id)
thread = threading.Thread(target=send_message_and_measure_ping)
thread.start()
@app.on_message(filters.command(["stats"]))
def stats_handler(client: Client, message: types.Message):
redis = Redis()
chat_id = message.chat.id
client.send_chat_action(chat_id, enums.ChatAction.TYPING)
if os.uname().sysname == "Darwin" or ".heroku" in os.getenv("PYTHONHOME", ""):
bot_info = "ping unavailable."
bot_info = "Stats Unavailable."
else:
bot_info = get_runtime("ytdlbot_ytdl_1", "YouTube-dl")
if message.chat.username == OWNER: