TheHamkerCat преди 4 години
родител
ревизия
bd977079c5
променени са 1 файла, в които са добавени 44 реда и са изтрити 0 реда
  1. 44 0
      wbb/modules/misc.py

+ 44 - 0
wbb/modules/misc.py

@@ -21,9 +21,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 """
+import re
 import secrets
 import string
+import subprocess
 from asyncio import Lock
+from re import findall
 
 from pyrogram import filters
 
@@ -88,10 +91,51 @@ __HELP__ = """
 /backup
     Backup database
 
+/ping
+    Check ping of all 5 DCs.
+    
 #RTFM - Tell noobs to read the manual
 """
 
 ASQ_LOCK = Lock()
+PING_LOCK = Lock()
+
+
+@app2.on_message(
+    filters.command("ping", prefixes=USERBOT_PREFIX)
+    & ~filters.edited
+)
+@app.on_message(filters.command("ping") & ~filters.edited)
+async def ping_handler(_, message):
+    m = await eor(message, text="Pinging datacenters...")
+    async with PING_LOCK:
+        ips = {
+            "dc1": "149.154.175.53",
+            "dc2": "149.154.167.51",
+            "dc3": "149.154.175.100",
+            "dc4": "149.154.167.91",
+            "dc5": "91.108.56.130",
+        }
+        text = "**Pings:**\n"
+
+        for dc, ip in ips.items():
+            try:
+                shell = subprocess.run(
+                    ["ping", "-c", "1", "-W", "2", ip],
+                    text=True,
+                    check=True,
+                    capture_output=True
+                )
+                resp_time = findall(r"time=.+m?s", shell.stdout, re.MULTILINE)[
+                    0].replace(
+                    "time=", ""
+                )
+
+                text += f"    **{dc.upper()}:** {resp_time} ✅\n"
+            except Exception:
+                # There's a cross emoji here, but it's invisible.
+                text += f"    **{dc.upper}:** ❌\n"
+        await m.edit(text)
 
 
 @app.on_message(filters.command("asq") & ~filters.edited)