Ultroid v0.3 Updates
Co-authored-by: Aditya <xditya@ultroid.tech> Co-authored-by: Danish <danish@ultroid.tech> Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com> Co-authored-by: TechiError <error@notavailable.live> Co-authored-by: Avish Kumar <85635883+aviskumar@users.noreply.github.com> Co-authored-by: Vɪɴᴀʏᴀᴋ Pᴀɴᴅᴇʏ <87496159+harpia-vieillot@users.noreply.github.com> Co-authored-by: Shrimadhav U K <6317196+spechide@users.noreply.github.com> Co-authored-by: Dark <darkbeamer.official@gmail.com> Co-authored-by: Muhamad Risman Aziz <62795826+mrismanaziz@users.noreply.github.com> Co-authored-by: Ashik Muhammed <84127769+MR-JINN-OF-TG@users.noreply.github.com> Co-authored-by: MMETMA <79155572+MMETMA@users.noreply.github.com> Co-authored-by: amirmehdinzri <94852182+amirmehdinzri@users.noreply.github.com>
This commit is contained in:
276
plugins/bot.py
276
plugins/bot.py
@@ -1,5 +1,5 @@
|
||||
# Ultroid - UserBot
|
||||
# Copyright (C) 2021 TeamUltroid
|
||||
# Copyright (C) 2021-2022 TeamUltroid
|
||||
#
|
||||
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
||||
# PLease read the GNU Affero General Public License in
|
||||
@@ -7,12 +7,15 @@
|
||||
"""
|
||||
✘ Commands Available
|
||||
|
||||
• `{i}alive` | `{i}ialive`
|
||||
• `{i}alive` | `{i}alive inline`
|
||||
Check if your bot is working.
|
||||
|
||||
• `{i}ping`
|
||||
Check Ultroid's response time.
|
||||
|
||||
• `{i}update`
|
||||
See changelogs if any update is available.
|
||||
|
||||
• `{i}cmds`
|
||||
View all plugin names.
|
||||
|
||||
@@ -21,10 +24,8 @@
|
||||
|
||||
• `{i}logs (sys)`
|
||||
Get the full terminal logs.
|
||||
|
||||
• `{i}logs carbon`
|
||||
Get the carbonized sys logs.
|
||||
|
||||
• `{i}logs heroku`
|
||||
Get the latest 100 lines of heroku logs.
|
||||
|
||||
@@ -40,19 +41,20 @@ from random import choice
|
||||
from git import Repo
|
||||
from pyUltroid.version import __version__ as UltVer
|
||||
from telethon import __version__
|
||||
from telethon.errors.rpcerrorlist import ChatSendMediaForbiddenError
|
||||
from telethon.errors.rpcerrorlist import (
|
||||
BotMethodInvalidError,
|
||||
ChatSendMediaForbiddenError,
|
||||
)
|
||||
from telethon.utils import resolve_bot_file_id
|
||||
|
||||
try:
|
||||
from carbonnow import Carbon
|
||||
except ImportError:
|
||||
Carbon = None
|
||||
|
||||
from . import (
|
||||
ATRA_COL,
|
||||
INLINE_PIC,
|
||||
LOGS,
|
||||
OWNER_NAME,
|
||||
ULTROID_IMAGES,
|
||||
Button,
|
||||
Carbon,
|
||||
Telegraph,
|
||||
Var,
|
||||
allcmds,
|
||||
@@ -72,8 +74,17 @@ from . import (
|
||||
udB,
|
||||
ultroid_cmd,
|
||||
ultroid_version,
|
||||
updater,
|
||||
)
|
||||
|
||||
ULTPIC = INLINE_PIC or choice(ULTROID_IMAGES)
|
||||
buttons = [
|
||||
[
|
||||
Button.url(get_string("bot_3"), "https://github.com/TeamUltroid/Ultroid"),
|
||||
Button.url(get_string("bot_4"), "t.me/UltroidSupport"),
|
||||
]
|
||||
]
|
||||
|
||||
# Will move to strings
|
||||
alive_txt = """
|
||||
The Ultroid Userbot
|
||||
@@ -83,6 +94,8 @@ The Ultroid Userbot
|
||||
◍ Telethon - {}
|
||||
"""
|
||||
|
||||
in_alive = "{}\n\n🌀 <b>Ultroid Version -><b> <code>{}</code>\n🌀 <b>PyUltroid -></b> <code>{}</code>\n🌀 <b>Python -></b> <code>{}</code>\n🌀 <b>Uptime -></b> <code>{}</code>\n🌀 <b>Branch -></b> [ {} ]\n\n• <b>Join @TheUltroid</b>"
|
||||
|
||||
|
||||
@callback("alive")
|
||||
async def alive(event):
|
||||
@@ -91,90 +104,92 @@ async def alive(event):
|
||||
|
||||
|
||||
@ultroid_cmd(
|
||||
pattern="alive$",
|
||||
pattern="alive ?(.*)",
|
||||
)
|
||||
async def lol(ult):
|
||||
pic = udB.get("ALIVE_PIC")
|
||||
uptime = time_formatter((time.time() - start_time) * 1000)
|
||||
header = udB.get("ALIVE_TEXT") or get_string("bot_1")
|
||||
y = Repo().active_branch
|
||||
xx = Repo().remotes[0].config_reader.get("url")
|
||||
rep = xx.replace(".git", f"/tree/{y}")
|
||||
kk = f" `[{y}]({rep})` "
|
||||
als = (get_string("alive_1")).format(
|
||||
header,
|
||||
OWNER_NAME,
|
||||
ultroid_version,
|
||||
UltVer,
|
||||
uptime,
|
||||
pyver(),
|
||||
__version__,
|
||||
kk,
|
||||
)
|
||||
if pic is None:
|
||||
await eor(ult, als)
|
||||
elif "telegra" in pic:
|
||||
try:
|
||||
await ult.reply(als, file=pic, link_preview=False)
|
||||
await ult.delete()
|
||||
except ChatSendMediaForbiddenError:
|
||||
await eor(ult, als, link_preview=False)
|
||||
else:
|
||||
try:
|
||||
await ult.reply(file=pic)
|
||||
await ult.reply(als, link_preview=False)
|
||||
await ult.delete()
|
||||
except ChatSendMediaForbiddenError:
|
||||
await eor(ult, als, link_preview=False)
|
||||
|
||||
|
||||
@ultroid_cmd(
|
||||
pattern="ialive$",
|
||||
)
|
||||
async def is_on(ult):
|
||||
if not ult.client._bot:
|
||||
await ult.delete()
|
||||
match = ult.pattern_match.group(1)
|
||||
inline = None
|
||||
if match in ["inline", "i"]:
|
||||
try:
|
||||
res = await ult.client.inline_query(asst.me.username, "alive")
|
||||
await res[0].click(ult.chat_id)
|
||||
except Exception as er:
|
||||
LOGS.info(er)
|
||||
return
|
||||
pic = udB.get("ALIVE_PIC")
|
||||
return await res[0].click(ult.chat_id)
|
||||
except BotMethodInvalidError:
|
||||
pass
|
||||
except BaseException as er:
|
||||
LOGS.exception(er)
|
||||
inline = True
|
||||
pic = udB.get_key("ALIVE_PIC")
|
||||
uptime = time_formatter((time.time() - start_time) * 1000)
|
||||
header = udB.get("ALIVE_TEXT") or get_string("bot_1")
|
||||
header = udB.get_key("ALIVE_TEXT") or get_string("bot_1")
|
||||
y = Repo().active_branch
|
||||
xx = Repo().remotes[0].config_reader.get("url")
|
||||
rep = xx.replace(".git", f"/tree/{y}")
|
||||
kk = f" `[{y}]({rep})` "
|
||||
als = (get_string("alive_1")).format(
|
||||
header,
|
||||
OWNER_NAME,
|
||||
ultroid_version,
|
||||
UltVer,
|
||||
uptime,
|
||||
pyver(),
|
||||
__version__,
|
||||
kk,
|
||||
)
|
||||
buttons = [
|
||||
[Button.inline(get_string("bot_2"), "alive")],
|
||||
[
|
||||
Button.url(get_string("bot_3"), "https://github.com/TeamUltroid/Ultroid"),
|
||||
Button.url(get_string("bot_4"), "t.me/UltroidSupport"),
|
||||
],
|
||||
]
|
||||
await ult.client.send_message(
|
||||
ult.chat_id, als, file=pic, buttons=buttons, link_preview=False
|
||||
if inline:
|
||||
kk = f"<a href={rep}>{y}</a>"
|
||||
parse = "html"
|
||||
als = in_alive.format(
|
||||
header,
|
||||
ultroid_version,
|
||||
UltVer,
|
||||
pyver(),
|
||||
uptime,
|
||||
kk,
|
||||
)
|
||||
if _e := udB.get_key("ALIVE_EMOJI"):
|
||||
als = als.replace("🌀", _e)
|
||||
else:
|
||||
parse = "md"
|
||||
als = (get_string("alive_1")).format(
|
||||
header,
|
||||
OWNER_NAME,
|
||||
ultroid_version,
|
||||
UltVer,
|
||||
uptime,
|
||||
pyver(),
|
||||
__version__,
|
||||
kk,
|
||||
)
|
||||
if a := udB.get_key("ALIVE_EMOJI"):
|
||||
als = als.replace("✵", a)
|
||||
if pic:
|
||||
try:
|
||||
await ult.reply(
|
||||
als,
|
||||
file=pic,
|
||||
parse_mode=parse,
|
||||
link_preview=False,
|
||||
buttons=buttons if inline else None,
|
||||
)
|
||||
await ult.try_delete()
|
||||
except ChatSendMediaForbiddenError:
|
||||
pass
|
||||
except BaseException as er:
|
||||
LOGS.exception(er)
|
||||
try:
|
||||
await ult.reply(file=pic)
|
||||
await ult.reply(
|
||||
als,
|
||||
parse_mode=parse,
|
||||
buttons=buttons if inline else None,
|
||||
link_preview=False,
|
||||
)
|
||||
return await ult.try_delete()
|
||||
except BaseException as er:
|
||||
LOGS.exception(er)
|
||||
await eor(
|
||||
ult,
|
||||
als,
|
||||
parse_mode=parse,
|
||||
link_preview=False,
|
||||
buttons=buttons if inline else None,
|
||||
)
|
||||
|
||||
|
||||
@ultroid_cmd(pattern="ping$", chats=[], type=["official", "assistant"])
|
||||
async def _(event):
|
||||
if event.out:
|
||||
await event.delete()
|
||||
start = time.time()
|
||||
x = await event.respond("Pong !")
|
||||
x = await event.eor("Pong !")
|
||||
end = round((time.time() - start) * 1000)
|
||||
uptime = time_formatter((time.time() - start_time) * 1000)
|
||||
await x.edit(get_string("ping").format(end, uptime))
|
||||
@@ -195,12 +210,15 @@ heroku_api = Var.HEROKU_API
|
||||
fullsudo=True,
|
||||
)
|
||||
async def restartbt(ult):
|
||||
ok = await eor(ult, get_string("bot_5"))
|
||||
ok = await ult.eor(get_string("bot_5"))
|
||||
call_back()
|
||||
if heroku_api:
|
||||
return await restart(ok)
|
||||
await bash("git pull && pip3 install -r requirements.txt")
|
||||
os.execl(sys.executable, sys.executable, "-m", "pyUltroid")
|
||||
if len(sys.argv) > 1:
|
||||
os.execl(sys.executable, sys.executable, "main.py")
|
||||
else:
|
||||
os.execl(sys.executable, sys.executable, "-m", "pyUltroid")
|
||||
|
||||
|
||||
@ultroid_cmd(
|
||||
@@ -217,52 +235,54 @@ async def shutdownbot(ult):
|
||||
)
|
||||
async def _(event):
|
||||
opt = event.pattern_match.group(1)
|
||||
file = f"ultroid{sys.argv[-1]}.log" if len(sys.argv) > 1 else "ultroid.log"
|
||||
if opt == "heroku":
|
||||
await heroku_logs(event)
|
||||
elif opt == "carbon" and Carbon:
|
||||
event = await eor(event, get_string("com_1"))
|
||||
code = open("ultroid.log", "r").read()[-2500:]
|
||||
event = await event.eor(get_string("com_1"))
|
||||
code = open(file, "r").read()[-2500:]
|
||||
file = await Carbon(
|
||||
base_url="https://carbonara.vercel.app/api/cook",
|
||||
file_name="ultroid-logs",
|
||||
code=code,
|
||||
background=choice(ATRA_COL),
|
||||
).memorize("ultroid-logs")
|
||||
backgroundColor=choice(ATRA_COL),
|
||||
)
|
||||
await event.reply("**Ultroid Logs.**", file=file)
|
||||
elif opt == "open":
|
||||
file = open("ultroid.log", "r").read()[-4000:]
|
||||
return await event.eor(f"`{file}`")
|
||||
else:
|
||||
await def_logs(event)
|
||||
await event.delete()
|
||||
await def_logs(event, file)
|
||||
await event.try_delete()
|
||||
|
||||
|
||||
@in_pattern("alive", owner=True)
|
||||
async def inline_alive(ult):
|
||||
pic = udB.get("ALIVE_PIC")
|
||||
pic = udB.get_key("ALIVE_PIC")
|
||||
uptime = time_formatter((time.time() - start_time) * 1000)
|
||||
header = udB.get("ALIVE_TEXT") or get_string("bot_1")
|
||||
header = udB.get_key("ALIVE_TEXT") or get_string("bot_1")
|
||||
y = Repo().active_branch
|
||||
xx = Repo().remotes[0].config_reader.get("url")
|
||||
rep = xx.replace(".git", f"/tree/{y}")
|
||||
kk = f" `[{y}]({rep})` "
|
||||
als = (get_string("alive_1")).format(
|
||||
kk = f"<a href={rep}>{y}</a>"
|
||||
als = in_alive.format(
|
||||
header,
|
||||
OWNER_NAME,
|
||||
ultroid_version,
|
||||
UltVer,
|
||||
uptime,
|
||||
pyver(),
|
||||
__version__,
|
||||
uptime,
|
||||
kk,
|
||||
)
|
||||
buttons = [
|
||||
[
|
||||
Button.url(get_string("bot_3"), "https://github.com/TeamUltroid/Ultroid"),
|
||||
Button.url(get_string("bot_4"), "t.me/UltroidSupport"),
|
||||
]
|
||||
]
|
||||
if _e := udB.get_key("ALIVE_EMOJI"):
|
||||
als = als.replace("🌀", _e)
|
||||
builder = ult.builder
|
||||
if pic:
|
||||
try:
|
||||
if ".jpg" in pic:
|
||||
results = [await builder.photo(pic, text=als, buttons=buttons)]
|
||||
results = [
|
||||
await builder.photo(
|
||||
pic, text=als, parse_mode="html", buttons=buttons
|
||||
)
|
||||
]
|
||||
else:
|
||||
_pic = resolve_bot_file_id(pic)
|
||||
if _pic:
|
||||
@@ -275,6 +295,7 @@ async def inline_alive(ult):
|
||||
pic,
|
||||
title="Inline Alive",
|
||||
description="@TheUltroid",
|
||||
parse_mode="html",
|
||||
buttons=buttons,
|
||||
)
|
||||
]
|
||||
@@ -282,6 +303,55 @@ async def inline_alive(ult):
|
||||
except BaseException as er:
|
||||
LOGS.info(er)
|
||||
result = [
|
||||
await builder.article("Alive", text=als, link_preview=False, buttons=buttons)
|
||||
await builder.article(
|
||||
"Alive", text=als, parse_mode="html", link_preview=False, buttons=buttons
|
||||
)
|
||||
]
|
||||
await ult.answer(result)
|
||||
|
||||
|
||||
@ultroid_cmd(pattern="update ?(.*)")
|
||||
async def _(e):
|
||||
xx = await e.eor(get_string("upd_1"))
|
||||
if e.pattern_match.group(1) and (
|
||||
"fast" in e.pattern_match.group(1) or "soft" in e.pattern_match.group(1)
|
||||
):
|
||||
await bash("git pull -f && pip3 install -r requirements.txt")
|
||||
call_back()
|
||||
await xx.edit(get_string("upd_7"))
|
||||
os.execl(sys.executable, "python3", "-m", "pyUltroid")
|
||||
return
|
||||
m = await updater()
|
||||
branch = (Repo.init()).active_branch
|
||||
if m:
|
||||
x = await asst.send_file(
|
||||
udB.get_key("LOG_CHANNEL"),
|
||||
ULTPIC,
|
||||
caption="• **Update Available** •",
|
||||
force_document=False,
|
||||
buttons=Button.inline("Changelogs", data="changes"),
|
||||
)
|
||||
Link = x.message_link
|
||||
await xx.edit(
|
||||
f'<strong><a href="{Link}">[ChangeLogs]</a></strong>',
|
||||
parse_mode="html",
|
||||
link_preview=False,
|
||||
)
|
||||
else:
|
||||
await xx.edit(
|
||||
f'<code>Your BOT is </code><strong>up-to-date</strong><code> with </code><strong><a href="https://github.com/TeamUltroid/Ultroid/tree/{branch}">[{branch}]</a></strong>',
|
||||
parse_mode="html",
|
||||
link_preview=False,
|
||||
)
|
||||
|
||||
|
||||
@callback("updtavail", owner=True)
|
||||
async def updava(event):
|
||||
await event.delete()
|
||||
await asst.send_file(
|
||||
udB.get_key("LOG_CHANNEL"),
|
||||
ULTPIC,
|
||||
caption="• **Update Available** •",
|
||||
force_document=False,
|
||||
buttons=Button.inline("Changelogs", data="changes"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user