Skip to content

Commit

Permalink
Bug fixes V2.1 (#467)
Browse files Browse the repository at this point in the history
* Ultroid 2025 

Co-authored-by: New-dev0 <New-dev0@users.noreply.github.com>
Co-authored-by: Amit Sharma <buddhhu@users.noreply.github.com>
Co-authored-by: TechiError <techierror@users.noreply.github.com>
Co-authored-by: Aditya <me@xditya.me>
Co-authored-by: 1Danish-00 <danish@ultroid.tech> 
Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com>
Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com>
Co-authored-by: sppidy <sppidy@users.noreply.github.com> by Devesh Pal
  • Loading branch information
8 people authored Feb 23, 2025
1 parent 9e7a0cf commit c5c7916
Show file tree
Hide file tree
Showing 32 changed files with 566 additions and 383 deletions.
26 changes: 13 additions & 13 deletions assistant/callbackstuffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from pyUltroid.fns.gDrive import GDriveManager
except ImportError:
GDriveManager = None
from telegraph import upload_file as upl
from telethon import Button, events
from catbox import CatboxUploader
from telethon.tl.types import MessageMediaWebPage
from telethon.utils import get_peer_id

Expand All @@ -34,9 +34,9 @@
# --------------------------------------------------------------------#
telegraph = telegraph_client()
GDrive = GDriveManager() if GDriveManager else None
uploader = CatboxUploader()
# --------------------------------------------------------------------#


def text_to_url(event):
"""function to get media url (with|without) Webpage"""
if isinstance(event.media, MessageMediaWebPage):
Expand Down Expand Up @@ -322,9 +322,9 @@ async def update(eve):
await eve.edit(get_string("clst_1"))
call_back()
await bash("git pull && pip3 install -r requirements.txt")
await bash("pip3 install -r requirements.txt --break-system-packages")
execl(sys.executable, sys.executable, "-m", "pyUltroid")


@callback(re.compile("changes(.*)"), owner=True)
async def changes(okk):
match = okk.data_match.group(1).decode("utf-8")
Expand Down Expand Up @@ -384,11 +384,14 @@ async def _(e):
if "|" in ok:
ok, index = ok.split("|")
with open(ok, "r") as hmm:
_, key = await get_paste(hmm.read())
link = f"https://spaceb.in/{key}"
raw = f"https://spaceb.in/api/v1/documents/{key}/raw"
if not _:
_, data = await get_paste(hmm.read())
if not data.get("link"):
return await e.answer(key[:30], alert=True)
if not key.startswith("http"):
link, raw = data["link"], data["raw"]
else:
link = key
raw = f"{key}/raw"
if ok.startswith("addons"):
key = "Addons"
elif ok.startswith("vcbot"):
Expand Down Expand Up @@ -830,8 +833,7 @@ async def media(event):
else:
media = await event.client.download_media(response, "alvpc")
try:
x = upl(media)
url = f"https://graph.org/{x[0]}"
url = uploader.upload_file(media)
remove(media)
except BaseException as er:
LOGS.exception(er)
Expand Down Expand Up @@ -969,8 +971,7 @@ async def media(event):
url = response.file.id
else:
try:
x = upl(media)
url = f"https://graph.org/{x[0]}"
url = uploader.upload_file(media)
remove(media)
except BaseException as er:
LOGS.exception(er)
Expand Down Expand Up @@ -1239,8 +1240,7 @@ async def media(event):
url = text_to_url(response)
else:
try:
x = upl(media)
url = f"https://graph.org/{x[0]}"
url = uploader.upload_file(media)
remove(media)
except BaseException as er:
LOGS.exception(er)
Expand Down
39 changes: 26 additions & 13 deletions assistant/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@
"""

import asyncio
import re
import re, uuid, operator
from random import choice, shuffle

from akipy.async_akipy import Akinator, akipyLOGS
from akipy.async_akipy import Akinator
from telethon.errors.rpcerrorlist import BotMethodInvalidError
from telethon.events import Raw
from telethon.tl.types import InputMediaPoll, Poll, PollAnswer, UpdateMessagePollVote

from pyUltroid._misc._decorators import ultroid_cmd
from logging import getLogger
from html import unescape
from telethon.tl.types import TextWithEntities
from pyUltroid.fns.helper import inline_mention
from pyUltroid.fns.tools import async_searcher
from telethon.errors import ChatSendStickersForbiddenError

from . import * # Ensure this import matches your project structure

games = {}
aki_photo = "https://graph.org/file/3cc8825c029fd0cab9edc.jpg"

akipyLOGS = getLogger("akipy")

@ultroid_cmd(pattern="akinator")
async def akina(e):
Expand Down Expand Up @@ -133,11 +138,7 @@ async def eiagx(e):

# ----------------------- Main Command ------------------- #

GIMAGES = [
"https://graph.org/file/1c51015bae5205a65fd69.jpg",
"https://imgwhale.xyz/3xyr322l64j9590",
]

GIMAGE = "https://graph.org/file/1c51015bae5205a65fd69.jpg"

@asst_cmd(pattern="startgame", owner=True)
async def magic(event):
Expand All @@ -147,7 +148,7 @@ async def magic(event):
]
await event.reply(
get_string("games_1"),
file=choice(GIMAGES),
file=GIMAGE,
buttons=buttons,
)

Expand Down Expand Up @@ -243,18 +244,21 @@ async def choose_cata(event):
if TRIVIA_CHATS[chat].get("cancel") is not None:
break
ansi = str(uuid.uuid1()).split("-")[0].encode()
opts = [PollAnswer(unescape(q["correct_answer"]), ansi)]
opts = [PollAnswer(TextWithEntities(unescape(q["correct_answer"]), entities=[]), ansi)]
[
opts.append(
PollAnswer(unescape(a), str(uuid.uuid1()).split("-")[0].encode())
PollAnswer(TextWithEntities(unescape(a), entities=[]), str(uuid.uuid1()).split("-")[0].encode())
)
for a in q["incorrect_answers"]
]
shuffle(opts)
poll = InputMediaPoll(
Poll(
0,
f"[{copper+1}]. " + unescape(q["question"]),
TextWithEntities(
f"[{copper+1}]. " + unescape(q["question"]),
entities=[]
),
answers=opts,
public_voters=True,
quiz=True,
Expand Down Expand Up @@ -298,13 +302,22 @@ async def choose_cata(event):
@asst.on(
Raw(UpdateMessagePollVote, func=lambda x: TRIVIA_CHATS and POLLS.get(x.poll_id))
)
async def pollish(eve):
async def pollish(eve: UpdateMessagePollVote):
if POLLS.get(eve.poll_id)["chat"] not in TRIVIA_CHATS.keys():
return
if not eve.options:
# Consider as correct answer if no options selected
chat = POLLS.get(eve.poll_id)["chat"]
user = eve.peer.user_id
if not TRIVIA_CHATS.get(chat, {}).get(user):
TRIVIA_CHATS[chat][user] = 1
else:
TRIVIA_CHATS[chat][user] += 1
return
if POLLS[eve.poll_id]["answer"] != eve.options[0]:
return
chat = POLLS.get(eve.poll_id)["chat"]
user = eve.user_id
user = eve.peer.user_id
if not TRIVIA_CHATS.get(chat, {}).get(user):
TRIVIA_CHATS[chat][user] = 1
else:
Expand Down
5 changes: 5 additions & 0 deletions plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pyUltroid.startup._database import _BaseDatabase as Database
from pyUltroid.version import __version__, ultroid_version
from strings import get_help, get_string
from catbox import CatboxUploader

udB: Database

Expand All @@ -50,6 +51,9 @@ def inline_pic():


Telegraph = telegraph_client()
cat_uploader = CatboxUploader()

upload_file = cat_uploader.upload_file

List = []
Dict = {}
Expand Down Expand Up @@ -84,6 +88,7 @@ def inline_pic():
"Mr.Steal-Your-Sticker is stealing this sticker... ",
]


ATRA_COL = [
"DarkCyan",
"DeepSkyBlue",
Expand Down
8 changes: 6 additions & 2 deletions plugins/_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ async def inline_handler(event):
@in_pattern("pasta", owner=True)
async def _(event):
ok = event.text.split("-")[1]
link = f"https://spaceb.in/{ok}"
raw = f"https://spaceb.in/api/v1/documents/{ok}/raw"
if not ok.startswith("http"):
link = f"https://spaceb.in/{ok}"
raw = f"https://spaceb.in/api/v1/documents/{ok}/raw"
else:
link = ok
raw = f"{ok}/raw"
result = await event.builder.article(
title="Paste",
text="Pasted to Spacebin 🌌",
Expand Down
5 changes: 2 additions & 3 deletions plugins/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import asyncio

from telegraph import upload_file as uf
from telethon import events

from pyUltroid.dB.afk_db import add_afk, del_afk, is_afk
Expand All @@ -28,6 +27,7 @@
udB,
ultroid_bot,
ultroid_cmd,
upload_file
)

old_afk_msg = []
Expand All @@ -50,8 +50,7 @@ async def set_afk(event):
media_type = mediainfo(reply.media)
if media_type.startswith(("pic", "gif")):
file = await event.client.download_media(reply.media)
iurl = uf(file)
media = f"https://graph.org{iurl[0]}"
media = upload_file(file)
else:
media = reply.file.id
await event.eor("`Done`", time=2)
Expand Down
13 changes: 3 additions & 10 deletions plugins/asstcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@

from pyUltroid.dB.asstcmd_db import add_cmd, cmd_reply, list_cmds, rem_cmd
from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button

try:
from telegraph import upload_file as uf
except ImportError:
uf = None
from telethon import events, utils

from . import asst, get_string, mediainfo, udB, ultroid_cmd
from . import asst, get_string, mediainfo, udB, ultroid_cmd, upload_file


@ultroid_cmd(pattern="addcmd( (.*)|$)")
Expand All @@ -36,16 +31,14 @@ async def ac(e):
wut = mediainfo(wt.media)
if wut.startswith(("pic", "gif")):
dl = await e.client.download_media(wt.media)
variable = uf(dl)
m = upload_file(dl)
os.remove(dl)
m = f"https://graph.org{variable[0]}"
elif wut == "video":
if wt.media.document.size > 8 * 1000 * 1000:
return await e.eor(get_string("com_4"), time=5)
dl = await e.client.download_media(wt.media)
variable = uf(dl)
m = upload_file(dl)
os.remove(dl)
m = f"https://graph.org{variable[0]}"
else:
m = utils.pack_bot_file_id(wt.media)
if wt.text:
Expand Down
15 changes: 9 additions & 6 deletions plugins/audiotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
mediainfo,
stdr,
time_formatter,
ultroid_cmd,
uploader,
ultroid_cmd
)

__doc__ = get_help("help_audiotools")
Expand Down Expand Up @@ -104,13 +103,15 @@ async def trim_aud(e):
await bash(cmd)
os.remove(file.name)
f_time = time.time()
mmmm = await uploader(out, out, f_time, xxx, f"Uploading {out}...")
n_file, _ = await e.client.fast_uploader(
out, show_progress=True, event=e, message="Uploading...", to_delete=True
)
attributes = await set_attributes(out)

caption = get_string("audiotools_7").format(ss, dd)
await e.client.send_file(
e.chat_id,
mmmm,
n_file,
thumb=ULTConfig.thumb,
caption=caption,
attributes=attributes,
Expand Down Expand Up @@ -147,13 +148,15 @@ async def ex_aud(e):

f_time = time.time()
try:
fo = await uploader(out_file, out_file, f_time, msg, f"Uploading {out_file}...")
n_file, _ = await e.client.fast_uploader(
out_file, show_progress=True, event=e, message="Uploading...", to_delete=True
)

except FileNotFoundError:
return await eor(msg, get_string("audiotools_9"))
await e.reply(
get_string("audiotools_10"),
file=fo,
file=n_file,
thumb=ULTConfig.thumb,
attributes=attributes,
)
Expand Down
2 changes: 2 additions & 0 deletions plugins/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ async def restartbt(ult):
if heroku_api:
return await restart(ok)
await bash("git pull && pip3 install -r requirements.txt")
await bash("pip3 install -r requirements.txt --break-system-packages")
if len(sys.argv) > 1:
os.execl(sys.executable, sys.executable, "main.py")
else:
Expand Down Expand Up @@ -324,6 +325,7 @@ async def _(e):
or "soft" in e.pattern_match.group(1).strip()
):
await bash("git pull -f && pip3 install -r requirements.txt")
await bash("pip3 install -r requirements.txt --break-system-packages")
call_back()
await xx.edit(get_string("upd_7"))
os.execl(sys.executable, "python3", "-m", "pyUltroid")
Expand Down
8 changes: 3 additions & 5 deletions plugins/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import os

from telegraph import upload_file as uf
from . import upload_file as uf
from telethon.utils import pack_bot_file_id

from pyUltroid.fns.tools import create_tl_btn, get_msg_button
Expand All @@ -31,15 +31,13 @@ async def butt(event):
wut = mediainfo(wt.media)
if wut and wut.startswith(("pic", "gif")):
dl = await wt.download_media()
variable = uf(dl)
media = f"https://graph.org{variable[0]}"
media = uf(dl)
elif wut == "video":
if wt.media.document.size > 8 * 1000 * 1000:
return await event.eor(get_string("com_4"), time=5)
dl = await wt.download_media()
variable = uf(dl)
media = uf(dl)
os.remove(dl)
media = f"https://graph.org{variable[0]}"
else:
media = pack_bot_file_id(wt.media)
try:
Expand Down
Loading

0 comments on commit c5c7916

Please sign in to comment.