Release v0.0.6
Co-authored-by: Aakash <BLUE-DEVIL1134@users.noreply.github.com> Co-authored-by: Aditya <me@xditya.me> Co-authored-by: Danish <danish@ultroid.tech> Co-authored-by: buddhhu <buddhuu@users.noreply.github.com> Co-authored-by: sppidy <sppidy@users.noreply.github.com> Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com> Co-authored-by: divkix <divkix@users.noreply.github.com> Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com> Co-authored-by: Programming Error <error@notavailable.live> Co-authored-by: New-dev0 <New-dev0@notavailable.live>
This commit is contained in:
171
plugins/bot.py
171
plugins/bot.py
@@ -18,31 +18,26 @@
|
||||
View all plugin names.
|
||||
|
||||
• `{i}restart`
|
||||
s - soft restart
|
||||
To restart your bot.
|
||||
|
||||
• `{i}logs`
|
||||
Get the last 100 lines from heroku logs.
|
||||
• `{i}logs (sys)`
|
||||
Get the full terminal logs.
|
||||
|
||||
• `{i}usage`
|
||||
Get app usage details.
|
||||
• `{i}logs heroku`
|
||||
Get the latest 100 lines of heroku logs.
|
||||
|
||||
• `{i}shutdown`
|
||||
Turn off your bot.
|
||||
"""
|
||||
|
||||
import math
|
||||
import shutil
|
||||
import time
|
||||
from datetime import datetime as dt
|
||||
from platform import python_version as pyver
|
||||
|
||||
import heroku3
|
||||
import psutil
|
||||
import requests
|
||||
from git import Repo
|
||||
from pyUltroid import __version__ as UltVer
|
||||
from search_engine_parser.core.utils import get_rand_user_agent as grua
|
||||
from telethon import __version__
|
||||
from telethon.errors.rpcerrorlist import ChatSendMediaForbiddenError
|
||||
|
||||
@@ -88,17 +83,19 @@ async def lol(ult):
|
||||
return await eor(ult, als)
|
||||
elif pic is not None and "telegra" in pic:
|
||||
try:
|
||||
await ult.reply(als, file=pic)
|
||||
await ultroid_bot.send_message(
|
||||
ult.chat_id, als, file=pic, link_preview=False
|
||||
)
|
||||
await ult.delete()
|
||||
except ChatSendMediaForbiddenError:
|
||||
await eor(ult, als)
|
||||
await eor(ult, als, link_preview=False)
|
||||
else:
|
||||
try:
|
||||
await ultroid_bot.send_message(ult.chat_id, file=pic)
|
||||
await ultroid_bot.send_message(ult.chat_id, als)
|
||||
await ultroid_bot.send_message(ult.chat_id, als, link_preview=False)
|
||||
await ult.delete()
|
||||
except ChatSendMediaForbiddenError:
|
||||
await eor(ult, als)
|
||||
await eor(ult, als, link_preview=False)
|
||||
|
||||
|
||||
@ultroid_cmd(
|
||||
@@ -124,17 +121,73 @@ async def cmds(event):
|
||||
pattern="restart$",
|
||||
)
|
||||
async def restartbt(ult):
|
||||
if not Var.HEROKU_API:
|
||||
if Var.HEROKU_API:
|
||||
await eor(ult, "`Restarting..`")
|
||||
await bash("pkill python3 && python3 -m pyUltroid")
|
||||
try:
|
||||
await restart(ult)
|
||||
except BaseException:
|
||||
await bash("pkill python3 && python3 -m pyUltroid")
|
||||
else:
|
||||
await restart(ult)
|
||||
await bash("pkill python3 && python3 -m pyUltroid")
|
||||
|
||||
|
||||
@ultroid_cmd(pattern="shutdown")
|
||||
async def shutdownbot(ult):
|
||||
try:
|
||||
dyno = ult.text.split(" ", maxsplit=1)[1]
|
||||
except IndexError:
|
||||
dyno = None
|
||||
if dyno:
|
||||
if dyno not in ["userbot", "vcbot", "web", "worker"]:
|
||||
await eor(ult, "Invalid Dyno Type specified !")
|
||||
return
|
||||
await shutdown(ult, dyno)
|
||||
else:
|
||||
await shutdown(ult)
|
||||
|
||||
|
||||
@ultroid_cmd(
|
||||
pattern="logs$",
|
||||
pattern="logs",
|
||||
)
|
||||
async def _(ult):
|
||||
async def get_logs(event):
|
||||
try:
|
||||
opt = event.text.split(" ", maxsplit=1)[1]
|
||||
except IndexError:
|
||||
return await def_logs(event)
|
||||
if opt == "heroku":
|
||||
await heroku_logs(event)
|
||||
elif opt == "sys":
|
||||
await def_logs(event)
|
||||
else:
|
||||
await def_logs(event)
|
||||
|
||||
|
||||
async def heroku_logs(event):
|
||||
if HEROKU_API is None and HEROKU_APP_NAME is None:
|
||||
return await eor(
|
||||
event, "Please set `HEROKU_APP_NAME` and `HEROKU_API` in vars."
|
||||
)
|
||||
await eor(event, "`Downloading Logs...`")
|
||||
ok = app.get_log()
|
||||
with open("ultroid-heroku.log", "w") as log:
|
||||
log.write(ok)
|
||||
key = (
|
||||
requests.post("https://nekobin.com/api/documents", json={"content": ok})
|
||||
.json()
|
||||
.get("result")
|
||||
.get("key")
|
||||
)
|
||||
url = f"https://nekobin.com/{key}"
|
||||
await ultroid.send_file(
|
||||
event.chat_id,
|
||||
file="ultroid-heroku.log",
|
||||
thumb="resources/extras/logo_rdm.png",
|
||||
caption=f"**Ultroid Heroku Logs.**\nPasted [here]({url}) too!",
|
||||
)
|
||||
os.remove("ultroid-heroku.log")
|
||||
|
||||
|
||||
async def def_logs(ult):
|
||||
xx = await eor(ult, "`Processing...`")
|
||||
with open("ultroid.log") as f:
|
||||
k = f.read()
|
||||
@@ -148,89 +201,11 @@ async def _(ult):
|
||||
await ultroid.send_file(
|
||||
ult.chat_id,
|
||||
file="ultroid.log",
|
||||
thumb="resources/extras/logo_rdm.png",
|
||||
caption=f"**Ultroid Logs.**\nPasted [here](https://nekobin.com/{key}) too!",
|
||||
thumb="resources/extras/new_thumb.jpg",
|
||||
caption=f"**Ultroid Logs.**\nPasted [here]({url}) too!",
|
||||
)
|
||||
await xx.edit("Done")
|
||||
await xx.delete()
|
||||
|
||||
|
||||
@ultroid_cmd(
|
||||
pattern="usage$",
|
||||
)
|
||||
async def dyno_usage(dyno):
|
||||
if not HEROKU_API and HEROKU_APP_NAME:
|
||||
return
|
||||
dyn = await eor(dyno, "`Processing...`")
|
||||
useragent = grua()
|
||||
user_id = Heroku.account().id
|
||||
headers = {
|
||||
"User-Agent": useragent,
|
||||
"Authorization": f"Bearer {Var.HEROKU_API}",
|
||||
"Accept": "application/vnd.heroku+json; version=3.account-quotas",
|
||||
}
|
||||
path = "/accounts/" + user_id + "/actions/get-quota"
|
||||
r = requests.get(heroku_api + path, headers=headers)
|
||||
if r.status_code != 200:
|
||||
return await dyno.edit(
|
||||
"`Error: something bad happened`\n\n" f">.`{r.reason}`\n",
|
||||
)
|
||||
result = r.json()
|
||||
quota = result["account_quota"]
|
||||
quota_used = result["quota_used"]
|
||||
remaining_quota = quota - quota_used
|
||||
percentage = math.floor(remaining_quota / quota * 100)
|
||||
minutes_remaining = remaining_quota / 60
|
||||
hours = math.floor(minutes_remaining / 60)
|
||||
minutes = math.floor(minutes_remaining % 60)
|
||||
App = result["apps"]
|
||||
try:
|
||||
App[0]["quota_used"]
|
||||
except IndexError:
|
||||
AppQuotaUsed = 0
|
||||
AppPercentage = 0
|
||||
else:
|
||||
AppQuotaUsed = App[0]["quota_used"] / 60
|
||||
AppPercentage = math.floor(App[0]["quota_used"] * 100 / quota)
|
||||
AppHours = math.floor(AppQuotaUsed / 60)
|
||||
AppMinutes = math.floor(AppQuotaUsed % 60)
|
||||
total, used, free = shutil.disk_usage(".")
|
||||
cpuUsage = psutil.cpu_percent()
|
||||
memory = psutil.virtual_memory().percent
|
||||
disk = psutil.disk_usage("/").percent
|
||||
upload = humanbytes(psutil.net_io_counters().bytes_sent)
|
||||
down = humanbytes(psutil.net_io_counters().bytes_recv)
|
||||
TOTAL = humanbytes(total)
|
||||
USED = humanbytes(used)
|
||||
FREE = humanbytes(free)
|
||||
return await eod(
|
||||
dyn,
|
||||
get_string("usage").format(
|
||||
Var.HEROKU_APP_NAME,
|
||||
AppHours,
|
||||
AppMinutes,
|
||||
AppPercentage,
|
||||
hours,
|
||||
minutes,
|
||||
percentage,
|
||||
TOTAL,
|
||||
USED,
|
||||
FREE,
|
||||
upload,
|
||||
down,
|
||||
cpuUsage,
|
||||
memory,
|
||||
disk,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@ultroid_cmd(
|
||||
pattern="shutdown$",
|
||||
)
|
||||
async def shht(event):
|
||||
await eor(event, get_string("shutdown").format(OWNER_NAME))
|
||||
await ultroid_bot.disconnect()
|
||||
|
||||
|
||||
HELP.update({f"{__name__.split('.')[1]}": f"{__doc__.format(i=HNDLR)}"})
|
||||
|
||||
Reference in New Issue
Block a user