mirror of
https://github.com/Nick80835/microbot
synced 2025-09-01 15:05:48 +00:00
add ip and ping
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import io
|
import io
|
||||||
|
from re import sub
|
||||||
|
|
||||||
from gtts import gTTS
|
from gtts import gTTS
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@@ -70,6 +71,39 @@ async def text_to_speech(event):
|
|||||||
await event.client.send_file(event.chat_id, tts_bytesio, voice_note=True, reply_to=reply or event)
|
await event.client.send_file(event.chat_id, tts_bytesio, voice_note=True, reply_to=reply or event)
|
||||||
|
|
||||||
|
|
||||||
|
@ldr.add(pattern="ip")
|
||||||
|
async def ip_lookup(event):
|
||||||
|
ip, _ = await get_text_arg(event)
|
||||||
|
|
||||||
|
if not ip:
|
||||||
|
await event.reply("`Provide an IP!`")
|
||||||
|
return
|
||||||
|
|
||||||
|
lookup_json = get(f"http://ip-api.com/json/{ip}").json()
|
||||||
|
fixed_lookup = {}
|
||||||
|
|
||||||
|
for key, value in lookup_json.items():
|
||||||
|
special = {"lat": "Latitude", "lon": "Longitude", "isp": "ISP", "as": "AS", "asname": "AS name"}
|
||||||
|
if key in special:
|
||||||
|
fixed_lookup[special[key]] = str(value)
|
||||||
|
continue
|
||||||
|
|
||||||
|
key = sub(r"([a-z])([A-Z])", r"\g<1> \g<2>", key)
|
||||||
|
key = key.capitalize()
|
||||||
|
|
||||||
|
if not value:
|
||||||
|
value = "None"
|
||||||
|
|
||||||
|
fixed_lookup[key] = str(value)
|
||||||
|
|
||||||
|
text = ""
|
||||||
|
|
||||||
|
for key, value in fixed_lookup.items():
|
||||||
|
text = text + f"**{key}:** `{value}`\n"
|
||||||
|
|
||||||
|
await event.reply(text)
|
||||||
|
|
||||||
|
|
||||||
@ldr.add(pattern="chatid")
|
@ldr.add(pattern="chatid")
|
||||||
async def chatidgetter(event):
|
async def chatidgetter(event):
|
||||||
if event.is_reply:
|
if event.is_reply:
|
||||||
|
@@ -48,6 +48,14 @@ async def shutdown(event):
|
|||||||
await micro_bot.stop_client()
|
await micro_bot.stop_client()
|
||||||
|
|
||||||
|
|
||||||
|
@ldr.add(pattern="ping")
|
||||||
|
async def ping(event):
|
||||||
|
start = time_ns()
|
||||||
|
ping_msg = await event.reply("`Ping…`")
|
||||||
|
time_taken_ms = (time_ns() - start) / 1000000
|
||||||
|
await ping_msg.edit(f"`Ping… Pong! -> `**{time_taken_ms}**`ms`")
|
||||||
|
|
||||||
|
|
||||||
@ldr.add(pattern="repo")
|
@ldr.add(pattern="repo")
|
||||||
async def bot_repo(event):
|
async def bot_repo(event):
|
||||||
await event.reply("https://github.com/Nick80835/microbot")
|
await event.reply("https://github.com/Nick80835/microbot")
|
||||||
|
Reference in New Issue
Block a user