Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
818b408
1
Parent(s): 702d428
update fix
Browse files- pydvpl_bot.py +30 -26
pydvpl_bot.py
CHANGED
|
@@ -422,43 +422,47 @@ async def ping(ctx):
|
|
| 422 |
# Calculate shared latency
|
| 423 |
shared_latency = round((bot.latency * 1000) - client_latency)
|
| 424 |
|
| 425 |
-
await msg.edit(content=f"Pong! Client latency is {client_latency:.2f}ms. - Shared latency is {shared_latency}ms.")
|
| 426 |
|
| 427 |
await ctx.reply(f"The command `ping` was executed by - {ctx.author.mention}")
|
| 428 |
|
| 429 |
|
| 430 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 431 |
|
|
|
|
|
|
|
| 432 |
|
| 433 |
@bot.command()
|
| 434 |
-
async def pinger(ctx,
|
| 435 |
try:
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
#
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
|
| 444 |
-
#
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
|
|
|
|
|
|
|
|
|
| 456 |
|
| 457 |
-
except Exception as e:
|
| 458 |
-
await msg.edit(content=f'Error occurred: {e}')
|
| 459 |
-
|
| 460 |
-
# Send the author information
|
| 461 |
-
await ctx.reply(f"The command `ping` was executed by - {ctx.author.mention}")
|
| 462 |
|
| 463 |
|
| 464 |
|
|
|
|
| 422 |
# Calculate shared latency
|
| 423 |
shared_latency = round((bot.latency * 1000) - client_latency)
|
| 424 |
|
| 425 |
+
await msg.edit(content=f"Pong! 🏓 Client latency is {client_latency:.2f}ms. - Shared latency is {shared_latency}ms.")
|
| 426 |
|
| 427 |
await ctx.reply(f"The command `ping` was executed by - {ctx.author.mention}")
|
| 428 |
|
| 429 |
|
| 430 |
# FUNCTION ------------------------------------------------------ SPLIT
|
| 431 |
|
| 432 |
+
import socket
|
| 433 |
+
import time
|
| 434 |
|
| 435 |
@bot.command()
|
| 436 |
+
async def pinger(ctx, target):
|
| 437 |
try:
|
| 438 |
+
# Attempt to resolve the target to an IP address
|
| 439 |
+
ip_address = socket.gethostbyname(target)
|
| 440 |
+
|
| 441 |
+
# Create a socket object
|
| 442 |
+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 443 |
+
|
| 444 |
+
# Set a timeout for the connection attempt
|
| 445 |
+
s.settimeout(5)
|
| 446 |
+
|
| 447 |
+
# Record the start time
|
| 448 |
+
start_time = time.time()
|
| 449 |
|
| 450 |
+
# Connect to the target IP address on port 80 (HTTP)
|
| 451 |
+
s.connect((ip_address, 80))
|
| 452 |
+
|
| 453 |
+
# Calculate the round trip time (RTT)
|
| 454 |
+
rtt = (time.time() - start_time) * 1000 # Convert to milliseconds
|
| 455 |
+
|
| 456 |
+
# Send a message indicating success with latency
|
| 457 |
+
await ctx.send(f'Ping to {target} successful! 🟢 Latency: {rtt:.2f}ms')
|
| 458 |
+
|
| 459 |
+
# Close the socket
|
| 460 |
+
s.close()
|
| 461 |
+
except socket.gaierror:
|
| 462 |
+
await ctx.send(f'Error: Unable to resolve {target} to an IP address. 🔴')
|
| 463 |
+
except socket.error:
|
| 464 |
+
await ctx.send(f'Error: {target} is unreachable. 🔴')
|
| 465 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
|
| 467 |
|
| 468 |
|