From d82cc7d24ed1829cd709b30013f9673ff2d1545a Mon Sep 17 00:00:00 2001 From: Devesh Pal Date: Sat, 1 Jan 2022 20:35:38 +0530 Subject: [PATCH] Ultroid v0.3 fixes Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com> --- README.md | 5 ++ assistant/callbackstuffs.py | 9 +-- plugins/_help.py | 3 +- plugins/_inline.py | 2 +- plugins/_userlogs.py | 2 + plugins/admintools.py | 9 ++- plugins/channelhacks.py | 112 ++++++++++++++++++++---------------- plugins/gdrive.py | 3 +- plugins/glitch.py | 11 ++-- plugins/mute.py | 18 +++--- plugins/notes.py | 4 +- plugins/nsfwfilter.py | 2 +- plugins/search.py | 2 +- plugins/specialtools.py | 2 +- requirements.txt | 2 +- strings/strings.py | 3 + 16 files changed, 107 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index bde6161..c0f8e6c 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,11 @@ Get the [Necessary Variables](#Necessary-Variables) and then click the button be [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://deploy.ultroid.tech) +## Deploy to Railway +Get the [Necessary Variables](#Necessary-Variables) and then click the button below! + +[![Deploy on Railway](https://railway.app/button.svg)](https://deploy.ultroid.tech/railway) + ## Deploy Locally - [Traditional Method](#local-deploy---traditional-method) - [Easy Method](#local-deploy---easy-method) diff --git a/assistant/callbackstuffs.py b/assistant/callbackstuffs.py index d684aa1..247954e 100644 --- a/assistant/callbackstuffs.py +++ b/assistant/callbackstuffs.py @@ -461,7 +461,7 @@ async def _(e): async def _(e): if not e.is_private: return - await e.edit( + msg = ( "Send your FOLDER ID\n\n" + "For FOLDER ID:\n" + "1. Open Google Drive App.\n" @@ -469,9 +469,10 @@ async def _(e): + "3. Make that folder public.\n" + "4. Send link of that folder." ) - async with asst.conversation(e.sender_id) as conv: - reply = conv.wait_event(events.NewMessage(from_users=e.sender_id)) - repl = await reply + await e.delete() + async with asst.conversation(e.sender_id, timeout=150) as conv: + await conv.send_message(msg) + repl = await conv.get_response() id = repl.text if id.startswith("https"): id = id.split("?id=")[-1] diff --git a/plugins/_help.py b/plugins/_help.py index 5a92e3a..a30a92d 100644 --- a/plugins/_help.py +++ b/plugins/_help.py @@ -78,8 +78,7 @@ async def _help(ult): except BotMethodInvalidError: z = [] for x in LIST.values(): - for y in x: - z.append(y) + z.extend(x) cmd = len(z) + 10 if udB.get_key("MANAGER") and udB.get_key("DUAL_HNDLR") == "/": _main_help_menu[2:3] = [[Button.inline("• Manager Help •", "mngbtn")]] diff --git a/plugins/_inline.py b/plugins/_inline.py index c523326..aa0d6b3 100644 --- a/plugins/_inline.py +++ b/plugins/_inline.py @@ -215,7 +215,7 @@ async def uptd_plugin(event): @callback(data="doupdate", owner=True) async def _(event): - if not updater(): + if not await updater(): return await event.answer(get_string("inline_9"), cache_time=0, alert=True) if not INLINE_PIC: return await event.answer(f"Do '{HNDLR}update' to update..") diff --git a/plugins/_userlogs.py b/plugins/_userlogs.py index ef8dda7..9b43324 100644 --- a/plugins/_userlogs.py +++ b/plugins/_userlogs.py @@ -109,6 +109,8 @@ if udB.get_key("TAG_LOG"): if event.chat_id not in TAG_EDITS: if event.sender_id == udB.get_key("TAG_LOG"): return + if event.is_private: + return entities = event.get_entities_text() if entities: is_self = False diff --git a/plugins/admintools.py b/plugins/admintools.py index c3a0dac..d8e033f 100644 --- a/plugins/admintools.py +++ b/plugins/admintools.py @@ -179,6 +179,8 @@ async def uunban(ult): async def kck(ult): if "kickme" in ult.text: return + if ult.is_private: + return await ult.eor("`Use this in Group/Channel.`", time=5) ml = ult.text.split(" ", maxsplit=1)[0] xx = await ult.eor(get_string("com_1")) something = await get_uinfo(ult) @@ -206,9 +208,9 @@ async def kck(ult): await xx.edit(text) -@ultroid_cmd(pattern="tban ?(.*)", manager=True, require="ban_users") +@ultroid_cmd(pattern="tban ?(.*)", admins_only=True, manager=True, require="ban_users") async def tkicki(e): - huh = e.text.split(" ") + huh = e.text.split() inputt = None try: tme = huh[1] @@ -240,7 +242,7 @@ async def tkicki(e): return await e.eor(str(m)) -@ultroid_cmd(pattern="pin$", manager=True, require="pin_messages") +@ultroid_cmd(pattern="pin$", admins_only=True, manager=True, require="pin_messages") async def pin(msg): if not msg.is_reply: return await eor(msg, get_string("pin_1")) @@ -260,6 +262,7 @@ async def pin(msg): @ultroid_cmd( pattern="unpin($| (.*))", + admins_only=True, manager=True, require="pin_messages", ) diff --git a/plugins/channelhacks.py b/plugins/channelhacks.py index 9115d64..f8e0b2d 100644 --- a/plugins/channelhacks.py +++ b/plugins/channelhacks.py @@ -7,7 +7,6 @@ """ ✘ Commands Available - 🔹 `{i}shift | ` This will transfer all old post from channel A to channel B. (u can use username or id of channel too) @@ -50,24 +49,32 @@ from pyUltroid.dB.ch_db import ( rem_destination, rem_source_channel, ) +from telethon.errors.rpcerrorlist import FloodWaitError +from telethon.utils import get_display_name, get_peer_id -from . import asst, eor, events, get_string, udB, ultroid_bot, ultroid_cmd +from . import LOGS, asst, eor, events, get_string, udB, ultroid_bot, ultroid_cmd + +ERROR = {} -@ultroid_bot.on(events.NewMessage()) -async def _(e): - if udB.get_key("AUTOPOST") != "True": +async def autopost_func(e): + if not udB.get_key("AUTOPOST"): return x = get_source_channels() th = await e.get_chat() - if str(th.id) not in x: + if get_peer_id(th) not in x: return y = get_destinations() for ys in y: try: - await ultroid_bot.send_message(int(ys), e.message) + await e.client.send_message(int(ys), e.message) except Exception as ex: - await asst.send_message(int(udB.get_key("LOG_CHANNEL")), str(ex)) + try: + ERROR[str(ex)] + except KeyError: + ERROR.update({str(ex): ex}) + Error = f"**Error on AUTOPOST**\n\n`{ex}`" + await asst.send_message(udB.get_key("LOG_CHANNEL"), Error) @ultroid_cmd(pattern="shift (.*)") @@ -76,44 +83,43 @@ async def _(e): z = await e.eor(get_string("com_1")) a, b = x.split("|") try: - c = int(a) + c = await e.client.parse_id(a) except Exception: - try: - c = (await e.client.get_entity(a)).id - except Exception: - await z.edit(get_string("cha_1")) - return + await z.edit(get_string("cha_1")) + return try: - d = int(b) - except Exception: - try: - d = (await e.client.get_entity(b)).id - except Exception: - await z.edit(get_string("cha_1")) - return + d = await e.client.parse_id(b) + except Exception as er: + LOGS.exception(er) + await z.edit(get_string("cha_1")) + return async for msg in e.client.iter_messages(int(c), reverse=True): try: await asyncio.sleep(2) await e.client.send_message(int(d), msg) - except BaseException: - pass + except FloodWaitError as er: + await asyncio.sleep(er.seconds + 5) + await e.client.send_message(int(d), msg) + except BaseException as er: + LOGS.exception(er) await z.edit("Done") @ultroid_cmd(pattern="asource (.*)") async def source(e): x = e.pattern_match.group(1) - try: - y = int(x) - except Exception: + if not x: + y = e.chat_id + else: try: - y = int((await ultroid_bot.get_entity(x)).id) - except Exception as es: - print(es) + y = await e.client.parse_id(x) + except Exception as er: + LOGS.exception(er) return if not is_source_channel_added(y): add_source_channel(y) await e.eor(get_string("cha_2")) + ultroid_bot.add_handler(autopost_func, events.NewMessage()) elif is_source_channel_added(y): await e.eor(get_string("cha_3")) @@ -127,14 +133,14 @@ async def dd(event): udB.del_key("CH_SOURCE") await x.edit(get_string("cha_4")) return - try: - y = int(chat_id) - except Exception: + if chat_id: try: - y = int((await event.client.get_entity(chat_id)).id) - except Exception as es: - print(es) + y = await e.client.parse_id(chat_id) + except Exception as er: + LOGS.exception(er) return + else: + y = event.chat_id if is_source_channel_added(y): rem_source_channel(y) await eor(x, get_string("cha_5"), time=3) @@ -148,15 +154,15 @@ async def dd(event): @ultroid_cmd(pattern="listsource") async def list_all(event): x = await event.eor(get_string("com_1")) - channels = get_source_channels() num = get_no_source_channels() - if num == 0: + if not num: return await eor(x, "No chats were added.", time=5) msg = get_string("cha_8") + channels = get_source_channels() for channel in channels: name = "" try: - name = (await event.client.get_entity(int(channel))).title + name = get_display_name(await event.client.get_entity(int(channel))) except BaseException: name = "" msg += f"\n=> **{name}** [`{channel}`]" @@ -181,14 +187,14 @@ async def list_all(event): @ultroid_cmd(pattern="adest (.*)") async def destination(e): x = e.pattern_match.group(1) - try: - y = int(x) - except Exception: + if x: try: - y = int((await e.client.get_entity(x)).id) - except Exception as es: - print(es) + y = await e.client.parse_id(x) + except Exception as er: + LOGS.exception(er) return + else: + y = e.chat_id if not is_destination_added(y): add_destination(y) await e.eor("Destination added succesfully") @@ -205,14 +211,14 @@ async def dd(event): udB.del_key("CH_DESTINATION") await x.edit("Destinations database cleared.") return - try: - y = int(chat_id) - except Exception: + if chat_id: try: - y = int((await event.client.get_entity(chat_id)).id) - except Exception as es: - print(es) + y = await e.client.parse_id(chat_id) + except Exception as er: + LOGS.exception(er) return + else: + y = event.chat_id if is_destination_added(y): rem_destination(y) await eor(x, "Destination removed from database") @@ -235,7 +241,7 @@ async def list_all(event): for channel in channels: name = "" try: - name = (await ultroid_bot.get_entity(int(channel))).title + name = get_display_name(await ultroid_bot.get_entity(int(channel))) except BaseException: name = "" msg += f"\n=> **{name}** [`{channel}`]" @@ -255,3 +261,7 @@ async def list_all(event): await x.delete() else: await x.edit(msg) + + +if udB.get_key("AUTOPOST"): + ultroid_bot.add_handler(autopost_func, events.NewMessage()) diff --git a/plugins/gdrive.py b/plugins/gdrive.py index fc3d74d..3f98de9 100644 --- a/plugins/gdrive.py +++ b/plugins/gdrive.py @@ -244,11 +244,12 @@ async def _(event): fullsudo=True, ) async def _(event): + GDrive = GDriveManager() if not os.path.exists(GDrive.token_file): return await event.eor(get_string("gdrive_6").format(asst.me.username)) if GDrive.folder_id: await event.eor( - "`Here is Your G-Drive Folder link : `\n" + "`Your G-Drive Folder link : `\n" + "https://drive.google.com/folderview?id=" + GDrive.folder_id, ) diff --git a/plugins/glitch.py b/plugins/glitch.py index e072b9e..0ecb8d1 100644 --- a/plugins/glitch.py +++ b/plugins/glitch.py @@ -5,7 +5,6 @@ # PLease read the GNU Affero General Public License in # . """ - ✘ Commands Available - •`{i}glitch ` @@ -27,11 +26,15 @@ async def _(e): reply = await e.get_reply_message() if not (reply and reply.media): return await e.eor(get_string("cvt_3")) + xx = await e.eor(get_string("glitch_1")) wut = mediainfo(reply.media) if not wut.startswith(("pic", "sticker")): - return await e.eor(get_string("com_4")) - xx = await e.eor(get_string("glitch_1")) - ok = await e.client.download_media(reply.media) + if reply.document and reply.document.thumbs: + ok = await reply.download_media(thumb=-1) + else: + return await xx.eor(get_string("com_4")) + else: + ok = await reply.download_media() cmd = f"glitch_me gif --line_count 200 -f 10 -d 50 '{ok}' ult.gif" stdout, stderr = await bash(cmd) await e.reply(file="ult.gif", force_document=False) diff --git a/plugins/mute.py b/plugins/mute.py index e2ccbcc..1591e02 100644 --- a/plugins/mute.py +++ b/plugins/mute.py @@ -29,6 +29,7 @@ from pyUltroid.dB.mute_db import is_muted, mute, unmute from pyUltroid.functions.admins import ban_time from telethon import events +from telethon.utils import get_display_name from . import eod, get_string, inline_mention, ultroid_bot, ultroid_cmd @@ -54,7 +55,7 @@ async def startmute(event): return await xx.edit(str(x)) elif event.reply_to_msg_id: userid = (await event.get_reply_message()).sender_id - elif private: + elif event.is_private: userid = event.chat_id else: return await xx.eor("`Reply to a user or add their userid.`", time=5) @@ -77,7 +78,6 @@ async def startmute(event): async def endmute(event): xx = await event.eor("`Unmuting...`") input = event.pattern_match.group(1) - private = event.is_private if input: try: userid = await event.client.parse_id(input_) @@ -85,7 +85,7 @@ async def endmute(event): return await xx.edit(str(x)) elif event.reply_to_msg_id: userid = (await event.get_reply_message()).sender_id - elif private: + elif event.is_private: userid = event.chat_id else: return await xx.eor("`Reply to a user or add their userid.`", time=5) @@ -103,7 +103,7 @@ async def endmute(event): ) async def _(e): xx = await e.eor("`Muting...`") - huh = e.text.split(" ") + huh = e.text.split() try: tme = huh[1] except IndexError: @@ -143,7 +143,7 @@ async def _(e): @ultroid_cmd( pattern="unmute ?(.*)", - groups_only=True, + admins_only=True, manager=True, ) async def _(e): @@ -175,18 +175,14 @@ async def _(e): await xx.eor(f"`{m}`", time=5) -@ultroid_cmd( - pattern="mute ?(.*)", - groups_only=True, - manager=True, -) +@ultroid_cmd(pattern="mute ?(.*)", admins_only=True, manager=True, require="ban_users") async def _(e): xx = await e.eor("`Muting...`") input = e.pattern_match.group(1) chat = await e.get_chat() if e.reply_to_msg_id: userid = (await e.get_reply_message()).sender_id - name = (await e.client.get_entity(userid)).first_name + name = get_display_name(await e.client.get_entity(userid)) elif input: try: userid = await e.client.parse_id(input) diff --git a/plugins/notes.py b/plugins/notes.py index 260fccd..9712bc4 100644 --- a/plugins/notes.py +++ b/plugins/notes.py @@ -104,7 +104,9 @@ async def notes(e): if k.get("button"): btn = create_tl_btn(k["button"]) return await something(e, msg, media, btn) - await e.reply(msg, file=media) + await e.client.send_message( + e.chat_id, msg, file=media, reply_to=e.reply_to_msg_id or e.id + ) if udB.get_key("NOTE"): diff --git a/plugins/nsfwfilter.py b/plugins/nsfwfilter.py index 37b612b..bada708 100644 --- a/plugins/nsfwfilter.py +++ b/plugins/nsfwfilter.py @@ -63,7 +63,7 @@ async def nsfw_check(e): if pic and not nsfw: r = await async_searcher( "https://api.deepai.org/api/nsfw-detector", - files={ + data={ "image": open(pic, "rb"), }, post=True, diff --git a/plugins/search.py b/plugins/search.py index 8efd57a..4c056e7 100644 --- a/plugins/search.py +++ b/plugins/search.py @@ -169,7 +169,7 @@ async def reverse(event): "format": "jpg", "output_directory": "./resources/downloads/", } - pth = gi.download(args) + pth = await gi.download(args) ok = pth[0][text] await event.client.send_file( event.chat_id, diff --git a/plugins/specialtools.py b/plugins/specialtools.py index 6b9a02b..e63b119 100644 --- a/plugins/specialtools.py +++ b/plugins/specialtools.py @@ -293,7 +293,7 @@ async def wall(event): "format": "jpg", "output_directory": "./resources/downloads/", } - gi.download(args) + await gi.download(args) xx = choice(os.listdir(os.path.abspath(f"./resources/downloads/{query}/"))) await event.client.send_file(event.chat_id, f"./resources/downloads/{query}/{xx}") rmtree(f"./resources/downloads/{query}/") diff --git a/requirements.txt b/requirements.txt index a21fc76..0461126 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Important Requirements here. https://github.com/New-dev0/Telethon/archive/Vector.zip -py-Ultroid==2022.1.1 +py-Ultroid==2022.1.1.1 pytgcalls==3.0.0.dev19 diff --git a/strings/strings.py b/strings/strings.py index b66d843..ade499c 100644 --- a/strings/strings.py +++ b/strings/strings.py @@ -41,6 +41,9 @@ def get_string(key: str) -> Any: return tr except KeyError: return f"Warning: could not load any string with the key `{key}`" + except Exception as er: + LOGS.exception(er) + return languages["en"].get(key) or f"Failed to load language string '{key}'" def get_languages() -> Dict[str, Union[str, List[str]]]: