Spaces:
Sleeping
Sleeping
Delete plugins
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- plugins/__init__.py +0 -102
- plugins/_chatactions.py +0 -350
- plugins/_help.py +0 -136
- plugins/_inline.py +0 -451
- plugins/_ultroid.py +0 -66
- plugins/_userlogs.py +0 -297
- plugins/_wspr.py +0 -204
- plugins/admintools.py +0 -472
- plugins/afk.py +0 -166
- plugins/afscrp.py +0 -95
- plugins/antiflood.py +0 -121
- plugins/asstcmd.py +0 -107
- plugins/audiotools.py +0 -160
- plugins/autoban.py +0 -59
- plugins/autopic.py +0 -84
- plugins/beautify.py +0 -210
- plugins/blacklist.py +0 -69
- plugins/bot.py +0 -358
- plugins/broadcast.py +0 -216
- plugins/button.py +0 -56
- plugins/calculator.py +0 -153
- plugins/channelhacks.py +0 -224
- plugins/chatbot.py +0 -174
- plugins/chats.py +0 -368
- plugins/cleanaction.py +0 -48
- plugins/codefix.py +0 -241
- plugins/codegpt.py +0 -302
- plugins/compressor.py +0 -175
- plugins/converter.py +0 -191
- plugins/core.py +0 -124
- plugins/database.py +0 -77
- plugins/dbx.py +0 -123
- plugins/devtools.py +0 -404
- plugins/downloadupload.py +0 -222
- plugins/echo.py +0 -76
- plugins/extra.py +0 -85
- plugins/fakeaction.py +0 -36
- plugins/fileshare.py +0 -95
- plugins/filter.py +0 -102
- plugins/flux2.py +0 -95
- plugins/fontgen.py +0 -60
- plugins/forcesubscribe.py +0 -179
- plugins/gdrive.py +0 -232
- plugins/gemi.py +0 -413
- plugins/giftools.py +0 -128
- plugins/glitch.py +0 -42
- plugins/globaltools.py +0 -753
- plugins/gpt.py +0 -183
- plugins/greetings.py +0 -205
- plugins/imagetools.py +0 -292
plugins/__init__.py
DELETED
@@ -1,102 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
import asyncio
|
9 |
-
import os
|
10 |
-
import time
|
11 |
-
from random import choice
|
12 |
-
|
13 |
-
import requests
|
14 |
-
from telethon import Button, events
|
15 |
-
from telethon.tl import functions, types # pylint:ignore
|
16 |
-
from telethon.tl.custom.message import CustomMarkdown
|
17 |
-
|
18 |
-
from pyUltroid import *
|
19 |
-
from pyUltroid._misc._assistant import asst_cmd, callback, in_pattern
|
20 |
-
from pyUltroid._misc._decorators import ultroid_cmd
|
21 |
-
from pyUltroid._misc._wrappers import eod, eor
|
22 |
-
from pyUltroid.dB import DEVLIST, ULTROID_IMAGES
|
23 |
-
from pyUltroid.fns.helper import *
|
24 |
-
from pyUltroid.fns.misc import *
|
25 |
-
from pyUltroid.fns.tools import *
|
26 |
-
from pyUltroid.startup._database import _BaseDatabase as Database
|
27 |
-
from pyUltroid.version import __version__, ultroid_version
|
28 |
-
from strings import get_help, get_string
|
29 |
-
|
30 |
-
udB: Database
|
31 |
-
|
32 |
-
Redis = udB.get_key
|
33 |
-
con = TgConverter
|
34 |
-
quotly = Quotly()
|
35 |
-
OWNER_NAME = ultroid_bot.full_name
|
36 |
-
OWNER_ID = ultroid_bot.uid
|
37 |
-
|
38 |
-
ultroid_bot: UltroidClient
|
39 |
-
asst: UltroidClient
|
40 |
-
|
41 |
-
LOG_CHANNEL = udB.get_key("LOG_CHANNEL")
|
42 |
-
|
43 |
-
ultroid_bot.parse_mode = CustomMarkdown()
|
44 |
-
|
45 |
-
def inline_pic():
|
46 |
-
INLINE_PIC = udB.get_key("INLINE_PIC")
|
47 |
-
if INLINE_PIC is None:
|
48 |
-
INLINE_PIC = choice(ULTROID_IMAGES)
|
49 |
-
elif INLINE_PIC == False:
|
50 |
-
INLINE_PIC = None
|
51 |
-
return INLINE_PIC
|
52 |
-
|
53 |
-
|
54 |
-
Telegraph = telegraph_client()
|
55 |
-
|
56 |
-
List = []
|
57 |
-
Dict = {}
|
58 |
-
InlinePlugin = {}
|
59 |
-
N = 0
|
60 |
-
cmd = ultroid_cmd
|
61 |
-
STUFF = {}
|
62 |
-
|
63 |
-
# Chats, which needs to be ignore for some cases
|
64 |
-
# Considerably, there can be many
|
65 |
-
# Feel Free to Add Any other...
|
66 |
-
|
67 |
-
NOSPAM_CHAT = [
|
68 |
-
-1001361294038, # UltroidSupportChat
|
69 |
-
-1001387666944, # PyrogramChat
|
70 |
-
-1001109500936, # TelethonChat
|
71 |
-
-1001050982793, # Python
|
72 |
-
-1001256902287, # DurovsChat
|
73 |
-
-1001473548283, # SharingUserbot
|
74 |
-
]
|
75 |
-
|
76 |
-
KANGING_STR = [
|
77 |
-
"Using Witchery to kang this sticker...",
|
78 |
-
"Plagiarising hehe...",
|
79 |
-
"Inviting this sticker over to my pack...",
|
80 |
-
"Kanging this sticker...",
|
81 |
-
"Hey that's a nice sticker!\nMind if I kang?!..",
|
82 |
-
"Hehe me stel ur stiker...",
|
83 |
-
"Ay look over there (☉。☉)!→\nWhile I kang this...",
|
84 |
-
"Roses are red violets are blue, kanging this sticker so my pack looks cool",
|
85 |
-
"Imprisoning this sticker...",
|
86 |
-
"Mr.Steal-Your-Sticker is stealing this sticker... ",
|
87 |
-
]
|
88 |
-
|
89 |
-
ATRA_COL = [
|
90 |
-
"DarkCyan",
|
91 |
-
"DeepSkyBlue",
|
92 |
-
"DarkTurquoise",
|
93 |
-
"Cyan",
|
94 |
-
"LightSkyBlue",
|
95 |
-
"Turquoise",
|
96 |
-
"MediumVioletRed",
|
97 |
-
"Aquamarine",
|
98 |
-
"Lightcyan",
|
99 |
-
"Azure",
|
100 |
-
"Moccasin",
|
101 |
-
"PowderBlue",
|
102 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/_chatactions.py
DELETED
@@ -1,350 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
import asyncio
|
9 |
-
|
10 |
-
from telethon import events
|
11 |
-
from telethon.errors.rpcerrorlist import UserNotParticipantError
|
12 |
-
from telethon.tl.functions.channels import GetParticipantRequest
|
13 |
-
from telethon.utils import get_display_name
|
14 |
-
|
15 |
-
from pyUltroid.dB import stickers
|
16 |
-
from pyUltroid.dB.echo_db import check_echo
|
17 |
-
from pyUltroid.dB.forcesub_db import get_forcesetting
|
18 |
-
from pyUltroid.dB.gban_mute_db import is_gbanned
|
19 |
-
from pyUltroid.dB.greetings_db import get_goodbye, get_welcome, must_thank
|
20 |
-
from pyUltroid.dB.nsfw_db import is_profan
|
21 |
-
from pyUltroid.fns.helper import check_reply_to, inline_mention
|
22 |
-
from pyUltroid.fns.tools import (
|
23 |
-
async_searcher,
|
24 |
-
create_tl_btn,
|
25 |
-
get_chatbot_reply,
|
26 |
-
get_oracle_reply,
|
27 |
-
)
|
28 |
-
|
29 |
-
try:
|
30 |
-
from ProfanityDetector import detector
|
31 |
-
except ImportError:
|
32 |
-
detector = None
|
33 |
-
from . import LOG_CHANNEL, LOGS, asst, get_string, types, udB, ultroid_bot
|
34 |
-
from ._inline import something
|
35 |
-
|
36 |
-
if not udB.get_key("ORACLE_USERS"):
|
37 |
-
udB.set_key("ORACLE_USERS", {})
|
38 |
-
if not udB.get_key("CHATBOT_USERS"):
|
39 |
-
udB.set_key("CHATBOT_USERS", {})
|
40 |
-
|
41 |
-
@ultroid_bot.on(events.ChatAction())
|
42 |
-
async def Function(event):
|
43 |
-
try:
|
44 |
-
await DummyHandler(event)
|
45 |
-
except Exception as er:
|
46 |
-
LOGS.exception(er)
|
47 |
-
|
48 |
-
|
49 |
-
async def DummyHandler(ult):
|
50 |
-
# clean chat actions
|
51 |
-
key = udB.get_key("CLEANCHAT") or []
|
52 |
-
if ult.chat_id in key:
|
53 |
-
try:
|
54 |
-
await ult.delete()
|
55 |
-
except BaseException:
|
56 |
-
pass
|
57 |
-
|
58 |
-
# thank members
|
59 |
-
if must_thank(ult.chat_id):
|
60 |
-
chat_count = (await ult.client.get_participants(ult.chat_id, limit=0)).total
|
61 |
-
if chat_count % 100 == 0:
|
62 |
-
stik_id = chat_count / 100 - 1
|
63 |
-
sticker = stickers[stik_id]
|
64 |
-
await ult.respond(file=sticker)
|
65 |
-
# force subscribe
|
66 |
-
if (
|
67 |
-
udB.get_key("FORCESUB")
|
68 |
-
and ((ult.user_joined or ult.user_added))
|
69 |
-
and get_forcesetting(ult.chat_id)
|
70 |
-
):
|
71 |
-
user = await ult.get_user()
|
72 |
-
if not user.bot:
|
73 |
-
joinchat = get_forcesetting(ult.chat_id)
|
74 |
-
try:
|
75 |
-
await ultroid_bot(GetParticipantRequest(int(joinchat), user.id))
|
76 |
-
except UserNotParticipantError:
|
77 |
-
await ultroid_bot.edit_permissions(
|
78 |
-
ult.chat_id, user.id, send_messages=False
|
79 |
-
)
|
80 |
-
res = await ultroid_bot.inline_query(
|
81 |
-
asst.me.username, f"fsub {user.id}_{joinchat}"
|
82 |
-
)
|
83 |
-
await res[0].click(ult.chat_id, reply_to=ult.action_message.id)
|
84 |
-
|
85 |
-
if ult.user_joined or ult.added_by:
|
86 |
-
user = await ult.get_user()
|
87 |
-
chat = await ult.get_chat()
|
88 |
-
# gbans and @UltroidBans checks
|
89 |
-
if udB.get_key("ULTROID_BANS"):
|
90 |
-
try:
|
91 |
-
is_banned = await async_searcher(
|
92 |
-
"https://bans.ultroid.tech/api/status",
|
93 |
-
json={"userId": user.id},
|
94 |
-
post=True,
|
95 |
-
re_json=True,
|
96 |
-
)
|
97 |
-
if is_banned["is_banned"]:
|
98 |
-
await ult.client.edit_permissions(
|
99 |
-
chat.id,
|
100 |
-
user.id,
|
101 |
-
view_messages=False,
|
102 |
-
)
|
103 |
-
await ult.respond(
|
104 |
-
f'**@UltroidBans:** Banned user detected and banned!\n`{str(is_banned)}`.\nBan reason: {is_banned["reason"]}',
|
105 |
-
)
|
106 |
-
|
107 |
-
except BaseException:
|
108 |
-
pass
|
109 |
-
reason = is_gbanned(user.id)
|
110 |
-
if reason and chat.admin_rights:
|
111 |
-
try:
|
112 |
-
await ult.client.edit_permissions(
|
113 |
-
chat.id,
|
114 |
-
user.id,
|
115 |
-
view_messages=False,
|
116 |
-
)
|
117 |
-
gban_watch = get_string("can_1").format(inline_mention(user), reason)
|
118 |
-
await ult.reply(gban_watch)
|
119 |
-
except Exception as er:
|
120 |
-
LOGS.exception(er)
|
121 |
-
|
122 |
-
# greetings
|
123 |
-
elif get_welcome(ult.chat_id):
|
124 |
-
user = await ult.get_user()
|
125 |
-
chat = await ult.get_chat()
|
126 |
-
title = chat.title or "this chat"
|
127 |
-
count = (
|
128 |
-
chat.participants_count
|
129 |
-
or (await ult.client.get_participants(chat, limit=0)).total
|
130 |
-
)
|
131 |
-
mention = inline_mention(user)
|
132 |
-
name = user.first_name
|
133 |
-
fullname = get_display_name(user)
|
134 |
-
uu = user.username
|
135 |
-
username = f"@{uu}" if uu else mention
|
136 |
-
wel = get_welcome(ult.chat_id)
|
137 |
-
msgg = wel["welcome"]
|
138 |
-
med = wel["media"] or None
|
139 |
-
userid = user.id
|
140 |
-
msg = None
|
141 |
-
if msgg:
|
142 |
-
msg = msgg.format(
|
143 |
-
mention=mention,
|
144 |
-
group=title,
|
145 |
-
count=count,
|
146 |
-
name=name,
|
147 |
-
fullname=fullname,
|
148 |
-
username=username,
|
149 |
-
userid=userid,
|
150 |
-
)
|
151 |
-
if wel.get("button"):
|
152 |
-
btn = create_tl_btn(wel["button"])
|
153 |
-
await something(ult, msg, med, btn)
|
154 |
-
elif msg:
|
155 |
-
send = await ult.reply(
|
156 |
-
msg,
|
157 |
-
file=med,
|
158 |
-
)
|
159 |
-
await asyncio.sleep(150)
|
160 |
-
await send.delete()
|
161 |
-
else:
|
162 |
-
await ult.reply(file=med)
|
163 |
-
elif (ult.user_left or ult.user_kicked) and get_goodbye(ult.chat_id):
|
164 |
-
user = await ult.get_user()
|
165 |
-
chat = await ult.get_chat()
|
166 |
-
title = chat.title or "this chat"
|
167 |
-
count = (
|
168 |
-
chat.participants_count
|
169 |
-
or (await ult.client.get_participants(chat, limit=0)).total
|
170 |
-
)
|
171 |
-
mention = inline_mention(user)
|
172 |
-
name = user.first_name
|
173 |
-
fullname = get_display_name(user)
|
174 |
-
uu = user.username
|
175 |
-
username = f"@{uu}" if uu else mention
|
176 |
-
wel = get_goodbye(ult.chat_id)
|
177 |
-
msgg = wel["goodbye"]
|
178 |
-
med = wel["media"]
|
179 |
-
userid = user.id
|
180 |
-
msg = None
|
181 |
-
if msgg:
|
182 |
-
msg = msgg.format(
|
183 |
-
mention=mention,
|
184 |
-
group=title,
|
185 |
-
count=count,
|
186 |
-
name=name,
|
187 |
-
fullname=fullname,
|
188 |
-
username=username,
|
189 |
-
userid=userid,
|
190 |
-
)
|
191 |
-
if wel.get("button"):
|
192 |
-
btn = create_tl_btn(wel["button"])
|
193 |
-
await something(ult, msg, med, btn)
|
194 |
-
elif msg:
|
195 |
-
send = await ult.reply(
|
196 |
-
msg,
|
197 |
-
file=med,
|
198 |
-
)
|
199 |
-
await asyncio.sleep(150)
|
200 |
-
await send.delete()
|
201 |
-
else:
|
202 |
-
await ult.reply(file=med)
|
203 |
-
|
204 |
-
|
205 |
-
@ultroid_bot.on(events.NewMessage(incoming=True))
|
206 |
-
async def chatBot_replies(e):
|
207 |
-
if e.sender_id in udB.get_key("CHATBOT_USERS"):
|
208 |
-
xxrep = await check_reply_to(e)
|
209 |
-
else:
|
210 |
-
return
|
211 |
-
|
212 |
-
if xxrep:
|
213 |
-
sender = await e.get_sender()
|
214 |
-
if not isinstance(sender, types.User) or sender.bot:
|
215 |
-
return
|
216 |
-
if check_echo(e.chat_id, e.sender_id):
|
217 |
-
try:
|
218 |
-
await e.respond(e.message)
|
219 |
-
except Exception as er:
|
220 |
-
LOGS.exception(er)
|
221 |
-
key = udB.get_key("CHATBOT_USERS") or {}
|
222 |
-
if e.text and key.get(e.chat_id) and sender.id in key[e.chat_id]:
|
223 |
-
# Simulate typing indicator
|
224 |
-
async with e.client.action(e.chat_id, "typing"):
|
225 |
-
msg = await get_chatbot_reply(e.message.message)
|
226 |
-
if msg:
|
227 |
-
sleep = udB.get_key("CHATBOT_SLEEP") or 1.5
|
228 |
-
await asyncio.sleep(sleep)
|
229 |
-
|
230 |
-
# Check if the message length exceeds a certain threshold
|
231 |
-
if len(msg) > 4096:
|
232 |
-
# Create a temporary text file
|
233 |
-
with tempfile.NamedTemporaryFile(
|
234 |
-
mode="w+", delete=False
|
235 |
-
) as temp_file:
|
236 |
-
temp_file.write(msg)
|
237 |
-
|
238 |
-
# Send the text file with a caption
|
239 |
-
await e.client.send_file(
|
240 |
-
e.chat_id,
|
241 |
-
temp_file.name,
|
242 |
-
caption="Here is the response in a text file.",
|
243 |
-
)
|
244 |
-
|
245 |
-
# Delete the temporary text file
|
246 |
-
os.remove(temp_file.name)
|
247 |
-
else:
|
248 |
-
# Send the message directly
|
249 |
-
await e.reply(msg)
|
250 |
-
|
251 |
-
chat = await e.get_chat()
|
252 |
-
if e.is_group and sender.username:
|
253 |
-
await uname_stuff(e.sender_id, sender.username, sender.first_name)
|
254 |
-
elif e.is_private and chat.username:
|
255 |
-
await uname_stuff(e.sender_id, chat.username, chat.first_name)
|
256 |
-
if detector and is_profan(e.chat_id) and e.text:
|
257 |
-
x, y = detector(e.text)
|
258 |
-
if y:
|
259 |
-
await e.delete()
|
260 |
-
|
261 |
-
|
262 |
-
@ultroid_bot.on(events.NewMessage(incoming=True))
|
263 |
-
async def oracleBot_replies(e):
|
264 |
-
if e.sender_id in udB.get_key("ORACLE_USERS"):
|
265 |
-
xxxrep = await check_reply_to(e)
|
266 |
-
else:
|
267 |
-
return
|
268 |
-
|
269 |
-
if xxxrep:
|
270 |
-
sender = await e.get_sender()
|
271 |
-
if not isinstance(sender, types.User) or sender.bot:
|
272 |
-
return
|
273 |
-
if check_echo(e.chat_id, e.sender_id):
|
274 |
-
try:
|
275 |
-
await e.respond(e.message)
|
276 |
-
except Exception as er:
|
277 |
-
LOGS.exception(er)
|
278 |
-
key = udB.get_key("ORACLE_USERS") or {}
|
279 |
-
if e.text and key.get(e.chat_id) and sender.id in key[e.chat_id]:
|
280 |
-
# Simulate typing indicator
|
281 |
-
async with e.client.action(e.chat_id, "typing"):
|
282 |
-
msg = await get_oracle_reply(
|
283 |
-
e.message.message, user_id=sender.id, mongo_url=MONGO_URI
|
284 |
-
)
|
285 |
-
if msg:
|
286 |
-
sleep = udB.get_key("ORACLE_SLEEP") or 1.5
|
287 |
-
await asyncio.sleep(sleep)
|
288 |
-
|
289 |
-
# Check if the message length exceeds a certain threshold
|
290 |
-
if len(msg) > 4096:
|
291 |
-
# Create a temporary text file
|
292 |
-
with tempfile.NamedTemporaryFile(
|
293 |
-
mode="w+", delete=False
|
294 |
-
) as temp_file:
|
295 |
-
temp_file.write(msg)
|
296 |
-
|
297 |
-
# Send the text file with a caption
|
298 |
-
await e.client.send_file(
|
299 |
-
e.chat_id,
|
300 |
-
temp_file.name,
|
301 |
-
caption="Here is the response in a text file",
|
302 |
-
)
|
303 |
-
|
304 |
-
# Delete the temporary text file
|
305 |
-
os.remove(temp_file.name)
|
306 |
-
else:
|
307 |
-
# Send the message directly
|
308 |
-
await e.reply(msg)
|
309 |
-
|
310 |
-
chat = await e.get_chat()
|
311 |
-
if e.is_group and sender.username:
|
312 |
-
await uname_stuff(e.sender_id, sender.username, sender.first_name)
|
313 |
-
elif e.is_private and chat.username:
|
314 |
-
await uname_stuff(e.sender_id, chat.username, chat.first_name)
|
315 |
-
if detector and is_profan(e.chat_id) and e.text:
|
316 |
-
x, y = detector(e.text)
|
317 |
-
if y:
|
318 |
-
await e.delete()
|
319 |
-
|
320 |
-
|
321 |
-
@ultroid_bot.on(events.Raw(types.UpdateUserName))
|
322 |
-
async def uname_change(e):
|
323 |
-
await uname_stuff(e.user_id, e.usernames[0] if e.usernames else None, e.first_name)
|
324 |
-
|
325 |
-
|
326 |
-
async def uname_stuff(id, uname, name):
|
327 |
-
if udB.get_key("USERNAME_LOG"):
|
328 |
-
old_ = udB.get_key("USERNAME_DB") or {}
|
329 |
-
old = old_.get(id)
|
330 |
-
# Ignore Name Logs
|
331 |
-
if old and old == uname:
|
332 |
-
return
|
333 |
-
if old and uname:
|
334 |
-
await asst.send_message(
|
335 |
-
LOG_CHANNEL,
|
336 |
-
get_string("can_2").format(old, uname),
|
337 |
-
)
|
338 |
-
elif old:
|
339 |
-
await asst.send_message(
|
340 |
-
LOG_CHANNEL,
|
341 |
-
get_string("can_3").format(f"[{name}](tg://user?id={id})", old),
|
342 |
-
)
|
343 |
-
elif uname:
|
344 |
-
await asst.send_message(
|
345 |
-
LOG_CHANNEL,
|
346 |
-
get_string("can_4").format(f"[{name}](tg://user?id={id})", uname),
|
347 |
-
)
|
348 |
-
|
349 |
-
old_[id] = uname
|
350 |
-
udB.set_key("USERNAME_DB", old_)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/_help.py
DELETED
@@ -1,136 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from telethon.errors.rpcerrorlist import (
|
9 |
-
BotInlineDisabledError,
|
10 |
-
BotMethodInvalidError,
|
11 |
-
BotResponseTimeoutError,
|
12 |
-
)
|
13 |
-
from telethon.tl.custom import Button
|
14 |
-
|
15 |
-
from pyUltroid.dB._core import HELP, LIST
|
16 |
-
from pyUltroid.fns.tools import cmd_regex_replace
|
17 |
-
|
18 |
-
from . import HNDLR, LOGS, OWNER_NAME, asst, get_string, inline_pic, udB, ultroid_cmd
|
19 |
-
|
20 |
-
_main_help_menu = [
|
21 |
-
[
|
22 |
-
Button.inline(get_string("help_4"), data="uh_Official_"),
|
23 |
-
Button.inline(get_string("help_5"), data="uh_Addons_"),
|
24 |
-
],
|
25 |
-
[
|
26 |
-
Button.inline(get_string("help_6"), data="uh_VCBot_"),
|
27 |
-
Button.inline(get_string("help_7"), data="inlone"),
|
28 |
-
],
|
29 |
-
[
|
30 |
-
Button.inline(get_string("help_8"), data="ownr"),
|
31 |
-
Button.url(
|
32 |
-
get_string("help_9"), url=f"https://t.me/{asst.me.username}?start=set"
|
33 |
-
),
|
34 |
-
],
|
35 |
-
[Button.inline(get_string("help_10"), data="close")],
|
36 |
-
]
|
37 |
-
|
38 |
-
|
39 |
-
@ultroid_cmd(pattern="help( (.*)|$)")
|
40 |
-
async def _help(ult):
|
41 |
-
plug = ult.pattern_match.group(1).strip()
|
42 |
-
chat = await ult.get_chat()
|
43 |
-
if plug:
|
44 |
-
try:
|
45 |
-
if plug in HELP["Official"]:
|
46 |
-
output = f"**Plugin** - `{plug}`\n"
|
47 |
-
for i in HELP["Official"][plug]:
|
48 |
-
output += i
|
49 |
-
output += "\n© @TeamUltroid"
|
50 |
-
await ult.eor(output)
|
51 |
-
elif HELP.get("Addons") and plug in HELP["Addons"]:
|
52 |
-
output = f"**Plugin** - `{plug}`\n"
|
53 |
-
for i in HELP["Addons"][plug]:
|
54 |
-
output += i
|
55 |
-
output += "\n© @TeamUltroid"
|
56 |
-
await ult.eor(output)
|
57 |
-
elif HELP.get("VCBot") and plug in HELP["VCBot"]:
|
58 |
-
output = f"**Plugin** - `{plug}`\n"
|
59 |
-
for i in HELP["VCBot"][plug]:
|
60 |
-
output += i
|
61 |
-
output += "\n© @TeamUltroid"
|
62 |
-
await ult.eor(output)
|
63 |
-
else:
|
64 |
-
try:
|
65 |
-
x = get_string("help_11").format(plug)
|
66 |
-
for d in LIST[plug]:
|
67 |
-
x += HNDLR + d
|
68 |
-
x += "\n"
|
69 |
-
x += "\n© @TeamUltroid"
|
70 |
-
await ult.eor(x)
|
71 |
-
except BaseException:
|
72 |
-
file = None
|
73 |
-
compare_strings = []
|
74 |
-
for file_name in LIST:
|
75 |
-
compare_strings.append(file_name)
|
76 |
-
value = LIST[file_name]
|
77 |
-
for j in value:
|
78 |
-
j = cmd_regex_replace(j)
|
79 |
-
compare_strings.append(j)
|
80 |
-
if j.strip() == plug:
|
81 |
-
file = file_name
|
82 |
-
break
|
83 |
-
if not file:
|
84 |
-
# the enter command/plugin name is not found
|
85 |
-
text = f"`{plug}` is not a valid plugin!"
|
86 |
-
best_match = None
|
87 |
-
for _ in compare_strings:
|
88 |
-
if plug in _ and not _.startswith("_"):
|
89 |
-
best_match = _
|
90 |
-
break
|
91 |
-
if best_match:
|
92 |
-
text += f"\nDid you mean `{best_match}`?"
|
93 |
-
return await ult.eor(text)
|
94 |
-
output = f"**Command** `{plug}` **found in plugin** - `{file}`\n"
|
95 |
-
if file in HELP["Official"]:
|
96 |
-
for i in HELP["Official"][file]:
|
97 |
-
output += i
|
98 |
-
elif HELP.get("Addons") and file in HELP["Addons"]:
|
99 |
-
for i in HELP["Addons"][file]:
|
100 |
-
output += i
|
101 |
-
elif HELP.get("VCBot") and file in HELP["VCBot"]:
|
102 |
-
for i in HELP["VCBot"][file]:
|
103 |
-
output += i
|
104 |
-
output += "\n© @TeamUltroid"
|
105 |
-
await ult.eor(output)
|
106 |
-
except BaseException as er:
|
107 |
-
LOGS.exception(er)
|
108 |
-
await ult.eor("Error 🤔 occured.")
|
109 |
-
else:
|
110 |
-
try:
|
111 |
-
results = await ult.client.inline_query(asst.me.username, "ultd")
|
112 |
-
except BotMethodInvalidError:
|
113 |
-
z = []
|
114 |
-
for x in LIST.values():
|
115 |
-
z.extend(x)
|
116 |
-
cmd = len(z) + 10
|
117 |
-
if udB.get_key("MANAGER") and udB.get_key("DUAL_HNDLR") == "/":
|
118 |
-
_main_help_menu[2:3] = [[Button.inline("• Manager Help •", "mngbtn")]]
|
119 |
-
return await ult.reply(
|
120 |
-
get_string("inline_4").format(
|
121 |
-
OWNER_NAME,
|
122 |
-
len(HELP["Official"]),
|
123 |
-
len(HELP["Addons"] if "Addons" in HELP else []),
|
124 |
-
cmd,
|
125 |
-
),
|
126 |
-
file=inline_pic(),
|
127 |
-
buttons=_main_help_menu,
|
128 |
-
)
|
129 |
-
except BotResponseTimeoutError:
|
130 |
-
return await ult.eor(
|
131 |
-
get_string("help_2").format(HNDLR),
|
132 |
-
)
|
133 |
-
except BotInlineDisabledError:
|
134 |
-
return await ult.eor(get_string("help_3"))
|
135 |
-
await results[0].click(chat.id, reply_to=ult.reply_to_msg_id, hide_via=True)
|
136 |
-
await ult.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/_inline.py
DELETED
@@ -1,451 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
import re
|
9 |
-
import time
|
10 |
-
from datetime import datetime
|
11 |
-
from os import remove
|
12 |
-
|
13 |
-
from git import Repo
|
14 |
-
from telethon import Button
|
15 |
-
from telethon.tl.types import InputWebDocument, Message
|
16 |
-
from telethon.utils import resolve_bot_file_id
|
17 |
-
|
18 |
-
from pyUltroid._misc._assistant import callback, in_pattern
|
19 |
-
from pyUltroid.dB._core import HELP, LIST
|
20 |
-
from pyUltroid.fns.helper import gen_chlog, time_formatter, updater
|
21 |
-
from pyUltroid.fns.misc import split_list
|
22 |
-
|
23 |
-
from . import (
|
24 |
-
HNDLR,
|
25 |
-
LOGS,
|
26 |
-
OWNER_NAME,
|
27 |
-
InlinePlugin,
|
28 |
-
asst,
|
29 |
-
get_string,
|
30 |
-
inline_pic,
|
31 |
-
split_list,
|
32 |
-
start_time,
|
33 |
-
udB,
|
34 |
-
)
|
35 |
-
from ._help import _main_help_menu
|
36 |
-
|
37 |
-
# ================================================#
|
38 |
-
|
39 |
-
helps = get_string("inline_1")
|
40 |
-
|
41 |
-
add_ons = udB.get_key("ADDONS")
|
42 |
-
|
43 |
-
zhelps = get_string("inline_3") if add_ons is False else get_string("inline_2")
|
44 |
-
PLUGINS = HELP.get("Official", [])
|
45 |
-
ADDONS = HELP.get("Addons", [])
|
46 |
-
upage = 0
|
47 |
-
# ============================================#
|
48 |
-
|
49 |
-
# --------------------BUTTONS--------------------#
|
50 |
-
|
51 |
-
SUP_BUTTONS = [
|
52 |
-
[
|
53 |
-
Button.url("• Repo •", url="https://github.com/TeamUltroid/Ultroid"),
|
54 |
-
Button.url("• Support •", url="t.me/UltroidSupportChat"),
|
55 |
-
],
|
56 |
-
]
|
57 |
-
|
58 |
-
# --------------------BUTTONS--------------------#
|
59 |
-
|
60 |
-
|
61 |
-
@in_pattern(owner=True, func=lambda x: not x.text)
|
62 |
-
async def inline_alive(o):
|
63 |
-
TLINK = inline_pic() or "https://graph.org/file/74d6259983e0642923fdb.jpg"
|
64 |
-
MSG = "• **Ultroid Userbot •**"
|
65 |
-
WEB0 = InputWebDocument(
|
66 |
-
"https://graph.org/file/acd4f5d61369f74c5e7a7.jpg", 0, "image/jpg", []
|
67 |
-
)
|
68 |
-
RES = [
|
69 |
-
await o.builder.article(
|
70 |
-
type="photo",
|
71 |
-
text=MSG,
|
72 |
-
include_media=True,
|
73 |
-
buttons=SUP_BUTTONS,
|
74 |
-
title="Ultroid Userbot",
|
75 |
-
description="Userbot | Telethon",
|
76 |
-
url=TLINK,
|
77 |
-
thumb=WEB0,
|
78 |
-
content=InputWebDocument(TLINK, 0, "image/jpg", []),
|
79 |
-
)
|
80 |
-
]
|
81 |
-
await o.answer(
|
82 |
-
RES,
|
83 |
-
private=True,
|
84 |
-
cache_time=300,
|
85 |
-
switch_pm="👥 ULTROID PORTAL",
|
86 |
-
switch_pm_param="start",
|
87 |
-
)
|
88 |
-
|
89 |
-
|
90 |
-
@in_pattern("ultd", owner=True)
|
91 |
-
async def inline_handler(event):
|
92 |
-
z = []
|
93 |
-
for x in LIST.values():
|
94 |
-
z.extend(x)
|
95 |
-
text = get_string("inline_4").format(
|
96 |
-
OWNER_NAME,
|
97 |
-
len(HELP.get("Official", [])),
|
98 |
-
len(HELP.get("Addons", [])),
|
99 |
-
len(z),
|
100 |
-
)
|
101 |
-
if inline_pic():
|
102 |
-
result = await event.builder.photo(
|
103 |
-
file=inline_pic(),
|
104 |
-
link_preview=False,
|
105 |
-
text=text,
|
106 |
-
buttons=_main_help_menu,
|
107 |
-
)
|
108 |
-
else:
|
109 |
-
result = await event.builder.article(
|
110 |
-
title="Ultroid Help Menu", text=text, buttons=_main_help_menu
|
111 |
-
)
|
112 |
-
await event.answer([result], private=True, cache_time=300, gallery=True)
|
113 |
-
|
114 |
-
|
115 |
-
@in_pattern("pasta", owner=True)
|
116 |
-
async def _(event):
|
117 |
-
ok = event.text.split("-")[1]
|
118 |
-
link = f"https://spaceb.in/{ok}"
|
119 |
-
raw = f"https://spaceb.in/api/{ok}/raw"
|
120 |
-
result = await event.builder.article(
|
121 |
-
title="Paste",
|
122 |
-
text="Pasted to Spacebin 🌌",
|
123 |
-
buttons=[
|
124 |
-
[
|
125 |
-
Button.url("SpaceBin", url=link),
|
126 |
-
Button.url("Raw", url=raw),
|
127 |
-
],
|
128 |
-
],
|
129 |
-
)
|
130 |
-
await event.answer([result])
|
131 |
-
|
132 |
-
|
133 |
-
@callback("ownr", owner=True)
|
134 |
-
async def setting(event):
|
135 |
-
z = []
|
136 |
-
for x in LIST.values():
|
137 |
-
z.extend(x)
|
138 |
-
await event.edit(
|
139 |
-
get_string("inline_4").format(
|
140 |
-
OWNER_NAME,
|
141 |
-
len(HELP.get("Official", [])),
|
142 |
-
len(HELP.get("Addons", [])),
|
143 |
-
len(z),
|
144 |
-
),
|
145 |
-
file=inline_pic(),
|
146 |
-
link_preview=False,
|
147 |
-
buttons=[
|
148 |
-
[
|
149 |
-
Button.inline("•Pɪɴɢ•", data="pkng"),
|
150 |
-
Button.inline("•Uᴘᴛɪᴍᴇ•", data="upp"),
|
151 |
-
],
|
152 |
-
[
|
153 |
-
Button.inline("•Stats•", data="alive"),
|
154 |
-
Button.inline("•Uᴘᴅᴀᴛᴇ•", data="doupdate"),
|
155 |
-
],
|
156 |
-
[Button.inline("« Bᴀᴄᴋ", data="open")],
|
157 |
-
],
|
158 |
-
)
|
159 |
-
|
160 |
-
|
161 |
-
_strings = {"Official": helps, "Addons": zhelps, "VCBot": get_string("inline_6")}
|
162 |
-
|
163 |
-
|
164 |
-
@callback(re.compile("uh_(.*)"), owner=True)
|
165 |
-
async def help_func(ult):
|
166 |
-
key, count = ult.data_match.group(1).decode("utf-8").split("_")
|
167 |
-
if key == "VCBot" and HELP.get("VCBot") is None:
|
168 |
-
return await ult.answer(get_string("help_12"), alert=True)
|
169 |
-
elif key == "Addons" and HELP.get("Addons") is None:
|
170 |
-
return await ult.answer(get_string("help_13").format(HNDLR), alert=True)
|
171 |
-
if "|" in count:
|
172 |
-
_, count = count.split("|")
|
173 |
-
count = int(count) if count else 0
|
174 |
-
text = _strings.get(key, "").format(OWNER_NAME, len(HELP.get(key)))
|
175 |
-
await ult.edit(text, buttons=page_num(count, key), link_preview=False)
|
176 |
-
|
177 |
-
|
178 |
-
@callback(re.compile("uplugin_(.*)"), owner=True)
|
179 |
-
async def uptd_plugin(event):
|
180 |
-
key, file = event.data_match.group(1).decode("utf-8").split("_")
|
181 |
-
index = None
|
182 |
-
if "|" in file:
|
183 |
-
file, index = file.split("|")
|
184 |
-
key_ = HELP.get(key, [])
|
185 |
-
hel_p = f"Plugin Name - `{file}`\n"
|
186 |
-
help_ = ""
|
187 |
-
try:
|
188 |
-
for i in key_[file]:
|
189 |
-
help_ += i
|
190 |
-
except BaseException:
|
191 |
-
if file in LIST:
|
192 |
-
help_ = get_string("help_11").format(file)
|
193 |
-
for d in LIST[file]:
|
194 |
-
help_ += HNDLR + d
|
195 |
-
help_ += "\n"
|
196 |
-
if not help_:
|
197 |
-
help_ = f"{file} has no Detailed Help!"
|
198 |
-
help_ += "\n© @TeamUltroid"
|
199 |
-
buttons = []
|
200 |
-
if inline_pic():
|
201 |
-
data = f"sndplug_{key}_{file}"
|
202 |
-
if index is not None:
|
203 |
-
data += f"|{index}"
|
204 |
-
buttons.append(
|
205 |
-
[
|
206 |
-
Button.inline(
|
207 |
-
"« Sᴇɴᴅ Pʟᴜɢɪɴ »",
|
208 |
-
data=data,
|
209 |
-
)
|
210 |
-
]
|
211 |
-
)
|
212 |
-
data = f"uh_{key}_"
|
213 |
-
if index is not None:
|
214 |
-
data += f"|{index}"
|
215 |
-
buttons.append(
|
216 |
-
[
|
217 |
-
Button.inline("« Bᴀᴄᴋ", data=data),
|
218 |
-
]
|
219 |
-
)
|
220 |
-
try:
|
221 |
-
await event.edit(help_, buttons=buttons)
|
222 |
-
except Exception as er:
|
223 |
-
LOGS.exception(er)
|
224 |
-
help = f"Do `{HNDLR}help {key}` to get list of commands."
|
225 |
-
await event.edit(help, buttons=buttons)
|
226 |
-
|
227 |
-
|
228 |
-
@callback(data="doupdate", owner=True)
|
229 |
-
async def _(event):
|
230 |
-
if not await updater():
|
231 |
-
return await event.answer(get_string("inline_9"), cache_time=0, alert=True)
|
232 |
-
if not inline_pic():
|
233 |
-
return await event.answer(f"Do '{HNDLR}update' to update..")
|
234 |
-
repo = Repo.init()
|
235 |
-
changelog, tl_chnglog = await gen_chlog(
|
236 |
-
repo, f"HEAD..upstream/{repo.active_branch}"
|
237 |
-
)
|
238 |
-
changelog_str = changelog + "\n\n" + get_string("inline_8")
|
239 |
-
if len(changelog_str) > 1024:
|
240 |
-
await event.edit(get_string("upd_4"))
|
241 |
-
with open("ultroid_updates.txt", "w+") as file:
|
242 |
-
file.write(tl_chnglog)
|
243 |
-
await event.edit(
|
244 |
-
get_string("upd_5"),
|
245 |
-
file="ultroid_updates.txt",
|
246 |
-
buttons=[
|
247 |
-
[Button.inline("• Uᴘᴅᴀᴛᴇ Nᴏᴡ •", data="updatenow")],
|
248 |
-
[Button.inline("« Bᴀᴄᴋ", data="ownr")],
|
249 |
-
],
|
250 |
-
)
|
251 |
-
remove("ultroid_updates.txt")
|
252 |
-
else:
|
253 |
-
await event.edit(
|
254 |
-
changelog_str,
|
255 |
-
buttons=[
|
256 |
-
[Button.inline("Update Now", data="updatenow")],
|
257 |
-
[Button.inline("« Bᴀᴄᴋ", data="ownr")],
|
258 |
-
],
|
259 |
-
parse_mode="html",
|
260 |
-
)
|
261 |
-
|
262 |
-
|
263 |
-
@callback(data="pkng", owner=True)
|
264 |
-
async def _(event):
|
265 |
-
start = datetime.now()
|
266 |
-
end = datetime.now()
|
267 |
-
ms = (end - start).microseconds
|
268 |
-
pin = f"🌋Pɪɴɢ = {ms} microseconds"
|
269 |
-
await event.answer(pin, cache_time=0, alert=True)
|
270 |
-
|
271 |
-
|
272 |
-
@callback(data="upp", owner=True)
|
273 |
-
async def _(event):
|
274 |
-
uptime = time_formatter((time.time() - start_time) * 1000)
|
275 |
-
pin = f"🙋Uᴘᴛɪᴍᴇ = {uptime}"
|
276 |
-
await event.answer(pin, cache_time=0, alert=True)
|
277 |
-
|
278 |
-
|
279 |
-
@callback(data="inlone", owner=True)
|
280 |
-
async def _(e):
|
281 |
-
_InButtons = [
|
282 |
-
Button.switch_inline(_, query=InlinePlugin[_], same_peer=True)
|
283 |
-
for _ in list(InlinePlugin.keys())
|
284 |
-
]
|
285 |
-
InButtons = split_list(_InButtons, 2)
|
286 |
-
|
287 |
-
button = InButtons.copy()
|
288 |
-
button.append(
|
289 |
-
[
|
290 |
-
Button.inline("« Bᴀᴄᴋ", data="open"),
|
291 |
-
],
|
292 |
-
)
|
293 |
-
await e.edit(buttons=button, link_preview=False)
|
294 |
-
|
295 |
-
|
296 |
-
@callback(data="open", owner=True)
|
297 |
-
async def opner(event):
|
298 |
-
z = []
|
299 |
-
for x in LIST.values():
|
300 |
-
z.extend(x)
|
301 |
-
await event.edit(
|
302 |
-
get_string("inline_4").format(
|
303 |
-
OWNER_NAME,
|
304 |
-
len(HELP.get("Official", [])),
|
305 |
-
len(HELP.get("Addons", [])),
|
306 |
-
len(z),
|
307 |
-
),
|
308 |
-
buttons=_main_help_menu,
|
309 |
-
link_preview=False,
|
310 |
-
)
|
311 |
-
|
312 |
-
|
313 |
-
@callback(data="close", owner=True)
|
314 |
-
async def on_plug_in_callback_query_handler(event):
|
315 |
-
await event.edit(
|
316 |
-
get_string("inline_5"),
|
317 |
-
buttons=Button.inline("Oᴘᴇɴ Aɢᴀɪɴ", data="open"),
|
318 |
-
)
|
319 |
-
|
320 |
-
|
321 |
-
def page_num(index, key):
|
322 |
-
rows = udB.get_key("HELP_ROWS") or 5
|
323 |
-
cols = udB.get_key("HELP_COLUMNS") or 2
|
324 |
-
loaded = HELP.get(key, [])
|
325 |
-
emoji = udB.get_key("EMOJI_IN_HELP") or "✘"
|
326 |
-
List = [
|
327 |
-
Button.inline(f"{emoji} {x} {emoji}", data=f"uplugin_{key}_{x}|{index}")
|
328 |
-
for x in sorted(loaded)
|
329 |
-
]
|
330 |
-
all_ = split_list(List, cols)
|
331 |
-
fl_ = split_list(all_, rows)
|
332 |
-
try:
|
333 |
-
new_ = fl_[index]
|
334 |
-
except IndexError:
|
335 |
-
new_ = fl_[0] if fl_ else []
|
336 |
-
index = 0
|
337 |
-
if index == 0 and len(fl_) == 1:
|
338 |
-
new_.append([Button.inline("« Bᴀᴄᴋ »", data="open")])
|
339 |
-
else:
|
340 |
-
new_.append(
|
341 |
-
[
|
342 |
-
Button.inline(
|
343 |
-
"« Pʀᴇᴠɪᴏ���s",
|
344 |
-
data=f"uh_{key}_{index-1}",
|
345 |
-
),
|
346 |
-
Button.inline("« Bᴀᴄᴋ »", data="open"),
|
347 |
-
Button.inline(
|
348 |
-
"Nᴇxᴛ »",
|
349 |
-
data=f"uh_{key}_{index+1}",
|
350 |
-
),
|
351 |
-
]
|
352 |
-
)
|
353 |
-
return new_
|
354 |
-
|
355 |
-
|
356 |
-
# --------------------------------------------------------------------------------- #
|
357 |
-
|
358 |
-
|
359 |
-
STUFF = {}
|
360 |
-
|
361 |
-
|
362 |
-
@in_pattern("stf(.*)", owner=True)
|
363 |
-
async def ibuild(e):
|
364 |
-
n = e.pattern_match.group(1).strip()
|
365 |
-
builder = e.builder
|
366 |
-
if not (n and n.isdigit()):
|
367 |
-
return
|
368 |
-
ok = STUFF.get(int(n))
|
369 |
-
txt = ok.get("msg")
|
370 |
-
pic = ok.get("media")
|
371 |
-
btn = ok.get("button")
|
372 |
-
if not (pic or txt):
|
373 |
-
txt = "Hey!"
|
374 |
-
if pic:
|
375 |
-
try:
|
376 |
-
include_media = True
|
377 |
-
mime_type, _pic = None, None
|
378 |
-
cont, results = None, None
|
379 |
-
try:
|
380 |
-
ext = str(pic).split(".")[-1].lower()
|
381 |
-
except BaseException:
|
382 |
-
ext = None
|
383 |
-
if ext in ["img", "jpg", "png"]:
|
384 |
-
_type = "photo"
|
385 |
-
mime_type = "image/jpg"
|
386 |
-
elif ext in ["mp4", "mkv", "gif"]:
|
387 |
-
mime_type = "video/mp4"
|
388 |
-
_type = "gif"
|
389 |
-
else:
|
390 |
-
try:
|
391 |
-
if "telethon.tl.types" in str(type(pic)):
|
392 |
-
_pic = pic
|
393 |
-
else:
|
394 |
-
_pic = resolve_bot_file_id(pic)
|
395 |
-
except BaseException:
|
396 |
-
pass
|
397 |
-
if _pic:
|
398 |
-
results = [
|
399 |
-
await builder.document(
|
400 |
-
_pic,
|
401 |
-
title="Ultroid Op",
|
402 |
-
text=txt,
|
403 |
-
description="@TeamUltroid",
|
404 |
-
buttons=btn,
|
405 |
-
link_preview=False,
|
406 |
-
)
|
407 |
-
]
|
408 |
-
else:
|
409 |
-
_type = "article"
|
410 |
-
include_media = False
|
411 |
-
if not results:
|
412 |
-
if include_media:
|
413 |
-
cont = InputWebDocument(pic, 0, mime_type, [])
|
414 |
-
results = [
|
415 |
-
await builder.article(
|
416 |
-
title="Ultroid Op",
|
417 |
-
type=_type,
|
418 |
-
text=txt,
|
419 |
-
description="@TeamUltroid",
|
420 |
-
include_media=include_media,
|
421 |
-
buttons=btn,
|
422 |
-
thumb=cont,
|
423 |
-
content=cont,
|
424 |
-
link_preview=False,
|
425 |
-
)
|
426 |
-
]
|
427 |
-
return await e.answer(results)
|
428 |
-
except Exception as er:
|
429 |
-
LOGS.exception(er)
|
430 |
-
result = [
|
431 |
-
await builder.article("Ultroid Op", text=txt, link_preview=False, buttons=btn)
|
432 |
-
]
|
433 |
-
await e.answer(result)
|
434 |
-
|
435 |
-
|
436 |
-
async def something(e, msg, media, button, reply=True, chat=None):
|
437 |
-
if e.client._bot:
|
438 |
-
return await e.reply(msg, file=media, buttons=button)
|
439 |
-
num = len(STUFF) + 1
|
440 |
-
STUFF.update({num: {"msg": msg, "media": media, "button": button}})
|
441 |
-
try:
|
442 |
-
res = await e.client.inline_query(asst.me.username, f"stf{num}")
|
443 |
-
return await res[0].click(
|
444 |
-
chat or e.chat_id,
|
445 |
-
reply_to=bool(isinstance(e, Message) and reply),
|
446 |
-
hide_via=True,
|
447 |
-
silent=True,
|
448 |
-
)
|
449 |
-
|
450 |
-
except Exception as er:
|
451 |
-
LOGS.exception(er)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/_ultroid.py
DELETED
@@ -1,66 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from telethon.errors import (
|
9 |
-
BotMethodInvalidError,
|
10 |
-
ChatSendInlineForbiddenError,
|
11 |
-
ChatSendMediaForbiddenError,
|
12 |
-
)
|
13 |
-
|
14 |
-
from . import LOG_CHANNEL, LOGS, Button, asst, eor, get_string, ultroid_cmd
|
15 |
-
|
16 |
-
REPOMSG = """
|
17 |
-
• **ULTROID USERBOT** •\n
|
18 |
-
• Repo - [Click Here](https://github.com/TeamUltroid/Ultroid)
|
19 |
-
• Addons - [Click Here](https://github.com/TeamUltroid/UltroidAddons)
|
20 |
-
• Support - @UltroidSupportChat
|
21 |
-
"""
|
22 |
-
|
23 |
-
RP_BUTTONS = [
|
24 |
-
[
|
25 |
-
Button.url(get_string("bot_3"), "https://github.com/TeamUltroid/Ultroid"),
|
26 |
-
Button.url("Addons", "https://github.com/TeamUltroid/UltroidAddons"),
|
27 |
-
],
|
28 |
-
[Button.url("Support Group", "t.me/UltroidSupportChat")],
|
29 |
-
]
|
30 |
-
|
31 |
-
ULTSTRING = """🎇 **Thanks for Deploying Ultroid Userbot!**
|
32 |
-
|
33 |
-
• Here, are the Some Basic stuff from, where you can Know, about its Usage."""
|
34 |
-
|
35 |
-
|
36 |
-
@ultroid_cmd(
|
37 |
-
pattern="repo$",
|
38 |
-
manager=True,
|
39 |
-
)
|
40 |
-
async def repify(e):
|
41 |
-
try:
|
42 |
-
q = await e.client.inline_query(asst.me.username, "")
|
43 |
-
await q[0].click(e.chat_id)
|
44 |
-
return await e.delete()
|
45 |
-
except (
|
46 |
-
ChatSendInlineForbiddenError,
|
47 |
-
ChatSendMediaForbiddenError,
|
48 |
-
BotMethodInvalidError,
|
49 |
-
):
|
50 |
-
pass
|
51 |
-
except Exception as er:
|
52 |
-
LOGS.info(f"Error while repo command : {str(er)}")
|
53 |
-
await e.eor(REPOMSG)
|
54 |
-
|
55 |
-
|
56 |
-
@ultroid_cmd(pattern="ultroid$")
|
57 |
-
async def useUltroid(rs):
|
58 |
-
button = Button.inline("Start >>", "initft_2")
|
59 |
-
msg = await asst.send_message(
|
60 |
-
LOG_CHANNEL,
|
61 |
-
ULTSTRING,
|
62 |
-
file="https://graph.org/file/54a917cc9dbb94733ea5f.jpg",
|
63 |
-
buttons=button,
|
64 |
-
)
|
65 |
-
if not (rs.chat_id == LOG_CHANNEL and rs.client._bot):
|
66 |
-
await eor(rs, f"**[Click Here]({msg.message_link})**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/_userlogs.py
DELETED
@@ -1,297 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
import os
|
9 |
-
import re
|
10 |
-
|
11 |
-
from telethon.errors.rpcerrorlist import (
|
12 |
-
ChannelPrivateError,
|
13 |
-
ChatWriteForbiddenError,
|
14 |
-
MediaCaptionTooLongError,
|
15 |
-
MediaEmptyError,
|
16 |
-
MessageTooLongError,
|
17 |
-
PeerIdInvalidError,
|
18 |
-
UserNotParticipantError,
|
19 |
-
)
|
20 |
-
from telethon.tl.types import MessageEntityMention, MessageEntityMentionName, User
|
21 |
-
from telethon.utils import get_display_name
|
22 |
-
|
23 |
-
from pyUltroid.dB.botchat_db import tag_add, who_tag
|
24 |
-
|
25 |
-
from . import (
|
26 |
-
LOG_CHANNEL,
|
27 |
-
LOGS,
|
28 |
-
Button,
|
29 |
-
asst,
|
30 |
-
callback,
|
31 |
-
events,
|
32 |
-
get_string,
|
33 |
-
inline_mention,
|
34 |
-
udB,
|
35 |
-
ultroid_bot,
|
36 |
-
)
|
37 |
-
|
38 |
-
CACHE_SPAM = {}
|
39 |
-
TAG_EDITS = {}
|
40 |
-
|
41 |
-
|
42 |
-
@ultroid_bot.on(
|
43 |
-
events.NewMessage(
|
44 |
-
incoming=True,
|
45 |
-
func=lambda e: (e.mentioned),
|
46 |
-
),
|
47 |
-
)
|
48 |
-
async def all_messages_catcher(e):
|
49 |
-
x = await e.get_sender()
|
50 |
-
if isinstance(x, User) and (x.bot or x.verified):
|
51 |
-
return
|
52 |
-
if not udB.get_key("TAG_LOG"):
|
53 |
-
return
|
54 |
-
NEEDTOLOG = udB.get_key("TAG_LOG")
|
55 |
-
buttons = await parse_buttons(e)
|
56 |
-
try:
|
57 |
-
sent = await asst.send_message(NEEDTOLOG, e.message, buttons=buttons)
|
58 |
-
if TAG_EDITS.get(e.chat_id):
|
59 |
-
TAG_EDITS[e.chat_id].update({e.id: {"id": sent.id, "msg": e}})
|
60 |
-
else:
|
61 |
-
TAG_EDITS.update({e.chat_id: {e.id: {"id": sent.id, "msg": e}}})
|
62 |
-
tag_add(sent.id, e.chat_id, e.id)
|
63 |
-
except MediaEmptyError as er:
|
64 |
-
LOGS.debug(f"handling {er}.")
|
65 |
-
try:
|
66 |
-
msg = await asst.get_messages(e.chat_id, ids=e.id)
|
67 |
-
sent = await asst.send_message(NEEDTOLOG, msg, buttons=buttons)
|
68 |
-
if TAG_EDITS.get(e.chat_id):
|
69 |
-
TAG_EDITS[e.chat_id].update({e.id: {"id": sent.id, "msg": e}})
|
70 |
-
else:
|
71 |
-
TAG_EDITS.update({e.chat_id: {e.id: {"id": sent.id, "msg": e}}})
|
72 |
-
tag_add(sent.id, e.chat_id, e.id)
|
73 |
-
except Exception as me:
|
74 |
-
if not isinstance(me, (PeerIdInvalidError, ValueError)):
|
75 |
-
LOGS.exception(me)
|
76 |
-
if e.photo or e.sticker or e.gif:
|
77 |
-
try:
|
78 |
-
media = await e.download_media()
|
79 |
-
sent = await asst.send_message(
|
80 |
-
NEEDTOLOG, e.message.text, file=media, buttons=buttons
|
81 |
-
)
|
82 |
-
if TAG_EDITS.get(e.chat_id):
|
83 |
-
TAG_EDITS[e.chat_id].update({e.id: {"id": sent.id, "msg": e}})
|
84 |
-
else:
|
85 |
-
TAG_EDITS.update({e.chat_id: {e.id: {"id": sent.id, "msg": e}}})
|
86 |
-
return os.remove(media)
|
87 |
-
except Exception as er:
|
88 |
-
LOGS.exception(er)
|
89 |
-
await asst.send_message(NEEDTOLOG, get_string("com_4"), buttons=buttons)
|
90 |
-
except (PeerIdInvalidError, ValueError) as er:
|
91 |
-
LOGS.exception(er)
|
92 |
-
try:
|
93 |
-
CACHE_SPAM[NEEDTOLOG]
|
94 |
-
except KeyError:
|
95 |
-
await asst.send_message(
|
96 |
-
udB.get_key("LOG_CHANNEL"), get_string("userlogs_1")
|
97 |
-
)
|
98 |
-
CACHE_SPAM.update({NEEDTOLOG: True})
|
99 |
-
except ChatWriteForbiddenError:
|
100 |
-
try:
|
101 |
-
await asst.get_permissions(NEEDTOLOG, "me")
|
102 |
-
MSG = get_string("userlogs_4")
|
103 |
-
except UserNotParticipantError:
|
104 |
-
MSG = get_string("userlogs_2")
|
105 |
-
try:
|
106 |
-
CACHE_SPAM[NEEDTOLOG]
|
107 |
-
except KeyError:
|
108 |
-
await asst.send_message(LOG_CHANNEL, MSG)
|
109 |
-
CACHE_SPAM.update({NEEDTOLOG: True})
|
110 |
-
except Exception as er:
|
111 |
-
LOGS.exception(er)
|
112 |
-
|
113 |
-
|
114 |
-
if udB.get_key("TAG_LOG"):
|
115 |
-
|
116 |
-
@ultroid_bot.on(events.MessageEdited(func=lambda x: not x.out))
|
117 |
-
async def upd_edits(event):
|
118 |
-
x = event.sender
|
119 |
-
if isinstance(x, User) and (x.bot or x.verified):
|
120 |
-
return
|
121 |
-
if event.chat_id not in TAG_EDITS:
|
122 |
-
if event.sender_id == udB.get_key("TAG_LOG"):
|
123 |
-
return
|
124 |
-
if event.is_private:
|
125 |
-
return
|
126 |
-
if entities := event.get_entities_text():
|
127 |
-
is_self = False
|
128 |
-
username = event.client.me.username
|
129 |
-
if username:
|
130 |
-
username = username.lower()
|
131 |
-
for ent, text in entities:
|
132 |
-
if isinstance(ent, MessageEntityMention):
|
133 |
-
is_self = text[1:].lower() == username
|
134 |
-
elif isinstance(ent, MessageEntityMentionName):
|
135 |
-
is_self = ent.user_id == event.client.me.id
|
136 |
-
if is_self:
|
137 |
-
text = f"**#Edited & #Mentioned**\n\n{event.text}"
|
138 |
-
try:
|
139 |
-
sent = await asst.send_message(
|
140 |
-
udB.get_key("TAG_LOG"),
|
141 |
-
text,
|
142 |
-
buttons=await parse_buttons(event),
|
143 |
-
)
|
144 |
-
except Exception as er:
|
145 |
-
return LOGS.exception(er)
|
146 |
-
if TAG_EDITS.get(event.chat_id):
|
147 |
-
TAG_EDITS[event.chat_id].update({event.id: {"id": sent.id}})
|
148 |
-
else:
|
149 |
-
TAG_EDITS.update({event.chat_id: {event.id: {"id": sent.id}}})
|
150 |
-
return
|
151 |
-
d_ = TAG_EDITS[event.chat_id]
|
152 |
-
if not d_.get(event.id):
|
153 |
-
return
|
154 |
-
d_ = d_[event.id]
|
155 |
-
if d_["msg"].text == event.text:
|
156 |
-
return
|
157 |
-
msg = None
|
158 |
-
if d_.get("count"):
|
159 |
-
d_["count"] += 1
|
160 |
-
else:
|
161 |
-
msg = True
|
162 |
-
d_.update({"count": 1})
|
163 |
-
if d_["count"] > 10:
|
164 |
-
return # some limit to take edits
|
165 |
-
try:
|
166 |
-
MSG = await asst.get_messages(udB.get_key("TAG_LOG"), ids=d_["id"])
|
167 |
-
except Exception as er:
|
168 |
-
return LOGS.exception(er)
|
169 |
-
TEXT = MSG.text
|
170 |
-
if msg:
|
171 |
-
TEXT += "\n\n🖋 **Later Edited to !**"
|
172 |
-
strf = event.edit_date.strftime("%H:%M:%S")
|
173 |
-
if "\n" not in event.text:
|
174 |
-
TEXT += f"\n• `{strf}` : {event.text}"
|
175 |
-
else:
|
176 |
-
TEXT += f"\n• `{strf}` :\n-> {event.text}"
|
177 |
-
if d_["count"] == 10:
|
178 |
-
TEXT += "\n\n• __Only the first 10 Edits are shown.__"
|
179 |
-
try:
|
180 |
-
msg = await MSG.edit(TEXT, buttons=await parse_buttons(event))
|
181 |
-
d_["msg"] = msg
|
182 |
-
except (MessageTooLongError, MediaCaptionTooLongError):
|
183 |
-
del TAG_EDITS[event.chat_id][event.id]
|
184 |
-
except Exception as er:
|
185 |
-
LOGS.exception(er)
|
186 |
-
|
187 |
-
@ultroid_bot.on(
|
188 |
-
events.NewMessage(
|
189 |
-
outgoing=True,
|
190 |
-
chats=[udB.get_key("TAG_LOG")],
|
191 |
-
func=lambda e: e.reply_to,
|
192 |
-
)
|
193 |
-
)
|
194 |
-
async def idk(e):
|
195 |
-
id = e.reply_to_msg_id
|
196 |
-
chat, msg = who_tag(id)
|
197 |
-
if chat and msg:
|
198 |
-
try:
|
199 |
-
await ultroid_bot.send_message(chat, e.message, reply_to=msg)
|
200 |
-
except BaseException as er:
|
201 |
-
LOGS.exception(er)
|
202 |
-
|
203 |
-
|
204 |
-
# log for assistant/user joins/add
|
205 |
-
|
206 |
-
|
207 |
-
async def when_added_or_joined(event):
|
208 |
-
user = await event.get_user()
|
209 |
-
chat = await event.get_chat()
|
210 |
-
if not (user and user.is_self):
|
211 |
-
return
|
212 |
-
if getattr(chat, "username", None):
|
213 |
-
chat = f"[{chat.title}](https://t.me/{chat.username}/{event.action_message.id})"
|
214 |
-
else:
|
215 |
-
chat = f"[{chat.title}](https://t.me/c/{chat.id}/{event.action_message.id})"
|
216 |
-
key = "bot" if event.client._bot else "user"
|
217 |
-
buttons = Button.inline(
|
218 |
-
get_string("userlogs_3"), data=f"leave_ch_{event.chat_id}|{key}"
|
219 |
-
)
|
220 |
-
if event.user_added:
|
221 |
-
tmp = event.added_by
|
222 |
-
text = f"#ADD_LOG\n\n{inline_mention(tmp)} just added {inline_mention(user)} to {chat}."
|
223 |
-
elif event.from_request:
|
224 |
-
text = f"#APPROVAL_LOG\n\n{inline_mention(user)} just got Chat Join Approval to {chat}."
|
225 |
-
else:
|
226 |
-
text = f"#JOIN_LOG\n\n{inline_mention(user)} just joined {chat}."
|
227 |
-
await asst.send_message(udB.get_key("LOG_CHANNEL"), text, buttons=buttons)
|
228 |
-
|
229 |
-
|
230 |
-
asst.add_event_handler(
|
231 |
-
when_added_or_joined, events.ChatAction(func=lambda x: x.user_added)
|
232 |
-
)
|
233 |
-
ultroid_bot.add_event_handler(
|
234 |
-
when_added_or_joined,
|
235 |
-
events.ChatAction(func=lambda x: x.user_added or x.user_joined),
|
236 |
-
)
|
237 |
-
_client = {"bot": asst, "user": ultroid_bot}
|
238 |
-
|
239 |
-
|
240 |
-
@callback(
|
241 |
-
re.compile(
|
242 |
-
"leave_ch_(.*)",
|
243 |
-
),
|
244 |
-
from_users=[ultroid_bot.uid],
|
245 |
-
)
|
246 |
-
async def leave_ch_at(event):
|
247 |
-
cht = event.data_match.group(1).decode("UTF-8")
|
248 |
-
ch_id, client = cht.split("|")
|
249 |
-
try:
|
250 |
-
client = _client[client]
|
251 |
-
except KeyError:
|
252 |
-
return
|
253 |
-
try:
|
254 |
-
name = (await client.get_entity(int(ch_id))).title
|
255 |
-
await client.delete_dialog(int(ch_id))
|
256 |
-
except UserNotParticipantError:
|
257 |
-
pass
|
258 |
-
except ChannelPrivateError:
|
259 |
-
return await event.edit(
|
260 |
-
"`[CANT_ACCESS_CHAT]` `Maybe already left or got banned.`"
|
261 |
-
)
|
262 |
-
except Exception as er:
|
263 |
-
LOGS.exception(er)
|
264 |
-
return await event.answer(str(er))
|
265 |
-
await event.edit(get_string("userlogs_5").format(name))
|
266 |
-
|
267 |
-
|
268 |
-
@callback("do_nothing")
|
269 |
-
async def _(event):
|
270 |
-
await event.answer()
|
271 |
-
|
272 |
-
|
273 |
-
async def parse_buttons(event):
|
274 |
-
y, x = event.chat, event.sender
|
275 |
-
where_n, who_n = get_display_name(y), get_display_name(x)
|
276 |
-
where_l = event.message_link
|
277 |
-
buttons = [[Button.url(where_n, where_l)]]
|
278 |
-
if isinstance(x, User) and x.username:
|
279 |
-
try:
|
280 |
-
buttons.append(
|
281 |
-
[Button.mention(who_n, await asst.get_input_entity(x.username))]
|
282 |
-
)
|
283 |
-
except Exception as er:
|
284 |
-
LOGS.exception(er)
|
285 |
-
buttons.append([Button.url(who_n, f"t.me/{x.username}")])
|
286 |
-
elif getattr(x, "username"):
|
287 |
-
buttons.append([Button.url(who_n, f"t.me/{x.username}")])
|
288 |
-
else:
|
289 |
-
buttons.append([Button.url(who_n, where_l)])
|
290 |
-
replied = await event.get_reply_message()
|
291 |
-
if replied and replied.out:
|
292 |
-
button = Button.url("Replied to", replied.message_link)
|
293 |
-
if len(who_n) > 7:
|
294 |
-
buttons.append([button])
|
295 |
-
else:
|
296 |
-
buttons[-1].append(button)
|
297 |
-
return buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/_wspr.py
DELETED
@@ -1,204 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
import re
|
9 |
-
|
10 |
-
from telethon import Button
|
11 |
-
from telethon.errors.rpcerrorlist import (
|
12 |
-
BotInlineDisabledError,
|
13 |
-
BotResponseTimeoutError,
|
14 |
-
MessageNotModifiedError,
|
15 |
-
)
|
16 |
-
from telethon.tl import types
|
17 |
-
from telethon.tl.functions.users import GetFullUserRequest as gu
|
18 |
-
|
19 |
-
from . import (
|
20 |
-
HNDLR,
|
21 |
-
LOGS,
|
22 |
-
asst,
|
23 |
-
callback,
|
24 |
-
get_string,
|
25 |
-
in_pattern,
|
26 |
-
inline_mention,
|
27 |
-
ultroid_bot,
|
28 |
-
ultroid_cmd,
|
29 |
-
)
|
30 |
-
|
31 |
-
buddhhu = {}
|
32 |
-
|
33 |
-
|
34 |
-
@ultroid_cmd(
|
35 |
-
pattern="wspr( (.*)|$)",
|
36 |
-
)
|
37 |
-
async def _(e):
|
38 |
-
if e.reply_to_msg_id:
|
39 |
-
okk = await e.get_reply_message()
|
40 |
-
put = f"@{okk.sender.username}" if okk.sender.username else okk.sender_id
|
41 |
-
else:
|
42 |
-
put = e.pattern_match.group(1).strip()
|
43 |
-
if put:
|
44 |
-
try:
|
45 |
-
results = await e.client.inline_query(asst.me.username, f"msg {put}")
|
46 |
-
except BotResponseTimeoutError:
|
47 |
-
return await e.eor(
|
48 |
-
get_string("help_2").format(HNDLR),
|
49 |
-
)
|
50 |
-
except BotInlineDisabledError:
|
51 |
-
return await e.eor(get_string("help_3"))
|
52 |
-
await results[0].click(e.chat_id, reply_to=e.reply_to_msg_id, hide_via=True)
|
53 |
-
return await e.delete()
|
54 |
-
await e.eor(get_string("wspr_3"))
|
55 |
-
|
56 |
-
|
57 |
-
@in_pattern("wspr", owner=True)
|
58 |
-
async def _(e):
|
59 |
-
iuser = e.query.user_id
|
60 |
-
zzz = e.text.split(maxsplit=2)
|
61 |
-
try:
|
62 |
-
query = zzz[1]
|
63 |
-
if query.isdigit():
|
64 |
-
query = int(query)
|
65 |
-
logi = await ultroid_bot.get_entity(query)
|
66 |
-
if not isinstance(logi, types.User):
|
67 |
-
raise ValueError("Invalid Username.")
|
68 |
-
except IndexError:
|
69 |
-
sur = await e.builder.article(
|
70 |
-
title="Give Username",
|
71 |
-
description="You Didn't Type Username or id.",
|
72 |
-
text="You Didn't Type Username or id.",
|
73 |
-
)
|
74 |
-
return await e.answer([sur])
|
75 |
-
except ValueError as er:
|
76 |
-
LOGS.exception(er)
|
77 |
-
sur = await e.builder.article(
|
78 |
-
title="User Not Found",
|
79 |
-
description="Make sure username or id is correct.",
|
80 |
-
text="Make sure username or id is correct.",
|
81 |
-
)
|
82 |
-
return await e.answer([sur])
|
83 |
-
try:
|
84 |
-
desc = zzz[2]
|
85 |
-
except IndexError:
|
86 |
-
sur = await e.builder.article(
|
87 |
-
title="Type ur msg", text="You Didn't Type Your Msg"
|
88 |
-
)
|
89 |
-
return await e.answer([sur])
|
90 |
-
button = [
|
91 |
-
[
|
92 |
-
Button.inline("Secret Msg", data=f"dd_{e.id}"),
|
93 |
-
Button.inline("Delete Msg", data=f"del_{e.id}"),
|
94 |
-
],
|
95 |
-
[
|
96 |
-
Button.switch_inline(
|
97 |
-
"New", query=f"wspr {logi.username or logi.id}", same_peer=True
|
98 |
-
)
|
99 |
-
],
|
100 |
-
]
|
101 |
-
us = logi.username or logi.first_name
|
102 |
-
sur = await e.builder.article(
|
103 |
-
title=logi.first_name,
|
104 |
-
description=desc,
|
105 |
-
text=get_string("wspr_1").format(us),
|
106 |
-
buttons=button,
|
107 |
-
)
|
108 |
-
buddhhu.update({e.id: [logi.id, iuser, desc]})
|
109 |
-
await e.answer([sur])
|
110 |
-
|
111 |
-
|
112 |
-
@in_pattern("msg", owner=True)
|
113 |
-
async def _(e):
|
114 |
-
zzz = e.text.split(maxsplit=1)
|
115 |
-
desc = "Touch me"
|
116 |
-
try:
|
117 |
-
query = zzz[1]
|
118 |
-
if query.isdigit():
|
119 |
-
query = int(query)
|
120 |
-
logi = await ultroid_bot(gu(id=query))
|
121 |
-
user = logi.users[0]
|
122 |
-
mention = inline_mention(user)
|
123 |
-
x = user.status
|
124 |
-
if isinstance(x, types.UserStatusOnline):
|
125 |
-
status = "Online"
|
126 |
-
elif isinstance(x, types.UserStatusOffline):
|
127 |
-
status = "Offline"
|
128 |
-
elif isinstance(x, types.UserStatusRecently):
|
129 |
-
status = "Last Seen Recently"
|
130 |
-
elif isinstance(x, types.UserStatusLastMonth):
|
131 |
-
status = "Last seen months ago"
|
132 |
-
elif isinstance(x, types.UserStatusLastWeek):
|
133 |
-
status = "Last seen weeks ago"
|
134 |
-
else:
|
135 |
-
status = "Can't Tell"
|
136 |
-
text = f"**Name:** `{user.first_name}`\n"
|
137 |
-
text += f"**Id:** `{user.id}`\n"
|
138 |
-
if user.username:
|
139 |
-
text += f"**Username:** `{user.username}`\n"
|
140 |
-
url = f"https://t.me/{user.username}"
|
141 |
-
else:
|
142 |
-
text += f"**Mention:** `{mention}`\n"
|
143 |
-
url = f"tg://user?id={user.id}"
|
144 |
-
text += f"**Status:** `{status}`\n"
|
145 |
-
text += f"**About:** `{logi.full_user.about}`"
|
146 |
-
button = [
|
147 |
-
Button.url("Private", url=url),
|
148 |
-
Button.switch_inline(
|
149 |
-
"Secret msg",
|
150 |
-
query=f"wspr {query} Hello 👋",
|
151 |
-
same_peer=True,
|
152 |
-
),
|
153 |
-
]
|
154 |
-
sur = e.builder.article(
|
155 |
-
title=user.first_name,
|
156 |
-
description=desc,
|
157 |
-
text=text,
|
158 |
-
buttons=button,
|
159 |
-
)
|
160 |
-
except IndexError:
|
161 |
-
sur = e.builder.article(
|
162 |
-
title="Give Username",
|
163 |
-
description="You Didn't Type Username or id.",
|
164 |
-
text="You Didn't Type Username or id.",
|
165 |
-
)
|
166 |
-
except BaseException as er:
|
167 |
-
LOGS.exception(er)
|
168 |
-
name = get_string("wspr_4").format(query)
|
169 |
-
sur = e.builder.article(
|
170 |
-
title=name,
|
171 |
-
text=name,
|
172 |
-
)
|
173 |
-
|
174 |
-
await e.answer([sur])
|
175 |
-
|
176 |
-
|
177 |
-
@callback(
|
178 |
-
re.compile(
|
179 |
-
"dd_(.*)",
|
180 |
-
),
|
181 |
-
)
|
182 |
-
async def _(e):
|
183 |
-
ids = int(e.pattern_match.group(1).strip().decode("UTF-8"))
|
184 |
-
if buddhhu.get(ids):
|
185 |
-
if e.sender_id in buddhhu[ids]:
|
186 |
-
await e.answer(buddhhu[ids][-1], alert=True)
|
187 |
-
else:
|
188 |
-
await e.answer("Not For You", alert=True)
|
189 |
-
else:
|
190 |
-
await e.answer(get_string("wspr_2"), alert=True)
|
191 |
-
|
192 |
-
|
193 |
-
@callback(re.compile("del_(.*)"))
|
194 |
-
async def _(e):
|
195 |
-
ids = int(e.pattern_match.group(1).strip().decode("UTF-8"))
|
196 |
-
if buddhhu.get(ids):
|
197 |
-
if e.sender_id in buddhhu[ids]:
|
198 |
-
buddhhu.pop(ids)
|
199 |
-
try:
|
200 |
-
await e.edit(get_string("wspr_2"))
|
201 |
-
except MessageNotModifiedError:
|
202 |
-
pass
|
203 |
-
else:
|
204 |
-
await e.answer(get_string("wspr_5"), alert=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/admintools.py
DELETED
@@ -1,472 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_admintools")
|
11 |
-
|
12 |
-
import asyncio
|
13 |
-
|
14 |
-
from telethon.errors import BadRequestError
|
15 |
-
from telethon.errors.rpcerrorlist import ChatNotModifiedError, UserIdInvalidError
|
16 |
-
from telethon.tl.functions.channels import EditAdminRequest, GetFullChannelRequest
|
17 |
-
from telethon.tl.functions.messages import GetFullChatRequest, SetHistoryTTLRequest
|
18 |
-
from telethon.tl.types import InputMessagesFilterPinned
|
19 |
-
from telethon.utils import get_display_name
|
20 |
-
|
21 |
-
from pyUltroid.dB import DEVLIST
|
22 |
-
from pyUltroid.fns.admins import ban_time
|
23 |
-
from pyUltroid.fns.info import get_uinfo
|
24 |
-
|
25 |
-
from . import HNDLR, LOGS, eod, eor, get_string, inline_mention, types, ultroid_cmd
|
26 |
-
|
27 |
-
|
28 |
-
@ultroid_cmd(
|
29 |
-
pattern="promote( (.*)|$)",
|
30 |
-
admins_only=True,
|
31 |
-
manager=True,
|
32 |
-
require="add_admins",
|
33 |
-
fullsudo=True,
|
34 |
-
)
|
35 |
-
async def prmte(ult):
|
36 |
-
xx = await ult.eor(get_string("com_1"))
|
37 |
-
user, rank = await get_uinfo(ult)
|
38 |
-
rank = rank or "Admin"
|
39 |
-
FullRight = False
|
40 |
-
if not user:
|
41 |
-
return await xx.edit(get_string("pro_1"))
|
42 |
-
if rank.split()[0] == "-f":
|
43 |
-
try:
|
44 |
-
rank = rank.split(maxsplit=1)[1]
|
45 |
-
except IndexError:
|
46 |
-
rank = "Admin"
|
47 |
-
FullRight = True
|
48 |
-
try:
|
49 |
-
if FullRight:
|
50 |
-
await ult.client(
|
51 |
-
EditAdminRequest(ult.chat_id, user.id, ult.chat.admin_rights, rank)
|
52 |
-
)
|
53 |
-
else:
|
54 |
-
await ult.client.edit_admin(
|
55 |
-
ult.chat_id,
|
56 |
-
user.id,
|
57 |
-
invite_users=True,
|
58 |
-
ban_users=True,
|
59 |
-
delete_messages=True,
|
60 |
-
pin_messages=True,
|
61 |
-
manage_call=True,
|
62 |
-
title=rank,
|
63 |
-
)
|
64 |
-
await eod(
|
65 |
-
xx, get_string("pro_2").format(inline_mention(user), ult.chat.title, rank)
|
66 |
-
)
|
67 |
-
except Exception as ex:
|
68 |
-
return await xx.edit(f"`{ex}`")
|
69 |
-
|
70 |
-
|
71 |
-
@ultroid_cmd(
|
72 |
-
pattern="demote( (.*)|$)",
|
73 |
-
admins_only=True,
|
74 |
-
manager=True,
|
75 |
-
require="add_admins",
|
76 |
-
fullsudo=True,
|
77 |
-
)
|
78 |
-
async def dmote(ult):
|
79 |
-
xx = await ult.eor(get_string("com_1"))
|
80 |
-
user, rank = await get_uinfo(ult)
|
81 |
-
if not rank:
|
82 |
-
rank = "Not Admin"
|
83 |
-
if not user:
|
84 |
-
return await xx.edit(get_string("de_1"))
|
85 |
-
try:
|
86 |
-
await ult.client.edit_admin(
|
87 |
-
ult.chat_id,
|
88 |
-
user.id,
|
89 |
-
invite_users=None,
|
90 |
-
ban_users=None,
|
91 |
-
delete_messages=None,
|
92 |
-
pin_messages=None,
|
93 |
-
manage_call=None,
|
94 |
-
title=rank,
|
95 |
-
)
|
96 |
-
await eod(xx, get_string("de_2").format(inline_mention(user), ult.chat.title))
|
97 |
-
except Exception as ex:
|
98 |
-
return await xx.edit(f"`{ex}`")
|
99 |
-
|
100 |
-
|
101 |
-
@ultroid_cmd(
|
102 |
-
pattern="ban( (.*)|$)",
|
103 |
-
admins_only=True,
|
104 |
-
manager=True,
|
105 |
-
require="ban_users",
|
106 |
-
fullsudo=True,
|
107 |
-
)
|
108 |
-
async def bban(ult):
|
109 |
-
something = await get_uinfo(ult)
|
110 |
-
if not something:
|
111 |
-
return
|
112 |
-
user, reason = something
|
113 |
-
if not user:
|
114 |
-
return await eod(ult, get_string("ban_1"))
|
115 |
-
if user.id in DEVLIST:
|
116 |
-
return await eod(ult, get_string("ban_2"))
|
117 |
-
try:
|
118 |
-
await ult.client.edit_permissions(ult.chat_id, user.id, view_messages=False)
|
119 |
-
except UserIdInvalidError:
|
120 |
-
return await eod(ult, get_string("adm_1"))
|
121 |
-
except BadRequestError:
|
122 |
-
return await eod(ult, get_string("ban_3"))
|
123 |
-
senderme = inline_mention(await ult.get_sender())
|
124 |
-
userme = inline_mention(user)
|
125 |
-
text = get_string("ban_4").format(userme, senderme, ult.chat.title)
|
126 |
-
if reason:
|
127 |
-
text += get_string("ban_5").format(reason)
|
128 |
-
await eod(ult, text)
|
129 |
-
|
130 |
-
|
131 |
-
@ultroid_cmd(
|
132 |
-
pattern="unban( (.*)|$)",
|
133 |
-
admins_only=True,
|
134 |
-
manager=True,
|
135 |
-
require="ban_users",
|
136 |
-
fullsudo=True,
|
137 |
-
)
|
138 |
-
async def uunban(ult):
|
139 |
-
xx = await ult.eor(get_string("com_1"))
|
140 |
-
if ult.text[1:].startswith("unbanall"):
|
141 |
-
return
|
142 |
-
something = await get_uinfo(ult)
|
143 |
-
if not something:
|
144 |
-
return
|
145 |
-
user, reason = something
|
146 |
-
if not user:
|
147 |
-
return await xx.edit(get_string("unban_1"))
|
148 |
-
try:
|
149 |
-
await ult.client.edit_permissions(ult.chat_id, user.id, view_messages=True)
|
150 |
-
except UserIdInvalidError:
|
151 |
-
return await eod(ult, get_string("adm_1"))
|
152 |
-
except BadRequestError:
|
153 |
-
return await xx.edit(get_string("adm_2"))
|
154 |
-
sender = inline_mention(await ult.get_sender())
|
155 |
-
text = get_string("unban_3").format(inline_mention(user), sender, ult.chat.title)
|
156 |
-
if reason:
|
157 |
-
text += get_string("ban_5").format(reason)
|
158 |
-
await xx.edit(text)
|
159 |
-
|
160 |
-
|
161 |
-
@ultroid_cmd(
|
162 |
-
pattern="kick( (.*)|$)",
|
163 |
-
manager=True,
|
164 |
-
require="ban_users",
|
165 |
-
fullsudo=True,
|
166 |
-
)
|
167 |
-
async def kck(ult):
|
168 |
-
if "kickme" in ult.text:
|
169 |
-
return
|
170 |
-
if ult.is_private:
|
171 |
-
return await ult.eor("`Use this in Group/Channel.`", time=5)
|
172 |
-
ml = ult.text.split(" ", maxsplit=1)[0]
|
173 |
-
xx = await ult.eor(get_string("com_1"))
|
174 |
-
something = await get_uinfo(ult)
|
175 |
-
if not something:
|
176 |
-
return
|
177 |
-
user, reason = something
|
178 |
-
if not user:
|
179 |
-
return await xx.edit(get_string("adm_1"))
|
180 |
-
if user.id in DEVLIST:
|
181 |
-
return await xx.edit(get_string("kick_2"))
|
182 |
-
if getattr(user, "is_self", False):
|
183 |
-
return await xx.edit(get_string("kick_3"))
|
184 |
-
try:
|
185 |
-
await ult.client.kick_participant(ult.chat_id, user.id)
|
186 |
-
except BadRequestError as er:
|
187 |
-
LOGS.info(er)
|
188 |
-
return await xx.edit(get_string("kick_1"))
|
189 |
-
except Exception as e:
|
190 |
-
LOGS.exception(e)
|
191 |
-
return
|
192 |
-
text = get_string("kick_4").format(
|
193 |
-
inline_mention(user), inline_mention(await ult.get_sender()), ult.chat.title
|
194 |
-
)
|
195 |
-
if reason:
|
196 |
-
text += get_string("ban_5").format(reason)
|
197 |
-
await xx.edit(text)
|
198 |
-
|
199 |
-
|
200 |
-
@ultroid_cmd(
|
201 |
-
pattern="tban( (.*)|$)",
|
202 |
-
admins_only=True,
|
203 |
-
manager=True,
|
204 |
-
require="ban_users",
|
205 |
-
fullsudo=True,
|
206 |
-
)
|
207 |
-
async def tkicki(e):
|
208 |
-
huh = e.text.split()
|
209 |
-
inputt = None
|
210 |
-
try:
|
211 |
-
tme = huh[1]
|
212 |
-
except IndexError:
|
213 |
-
return await e.eor(get_string("adm_3"), time=15)
|
214 |
-
try:
|
215 |
-
inputt = huh[2]
|
216 |
-
except IndexError:
|
217 |
-
if e.reply_to_msg_id:
|
218 |
-
inputt = (await e.get_reply_message()).sender_id
|
219 |
-
if not inputt:
|
220 |
-
return await e.eor(get_string("tban_1"))
|
221 |
-
userid = await e.client.parse_id(inputt)
|
222 |
-
try:
|
223 |
-
user = await e.client.get_entity(userid)
|
224 |
-
except Exception as ex:
|
225 |
-
return await eor(e, f"`{ex}`")
|
226 |
-
try:
|
227 |
-
bun = ban_time(tme)
|
228 |
-
await e.client.edit_permissions(
|
229 |
-
e.chat_id, user.id, until_date=bun, view_messages=False
|
230 |
-
)
|
231 |
-
await eod(
|
232 |
-
e,
|
233 |
-
get_string("tban_2").format(inline_mention(user), e.chat.title, tme),
|
234 |
-
time=15,
|
235 |
-
)
|
236 |
-
except Exception as m:
|
237 |
-
return await e.eor(str(m))
|
238 |
-
|
239 |
-
|
240 |
-
@ultroid_cmd(pattern="pin$", manager=True, require="pin_messages", fullsudo=True)
|
241 |
-
async def pin(msg):
|
242 |
-
if not msg.is_reply:
|
243 |
-
return await eor(msg, get_string("pin_1"))
|
244 |
-
me = await msg.get_reply_message()
|
245 |
-
if me.is_private:
|
246 |
-
text = "`Pinned.`"
|
247 |
-
else:
|
248 |
-
text = f"Pinned [This Message]({me.message_link}) !"
|
249 |
-
try:
|
250 |
-
await msg.client.pin_message(msg.chat_id, me.id, notify=False)
|
251 |
-
except BadRequestError:
|
252 |
-
return await eor(msg, get_string("adm_2"))
|
253 |
-
except Exception as e:
|
254 |
-
return await eor(msg, f"**ERROR:**`{e}`")
|
255 |
-
await eor(msg, text)
|
256 |
-
|
257 |
-
|
258 |
-
@ultroid_cmd(
|
259 |
-
pattern="unpin($| (.*))",
|
260 |
-
manager=True,
|
261 |
-
require="pin_messages",
|
262 |
-
fullsudo=True,
|
263 |
-
)
|
264 |
-
async def unp(ult):
|
265 |
-
xx = await ult.eor(get_string("com_1"))
|
266 |
-
ch = (ult.pattern_match.group(1).strip()).strip()
|
267 |
-
msg = None
|
268 |
-
if ult.is_reply:
|
269 |
-
msg = ult.reply_to_msg_id
|
270 |
-
elif ch != "all":
|
271 |
-
return await xx.edit(get_string("unpin_1").format(HNDLR))
|
272 |
-
try:
|
273 |
-
await ult.client.unpin_message(ult.chat_id, msg)
|
274 |
-
except BadRequestError:
|
275 |
-
return await xx.edit(get_string("adm_2"))
|
276 |
-
except Exception as e:
|
277 |
-
return await xx.edit(f"**ERROR:**`{e}`")
|
278 |
-
await xx.edit("`Unpinned!`")
|
279 |
-
|
280 |
-
|
281 |
-
@ultroid_cmd(
|
282 |
-
pattern="tpin( (.*)|$)",
|
283 |
-
admins_only=True,
|
284 |
-
manager=True,
|
285 |
-
require="pin_messages",
|
286 |
-
fullsudo=True,
|
287 |
-
)
|
288 |
-
async def pin_message(ult):
|
289 |
-
match = ult.pattern_match.group(1).strip()
|
290 |
-
if not ult.is_reply:
|
291 |
-
return await ult.eor("`Reply to message..`", time=6)
|
292 |
-
if not match:
|
293 |
-
return await ult.eor("`Please provide time..`", time=8)
|
294 |
-
msg = await ult.eor(get_string("com_1"))
|
295 |
-
msg_id = ult.reply_to_msg_id
|
296 |
-
try:
|
297 |
-
time = ban_time(match)
|
298 |
-
await ult.client.pin_message(ult.chat_id, msg_id)
|
299 |
-
await msg.eor(f"`pinned for time` `{time}`", time=8)
|
300 |
-
except Exception as er:
|
301 |
-
return await msg.edit(str(er))
|
302 |
-
await asyncio.sleep(time)
|
303 |
-
try:
|
304 |
-
await ult.client.unpin_message(ult.chat_id, msg_id)
|
305 |
-
except Exception as er:
|
306 |
-
LOGS.exception(er)
|
307 |
-
|
308 |
-
|
309 |
-
@ultroid_cmd(pattern="purge( (.*)|$)", manager=True, require="delete_messages")
|
310 |
-
async def fastpurger(purg):
|
311 |
-
match = purg.pattern_match.group(1).strip()
|
312 |
-
try:
|
313 |
-
ABC = purg.text[6]
|
314 |
-
except IndexError:
|
315 |
-
ABC = None
|
316 |
-
if ABC and purg.text[6] in ["m", "a"]:
|
317 |
-
return
|
318 |
-
if not purg._client._bot and (
|
319 |
-
(match)
|
320 |
-
or (purg.is_reply and (purg.is_private or isinstance(purg.chat, types.Chat)))
|
321 |
-
):
|
322 |
-
p = 0
|
323 |
-
async for msg in purg.client.iter_messages(
|
324 |
-
purg.chat_id,
|
325 |
-
limit=int(match) if match else None,
|
326 |
-
min_id=purg.reply_to_msg_id if purg.is_reply else None,
|
327 |
-
):
|
328 |
-
await msg.delete()
|
329 |
-
p += 0
|
330 |
-
return await eor(purg, f"Purged {p} Messages! ", time=5)
|
331 |
-
if not purg.reply_to_msg_id:
|
332 |
-
return await eor(purg, get_string("purge_1"), time=10)
|
333 |
-
try:
|
334 |
-
await purg.client.delete_messages(
|
335 |
-
purg.chat_id, list(range(purg.reply_to_msg_id, purg.id))
|
336 |
-
)
|
337 |
-
|
338 |
-
except Exception as er:
|
339 |
-
LOGS.info(er)
|
340 |
-
await purg.eor("__Fast purge complete!__", time=5)
|
341 |
-
|
342 |
-
|
343 |
-
@ultroid_cmd(
|
344 |
-
pattern="purgeme( (.*)|$)",
|
345 |
-
)
|
346 |
-
async def fastpurgerme(purg):
|
347 |
-
if num := purg.pattern_match.group(1).strip():
|
348 |
-
try:
|
349 |
-
nnt = int(num)
|
350 |
-
except BaseException:
|
351 |
-
await eor(purg, get_string("com_3"), time=5)
|
352 |
-
return
|
353 |
-
mp = 0
|
354 |
-
async for mm in purg.client.iter_messages(
|
355 |
-
purg.chat_id, limit=nnt, from_user="me"
|
356 |
-
):
|
357 |
-
await mm.delete()
|
358 |
-
mp += 1
|
359 |
-
await eor(purg, f"Purged {mp} Messages!", time=5)
|
360 |
-
return
|
361 |
-
elif not purg.reply_to_msg_id:
|
362 |
-
return await eod(
|
363 |
-
purg,
|
364 |
-
"`Reply to a message to purge from or use it like ``purgeme <num>`",
|
365 |
-
time=10,
|
366 |
-
)
|
367 |
-
chat = await purg.get_input_chat()
|
368 |
-
msgs = []
|
369 |
-
async for msg in purg.client.iter_messages(
|
370 |
-
chat,
|
371 |
-
from_user="me",
|
372 |
-
min_id=purg.reply_to_msg_id,
|
373 |
-
):
|
374 |
-
msgs.append(msg)
|
375 |
-
if msgs:
|
376 |
-
await purg.client.delete_messages(chat, msgs)
|
377 |
-
await purg.eor(
|
378 |
-
"__Fast purge complete!__\n**Purged** `" + str(len(msgs)) + "` **messages.**",
|
379 |
-
time=5,
|
380 |
-
)
|
381 |
-
|
382 |
-
|
383 |
-
@ultroid_cmd(
|
384 |
-
pattern="purgeall$",
|
385 |
-
)
|
386 |
-
async def _(e):
|
387 |
-
if not e.is_reply:
|
388 |
-
return await eod(
|
389 |
-
e,
|
390 |
-
get_string("purgeall_1"),
|
391 |
-
)
|
392 |
-
|
393 |
-
msg = await e.get_reply_message()
|
394 |
-
name = msg.sender
|
395 |
-
try:
|
396 |
-
await e.client.delete_messages(e.chat_id, from_user=msg.sender_id)
|
397 |
-
await e.eor(get_string("purgeall_2").format(name.first_name), time=5)
|
398 |
-
except Exception as er:
|
399 |
-
return await e.eor(str(er), time=5)
|
400 |
-
|
401 |
-
|
402 |
-
@ultroid_cmd(pattern="pinned", manager=True, groups_only=True)
|
403 |
-
async def djshsh(event):
|
404 |
-
chat = await event.get_chat()
|
405 |
-
if isinstance(chat, types.Chat):
|
406 |
-
FChat = await event.client(GetFullChatRequest(chat.id))
|
407 |
-
elif isinstance(chat, types.Channel):
|
408 |
-
FChat = await event.client(GetFullChannelRequest(chat.id))
|
409 |
-
else:
|
410 |
-
return
|
411 |
-
msg_id = FChat.full_chat.pinned_msg_id
|
412 |
-
if not msg_id:
|
413 |
-
return await event.eor(get_string("pinned_1"))
|
414 |
-
msg = await event.client.get_messages(chat.id, ids=msg_id)
|
415 |
-
if msg:
|
416 |
-
await event.eor(get_string("pinned_2").format(msg.message_link))
|
417 |
-
|
418 |
-
|
419 |
-
@ultroid_cmd(
|
420 |
-
pattern="listpinned$",
|
421 |
-
)
|
422 |
-
async def get_all_pinned(event):
|
423 |
-
x = await event.eor(get_string("com_1"))
|
424 |
-
chat_id = (str(event.chat_id)).replace("-100", "")
|
425 |
-
chat_name = get_display_name(event.chat)
|
426 |
-
a = ""
|
427 |
-
c = 1
|
428 |
-
async for i in event.client.iter_messages(
|
429 |
-
event.chat_id, filter=InputMessagesFilterPinned
|
430 |
-
):
|
431 |
-
if i.message:
|
432 |
-
t = " ".join(i.message.split()[:4])
|
433 |
-
txt = f"{t}...."
|
434 |
-
else:
|
435 |
-
txt = "Go to message."
|
436 |
-
a += f"{c}. <a href=https://t.me/c/{chat_id}/{i.id}>{txt}</a>\n"
|
437 |
-
c += 1
|
438 |
-
|
439 |
-
if c == 1:
|
440 |
-
m = f"<b>The pinned message in {chat_name}:</b>\n\n"
|
441 |
-
else:
|
442 |
-
m = f"<b>List of pinned message(s) in {chat_name}:</b>\n\n"
|
443 |
-
|
444 |
-
if not a:
|
445 |
-
return await eor(x, get_string("listpin_1"), time=5)
|
446 |
-
|
447 |
-
await x.edit(m + a, parse_mode="html")
|
448 |
-
|
449 |
-
|
450 |
-
@ultroid_cmd(
|
451 |
-
pattern="autodelete( (.*)|$)",
|
452 |
-
admins_only=True,
|
453 |
-
)
|
454 |
-
async def autodelte(ult):
|
455 |
-
match = ult.pattern_match.group(1).strip()
|
456 |
-
if not match or match not in ["24h", "7d", "1m", "off"]:
|
457 |
-
return await ult.eor("`Please Use in Proper Format..`", time=5)
|
458 |
-
if match == "24h":
|
459 |
-
tt = 3600 * 24
|
460 |
-
elif match == "7d":
|
461 |
-
tt = 3600 * 24 * 7
|
462 |
-
elif match == "1m":
|
463 |
-
tt = 3600 * 24 * 31
|
464 |
-
else:
|
465 |
-
tt = 0
|
466 |
-
try:
|
467 |
-
await ult.client(SetHistoryTTLRequest(ult.chat_id, period=tt))
|
468 |
-
except ChatNotModifiedError:
|
469 |
-
return await ult.eor(
|
470 |
-
f"Auto Delete Setting is Already same to `{match}`", time=5
|
471 |
-
)
|
472 |
-
await ult.eor(f"Auto Delete Status Changed to `{match}` !")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/afk.py
DELETED
@@ -1,166 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_afk")
|
11 |
-
|
12 |
-
|
13 |
-
import asyncio
|
14 |
-
|
15 |
-
from telegraph import upload_file as uf
|
16 |
-
from telethon import events
|
17 |
-
|
18 |
-
from pyUltroid.dB.afk_db import add_afk, del_afk, is_afk
|
19 |
-
from pyUltroid.dB.base import KeyManager
|
20 |
-
|
21 |
-
from . import (
|
22 |
-
LOG_CHANNEL,
|
23 |
-
NOSPAM_CHAT,
|
24 |
-
Redis,
|
25 |
-
asst,
|
26 |
-
get_string,
|
27 |
-
mediainfo,
|
28 |
-
udB,
|
29 |
-
ultroid_bot,
|
30 |
-
ultroid_cmd,
|
31 |
-
)
|
32 |
-
|
33 |
-
old_afk_msg = []
|
34 |
-
|
35 |
-
is_approved = KeyManager("PMPERMIT", cast=list).contains
|
36 |
-
|
37 |
-
|
38 |
-
@ultroid_cmd(pattern="afk( (.*)|$)", owner_only=True)
|
39 |
-
async def set_afk(event):
|
40 |
-
if event.client._bot or is_afk():
|
41 |
-
return
|
42 |
-
text, media, media_type = None, None, None
|
43 |
-
if event.pattern_match.group(1).strip():
|
44 |
-
text = event.text.split(maxsplit=1)[1]
|
45 |
-
reply = await event.get_reply_message()
|
46 |
-
if reply:
|
47 |
-
if reply.text and not text:
|
48 |
-
text = reply.text
|
49 |
-
if reply.media:
|
50 |
-
media_type = mediainfo(reply.media)
|
51 |
-
if media_type.startswith(("pic", "gif")):
|
52 |
-
file = await event.client.download_media(reply.media)
|
53 |
-
iurl = uf(file)
|
54 |
-
media = f"https://graph.org{iurl[0]}"
|
55 |
-
else:
|
56 |
-
media = reply.file.id
|
57 |
-
await event.eor("`Done`", time=2)
|
58 |
-
add_afk(text, media_type, media)
|
59 |
-
ultroid_bot.add_handler(remove_afk, events.NewMessage(outgoing=True))
|
60 |
-
ultroid_bot.add_handler(
|
61 |
-
on_afk,
|
62 |
-
events.NewMessage(
|
63 |
-
incoming=True, func=lambda e: bool(e.mentioned or e.is_private)
|
64 |
-
),
|
65 |
-
)
|
66 |
-
msg1, msg2 = None, None
|
67 |
-
if text and media:
|
68 |
-
if "sticker" in media_type:
|
69 |
-
msg1 = await ultroid_bot.send_file(event.chat_id, file=media)
|
70 |
-
msg2 = await ultroid_bot.send_message(
|
71 |
-
event.chat_id, get_string("afk_5").format(text)
|
72 |
-
)
|
73 |
-
else:
|
74 |
-
msg1 = await ultroid_bot.send_message(
|
75 |
-
event.chat_id, get_string("afk_5").format(text), file=media
|
76 |
-
)
|
77 |
-
elif media:
|
78 |
-
if "sticker" in media_type:
|
79 |
-
msg1 = await ultroid_bot.send_file(event.chat_id, file=media)
|
80 |
-
msg2 = await ultroid_bot.send_message(event.chat_id, get_string("afk_6"))
|
81 |
-
else:
|
82 |
-
msg1 = await ultroid_bot.send_message(
|
83 |
-
event.chat_id, get_string("afk_6"), file=media
|
84 |
-
)
|
85 |
-
elif text:
|
86 |
-
msg1 = await event.respond(get_string("afk_5").format(text))
|
87 |
-
else:
|
88 |
-
msg1 = await event.respond(get_string("afk_6"))
|
89 |
-
old_afk_msg.append(msg1)
|
90 |
-
if msg2:
|
91 |
-
old_afk_msg.append(msg2)
|
92 |
-
return await asst.send_message(LOG_CHANNEL, msg2.text)
|
93 |
-
await asst.send_message(LOG_CHANNEL, msg1.text)
|
94 |
-
|
95 |
-
|
96 |
-
async def remove_afk(event):
|
97 |
-
if event.is_private and udB.get_key("PMSETTING") and not is_approved(event.chat_id):
|
98 |
-
return
|
99 |
-
elif "afk" in event.text.lower():
|
100 |
-
return
|
101 |
-
elif event.chat_id in NOSPAM_CHAT:
|
102 |
-
return
|
103 |
-
if is_afk():
|
104 |
-
_, _, _, afk_time = is_afk()
|
105 |
-
del_afk()
|
106 |
-
off = await event.reply(get_string("afk_1").format(afk_time))
|
107 |
-
await asst.send_message(LOG_CHANNEL, get_string("afk_2").format(afk_time))
|
108 |
-
for x in old_afk_msg:
|
109 |
-
try:
|
110 |
-
await x.delete()
|
111 |
-
except BaseException:
|
112 |
-
pass
|
113 |
-
await asyncio.sleep(10)
|
114 |
-
await off.delete()
|
115 |
-
|
116 |
-
|
117 |
-
async def on_afk(event):
|
118 |
-
if event.is_private and Redis("PMSETTING") and not is_approved(event.chat_id):
|
119 |
-
return
|
120 |
-
elif "afk" in event.text.lower():
|
121 |
-
return
|
122 |
-
elif not is_afk():
|
123 |
-
return
|
124 |
-
if event.chat_id in NOSPAM_CHAT:
|
125 |
-
return
|
126 |
-
sender = await event.get_sender()
|
127 |
-
if sender.bot or sender.verified:
|
128 |
-
return
|
129 |
-
text, media_type, media, afk_time = is_afk()
|
130 |
-
msg1, msg2 = None, None
|
131 |
-
if text and media:
|
132 |
-
if "sticker" in media_type:
|
133 |
-
msg1 = await event.reply(file=media)
|
134 |
-
msg2 = await event.reply(get_string("afk_3").format(afk_time, text))
|
135 |
-
else:
|
136 |
-
msg1 = await event.reply(
|
137 |
-
get_string("afk_3").format(afk_time, text), file=media
|
138 |
-
)
|
139 |
-
elif media:
|
140 |
-
if "sticker" in media_type:
|
141 |
-
msg1 = await event.reply(file=media)
|
142 |
-
msg2 = await event.reply(get_string("afk_4").format(afk_time))
|
143 |
-
else:
|
144 |
-
msg1 = await event.reply(get_string("afk_4").format(afk_time), file=media)
|
145 |
-
elif text:
|
146 |
-
msg1 = await event.reply(get_string("afk_3").format(afk_time, text))
|
147 |
-
else:
|
148 |
-
msg1 = await event.reply(get_string("afk_4").format(afk_time))
|
149 |
-
for x in old_afk_msg:
|
150 |
-
try:
|
151 |
-
await x.delete()
|
152 |
-
except BaseException:
|
153 |
-
pass
|
154 |
-
old_afk_msg.append(msg1)
|
155 |
-
if msg2:
|
156 |
-
old_afk_msg.append(msg2)
|
157 |
-
|
158 |
-
|
159 |
-
if udB.get_key("AFK_DB"):
|
160 |
-
ultroid_bot.add_handler(remove_afk, events.NewMessage(outgoing=True))
|
161 |
-
ultroid_bot.add_handler(
|
162 |
-
on_afk,
|
163 |
-
events.NewMessage(
|
164 |
-
incoming=True, func=lambda e: bool(e.mentioned or e.is_private)
|
165 |
-
),
|
166 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/afscrp.py
DELETED
@@ -1,95 +0,0 @@
|
|
1 |
-
import logging
|
2 |
-
from bs4 import BeautifulSoup
|
3 |
-
from googleapiclient.discovery import build
|
4 |
-
from . import ultroid_cmd, async_searcher, run_async, LOGS
|
5 |
-
import asyncio
|
6 |
-
from io import BytesIO
|
7 |
-
|
8 |
-
logging.getLogger("googleapiclient.discovery_cache").setLevel(logging.WARNING)
|
9 |
-
|
10 |
-
async def fetch_full_content(url):
|
11 |
-
try:
|
12 |
-
api_url = f"https://scraper.api.airforce/scrape?url={url}"
|
13 |
-
response = await async_searcher(api_url)
|
14 |
-
|
15 |
-
soup = BeautifulSoup(response, "html.parser")
|
16 |
-
main_content = soup.select_one("article") or soup.select_one("main") or soup
|
17 |
-
paragraphs = [
|
18 |
-
para.get_text(separator=" ").strip()
|
19 |
-
for para in main_content.find_all("p")
|
20 |
-
if len(para.get_text(strip=True)) > 30
|
21 |
-
and not any(
|
22 |
-
keyword in para.get_text().lower()
|
23 |
-
for keyword in [
|
24 |
-
"privacy",
|
25 |
-
"cookie",
|
26 |
-
"subscribe",
|
27 |
-
"sign up",
|
28 |
-
"terms",
|
29 |
-
"all rights reserved",
|
30 |
-
"see all",
|
31 |
-
"see more",
|
32 |
-
]
|
33 |
-
)
|
34 |
-
]
|
35 |
-
full_text = (
|
36 |
-
" ".join(paragraphs[:5]) if paragraphs else "No main content available."
|
37 |
-
)
|
38 |
-
return full_text
|
39 |
-
except Exception as e:
|
40 |
-
return f"Error fetching content: {e}"
|
41 |
-
|
42 |
-
async def google_search(query):
|
43 |
-
api_key = " AIzaSyCDOnsWu0cF8W-6jnWceUSHeuSmpC7b2g0 "
|
44 |
-
cse_id = "a44275f02ca2946da"
|
45 |
-
service = build("customsearch", "v1", developerKey=api_key)
|
46 |
-
|
47 |
-
results = service.cse().list(q=query, cx=cse_id, gl="AU").execute()
|
48 |
-
search_items = results.get("items", [])
|
49 |
-
|
50 |
-
search_results = await asyncio.gather(
|
51 |
-
*(fetch_search_result(item) for item in search_items)
|
52 |
-
)
|
53 |
-
|
54 |
-
return search_results
|
55 |
-
|
56 |
-
async def fetch_search_result(item):
|
57 |
-
title = item.get("title")
|
58 |
-
link = item.get("link")
|
59 |
-
snippet = item.get("snippet")
|
60 |
-
full_content = await fetch_full_content(link)
|
61 |
-
return (title, link, snippet, full_content)
|
62 |
-
|
63 |
-
async def display_readable_results(results):
|
64 |
-
readable_res = ""
|
65 |
-
for idx, result in enumerate(results, start=1):
|
66 |
-
title, link, snippet, full_content = result
|
67 |
-
full_content = (
|
68 |
-
full_content if full_content else "No additional content available."
|
69 |
-
)
|
70 |
-
readable_res += f"Result {idx}:\n"
|
71 |
-
readable_res += f"Title: {title}\n"
|
72 |
-
readable_res += f"Link: {link}\n"
|
73 |
-
readable_res += f"Snippet: {snippet}\n"
|
74 |
-
readable_res += f"Full Content: {full_content.strip()}\n"
|
75 |
-
readable_res += "\n" + "=" * 80 + "\n"
|
76 |
-
return readable_res
|
77 |
-
|
78 |
-
@ultroid_cmd(pattern="afscrp(?: (.*)|$)")
|
79 |
-
async def google_search_cmd(event):
|
80 |
-
query = event.pattern_match.group(1)
|
81 |
-
if not query:
|
82 |
-
return await event.eor("Please provide a query to search.")
|
83 |
-
moi = await event.eor("Searching Google...")
|
84 |
-
results = await google_search(query)
|
85 |
-
readable_results = await display_readable_results(results)
|
86 |
-
|
87 |
-
if len(readable_results) < 4095:
|
88 |
-
await moi.edit(readable_results)
|
89 |
-
else:
|
90 |
-
with BytesIO(readable_results.encode()) as file:
|
91 |
-
file.name = "google_search_results.txt"
|
92 |
-
await event.client.send_file(
|
93 |
-
event.chat_id, file, caption=f"Search results for: {query}", reply_to=event.reply_to_msg_id
|
94 |
-
)
|
95 |
-
await moi.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/antiflood.py
DELETED
@@ -1,121 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_antiflood")
|
11 |
-
|
12 |
-
|
13 |
-
import re
|
14 |
-
|
15 |
-
from telethon.events import NewMessage as NewMsg
|
16 |
-
|
17 |
-
from pyUltroid.dB import DEVLIST
|
18 |
-
from pyUltroid.dB.antiflood_db import get_flood, get_flood_limit, rem_flood, set_flood
|
19 |
-
from pyUltroid.fns.admins import admin_check
|
20 |
-
|
21 |
-
from . import Button, Redis, asst, callback, eod, get_string, ultroid_bot, ultroid_cmd
|
22 |
-
|
23 |
-
_check_flood = {}
|
24 |
-
|
25 |
-
if Redis("ANTIFLOOD"):
|
26 |
-
|
27 |
-
@ultroid_bot.on(
|
28 |
-
NewMsg(
|
29 |
-
chats=list(get_flood().keys()),
|
30 |
-
),
|
31 |
-
)
|
32 |
-
async def flood_checm(event):
|
33 |
-
count = 1
|
34 |
-
chat = (await event.get_chat()).title
|
35 |
-
if event.chat_id in _check_flood.keys():
|
36 |
-
if event.sender_id == list(_check_flood[event.chat_id].keys())[0]:
|
37 |
-
count = _check_flood[event.chat_id][event.sender_id]
|
38 |
-
_check_flood[event.chat_id] = {event.sender_id: count + 1}
|
39 |
-
else:
|
40 |
-
_check_flood[event.chat_id] = {event.sender_id: count}
|
41 |
-
else:
|
42 |
-
_check_flood[event.chat_id] = {event.sender_id: count}
|
43 |
-
if await admin_check(event, silent=True) or getattr(event.sender, "bot", None):
|
44 |
-
return
|
45 |
-
if event.sender_id in DEVLIST:
|
46 |
-
return
|
47 |
-
if _check_flood[event.chat_id][event.sender_id] >= int(
|
48 |
-
get_flood_limit(event.chat_id)
|
49 |
-
):
|
50 |
-
try:
|
51 |
-
name = event.sender.first_name
|
52 |
-
await event.client.edit_permissions(
|
53 |
-
event.chat_id, event.sender_id, send_messages=False
|
54 |
-
)
|
55 |
-
del _check_flood[event.chat_id]
|
56 |
-
await event.reply(f"#AntiFlood\n\n{get_string('antiflood_3')}")
|
57 |
-
await asst.send_message(
|
58 |
-
int(Redis("LOG_CHANNEL")),
|
59 |
-
f"#Antiflood\n\n`Muted `[{name}](tg://user?id={event.sender_id})` in {chat}`",
|
60 |
-
buttons=Button.inline(
|
61 |
-
"Unmute", data=f"anti_{event.sender_id}_{event.chat_id}"
|
62 |
-
),
|
63 |
-
)
|
64 |
-
except BaseException:
|
65 |
-
pass
|
66 |
-
|
67 |
-
|
68 |
-
@callback(
|
69 |
-
re.compile(
|
70 |
-
"anti_(.*)",
|
71 |
-
),
|
72 |
-
)
|
73 |
-
async def unmuting(e):
|
74 |
-
ino = (e.data_match.group(1)).decode("UTF-8").split("_")
|
75 |
-
user = int(ino[0])
|
76 |
-
chat = int(ino[1])
|
77 |
-
user_name = (await ultroid_bot.get_entity(user)).first_name
|
78 |
-
chat_title = (await ultroid_bot.get_entity(chat)).title
|
79 |
-
await ultroid_bot.edit_permissions(chat, user, send_messages=True)
|
80 |
-
await e.edit(
|
81 |
-
f"#Antiflood\n\n`Unmuted `[{user_name}](tg://user?id={user})` in {chat_title}`"
|
82 |
-
)
|
83 |
-
|
84 |
-
|
85 |
-
@ultroid_cmd(
|
86 |
-
pattern="setflood ?(\\d+)",
|
87 |
-
admins_only=True,
|
88 |
-
)
|
89 |
-
async def setflood(e):
|
90 |
-
input_ = e.pattern_match.group(1).strip()
|
91 |
-
if not input_:
|
92 |
-
return await e.eor("`What?`", time=5)
|
93 |
-
if not input_.isdigit():
|
94 |
-
return await e.eor(get_string("com_3"), time=5)
|
95 |
-
if m := set_flood(e.chat_id, input_):
|
96 |
-
return await eod(e, get_string("antiflood_4").format(input_))
|
97 |
-
|
98 |
-
|
99 |
-
@ultroid_cmd(
|
100 |
-
pattern="remflood$",
|
101 |
-
admins_only=True,
|
102 |
-
)
|
103 |
-
async def remove_flood(e):
|
104 |
-
hmm = rem_flood(e.chat_id)
|
105 |
-
try:
|
106 |
-
del _check_flood[e.chat_id]
|
107 |
-
except BaseException:
|
108 |
-
pass
|
109 |
-
if hmm:
|
110 |
-
return await e.eor(get_string("antiflood_1"), time=5)
|
111 |
-
await e.eor(get_string("antiflood_2"), time=5)
|
112 |
-
|
113 |
-
|
114 |
-
@ultroid_cmd(
|
115 |
-
pattern="getflood$",
|
116 |
-
admins_only=True,
|
117 |
-
)
|
118 |
-
async def getflood(e):
|
119 |
-
if ok := get_flood_limit(e.chat_id):
|
120 |
-
return await e.eor(get_string("antiflood_5").format(ok), time=5)
|
121 |
-
await e.eor(get_string("antiflood_2"), time=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/asstcmd.py
DELETED
@@ -1,107 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_asstcmd")
|
11 |
-
|
12 |
-
import os
|
13 |
-
|
14 |
-
from pyUltroid.dB.asstcmd_db import add_cmd, cmd_reply, list_cmds, rem_cmd
|
15 |
-
from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
|
16 |
-
|
17 |
-
try:
|
18 |
-
from telegraph import upload_file as uf
|
19 |
-
except ImportError:
|
20 |
-
uf = None
|
21 |
-
from telethon import events, utils
|
22 |
-
|
23 |
-
from . import asst, get_string, mediainfo, udB, ultroid_cmd
|
24 |
-
|
25 |
-
|
26 |
-
@ultroid_cmd(pattern="addcmd( (.*)|$)")
|
27 |
-
async def ac(e):
|
28 |
-
wrd = (e.pattern_match.group(1).strip()).lower()
|
29 |
-
wt = await e.get_reply_message()
|
30 |
-
if not (wt and wrd):
|
31 |
-
return await e.eor(get_string("asstcmd_1"), time=5)
|
32 |
-
if "/" in wrd:
|
33 |
-
wrd = wrd.replace("/", "")
|
34 |
-
btn = format_btn(wt.buttons) if wt.buttons else None
|
35 |
-
if wt and wt.media:
|
36 |
-
wut = mediainfo(wt.media)
|
37 |
-
if wut.startswith(("pic", "gif")):
|
38 |
-
dl = await e.client.download_media(wt.media)
|
39 |
-
variable = uf(dl)
|
40 |
-
os.remove(dl)
|
41 |
-
m = f"https://graph.org{variable[0]}"
|
42 |
-
elif wut == "video":
|
43 |
-
if wt.media.document.size > 8 * 1000 * 1000:
|
44 |
-
return await e.eor(get_string("com_4"), time=5)
|
45 |
-
dl = await e.client.download_media(wt.media)
|
46 |
-
variable = uf(dl)
|
47 |
-
os.remove(dl)
|
48 |
-
m = f"https://graph.org{variable[0]}"
|
49 |
-
else:
|
50 |
-
m = utils.pack_bot_file_id(wt.media)
|
51 |
-
if wt.text:
|
52 |
-
txt = wt.text
|
53 |
-
if not btn:
|
54 |
-
txt, btn = get_msg_button(wt.text)
|
55 |
-
add_cmd(wrd, txt, m, btn)
|
56 |
-
else:
|
57 |
-
add_cmd(wrd, None, m, btn)
|
58 |
-
else:
|
59 |
-
txt = wt.text
|
60 |
-
if not btn:
|
61 |
-
txt, btn = get_msg_button(wt.text)
|
62 |
-
add_cmd(wrd, txt, None, btn)
|
63 |
-
asst.add_handler(
|
64 |
-
astcmds,
|
65 |
-
events.NewMessage(
|
66 |
-
func=lambda x: x.text.startswith("/") and x.text[1:] in list(list_cmds())
|
67 |
-
),
|
68 |
-
)
|
69 |
-
await e.eor(get_string("asstcmd_4").format(wrd))
|
70 |
-
|
71 |
-
|
72 |
-
@ultroid_cmd(pattern="remcmd( (.*)|$)")
|
73 |
-
async def rc(e):
|
74 |
-
wrd = (e.pattern_match.group(1).strip()).lower()
|
75 |
-
if not wrd:
|
76 |
-
return await e.eor(get_string("asstcmd_2"), time=5)
|
77 |
-
wrd = wrd.replace("/", "")
|
78 |
-
rem_cmd(wrd)
|
79 |
-
await e.eor(get_string("asstcmd_3").format(wrd))
|
80 |
-
|
81 |
-
|
82 |
-
@ultroid_cmd(pattern="listcmd$")
|
83 |
-
async def lscmd(e):
|
84 |
-
if list_cmds():
|
85 |
-
ok = get_string("asstcmd_6")
|
86 |
-
for x in list_cmds():
|
87 |
-
ok += f"/{x}" + "\n"
|
88 |
-
return await e.eor(ok)
|
89 |
-
return await e.eor(get_string("asstcmd_5"))
|
90 |
-
|
91 |
-
|
92 |
-
async def astcmds(e):
|
93 |
-
xx = (e.text.replace("/", "")).lower().split()[0]
|
94 |
-
if cmd_reply(xx):
|
95 |
-
msg, media, bt = cmd_reply(xx)
|
96 |
-
if bt:
|
97 |
-
bt = create_tl_btn(bt)
|
98 |
-
await e.reply(msg, file=media, buttons=bt)
|
99 |
-
|
100 |
-
|
101 |
-
if udB.get_key("ASST_CMDS"):
|
102 |
-
asst.add_handler(
|
103 |
-
astcmds,
|
104 |
-
events.NewMessage(
|
105 |
-
func=lambda x: x.text.startswith("/") and x.text[1:] in list(list_cmds())
|
106 |
-
),
|
107 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/audiotools.py
DELETED
@@ -1,160 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
|
9 |
-
import os
|
10 |
-
import time
|
11 |
-
from datetime import datetime as dt
|
12 |
-
|
13 |
-
from pyUltroid.fns.tools import set_attributes
|
14 |
-
|
15 |
-
from . import (
|
16 |
-
LOGS,
|
17 |
-
ULTConfig,
|
18 |
-
bash,
|
19 |
-
downloader,
|
20 |
-
eod,
|
21 |
-
eor,
|
22 |
-
genss,
|
23 |
-
get_help,
|
24 |
-
get_string,
|
25 |
-
humanbytes,
|
26 |
-
mediainfo,
|
27 |
-
stdr,
|
28 |
-
time_formatter,
|
29 |
-
ultroid_cmd,
|
30 |
-
uploader,
|
31 |
-
)
|
32 |
-
|
33 |
-
__doc__ = get_help("help_audiotools")
|
34 |
-
|
35 |
-
|
36 |
-
@ultroid_cmd(pattern="makevoice$")
|
37 |
-
async def vnc(e):
|
38 |
-
if not e.reply_to:
|
39 |
-
return await eod(e, get_string("audiotools_1"))
|
40 |
-
r = await e.get_reply_message()
|
41 |
-
if not mediainfo(r.media).startswith(("audio", "video")):
|
42 |
-
return await eod(e, get_string("spcltool_1"))
|
43 |
-
xxx = await e.eor(get_string("com_1"))
|
44 |
-
file, _ = await e.client.fast_downloader(
|
45 |
-
r.document,
|
46 |
-
)
|
47 |
-
await xxx.edit(get_string("audiotools_2"))
|
48 |
-
await bash(
|
49 |
-
f"ffmpeg -i '{file.name}' -map 0:a -codec:a libopus -b:a 100k -vbr on out.opus"
|
50 |
-
)
|
51 |
-
try:
|
52 |
-
await e.client.send_message(
|
53 |
-
e.chat_id, file="out.opus", force_document=False, reply_to=r
|
54 |
-
)
|
55 |
-
except Exception as er:
|
56 |
-
LOGS.exception(er)
|
57 |
-
return await xxx.edit("`Failed to convert in Voice...`")
|
58 |
-
await xxx.delete()
|
59 |
-
os.remove(file.name)
|
60 |
-
os.remove("out.opus")
|
61 |
-
|
62 |
-
|
63 |
-
@ultroid_cmd(pattern="atrim( (.*)|$)")
|
64 |
-
async def trim_aud(e):
|
65 |
-
sec = e.pattern_match.group(1).strip()
|
66 |
-
if not sec or "-" not in sec:
|
67 |
-
return await eod(e, get_string("audiotools_3"))
|
68 |
-
a, b = sec.split("-")
|
69 |
-
if int(a) >= int(b):
|
70 |
-
return await eod(e, get_string("audiotools_4"))
|
71 |
-
vido = await e.get_reply_message()
|
72 |
-
if vido and vido.media and mediainfo(vido.media).startswith(("video", "audio")):
|
73 |
-
if hasattr(vido.media, "document"):
|
74 |
-
vfile = vido.media.document
|
75 |
-
name = vido.file.name
|
76 |
-
else:
|
77 |
-
vfile = vido.media
|
78 |
-
name = ""
|
79 |
-
if not name:
|
80 |
-
name = dt.now().isoformat("_", "seconds") + ".mp4"
|
81 |
-
xxx = await e.eor(get_string("audiotools_5"))
|
82 |
-
c_time = time.time()
|
83 |
-
file = await downloader(
|
84 |
-
f"resources/downloads/{name}",
|
85 |
-
vfile,
|
86 |
-
xxx,
|
87 |
-
c_time,
|
88 |
-
f"Downloading {name}...",
|
89 |
-
)
|
90 |
-
|
91 |
-
o_size = os.path.getsize(file.name)
|
92 |
-
d_time = time.time()
|
93 |
-
diff = time_formatter((d_time - c_time) * 1000)
|
94 |
-
file_name = (file.name).split("/")[-1]
|
95 |
-
out = file_name.replace(file_name.split(".")[-1], "_trimmed.aac")
|
96 |
-
if int(b) > int(await genss(file.name)):
|
97 |
-
os.remove(file.name)
|
98 |
-
return await eod(xxx, get_string("audiotools_6"))
|
99 |
-
ss, dd = stdr(int(a)), stdr(int(b))
|
100 |
-
xxx = await xxx.edit(
|
101 |
-
f"Downloaded `{file.name}` of `{humanbytes(o_size)}` in `{diff}`.\n\nNow Trimming Audio from `{ss}` to `{dd}`..."
|
102 |
-
)
|
103 |
-
cmd = f'ffmpeg -i "{file.name}" -preset ultrafast -ss {ss} -to {dd} -vn -acodec copy "{out}" -y'
|
104 |
-
await bash(cmd)
|
105 |
-
os.remove(file.name)
|
106 |
-
f_time = time.time()
|
107 |
-
mmmm = await uploader(out, out, f_time, xxx, f"Uploading {out}...")
|
108 |
-
attributes = await set_attributes(out)
|
109 |
-
|
110 |
-
caption = get_string("audiotools_7").format(ss, dd)
|
111 |
-
await e.client.send_file(
|
112 |
-
e.chat_id,
|
113 |
-
mmmm,
|
114 |
-
thumb=ULTConfig.thumb,
|
115 |
-
caption=caption,
|
116 |
-
attributes=attributes,
|
117 |
-
force_document=False,
|
118 |
-
reply_to=e.reply_to_msg_id,
|
119 |
-
)
|
120 |
-
await xxx.delete()
|
121 |
-
else:
|
122 |
-
await e.eor(get_string("audiotools_1"), time=5)
|
123 |
-
|
124 |
-
|
125 |
-
@ultroid_cmd(pattern="extractaudio$")
|
126 |
-
async def ex_aud(e):
|
127 |
-
reply = await e.get_reply_message()
|
128 |
-
if not (reply and reply.media and mediainfo(reply.media).startswith("video")):
|
129 |
-
return await e.eor(get_string("audiotools_8"))
|
130 |
-
name = reply.file.name or "video.mp4"
|
131 |
-
vfile = reply.media.document
|
132 |
-
msg = await e.eor(get_string("com_1"))
|
133 |
-
c_time = time.time()
|
134 |
-
file = await downloader(
|
135 |
-
f"resources/downloads/{name}",
|
136 |
-
vfile,
|
137 |
-
msg,
|
138 |
-
c_time,
|
139 |
-
f"Downloading {name}...",
|
140 |
-
)
|
141 |
-
|
142 |
-
out_file = f"{file.name}.aac"
|
143 |
-
cmd = f"ffmpeg -i {file.name} -vn -acodec copy {out_file}"
|
144 |
-
o, err = await bash(cmd)
|
145 |
-
os.remove(file.name)
|
146 |
-
attributes = await set_attributes(out_file)
|
147 |
-
|
148 |
-
f_time = time.time()
|
149 |
-
try:
|
150 |
-
fo = await uploader(out_file, out_file, f_time, msg, f"Uploading {out_file}...")
|
151 |
-
|
152 |
-
except FileNotFoundError:
|
153 |
-
return await eor(msg, get_string("audiotools_9"))
|
154 |
-
await e.reply(
|
155 |
-
get_string("audiotools_10"),
|
156 |
-
file=fo,
|
157 |
-
thumb=ULTConfig.thumb,
|
158 |
-
attributes=attributes,
|
159 |
-
)
|
160 |
-
await msg.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/autoban.py
DELETED
@@ -1,59 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_autoban")
|
11 |
-
|
12 |
-
from telethon import events
|
13 |
-
|
14 |
-
from pyUltroid.dB.base import KeyManager
|
15 |
-
|
16 |
-
from . import LOGS, asst, ultroid_bot, ultroid_cmd
|
17 |
-
|
18 |
-
Keym = KeyManager("DND_CHATS", cast=list)
|
19 |
-
|
20 |
-
|
21 |
-
def join_func(e):
|
22 |
-
return e.user_joined and Keym.contains(e.chat_id)
|
23 |
-
|
24 |
-
|
25 |
-
async def dnd_func(event):
|
26 |
-
for user in event.users:
|
27 |
-
try:
|
28 |
-
await (await event.client.kick_participant(event.chat_id, user)).delete()
|
29 |
-
except Exception as ex:
|
30 |
-
LOGS.error("Error in DND:")
|
31 |
-
LOGS.exception(ex)
|
32 |
-
await event.delete()
|
33 |
-
|
34 |
-
|
35 |
-
@ultroid_cmd(
|
36 |
-
pattern="autokick (on|off)$",
|
37 |
-
admins_only=True,
|
38 |
-
manager=True,
|
39 |
-
require="ban_users",
|
40 |
-
fullsudo=True,
|
41 |
-
)
|
42 |
-
async def _(event):
|
43 |
-
match = event.pattern_match.group(1)
|
44 |
-
if match == "on":
|
45 |
-
if Keym.contains(event.chat_id):
|
46 |
-
return await event.eor("`Chat already in do not disturb mode.`", time=3)
|
47 |
-
Keym.add(event.chat_id)
|
48 |
-
event.client.add_handler(dnd_func, events.ChatAction(func=join_func))
|
49 |
-
await event.eor("`Do not disturb mode activated for this chat.`", time=3)
|
50 |
-
elif match == "off":
|
51 |
-
if not Keym.contains(event.chat_id):
|
52 |
-
return await event.eor("`Chat is not in do not disturb mode.`", time=3)
|
53 |
-
Keym.remove(event.chat_id)
|
54 |
-
await event.eor("`Do not disturb mode deactivated for this chat.`", time=3)
|
55 |
-
|
56 |
-
|
57 |
-
if Keym.get():
|
58 |
-
ultroid_bot.add_handler(dnd_func, events.ChatAction(func=join_func))
|
59 |
-
asst.add_handler(dnd_func, events.ChatAction(func=join_func))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/autopic.py
DELETED
@@ -1,84 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
|
9 |
-
import asyncio
|
10 |
-
import os
|
11 |
-
import random
|
12 |
-
from random import shuffle
|
13 |
-
|
14 |
-
from telethon.tl.functions.photos import UploadProfilePhotoRequest
|
15 |
-
|
16 |
-
from pyUltroid.fns.helper import download_file
|
17 |
-
from pyUltroid.fns.tools import get_google_images
|
18 |
-
|
19 |
-
from . import LOGS, get_help, get_string, udB, ultroid_bot, ultroid_cmd
|
20 |
-
|
21 |
-
__doc__ = get_help("help_autopic")
|
22 |
-
|
23 |
-
|
24 |
-
@ultroid_cmd(pattern="autopic( (.*)|$)")
|
25 |
-
async def autopic(e):
|
26 |
-
search = e.pattern_match.group(1).strip()
|
27 |
-
if udB.get_key("AUTOPIC") and not search:
|
28 |
-
udB.del_key("AUTOPIC")
|
29 |
-
return await e.eor(get_string("autopic_5"))
|
30 |
-
if not search:
|
31 |
-
return await e.eor(get_string("autopic_1"), time=5)
|
32 |
-
e = await e.eor(get_string("com_1"))
|
33 |
-
gi = googleimagesdownload()
|
34 |
-
args = {
|
35 |
-
"keywords": search,
|
36 |
-
"limit": 50,
|
37 |
-
"format": "jpg",
|
38 |
-
"output_directory": "./resources/downloads/",
|
39 |
-
}
|
40 |
-
try:
|
41 |
-
pth = await gi.download(args)
|
42 |
-
ok = pth[0][search]
|
43 |
-
except Exception as er:
|
44 |
-
LOGS.exception(er)
|
45 |
-
return await e.eor(str(er))
|
46 |
-
if not ok:
|
47 |
-
return await e.eor(get_string("autopic_2").format(search), time=5)
|
48 |
-
await e.eor(get_string("autopic_3").format(search))
|
49 |
-
udB.set_key("AUTOPIC", search)
|
50 |
-
SLEEP_TIME = udB.get_key("SLEEP_TIME") or 1221
|
51 |
-
while True:
|
52 |
-
for lie in ok:
|
53 |
-
if udB.get_key("AUTOPIC") != search:
|
54 |
-
return
|
55 |
-
file = await e.client.upload_file(lie)
|
56 |
-
await e.client(UploadProfilePhotoRequest(file))
|
57 |
-
await asyncio.sleep(SLEEP_TIME)
|
58 |
-
shuffle(ok)
|
59 |
-
|
60 |
-
|
61 |
-
if search := udB.get_key("AUTOPIC"):
|
62 |
-
images = {}
|
63 |
-
sleep = udB.get_key("SLEEP_TIME") or 1221
|
64 |
-
|
65 |
-
async def autopic_func():
|
66 |
-
search = udB.get_key("AUTOPIC")
|
67 |
-
if images.get(search) is None:
|
68 |
-
images[search] = await get_google_images(search)
|
69 |
-
if not images.get(search):
|
70 |
-
return
|
71 |
-
img = random.choice(images[search])
|
72 |
-
filee = await download_file(img["original"], "resources/downloads/autopic.jpg")
|
73 |
-
file = await ultroid_bot.upload_file(filee)
|
74 |
-
await ultroid_bot(UploadProfilePhotoRequest(file))
|
75 |
-
os.remove(filee)
|
76 |
-
|
77 |
-
try:
|
78 |
-
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
79 |
-
|
80 |
-
schedule = AsyncIOScheduler()
|
81 |
-
schedule.add_job(autopic_func, "interval", seconds=sleep)
|
82 |
-
schedule.start()
|
83 |
-
except ModuleNotFoundError as er:
|
84 |
-
LOGS.error(f"autopic: '{er.name}' not installed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/beautify.py
DELETED
@@ -1,210 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_beautify")
|
11 |
-
|
12 |
-
|
13 |
-
import os
|
14 |
-
import random
|
15 |
-
|
16 |
-
from telethon.utils import get_display_name
|
17 |
-
from urllib.parse import urlencode
|
18 |
-
from . import Carbon, ultroid_cmd, get_string, inline_mention, LOGS
|
19 |
-
from secrets import token_hex
|
20 |
-
|
21 |
-
_colorspath = "resources/colorlist.txt"
|
22 |
-
|
23 |
-
if os.path.exists(_colorspath):
|
24 |
-
with open(_colorspath, "r") as f:
|
25 |
-
all_col = f.read().split()
|
26 |
-
else:
|
27 |
-
all_col = []
|
28 |
-
|
29 |
-
|
30 |
-
@ultroid_cmd(
|
31 |
-
pattern="(rc|c)arbon",
|
32 |
-
)
|
33 |
-
async def cr_bn(event):
|
34 |
-
xxxx = await event.eor(get_string("com_1"))
|
35 |
-
te = event.pattern_match.group(1)
|
36 |
-
col = random.choice(all_col) if te[0] == "r" else "White"
|
37 |
-
if event.reply_to_msg_id:
|
38 |
-
temp = await event.get_reply_message()
|
39 |
-
if temp.media:
|
40 |
-
b = await event.client.download_media(temp)
|
41 |
-
with open(b) as a:
|
42 |
-
code = a.read()
|
43 |
-
os.remove(b)
|
44 |
-
else:
|
45 |
-
code = temp.message
|
46 |
-
else:
|
47 |
-
try:
|
48 |
-
code = event.text.split(" ", maxsplit=1)[1]
|
49 |
-
except IndexError:
|
50 |
-
return await xxxx.eor(get_string("carbon_2"))
|
51 |
-
xx = await Carbon(code=code, file_name="ultroid_carbon", backgroundColor=col)
|
52 |
-
if isinstance(xx, dict):
|
53 |
-
await xxxx.edit(f"`{xx}`")
|
54 |
-
return
|
55 |
-
await xxxx.delete()
|
56 |
-
await event.reply(
|
57 |
-
f"Carbonised by {inline_mention(event.sender)}",
|
58 |
-
file=xx,
|
59 |
-
)
|
60 |
-
|
61 |
-
|
62 |
-
@ultroid_cmd(
|
63 |
-
pattern="ccarbon( (.*)|$)",
|
64 |
-
)
|
65 |
-
async def crbn(event):
|
66 |
-
match = event.pattern_match.group(1).strip()
|
67 |
-
if not match:
|
68 |
-
return await event.eor(get_string("carbon_3"))
|
69 |
-
msg = await event.eor(get_string("com_1"))
|
70 |
-
if event.reply_to_msg_id:
|
71 |
-
temp = await event.get_reply_message()
|
72 |
-
if temp.media:
|
73 |
-
b = await event.client.download_media(temp)
|
74 |
-
with open(b) as a:
|
75 |
-
code = a.read()
|
76 |
-
os.remove(b)
|
77 |
-
else:
|
78 |
-
code = temp.message
|
79 |
-
else:
|
80 |
-
try:
|
81 |
-
match = match.split(" ", maxsplit=1)
|
82 |
-
code = match[1]
|
83 |
-
match = match[0]
|
84 |
-
except IndexError:
|
85 |
-
return await msg.eor(get_string("carbon_2"))
|
86 |
-
xx = await Carbon(code=code, backgroundColor=match)
|
87 |
-
await msg.delete()
|
88 |
-
await event.reply(
|
89 |
-
f"Carbonised by {inline_mention(event.sender)}",
|
90 |
-
file=xx,
|
91 |
-
)
|
92 |
-
|
93 |
-
|
94 |
-
RaySoTheme = [
|
95 |
-
"meadow",
|
96 |
-
"breeze",
|
97 |
-
"raindrop",
|
98 |
-
"candy",
|
99 |
-
"crimson",
|
100 |
-
"falcon",
|
101 |
-
"sunset",
|
102 |
-
"noir",
|
103 |
-
"midnight",
|
104 |
-
"bitmap",
|
105 |
-
"ice",
|
106 |
-
"sand",
|
107 |
-
"forest",
|
108 |
-
"mono"
|
109 |
-
]
|
110 |
-
|
111 |
-
|
112 |
-
@ultroid_cmd(pattern="rayso")
|
113 |
-
async def pass_on(ult):
|
114 |
-
try:
|
115 |
-
from playwright.async_api import async_playwright
|
116 |
-
except ImportError:
|
117 |
-
await ult.eor("`playwright` is not installed!\nPlease install it to use this command..")
|
118 |
-
return
|
119 |
-
|
120 |
-
proc = await ult.eor(get_string("com_1"))
|
121 |
-
spli = ult.text.split()
|
122 |
-
theme, dark, title, text = None, True, get_display_name(ult.chat), None
|
123 |
-
|
124 |
-
if len(spli) > 2:
|
125 |
-
if spli[1] in RaySoTheme:
|
126 |
-
theme = spli[1]
|
127 |
-
dark = spli[2].lower().strip() in ["true", "t"]
|
128 |
-
elif len(spli) > 1:
|
129 |
-
if spli[1] in RaySoTheme:
|
130 |
-
theme = spli[1]
|
131 |
-
elif spli[1] == "list":
|
132 |
-
text = "**List of Rayso Themes:**\n" + "\n".join([f"- `{th_}`" for th_ in RaySoTheme])
|
133 |
-
await proc.eor(text)
|
134 |
-
return
|
135 |
-
else:
|
136 |
-
try:
|
137 |
-
text = ult.text.split(maxsplit=1)[1]
|
138 |
-
except IndexError:
|
139 |
-
pass
|
140 |
-
|
141 |
-
if not theme or theme not in RaySoTheme:
|
142 |
-
theme = random.choice(RaySoTheme)
|
143 |
-
|
144 |
-
if ult.is_reply:
|
145 |
-
try:
|
146 |
-
msg = await ult.get_reply_message()
|
147 |
-
text = msg.message
|
148 |
-
title = get_display_name(msg.sender)
|
149 |
-
except Exception as sam:
|
150 |
-
ErrInfo(sam)
|
151 |
-
|
152 |
-
if not text:
|
153 |
-
await proc.eor("No text to beautify!")
|
154 |
-
return
|
155 |
-
|
156 |
-
cleaned_text = "\n".join([line.strip() for line in text.splitlines()])
|
157 |
-
|
158 |
-
name = token_hex(8) + ".png"
|
159 |
-
data = {"darkMode": dark, "theme": theme, "title": title}
|
160 |
-
url = f"https://ray.so/#{urlencode(data)}"
|
161 |
-
|
162 |
-
async with async_playwright() as play:
|
163 |
-
try:
|
164 |
-
# browser = await play.chromium.launch(headless=False) # Set to False for debugging
|
165 |
-
browser = await play.chromium.launch(headless=True, args=["--disable-crash-reporter"])
|
166 |
-
page = await browser.new_page()
|
167 |
-
await page.goto(url, timeout=60000) # Increase timeout
|
168 |
-
await page.wait_for_load_state("networkidle")
|
169 |
-
|
170 |
-
try:
|
171 |
-
await page.wait_for_selector("div[class*='Editor_editor__']", timeout=60000)
|
172 |
-
editor = await page.query_selector("div[class*='Editor_editor__']")
|
173 |
-
await editor.focus()
|
174 |
-
await editor.click()
|
175 |
-
|
176 |
-
for line in cleaned_text.split("\n"):
|
177 |
-
await page.keyboard.type(line)
|
178 |
-
await page.keyboard.press("Enter")
|
179 |
-
|
180 |
-
await page.evaluate("""() => {
|
181 |
-
const button = document.querySelector('button[aria-label="Export as PNG"]');
|
182 |
-
button.click();
|
183 |
-
}""")
|
184 |
-
|
185 |
-
async with page.expect_download() as download_info:
|
186 |
-
download = await download_info.value
|
187 |
-
await download.save_as(name)
|
188 |
-
|
189 |
-
except playwright._impl._errors.TimeoutError:
|
190 |
-
LOGS.info("Timeout error: Selector not found within 60 seconds.")
|
191 |
-
await proc.eor("Failed to find the editor within 60 seconds.")
|
192 |
-
return
|
193 |
-
|
194 |
-
except Exception as e:
|
195 |
-
LOGS.info(f"Error occurred during playwright operation: {e}")
|
196 |
-
await proc.eor("An error occurred during the operation.")
|
197 |
-
return
|
198 |
-
|
199 |
-
finally:
|
200 |
-
if os.path.exists(name):
|
201 |
-
try:
|
202 |
-
await ult.reply(file=name)
|
203 |
-
await proc.try_delete()
|
204 |
-
os.remove(name)
|
205 |
-
except Exception as e:
|
206 |
-
LOGS.info(f"Error occurred while replying with the file: {e}")
|
207 |
-
await proc.eor("Failed to send the file.")
|
208 |
-
else:
|
209 |
-
LOGS.info(f"Error: File {name} not found or inaccessible.")
|
210 |
-
await proc.eor("Failed to save the file.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/blacklist.py
DELETED
@@ -1,69 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_blacklist")
|
11 |
-
|
12 |
-
|
13 |
-
from pyUltroid.dB.blacklist_db import (
|
14 |
-
add_blacklist,
|
15 |
-
get_blacklist,
|
16 |
-
list_blacklist,
|
17 |
-
rem_blacklist,
|
18 |
-
)
|
19 |
-
|
20 |
-
from . import events, get_string, udB, ultroid_bot, ultroid_cmd
|
21 |
-
|
22 |
-
|
23 |
-
@ultroid_cmd(pattern="blacklist( (.*)|$)", admins_only=True)
|
24 |
-
async def af(e):
|
25 |
-
wrd = e.pattern_match.group(1).strip()
|
26 |
-
chat = e.chat_id
|
27 |
-
if not (wrd):
|
28 |
-
return await e.eor(get_string("blk_1"), time=5)
|
29 |
-
wrd = e.text[11:]
|
30 |
-
heh = wrd.split(" ")
|
31 |
-
for z in heh:
|
32 |
-
add_blacklist(int(chat), z.lower())
|
33 |
-
ultroid_bot.add_handler(blacklist, events.NewMessage(incoming=True))
|
34 |
-
await e.eor(get_string("blk_2").format(wrd))
|
35 |
-
|
36 |
-
|
37 |
-
@ultroid_cmd(pattern="remblacklist( (.*)|$)", admins_only=True)
|
38 |
-
async def rf(e):
|
39 |
-
wrd = e.pattern_match.group(1).strip()
|
40 |
-
chat = e.chat_id
|
41 |
-
if not wrd:
|
42 |
-
return await e.eor(get_string("blk_3"), time=5)
|
43 |
-
wrd = e.text[14:]
|
44 |
-
heh = wrd.split(" ")
|
45 |
-
for z in heh:
|
46 |
-
rem_blacklist(int(chat), z.lower())
|
47 |
-
await e.eor(get_string("blk_4").format(wrd))
|
48 |
-
|
49 |
-
|
50 |
-
@ultroid_cmd(pattern="listblacklist$", admins_only=True)
|
51 |
-
async def lsnote(e):
|
52 |
-
if x := list_blacklist(e.chat_id):
|
53 |
-
sd = get_string("blk_5")
|
54 |
-
return await e.eor(sd + x)
|
55 |
-
await e.eor(get_string("blk_6"))
|
56 |
-
|
57 |
-
|
58 |
-
async def blacklist(e):
|
59 |
-
if x := get_blacklist(e.chat_id):
|
60 |
-
text = e.text.lower().split()
|
61 |
-
if any((z in text) for z in x):
|
62 |
-
try:
|
63 |
-
await e.delete()
|
64 |
-
except BaseException:
|
65 |
-
pass
|
66 |
-
|
67 |
-
|
68 |
-
if udB.get_key("BLACKLIST_DB"):
|
69 |
-
ultroid_bot.add_handler(blacklist, events.NewMessage(incoming=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/bot.py
DELETED
@@ -1,358 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_bot")
|
11 |
-
|
12 |
-
import os
|
13 |
-
import sys
|
14 |
-
import time
|
15 |
-
from platform import python_version as pyver
|
16 |
-
from random import choice
|
17 |
-
|
18 |
-
from telethon import __version__
|
19 |
-
from telethon.errors.rpcerrorlist import (
|
20 |
-
BotMethodInvalidError,
|
21 |
-
ChatSendMediaForbiddenError,
|
22 |
-
)
|
23 |
-
|
24 |
-
from pyUltroid.version import __version__ as UltVer
|
25 |
-
|
26 |
-
from . import HOSTED_ON, LOGS
|
27 |
-
|
28 |
-
try:
|
29 |
-
from git import Repo
|
30 |
-
except ImportError:
|
31 |
-
LOGS.error("bot: 'gitpython' module not found!")
|
32 |
-
Repo = None
|
33 |
-
|
34 |
-
from telethon.utils import resolve_bot_file_id
|
35 |
-
|
36 |
-
from . import (
|
37 |
-
ATRA_COL,
|
38 |
-
LOGS,
|
39 |
-
OWNER_NAME,
|
40 |
-
ULTROID_IMAGES,
|
41 |
-
Button,
|
42 |
-
Carbon,
|
43 |
-
Telegraph,
|
44 |
-
Var,
|
45 |
-
allcmds,
|
46 |
-
asst,
|
47 |
-
bash,
|
48 |
-
call_back,
|
49 |
-
callback,
|
50 |
-
def_logs,
|
51 |
-
eor,
|
52 |
-
get_string,
|
53 |
-
heroku_logs,
|
54 |
-
in_pattern,
|
55 |
-
inline_pic,
|
56 |
-
restart,
|
57 |
-
shutdown,
|
58 |
-
start_time,
|
59 |
-
time_formatter,
|
60 |
-
udB,
|
61 |
-
ultroid_cmd,
|
62 |
-
ultroid_version,
|
63 |
-
updater,
|
64 |
-
)
|
65 |
-
|
66 |
-
|
67 |
-
def ULTPIC():
|
68 |
-
return inline_pic() or choice(ULTROID_IMAGES)
|
69 |
-
|
70 |
-
|
71 |
-
buttons = [
|
72 |
-
[
|
73 |
-
Button.url(get_string("bot_3"), "https://github.com/TeamUltroid/Ultroid"),
|
74 |
-
Button.url(get_string("bot_4"), "t.me/UltroidSupportChat"),
|
75 |
-
]
|
76 |
-
]
|
77 |
-
|
78 |
-
# Will move to strings
|
79 |
-
alive_txt = """
|
80 |
-
The Ultroid Userbot
|
81 |
-
|
82 |
-
◍ Version - {}
|
83 |
-
◍ Py-Ultroid - {}
|
84 |
-
◍ Telethon - {}
|
85 |
-
"""
|
86 |
-
|
87 |
-
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 @TeamUltroid</b>"
|
88 |
-
|
89 |
-
|
90 |
-
@callback("alive")
|
91 |
-
async def alive(event):
|
92 |
-
text = alive_txt.format(ultroid_version, UltVer, __version__)
|
93 |
-
await event.answer(text, alert=True)
|
94 |
-
|
95 |
-
|
96 |
-
@ultroid_cmd(
|
97 |
-
pattern="alive( (.*)|$)",
|
98 |
-
)
|
99 |
-
async def lol(ult):
|
100 |
-
match = ult.pattern_match.group(1).strip()
|
101 |
-
inline = None
|
102 |
-
if match in ["inline", "i"]:
|
103 |
-
try:
|
104 |
-
res = await ult.client.inline_query(asst.me.username, "alive")
|
105 |
-
return await res[0].click(ult.chat_id)
|
106 |
-
except BotMethodInvalidError:
|
107 |
-
pass
|
108 |
-
except BaseException as er:
|
109 |
-
LOGS.exception(er)
|
110 |
-
inline = True
|
111 |
-
pic = udB.get_key("ALIVE_PIC")
|
112 |
-
if isinstance(pic, list):
|
113 |
-
pic = choice(pic)
|
114 |
-
uptime = time_formatter((time.time() - start_time) * 1000)
|
115 |
-
header = udB.get_key("ALIVE_TEXT") or get_string("bot_1")
|
116 |
-
# y = Repo().active_branch
|
117 |
-
y = "main"
|
118 |
-
# xx = Repo().remotes[0].config_reader.get("url")
|
119 |
-
xx = "https://github.com/ufoptg/UltroidBackup.git"
|
120 |
-
rep = xx.replace(".git", f"/tree/{y}")
|
121 |
-
kk = f" `[{y}]({rep})` "
|
122 |
-
if inline:
|
123 |
-
kk = f"<a href={rep}>{y}</a>"
|
124 |
-
parse = "html"
|
125 |
-
als = in_alive.format(
|
126 |
-
header,
|
127 |
-
f"{ultroid_version} [{HOSTED_ON}]",
|
128 |
-
UltVer,
|
129 |
-
pyver(),
|
130 |
-
uptime,
|
131 |
-
kk,
|
132 |
-
)
|
133 |
-
|
134 |
-
if _e := udB.get_key("ALIVE_EMOJI"):
|
135 |
-
als = als.replace("🌀", _e)
|
136 |
-
else:
|
137 |
-
parse = "md"
|
138 |
-
als = (get_string("alive_1")).format(
|
139 |
-
header,
|
140 |
-
OWNER_NAME,
|
141 |
-
f"{ultroid_version} [{HOSTED_ON}]",
|
142 |
-
UltVer,
|
143 |
-
uptime,
|
144 |
-
pyver(),
|
145 |
-
__version__,
|
146 |
-
kk,
|
147 |
-
)
|
148 |
-
|
149 |
-
if a := udB.get_key("ALIVE_EMOJI"):
|
150 |
-
als = als.replace("✵", a)
|
151 |
-
if pic:
|
152 |
-
try:
|
153 |
-
await ult.reply(
|
154 |
-
als,
|
155 |
-
file=pic,
|
156 |
-
parse_mode=parse,
|
157 |
-
link_preview=False,
|
158 |
-
buttons=buttons if inline else None,
|
159 |
-
)
|
160 |
-
return await ult.try_delete()
|
161 |
-
except ChatSendMediaForbiddenError:
|
162 |
-
pass
|
163 |
-
except BaseException as er:
|
164 |
-
LOGS.exception(er)
|
165 |
-
try:
|
166 |
-
await ult.reply(file=pic)
|
167 |
-
await ult.reply(
|
168 |
-
als,
|
169 |
-
parse_mode=parse,
|
170 |
-
buttons=buttons if inline else None,
|
171 |
-
link_preview=False,
|
172 |
-
)
|
173 |
-
return await ult.try_delete()
|
174 |
-
except BaseException as er:
|
175 |
-
LOGS.exception(er)
|
176 |
-
await eor(
|
177 |
-
ult,
|
178 |
-
als,
|
179 |
-
parse_mode=parse,
|
180 |
-
link_preview=False,
|
181 |
-
buttons=buttons if inline else None,
|
182 |
-
)
|
183 |
-
|
184 |
-
|
185 |
-
@ultroid_cmd(pattern="ping$", chats=[], type=["official", "assistant"])
|
186 |
-
async def _(event):
|
187 |
-
start = time.time()
|
188 |
-
x = await event.eor("Pong !")
|
189 |
-
end = round((time.time() - start) * 1000)
|
190 |
-
uptime = time_formatter((time.time() - start_time) * 1000)
|
191 |
-
await x.edit(get_string("ping").format(end, uptime))
|
192 |
-
|
193 |
-
|
194 |
-
@ultroid_cmd(
|
195 |
-
pattern="cmds$",
|
196 |
-
)
|
197 |
-
async def cmds(event):
|
198 |
-
await allcmds(event, Telegraph)
|
199 |
-
|
200 |
-
|
201 |
-
heroku_api = Var.HEROKU_API
|
202 |
-
|
203 |
-
|
204 |
-
@ultroid_cmd(
|
205 |
-
pattern="restart$",
|
206 |
-
fullsudo=True,
|
207 |
-
)
|
208 |
-
async def restartbt(ult):
|
209 |
-
ok = await ult.eor(get_string("bot_5"))
|
210 |
-
call_back()
|
211 |
-
who = "bot" if ult.client._bot else "user"
|
212 |
-
udB.set_key("_RESTART", f"{who}_{ult.chat_id}_{ok.id}")
|
213 |
-
if heroku_api:
|
214 |
-
return await restart(ok)
|
215 |
-
await bash("git pull && pip3 install -r requirements.txt")
|
216 |
-
if len(sys.argv) > 1:
|
217 |
-
os.execl(sys.executable, sys.executable, "main.py")
|
218 |
-
else:
|
219 |
-
os.execl(sys.executable, sys.executable, "-m", "pyUltroid")
|
220 |
-
|
221 |
-
|
222 |
-
@ultroid_cmd(
|
223 |
-
pattern="shutdown$",
|
224 |
-
fullsudo=True,
|
225 |
-
)
|
226 |
-
async def shutdownbot(ult):
|
227 |
-
await shutdown(ult)
|
228 |
-
|
229 |
-
|
230 |
-
@ultroid_cmd(
|
231 |
-
pattern="logs( (.*)|$)",
|
232 |
-
chats=[],
|
233 |
-
)
|
234 |
-
async def _(event):
|
235 |
-
opt = event.pattern_match.group(1).strip()
|
236 |
-
file = f"ultroid{sys.argv[-1]}.log" if len(sys.argv) > 1 else "ultroid.log"
|
237 |
-
if opt == "heroku":
|
238 |
-
await heroku_logs(event)
|
239 |
-
elif opt == "carbon" and Carbon:
|
240 |
-
event = await event.eor(get_string("com_1"))
|
241 |
-
with open(file, "r") as f:
|
242 |
-
code = f.read()[-2500:]
|
243 |
-
file = await Carbon(
|
244 |
-
file_name="ultroid-logs",
|
245 |
-
code=code,
|
246 |
-
backgroundColor=choice(ATRA_COL),
|
247 |
-
)
|
248 |
-
if isinstance(file, dict):
|
249 |
-
await event.eor(f"`{file}`")
|
250 |
-
return
|
251 |
-
await event.reply("**Ultroid Logs.**", file=file)
|
252 |
-
elif opt == "open":
|
253 |
-
with open("ultroid.log", "r") as f:
|
254 |
-
file = f.read()[-4000:]
|
255 |
-
return await event.eor(f"`{file}`")
|
256 |
-
else:
|
257 |
-
await def_logs(event, file)
|
258 |
-
await event.try_delete()
|
259 |
-
|
260 |
-
|
261 |
-
@in_pattern("alive", owner=True)
|
262 |
-
async def inline_alive(ult):
|
263 |
-
pic = udB.get_key("ALIVE_PIC")
|
264 |
-
if isinstance(pic, list):
|
265 |
-
pic = choice(pic)
|
266 |
-
uptime = time_formatter((time.time() - start_time) * 1000)
|
267 |
-
header = udB.get_key("ALIVE_TEXT") or get_string("bot_1")
|
268 |
-
y = Repo().active_branch
|
269 |
-
xx = Repo().remotes[0].config_reader.get("url")
|
270 |
-
rep = xx.replace(".git", f"/tree/{y}")
|
271 |
-
kk = f"<a href={rep}>{y}</a>"
|
272 |
-
als = in_alive.format(
|
273 |
-
header, f"{ultroid_version} [{HOSTED_ON}]", UltVer, pyver(), uptime, kk
|
274 |
-
)
|
275 |
-
|
276 |
-
if _e := udB.get_key("ALIVE_EMOJI"):
|
277 |
-
als = als.replace("🌀", _e)
|
278 |
-
builder = ult.builder
|
279 |
-
if pic:
|
280 |
-
try:
|
281 |
-
if ".jpg" in pic:
|
282 |
-
results = [
|
283 |
-
await builder.photo(
|
284 |
-
pic, text=als, parse_mode="html", buttons=buttons
|
285 |
-
)
|
286 |
-
]
|
287 |
-
else:
|
288 |
-
if _pic := resolve_bot_file_id(pic):
|
289 |
-
pic = _pic
|
290 |
-
buttons.insert(
|
291 |
-
0, [Button.inline(get_string("bot_2"), data="alive")]
|
292 |
-
)
|
293 |
-
results = [
|
294 |
-
await builder.document(
|
295 |
-
pic,
|
296 |
-
title="Inline Alive",
|
297 |
-
description="@TeamUltroid",
|
298 |
-
parse_mode="html",
|
299 |
-
buttons=buttons,
|
300 |
-
)
|
301 |
-
]
|
302 |
-
return await ult.answer(results)
|
303 |
-
except BaseException as er:
|
304 |
-
LOGS.exception(er)
|
305 |
-
result = [
|
306 |
-
await builder.article(
|
307 |
-
"Alive", text=als, parse_mode="html", link_preview=False, buttons=buttons
|
308 |
-
)
|
309 |
-
]
|
310 |
-
await ult.answer(result)
|
311 |
-
|
312 |
-
|
313 |
-
@ultroid_cmd(pattern="update( (.*)|$)")
|
314 |
-
async def _(e):
|
315 |
-
xx = await e.eor(get_string("upd_1"))
|
316 |
-
if e.pattern_match.group(1).strip() and (
|
317 |
-
"fast" in e.pattern_match.group(1).strip()
|
318 |
-
or "soft" in e.pattern_match.group(1).strip()
|
319 |
-
):
|
320 |
-
await bash("git pull -f && pip3 install -r requirements.txt")
|
321 |
-
call_back()
|
322 |
-
await xx.edit(get_string("upd_7"))
|
323 |
-
os.execl(sys.executable, "python3", "-m", "pyUltroid")
|
324 |
-
# return
|
325 |
-
m = await updater()
|
326 |
-
branch = (Repo.init()).active_branch
|
327 |
-
if m:
|
328 |
-
x = await asst.send_file(
|
329 |
-
udB.get_key("LOG_CHANNEL"),
|
330 |
-
ULTPIC(),
|
331 |
-
caption="• **Update Available** •",
|
332 |
-
force_document=False,
|
333 |
-
buttons=Button.inline("Changelogs", data="changes"),
|
334 |
-
)
|
335 |
-
Link = x.message_link
|
336 |
-
await xx.edit(
|
337 |
-
f'<strong><a href="{Link}">[ChangeLogs]</a></strong>',
|
338 |
-
parse_mode="html",
|
339 |
-
link_preview=False,
|
340 |
-
)
|
341 |
-
else:
|
342 |
-
await xx.edit(
|
343 |
-
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>',
|
344 |
-
parse_mode="html",
|
345 |
-
link_preview=False,
|
346 |
-
)
|
347 |
-
|
348 |
-
|
349 |
-
@callback("updtavail", owner=True)
|
350 |
-
async def updava(event):
|
351 |
-
await event.delete()
|
352 |
-
await asst.send_file(
|
353 |
-
udB.get_key("LOG_CHANNEL"),
|
354 |
-
ULTPIC(),
|
355 |
-
caption="• **Update Available** •",
|
356 |
-
force_document=False,
|
357 |
-
buttons=Button.inline("Changelogs", data="changes"),
|
358 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/broadcast.py
DELETED
@@ -1,216 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
|
9 |
-
from . import get_help
|
10 |
-
|
11 |
-
__doc__ = get_help("help_broadcast")
|
12 |
-
|
13 |
-
import asyncio
|
14 |
-
import io
|
15 |
-
|
16 |
-
from telethon.utils import get_display_name
|
17 |
-
|
18 |
-
from pyUltroid.dB.base import KeyManager
|
19 |
-
|
20 |
-
from . import HNDLR, LOGS, eor, get_string, udB, ultroid_bot, ultroid_cmd
|
21 |
-
|
22 |
-
KeyM = KeyManager("BROADCAST", cast=list)
|
23 |
-
|
24 |
-
|
25 |
-
@ultroid_cmd(
|
26 |
-
pattern="addch( (.*)|$)",
|
27 |
-
allow_sudo=False,
|
28 |
-
)
|
29 |
-
async def broadcast_adder(event):
|
30 |
-
msgg = event.pattern_match.group(1).strip()
|
31 |
-
x = await event.eor(get_string("bd_1"))
|
32 |
-
if msgg == "all":
|
33 |
-
await x.edit(get_string("bd_2"))
|
34 |
-
chats = [
|
35 |
-
e.entity
|
36 |
-
for e in await event.client.get_dialogs()
|
37 |
-
if (e.is_group or e.is_channel)
|
38 |
-
]
|
39 |
-
new = 0
|
40 |
-
for i in chats:
|
41 |
-
try:
|
42 |
-
if (
|
43 |
-
i.broadcast
|
44 |
-
and (i.creator or i.admin_rights)
|
45 |
-
and not KeyM.contains(i.id)
|
46 |
-
):
|
47 |
-
new += 1
|
48 |
-
cid = f"-100{i.id}"
|
49 |
-
KeyM.add(int(cid))
|
50 |
-
except Exception as Ex:
|
51 |
-
LOGS.exception(Ex)
|
52 |
-
await x.edit(get_string("bd_3").format(KeyM.count(), new))
|
53 |
-
return
|
54 |
-
if event.reply_to_msg_id:
|
55 |
-
previous_message = await event.get_reply_message()
|
56 |
-
raw_text = previous_message.text
|
57 |
-
lines = raw_text.split("\n")
|
58 |
-
length = len(lines)
|
59 |
-
for line_number in range(1, length - 2):
|
60 |
-
channel_id = lines[line_number][4:-1]
|
61 |
-
if not KeyM.contains(channel_id):
|
62 |
-
KeyM.add(channel_id)
|
63 |
-
await x.edit(get_string("bd_4"))
|
64 |
-
await asyncio.sleep(3)
|
65 |
-
await event.delete()
|
66 |
-
return
|
67 |
-
chat_id = event.chat_id
|
68 |
-
if chat_id == udB.get_key("LOG_CHANNEL"):
|
69 |
-
return
|
70 |
-
if KeyM.contains(chat_id):
|
71 |
-
await x.edit(get_string("bd_6"))
|
72 |
-
elif xx := KeyM.add(chat_id):
|
73 |
-
await x.edit(get_string("bd_5"))
|
74 |
-
else:
|
75 |
-
await x.edit(get_string("sf_8"))
|
76 |
-
await asyncio.sleep(3)
|
77 |
-
await x.delete()
|
78 |
-
|
79 |
-
|
80 |
-
@ultroid_cmd(
|
81 |
-
pattern="remch( (.*)|$)",
|
82 |
-
allow_sudo=False,
|
83 |
-
)
|
84 |
-
async def broadcast_remover(event):
|
85 |
-
chat_id = event.pattern_match.group(1).strip() or event.chat_id
|
86 |
-
x = await event.eor(get_string("com_1"))
|
87 |
-
if chat_id == "all":
|
88 |
-
await x.edit(get_string("bd_8"))
|
89 |
-
udB.del_key("BROADCAST")
|
90 |
-
await x.edit("Database cleared.")
|
91 |
-
return
|
92 |
-
if KeyM.contains(chat_id):
|
93 |
-
KeyM.remove(chat_id)
|
94 |
-
await x.edit(get_string("bd_7"))
|
95 |
-
else:
|
96 |
-
await x.edit(get_string("bd_9"))
|
97 |
-
await asyncio.sleep(3)
|
98 |
-
await x.delete()
|
99 |
-
|
100 |
-
|
101 |
-
@ultroid_cmd(
|
102 |
-
pattern="listchannels$",
|
103 |
-
)
|
104 |
-
async def list_all(event):
|
105 |
-
x = await event.eor(get_string("com_1"))
|
106 |
-
channels = KeyM.get()
|
107 |
-
num = KeyM.count()
|
108 |
-
if not channels:
|
109 |
-
return await eor(x, "No chats were added.", time=5)
|
110 |
-
msg = "Channels in database:\n"
|
111 |
-
for channel in channels:
|
112 |
-
name = ""
|
113 |
-
try:
|
114 |
-
name = get_display_name(await event.client.get_entity(channel))
|
115 |
-
except ValueError:
|
116 |
-
name = ""
|
117 |
-
msg += f"=> **{name}** [`{channel}`]\n"
|
118 |
-
msg += f"\nTotal {num} channels."
|
119 |
-
if len(msg) > 4096:
|
120 |
-
MSG = msg.replace("*", "").replace("`", "")
|
121 |
-
with io.BytesIO(str.encode(MSG)) as out_file:
|
122 |
-
out_file.name = "channels.txt"
|
123 |
-
await event.reply(
|
124 |
-
"Channels in Database",
|
125 |
-
file=out_file,
|
126 |
-
force_document=True,
|
127 |
-
allow_cache=False,
|
128 |
-
)
|
129 |
-
await x.delete()
|
130 |
-
else:
|
131 |
-
await x.edit(msg)
|
132 |
-
|
133 |
-
|
134 |
-
@ultroid_cmd(
|
135 |
-
pattern="forward$",
|
136 |
-
allow_sudo=False,
|
137 |
-
)
|
138 |
-
async def forw(event):
|
139 |
-
if not event.is_reply:
|
140 |
-
return await event.eor(get_string("ex_1"))
|
141 |
-
ultroid_bot = event.client
|
142 |
-
channels = KeyM.get()
|
143 |
-
x = await event.eor("Sending...")
|
144 |
-
if not channels:
|
145 |
-
return await x.edit(f"Please add channels by using `{HNDLR}add` in them.")
|
146 |
-
error_count = 0
|
147 |
-
sent_count = 0
|
148 |
-
previous_message = await event.get_reply_message()
|
149 |
-
error_count = 0
|
150 |
-
for channel in channels:
|
151 |
-
try:
|
152 |
-
await ultroid_bot.forward_messages(channel, previous_message)
|
153 |
-
sent_count += 1
|
154 |
-
await x.edit(
|
155 |
-
f"Sent : {sent_count}\nError : {error_count}\nTotal : {len(channels)}",
|
156 |
-
)
|
157 |
-
except Exception:
|
158 |
-
try:
|
159 |
-
await ultroid_bot.send_message(
|
160 |
-
udB.get_key("LOG_CHANNEL"),
|
161 |
-
f"Error in sending at {channel}.",
|
162 |
-
)
|
163 |
-
except Exception as Em:
|
164 |
-
LOGS.info(Em)
|
165 |
-
error_count += 1
|
166 |
-
await x.edit(
|
167 |
-
f"Sent : {sent_count}\nError : {error_count}\nTotal : {len(channels)}",
|
168 |
-
)
|
169 |
-
await x.edit(f"{sent_count} messages sent with {error_count} errors.")
|
170 |
-
if error_count > 0:
|
171 |
-
await ultroid_bot.send_message(
|
172 |
-
udB.get_key("LOG_CHANNEL"), f"{error_count} Errors"
|
173 |
-
)
|
174 |
-
|
175 |
-
|
176 |
-
@ultroid_cmd(
|
177 |
-
pattern="broadcast( (.*)|$)",
|
178 |
-
allow_sudo=False,
|
179 |
-
)
|
180 |
-
async def sending(event):
|
181 |
-
x = await event.eor(get_string("com_1"))
|
182 |
-
if not event.is_reply:
|
183 |
-
return await x.edit(get_string("ex_1"))
|
184 |
-
channels = KeyM.get()
|
185 |
-
if not channels:
|
186 |
-
return await x.edit(f"Please add channels by using `{HNDLR}add` in them.")
|
187 |
-
await x.edit("Sending....")
|
188 |
-
if event.reply_to_msg_id:
|
189 |
-
previous_message = await event.get_reply_message()
|
190 |
-
if previous_message.poll:
|
191 |
-
return await x.edit(f"Reply `{HNDLR}forward` for polls.")
|
192 |
-
if previous_message:
|
193 |
-
error_count = 0
|
194 |
-
sent_count = 0
|
195 |
-
for channel in channels:
|
196 |
-
try:
|
197 |
-
await ultroid_bot.send_message(channel, previous_message)
|
198 |
-
sent_count += 1
|
199 |
-
await x.edit(
|
200 |
-
f"Sent : {sent_count}\nError : {error_count}\nTotal : {len(channels)}",
|
201 |
-
)
|
202 |
-
except Exception as error:
|
203 |
-
await ultroid_bot.send_message(
|
204 |
-
udB.get_key("LOG_CHANNEL"),
|
205 |
-
f"Error in sending at {channel}.\n\n{error}",
|
206 |
-
)
|
207 |
-
error_count += 1
|
208 |
-
await x.edit(
|
209 |
-
f"Sent : {sent_count}\nError : {error_count}\nTotal : {len(channels)}",
|
210 |
-
)
|
211 |
-
await x.edit(f"{sent_count} messages sent with {error_count} errors.")
|
212 |
-
if error_count > 0:
|
213 |
-
await ultroid_bot.send_message(
|
214 |
-
udB.get_key("LOG_CHANNEL"),
|
215 |
-
f"{error_count} Errors",
|
216 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/button.py
DELETED
@@ -1,56 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_button")
|
11 |
-
|
12 |
-
import os
|
13 |
-
|
14 |
-
from telegraph import upload_file as uf
|
15 |
-
from telethon.utils import pack_bot_file_id
|
16 |
-
|
17 |
-
from pyUltroid.fns.tools import create_tl_btn, get_msg_button
|
18 |
-
|
19 |
-
from . import HNDLR, get_string, mediainfo, ultroid_cmd
|
20 |
-
from ._inline import something
|
21 |
-
|
22 |
-
|
23 |
-
@ultroid_cmd(pattern="button")
|
24 |
-
async def butt(event):
|
25 |
-
media, wut, text = None, None, None
|
26 |
-
if event.reply_to:
|
27 |
-
wt = await event.get_reply_message()
|
28 |
-
if wt.text:
|
29 |
-
text = wt.text
|
30 |
-
if wt.media:
|
31 |
-
wut = mediainfo(wt.media)
|
32 |
-
if wut and wut.startswith(("pic", "gif")):
|
33 |
-
dl = await wt.download_media()
|
34 |
-
variable = uf(dl)
|
35 |
-
media = f"https://graph.org{variable[0]}"
|
36 |
-
elif wut == "video":
|
37 |
-
if wt.media.document.size > 8 * 1000 * 1000:
|
38 |
-
return await event.eor(get_string("com_4"), time=5)
|
39 |
-
dl = await wt.download_media()
|
40 |
-
variable = uf(dl)
|
41 |
-
os.remove(dl)
|
42 |
-
media = f"https://graph.org{variable[0]}"
|
43 |
-
else:
|
44 |
-
media = pack_bot_file_id(wt.media)
|
45 |
-
try:
|
46 |
-
text = event.text.split(maxsplit=1)[1]
|
47 |
-
except IndexError:
|
48 |
-
if not text:
|
49 |
-
return await event.eor(
|
50 |
-
f"**Please give some text in correct format.**\n\n`{HNDLR}help button`",
|
51 |
-
)
|
52 |
-
text, buttons = get_msg_button(text)
|
53 |
-
if buttons:
|
54 |
-
buttons = create_tl_btn(buttons)
|
55 |
-
await something(event, text, media, buttons)
|
56 |
-
await event.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/calculator.py
DELETED
@@ -1,153 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
|
9 |
-
from . import get_help
|
10 |
-
|
11 |
-
__doc__ = get_help("help_calculator")
|
12 |
-
|
13 |
-
import re
|
14 |
-
|
15 |
-
from . import Button, asst, callback, get_string, in_pattern, udB, ultroid_cmd
|
16 |
-
|
17 |
-
CALC = {}
|
18 |
-
|
19 |
-
m = [
|
20 |
-
"AC",
|
21 |
-
"C",
|
22 |
-
"⌫",
|
23 |
-
"%",
|
24 |
-
"7",
|
25 |
-
"8",
|
26 |
-
"9",
|
27 |
-
"+",
|
28 |
-
"4",
|
29 |
-
"5",
|
30 |
-
"6",
|
31 |
-
"-",
|
32 |
-
"1",
|
33 |
-
"2",
|
34 |
-
"3",
|
35 |
-
"x",
|
36 |
-
"00",
|
37 |
-
"0",
|
38 |
-
".",
|
39 |
-
"÷",
|
40 |
-
]
|
41 |
-
tultd = [Button.inline(f"{x}", data=f"calc{x}") for x in m]
|
42 |
-
lst = list(zip(tultd[::4], tultd[1::4], tultd[2::4], tultd[3::4]))
|
43 |
-
lst.append([Button.inline("=", data="calc=")])
|
44 |
-
|
45 |
-
|
46 |
-
@ultroid_cmd(pattern="calc")
|
47 |
-
async def icalc(e):
|
48 |
-
udB.del_key("calc")
|
49 |
-
if e.client._bot:
|
50 |
-
return await e.reply(get_string("calc_1"), buttons=lst)
|
51 |
-
results = await e.client.inline_query(asst.me.username, "calc")
|
52 |
-
await results[0].click(e.chat_id, silent=True, hide_via=True)
|
53 |
-
await e.delete()
|
54 |
-
|
55 |
-
|
56 |
-
@in_pattern("calc", owner=True)
|
57 |
-
async def _(e):
|
58 |
-
calc = e.builder.article("Calc", text=get_string("calc_1"), buttons=lst)
|
59 |
-
await e.answer([calc])
|
60 |
-
|
61 |
-
|
62 |
-
@callback(re.compile("calc(.*)"), owner=True)
|
63 |
-
async def _(e):
|
64 |
-
x = (e.data_match.group(1)).decode()
|
65 |
-
user = e.query.user_id
|
66 |
-
get = None
|
67 |
-
if x == "AC":
|
68 |
-
if CALC.get(user):
|
69 |
-
CALC.pop(user)
|
70 |
-
await e.edit(
|
71 |
-
get_string("calc_1"),
|
72 |
-
buttons=[Button.inline(get_string("calc_2"), data="recalc")],
|
73 |
-
)
|
74 |
-
elif x == "C":
|
75 |
-
if CALC.get(user):
|
76 |
-
CALC.pop(user)
|
77 |
-
await e.answer("cleared")
|
78 |
-
elif x == "⌫":
|
79 |
-
if CALC.get(user):
|
80 |
-
get = CALC[user]
|
81 |
-
if get:
|
82 |
-
CALC.update({user: get[:-1]})
|
83 |
-
await e.answer(str(get[:-1]))
|
84 |
-
elif x == "%":
|
85 |
-
if CALC.get(user):
|
86 |
-
get = CALC[user]
|
87 |
-
if get:
|
88 |
-
CALC.update({user: f"{get}/100"})
|
89 |
-
await e.answer(str(f"{get}/100"))
|
90 |
-
elif x == "÷":
|
91 |
-
if CALC.get(user):
|
92 |
-
get = CALC[user]
|
93 |
-
if get:
|
94 |
-
CALC.update({user: f"{get}/"})
|
95 |
-
await e.answer(str(f"{get}/"))
|
96 |
-
elif x == "x":
|
97 |
-
if CALC.get(user):
|
98 |
-
get = CALC[user]
|
99 |
-
if get:
|
100 |
-
CALC.update({user: f"{get}*"})
|
101 |
-
await e.answer(str(f"{get}*"))
|
102 |
-
elif x == "=":
|
103 |
-
if CALC.get(user):
|
104 |
-
get = CALC[user]
|
105 |
-
if get:
|
106 |
-
if get.endswith(("*", ".", "/", "-", "+")):
|
107 |
-
get = get[:-1]
|
108 |
-
out = eval(get)
|
109 |
-
try:
|
110 |
-
num = float(out)
|
111 |
-
await e.answer(f"Answer : {num}", cache_time=0, alert=True)
|
112 |
-
except BaseException:
|
113 |
-
CALC.pop(user)
|
114 |
-
await e.answer(get_string("sf_8"), cache_time=0, alert=True)
|
115 |
-
await e.answer("None")
|
116 |
-
else:
|
117 |
-
if CALC.get(user):
|
118 |
-
get = CALC[user]
|
119 |
-
if get:
|
120 |
-
CALC.update({user: get + x})
|
121 |
-
return await e.answer(str(get + x))
|
122 |
-
CALC.update({user: x})
|
123 |
-
await e.answer(str(x))
|
124 |
-
|
125 |
-
|
126 |
-
@callback("recalc", owner=True)
|
127 |
-
async def _(e):
|
128 |
-
m = [
|
129 |
-
"AC",
|
130 |
-
"C",
|
131 |
-
"⌫",
|
132 |
-
"%",
|
133 |
-
"7",
|
134 |
-
"8",
|
135 |
-
"9",
|
136 |
-
"+",
|
137 |
-
"4",
|
138 |
-
"5",
|
139 |
-
"6",
|
140 |
-
"-",
|
141 |
-
"1",
|
142 |
-
"2",
|
143 |
-
"3",
|
144 |
-
"x",
|
145 |
-
"00",
|
146 |
-
"0",
|
147 |
-
".",
|
148 |
-
"÷",
|
149 |
-
]
|
150 |
-
tultd = [Button.inline(f"{x}", data=f"calc{x}") for x in m]
|
151 |
-
lst = list(zip(tultd[::4], tultd[1::4], tultd[2::4], tultd[3::4]))
|
152 |
-
lst.append([Button.inline("=", data="calc=")])
|
153 |
-
await e.edit(get_string("calc_1"), buttons=lst)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/channelhacks.py
DELETED
@@ -1,224 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
from . import get_help
|
8 |
-
|
9 |
-
__doc__ = get_help("help_channelhacks")
|
10 |
-
|
11 |
-
|
12 |
-
import asyncio
|
13 |
-
import io
|
14 |
-
|
15 |
-
from telethon.errors.rpcerrorlist import FloodWaitError
|
16 |
-
from telethon.utils import get_display_name, get_peer_id
|
17 |
-
|
18 |
-
from pyUltroid.dB.base import KeyManager
|
19 |
-
|
20 |
-
from . import LOGS, asst, eor, events, get_string, udB, ultroid_bot, ultroid_cmd
|
21 |
-
|
22 |
-
ERROR = {}
|
23 |
-
SourceM = KeyManager("CH_SOURCE", cast=list)
|
24 |
-
DestiM = KeyManager("CH_DESTINATIONS", cast=list)
|
25 |
-
|
26 |
-
|
27 |
-
async def autopost_func(e):
|
28 |
-
if not udB.get_key("AUTOPOST"):
|
29 |
-
return
|
30 |
-
x = SourceM.get()
|
31 |
-
th = await e.get_chat()
|
32 |
-
if get_peer_id(th) not in x:
|
33 |
-
return
|
34 |
-
y = DestiM.get()
|
35 |
-
for ys in y:
|
36 |
-
try:
|
37 |
-
await e.client.send_message(int(ys), e.message)
|
38 |
-
except Exception as ex:
|
39 |
-
try:
|
40 |
-
ERROR[str(ex)]
|
41 |
-
except KeyError:
|
42 |
-
ERROR.update({str(ex): ex})
|
43 |
-
Error = f"**Error on AUTOPOST**\n\n`{ex}`"
|
44 |
-
await asst.send_message(udB.get_key("LOG_CHANNEL"), Error)
|
45 |
-
|
46 |
-
|
47 |
-
@ultroid_cmd(pattern="shift (.*)")
|
48 |
-
async def _(e):
|
49 |
-
x = e.pattern_match.group(1).strip()
|
50 |
-
z = await e.eor(get_string("com_1"))
|
51 |
-
a, b = x.split("|")
|
52 |
-
try:
|
53 |
-
c = await e.client.parse_id(a)
|
54 |
-
except Exception:
|
55 |
-
await z.edit(get_string("cha_1"))
|
56 |
-
return
|
57 |
-
try:
|
58 |
-
d = await e.client.parse_id(b)
|
59 |
-
except Exception as er:
|
60 |
-
LOGS.exception(er)
|
61 |
-
await z.edit(get_string("cha_1"))
|
62 |
-
return
|
63 |
-
async for msg in e.client.iter_messages(int(c), reverse=True):
|
64 |
-
try:
|
65 |
-
await asyncio.sleep(2)
|
66 |
-
await e.client.send_message(int(d), msg)
|
67 |
-
except FloodWaitError as er:
|
68 |
-
await asyncio.sleep(er.seconds + 5)
|
69 |
-
await e.client.send_message(int(d), msg)
|
70 |
-
except BaseException as er:
|
71 |
-
LOGS.exception(er)
|
72 |
-
await z.edit("Done")
|
73 |
-
|
74 |
-
|
75 |
-
@ultroid_cmd(pattern="asource (.*)")
|
76 |
-
async def source(e):
|
77 |
-
if x := e.pattern_match.group(1).strip():
|
78 |
-
try:
|
79 |
-
y = await e.client.parse_id(x)
|
80 |
-
except Exception as er:
|
81 |
-
LOGS.exception(er)
|
82 |
-
return
|
83 |
-
else:
|
84 |
-
y = e.chat_id
|
85 |
-
if not SourceM.contains(y):
|
86 |
-
SourceM.add(y)
|
87 |
-
await e.eor(get_string("cha_2"))
|
88 |
-
ultroid_bot.add_handler(autopost_func, events.NewMessage())
|
89 |
-
else:
|
90 |
-
await e.eor(get_string("cha_3"))
|
91 |
-
|
92 |
-
|
93 |
-
@ultroid_cmd(pattern="dsource( (.*)|$)")
|
94 |
-
async def dd(event):
|
95 |
-
chat_id = event.pattern_match.group(1).strip()
|
96 |
-
x = await event.eor(get_string("com_1"))
|
97 |
-
if chat_id == "all":
|
98 |
-
await x.edit(get_string("bd_8"))
|
99 |
-
udB.del_key("CH_SOURCE")
|
100 |
-
await x.edit(get_string("cha_4"))
|
101 |
-
return
|
102 |
-
if chat_id:
|
103 |
-
try:
|
104 |
-
y = await event.client.parse_id(chat_id)
|
105 |
-
except Exception as er:
|
106 |
-
LOGS.exception(er)
|
107 |
-
return
|
108 |
-
else:
|
109 |
-
y = event.chat_id
|
110 |
-
if SourceM.contains(y):
|
111 |
-
SourceM.remove(y)
|
112 |
-
await eor(x, get_string("cha_5"), time=5)
|
113 |
-
else:
|
114 |
-
await eor(x, "Source channel is already removed from database. ", time=3)
|
115 |
-
|
116 |
-
|
117 |
-
@ultroid_cmd(pattern="listsource")
|
118 |
-
async def list_all(event):
|
119 |
-
x = await event.eor(get_string("com_1"))
|
120 |
-
num = SourceM.count()
|
121 |
-
if not num:
|
122 |
-
return await eor(x, "No chats were added.", time=5)
|
123 |
-
msg = get_string("cha_8")
|
124 |
-
channels = SourceM.get()
|
125 |
-
for channel in channels:
|
126 |
-
name = ""
|
127 |
-
try:
|
128 |
-
name = get_display_name(await event.client.get_entity(int(channel)))
|
129 |
-
except BaseException:
|
130 |
-
name = ""
|
131 |
-
msg += f"\n=> **{name}** [`{channel}`]"
|
132 |
-
msg += f"\nTotal {num} channels."
|
133 |
-
if len(msg) > 4096:
|
134 |
-
MSG = msg.replace("*", "").replace("`", "")
|
135 |
-
with io.BytesIO(str.encode(MSG)) as out_file:
|
136 |
-
out_file.name = "channels.txt"
|
137 |
-
await event.reply(
|
138 |
-
"Channels in database",
|
139 |
-
file=out_file,
|
140 |
-
force_document=True,
|
141 |
-
allow_cache=False,
|
142 |
-
)
|
143 |
-
await x.delete()
|
144 |
-
else:
|
145 |
-
await x.edit(msg)
|
146 |
-
|
147 |
-
|
148 |
-
@ultroid_cmd(pattern="adest (.*)")
|
149 |
-
async def destination(e):
|
150 |
-
if x := e.pattern_match.group(1).strip():
|
151 |
-
try:
|
152 |
-
y = await e.client.parse_id(x)
|
153 |
-
except Exception as er:
|
154 |
-
LOGS.exception(er)
|
155 |
-
return
|
156 |
-
else:
|
157 |
-
y = e.chat_id
|
158 |
-
if not DestiM.contains(y):
|
159 |
-
DestiM.add(y)
|
160 |
-
await e.eor("Destination added succesfully")
|
161 |
-
else:
|
162 |
-
await e.eor("Destination channel already added")
|
163 |
-
|
164 |
-
|
165 |
-
@ultroid_cmd(pattern="ddest( (.*)|$)")
|
166 |
-
async def dd(event):
|
167 |
-
chat_id = event.pattern_match.group(1).strip()
|
168 |
-
x = await event.eor(get_string("com_1"))
|
169 |
-
if chat_id == "all":
|
170 |
-
await x.edit(get_string("bd_8"))
|
171 |
-
udB.del_key("CH_DESTINATION")
|
172 |
-
await x.edit("Destinations database cleared.")
|
173 |
-
return
|
174 |
-
if chat_id:
|
175 |
-
try:
|
176 |
-
y = await event.client.parse_id(chat_id)
|
177 |
-
except Exception as er:
|
178 |
-
LOGS.exception(er)
|
179 |
-
return
|
180 |
-
else:
|
181 |
-
y = event.chat_id
|
182 |
-
if DestiM.contains(y):
|
183 |
-
DestiM.remove(y)
|
184 |
-
await eor(x, "Destination removed from database")
|
185 |
-
else:
|
186 |
-
await eor(x, "Destination channel is already removed from database. ", time=5)
|
187 |
-
|
188 |
-
|
189 |
-
@ultroid_cmd(pattern="listdest")
|
190 |
-
async def list_all(event):
|
191 |
-
ultroid_bot = event.client
|
192 |
-
x = await event.eor(get_string("com_1"))
|
193 |
-
channels = DestiM.get()
|
194 |
-
num = len(channels)
|
195 |
-
if not num:
|
196 |
-
return await eor(x, "No chats were added.", time=5)
|
197 |
-
msg = get_string("cha_7")
|
198 |
-
for channel in channels:
|
199 |
-
name = ""
|
200 |
-
try:
|
201 |
-
name = get_display_name(await ultroid_bot.get_entity(int(channel)))
|
202 |
-
except BaseException:
|
203 |
-
name = ""
|
204 |
-
msg += f"\n=> **{name}** [`{channel}`]"
|
205 |
-
msg += f"\nTotal {num} channels."
|
206 |
-
if len(msg) > 4096:
|
207 |
-
MSG = msg.replace("*", "").replace("`", "")
|
208 |
-
with io.BytesIO(str.encode(MSG)) as out_file:
|
209 |
-
out_file.name = "channels.txt"
|
210 |
-
await ultroid_bot.send_file(
|
211 |
-
event.chat_id,
|
212 |
-
out_file,
|
213 |
-
force_document=True,
|
214 |
-
allow_cache=False,
|
215 |
-
caption="Destination channels in database",
|
216 |
-
reply_to=event,
|
217 |
-
)
|
218 |
-
await x.delete()
|
219 |
-
else:
|
220 |
-
await x.edit(msg)
|
221 |
-
|
222 |
-
|
223 |
-
if udB.get_key("AUTOPOST"):
|
224 |
-
ultroid_bot.add_handler(autopost_func, events.NewMessage())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/chatbot.py
DELETED
@@ -1,174 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2024 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_chatbot")
|
11 |
-
|
12 |
-
|
13 |
-
from pyUltroid.fns.tools import get_chatbot_reply, get_oracle_reply
|
14 |
-
|
15 |
-
from . import LOGS, eod, get_string, inline_mention, udB, ultroid_bot, ultroid_cmd
|
16 |
-
|
17 |
-
try:
|
18 |
-
mongouri = udB.get_key("MONGO_URI")
|
19 |
-
except AttributeError:
|
20 |
-
if udB.get_key("MONGO_URI"):
|
21 |
-
mongouri = udB.get_key("MONGO_URI")
|
22 |
-
else:
|
23 |
-
udB.set_key("MONGO_URI", "")
|
24 |
-
LOGS.error("PLeasde set a MONGO_URI")
|
25 |
-
|
26 |
-
|
27 |
-
@ultroid_cmd(pattern="repoai")
|
28 |
-
async def im_oracle(event):
|
29 |
-
if event.reply_to:
|
30 |
-
message = (await event.get_reply_message()).text.strip()
|
31 |
-
else:
|
32 |
-
try:
|
33 |
-
message = event.text.split(" ", 1)[1]
|
34 |
-
except IndexError:
|
35 |
-
return await eod(event, get_string("tban_1"), time=10)
|
36 |
-
reply_ = await get_oracle_reply(
|
37 |
-
query=message, user_id=ultroid_bot.me.id, mongo_url=mongouri
|
38 |
-
)
|
39 |
-
await event.eor(reply_)
|
40 |
-
|
41 |
-
|
42 |
-
@ultroid_cmd(pattern="addoai")
|
43 |
-
async def add_oracle(event):
|
44 |
-
await oracle_bot_fn(event, type_="add")
|
45 |
-
|
46 |
-
|
47 |
-
@ultroid_cmd(pattern="remoai")
|
48 |
-
async def rem_oracle(event):
|
49 |
-
await oracle_bot_fn(event, type_="remov")
|
50 |
-
|
51 |
-
|
52 |
-
@ultroid_cmd(pattern="listoai")
|
53 |
-
async def listoracle(event):
|
54 |
-
key = udB.get_key("ORACLE_USERS") or {}
|
55 |
-
users = key.get(event.chat_id, [])
|
56 |
-
if not users:
|
57 |
-
return await event.eor(get_string("chab_2"), time=5)
|
58 |
-
msg = "**Total List Of Oracle Enabled Users In This Chat :**\n\n"
|
59 |
-
for i in users:
|
60 |
-
try:
|
61 |
-
user = await event.client.get_entity(int(i))
|
62 |
-
user = inline_mention(user)
|
63 |
-
except BaseException:
|
64 |
-
user = f"`{i}`"
|
65 |
-
msg += f"• {user}\n"
|
66 |
-
await event.eor(msg, link_preview=False)
|
67 |
-
|
68 |
-
|
69 |
-
async def oracle_bot_fn(event, type_):
|
70 |
-
if event.reply_to:
|
71 |
-
user_ = (await event.get_reply_message()).sender
|
72 |
-
else:
|
73 |
-
temp = event.text.split(maxsplit=1)
|
74 |
-
try:
|
75 |
-
user_ = await event.client.get_entity(await event.client.parse_id(temp[1]))
|
76 |
-
except BaseException as er:
|
77 |
-
LOGS.exception(er)
|
78 |
-
user_ = event.chat if event.is_private else None
|
79 |
-
if not user_:
|
80 |
-
return await eod(
|
81 |
-
event,
|
82 |
-
get_string("chab_1"),
|
83 |
-
)
|
84 |
-
key = udB.get_key("ORACLE_USERS") or {}
|
85 |
-
chat = event.chat_id
|
86 |
-
user = user_.id
|
87 |
-
if type_ == "add":
|
88 |
-
if key.get(chat):
|
89 |
-
if user not in key[chat]:
|
90 |
-
key[chat].append(user)
|
91 |
-
else:
|
92 |
-
key.update({chat: [user]})
|
93 |
-
elif type_ == "remov":
|
94 |
-
if key.get(chat):
|
95 |
-
if user in key[chat]:
|
96 |
-
key[chat].remove(user)
|
97 |
-
if chat in key and not key[chat]:
|
98 |
-
del key[chat]
|
99 |
-
udB.set_key("ORACLE_USERS", key)
|
100 |
-
await event.eor(f"**Oracle:**\n{type_}ed {inline_mention(user_)}")
|
101 |
-
|
102 |
-
|
103 |
-
@ultroid_cmd(pattern="repai")
|
104 |
-
async def im_lonely_chat_with_me(event):
|
105 |
-
if event.reply_to:
|
106 |
-
message = (await event.get_reply_message()).message
|
107 |
-
else:
|
108 |
-
try:
|
109 |
-
message = event.text.split(" ", 1)[1]
|
110 |
-
except IndexError:
|
111 |
-
return await eod(event, get_string("tban_1"), time=10)
|
112 |
-
reply_ = await get_chatbot_reply(message=message)
|
113 |
-
await event.eor(reply_)
|
114 |
-
|
115 |
-
|
116 |
-
@ultroid_cmd(pattern="addai")
|
117 |
-
async def add_chatBot(event):
|
118 |
-
await chat_bot_fn(event, type_="add")
|
119 |
-
|
120 |
-
|
121 |
-
@ultroid_cmd(pattern="remai")
|
122 |
-
async def rem_chatBot(event):
|
123 |
-
await chat_bot_fn(event, type_="remov")
|
124 |
-
|
125 |
-
|
126 |
-
@ultroid_cmd(pattern="listai")
|
127 |
-
async def lister(event):
|
128 |
-
key = udB.get_key("CHATBOT_USERS") or {}
|
129 |
-
users = key.get(event.chat_id, [])
|
130 |
-
if not users:
|
131 |
-
return await event.eor(get_string("chab_2"), time=5)
|
132 |
-
msg = "**Total List Of AI Enabled Users In This Chat :**\n\n"
|
133 |
-
for i in users:
|
134 |
-
try:
|
135 |
-
user = await event.client.get_entity(int(i))
|
136 |
-
user = inline_mention(user)
|
137 |
-
except BaseException:
|
138 |
-
user = f"`{i}`"
|
139 |
-
msg += f"• {user}\n"
|
140 |
-
await event.eor(msg, link_preview=False)
|
141 |
-
|
142 |
-
|
143 |
-
async def chat_bot_fn(event, type_):
|
144 |
-
if event.reply_to:
|
145 |
-
user_ = (await event.get_reply_message()).sender
|
146 |
-
else:
|
147 |
-
temp = event.text.split(maxsplit=1)
|
148 |
-
try:
|
149 |
-
user_ = await event.client.get_entity(await event.client.parse_id(temp[1]))
|
150 |
-
except BaseException as er:
|
151 |
-
LOGS.exception(er)
|
152 |
-
user_ = event.chat if event.is_private else None
|
153 |
-
if not user_:
|
154 |
-
return await eod(
|
155 |
-
event,
|
156 |
-
get_string("chab_1"),
|
157 |
-
)
|
158 |
-
key = udB.get_key("CHATBOT_USERS") or {}
|
159 |
-
chat = event.chat_id
|
160 |
-
user = user_.id
|
161 |
-
if type_ == "add":
|
162 |
-
if key.get(chat):
|
163 |
-
if user not in key[chat]:
|
164 |
-
key[chat].append(user)
|
165 |
-
else:
|
166 |
-
key.update({chat: [user]})
|
167 |
-
elif type_ == "remov":
|
168 |
-
if key.get(chat):
|
169 |
-
if user in key[chat]:
|
170 |
-
key[chat].remove(user)
|
171 |
-
if chat in key and not key[chat]:
|
172 |
-
del key[chat]
|
173 |
-
udB.set_key("CHATBOT_USERS", key)
|
174 |
-
await event.eor(f"**ChatBot:**\n{type_}ed {inline_mention(user_)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/chats.py
DELETED
@@ -1,368 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
from . import get_help
|
8 |
-
|
9 |
-
__doc__ = get_help("help_chats")
|
10 |
-
|
11 |
-
|
12 |
-
from telethon.errors import ChatAdminRequiredError as no_admin
|
13 |
-
from telethon.tl.functions.channels import (
|
14 |
-
CreateChannelRequest,
|
15 |
-
DeleteChannelRequest,
|
16 |
-
EditPhotoRequest,
|
17 |
-
GetFullChannelRequest,
|
18 |
-
UpdateUsernameRequest,
|
19 |
-
)
|
20 |
-
from telethon.tl.functions.messages import (
|
21 |
-
CreateChatRequest,
|
22 |
-
ExportChatInviteRequest,
|
23 |
-
GetFullChatRequest,
|
24 |
-
)
|
25 |
-
from telethon.tl.types import (
|
26 |
-
ChannelParticipantsKicked,
|
27 |
-
User,
|
28 |
-
UserStatusEmpty,
|
29 |
-
UserStatusLastMonth,
|
30 |
-
UserStatusLastWeek,
|
31 |
-
UserStatusOffline,
|
32 |
-
UserStatusOnline,
|
33 |
-
UserStatusRecently,
|
34 |
-
)
|
35 |
-
|
36 |
-
from . import HNDLR, LOGS, asst, con, get_string, mediainfo, os, types, udB, ultroid_cmd
|
37 |
-
|
38 |
-
|
39 |
-
@ultroid_cmd(
|
40 |
-
pattern="delchat",
|
41 |
-
groups_only=True,
|
42 |
-
)
|
43 |
-
async def _(e):
|
44 |
-
xx = await e.eor(get_string("com_1"))
|
45 |
-
try:
|
46 |
-
match = e.text.split(" ", maxsplit=1)[1]
|
47 |
-
chat = await e.client.parse_id(match)
|
48 |
-
except IndexError:
|
49 |
-
chat = e.chat_id
|
50 |
-
try:
|
51 |
-
await e.client(DeleteChannelRequest(chat))
|
52 |
-
except TypeError:
|
53 |
-
return await xx.eor(get_string("chats_1"), time=10)
|
54 |
-
except no_admin:
|
55 |
-
return await xx.eor(get_string("chats_2"), time=10)
|
56 |
-
await e.client.send_message(
|
57 |
-
int(udB.get_key("LOG_CHANNEL")), get_string("chats_6").format(e.chat_id)
|
58 |
-
)
|
59 |
-
|
60 |
-
|
61 |
-
@ultroid_cmd(
|
62 |
-
pattern="getlink( (.*)|$)",
|
63 |
-
groups_only=True,
|
64 |
-
manager=True,
|
65 |
-
)
|
66 |
-
async def _(e):
|
67 |
-
reply = await e.get_reply_message()
|
68 |
-
match = e.pattern_match.group(1).strip()
|
69 |
-
if reply and not isinstance(reply.sender, User):
|
70 |
-
chat = await reply.get_sender()
|
71 |
-
else:
|
72 |
-
chat = await e.get_chat()
|
73 |
-
if hasattr(chat, "username") and chat.username:
|
74 |
-
return await e.eor(f"Username: @{chat.username}")
|
75 |
-
request, usage, title, link = None, None, None, None
|
76 |
-
if match:
|
77 |
-
split = match.split(maxsplit=1)
|
78 |
-
request = split[0] in ["r", "request"]
|
79 |
-
title = "Created by Ultroid"
|
80 |
-
if len(split) > 1:
|
81 |
-
match = split[1]
|
82 |
-
spli = match.split(maxsplit=1)
|
83 |
-
if spli[0].isdigit():
|
84 |
-
usage = int(spli[0])
|
85 |
-
if len(spli) > 1:
|
86 |
-
title = spli[1]
|
87 |
-
elif not request:
|
88 |
-
if match.isdigit():
|
89 |
-
usage = int(match)
|
90 |
-
else:
|
91 |
-
title = match
|
92 |
-
if request and usage:
|
93 |
-
usage = 0
|
94 |
-
if request or title:
|
95 |
-
try:
|
96 |
-
r = await e.client(
|
97 |
-
ExportChatInviteRequest(
|
98 |
-
e.chat_id,
|
99 |
-
request_needed=request,
|
100 |
-
usage_limit=usage,
|
101 |
-
title=title,
|
102 |
-
),
|
103 |
-
)
|
104 |
-
except no_admin:
|
105 |
-
return await e.eor(get_string("chats_2"), time=10)
|
106 |
-
link = r.link
|
107 |
-
else:
|
108 |
-
if isinstance(chat, types.Chat):
|
109 |
-
FC = await e.client(GetFullChatRequest(chat.id))
|
110 |
-
elif isinstance(chat, types.Channel):
|
111 |
-
FC = await e.client(GetFullChannelRequest(chat.id))
|
112 |
-
else:
|
113 |
-
return
|
114 |
-
Inv = FC.full_chat.exported_invite
|
115 |
-
if Inv and not Inv.revoked:
|
116 |
-
link = Inv.link
|
117 |
-
if link:
|
118 |
-
return await e.eor(f"Link:- {link}")
|
119 |
-
await e.eor("`Failed to getlink!\nSeems like link is inaccessible to you...`")
|
120 |
-
|
121 |
-
|
122 |
-
@ultroid_cmd(
|
123 |
-
pattern="create (b|g|c)(?: |$)(.*)",
|
124 |
-
)
|
125 |
-
async def _(e):
|
126 |
-
type_of_group = e.pattern_match.group(1).strip()
|
127 |
-
group_name = e.pattern_match.group(2)
|
128 |
-
username = None
|
129 |
-
if " ; " in group_name:
|
130 |
-
group_ = group_name.split(" ; ", maxsplit=1)
|
131 |
-
group_name = group_[0]
|
132 |
-
username = group_[1]
|
133 |
-
xx = await e.eor(get_string("com_1"))
|
134 |
-
if type_of_group == "b":
|
135 |
-
try:
|
136 |
-
r = await e.client(
|
137 |
-
CreateChatRequest(
|
138 |
-
users=[asst.me.username],
|
139 |
-
title=group_name,
|
140 |
-
),
|
141 |
-
)
|
142 |
-
created_chat_id = r.chats[0].id
|
143 |
-
result = await e.client(
|
144 |
-
ExportChatInviteRequest(
|
145 |
-
peer=created_chat_id,
|
146 |
-
),
|
147 |
-
)
|
148 |
-
await xx.edit(
|
149 |
-
get_string("chats_4").format(group_name, result.link),
|
150 |
-
link_preview=False,
|
151 |
-
)
|
152 |
-
except Exception as ex:
|
153 |
-
await xx.edit(str(ex))
|
154 |
-
elif type_of_group in ["g", "c"]:
|
155 |
-
try:
|
156 |
-
r = await e.client(
|
157 |
-
CreateChannelRequest(
|
158 |
-
title=group_name,
|
159 |
-
about=get_string("chats_5"),
|
160 |
-
megagroup=type_of_group != "c",
|
161 |
-
)
|
162 |
-
)
|
163 |
-
|
164 |
-
created_chat_id = r.chats[0].id
|
165 |
-
if username:
|
166 |
-
await e.client(UpdateUsernameRequest(created_chat_id, username))
|
167 |
-
result = f"https://t.me/{username}"
|
168 |
-
else:
|
169 |
-
result = (
|
170 |
-
await e.client(
|
171 |
-
ExportChatInviteRequest(
|
172 |
-
peer=created_chat_id,
|
173 |
-
),
|
174 |
-
)
|
175 |
-
).link
|
176 |
-
await xx.edit(
|
177 |
-
get_string("chats_6").format(f"[{group_name}]({result})"),
|
178 |
-
link_preview=False,
|
179 |
-
)
|
180 |
-
except Exception as ex:
|
181 |
-
await xx.edit(str(ex))
|
182 |
-
|
183 |
-
|
184 |
-
# ---------------------------------------------------------------- #
|
185 |
-
|
186 |
-
|
187 |
-
@ultroid_cmd(
|
188 |
-
pattern="setgpic( (.*)|$)", admins_only=True, manager=True, require="change_info"
|
189 |
-
)
|
190 |
-
async def _(ult):
|
191 |
-
if not ult.is_reply:
|
192 |
-
return await ult.eor("`Reply to a Media..`", time=5)
|
193 |
-
match = ult.pattern_match.group(1).strip()
|
194 |
-
if not ult.client._bot and match:
|
195 |
-
try:
|
196 |
-
chat = await ult.client.parse_id(match)
|
197 |
-
except Exception as ok:
|
198 |
-
return await ult.eor(str(ok))
|
199 |
-
else:
|
200 |
-
chat = ult.chat_id
|
201 |
-
reply = await ult.get_reply_message()
|
202 |
-
if reply.photo or reply.sticker or reply.video:
|
203 |
-
replfile = await reply.download_media()
|
204 |
-
elif reply.document and reply.document.thumbs:
|
205 |
-
replfile = await reply.download_media(thumb=-1)
|
206 |
-
else:
|
207 |
-
return await ult.eor("Reply to a Photo or Video..")
|
208 |
-
mediain = mediainfo(reply.media)
|
209 |
-
if "animated" in mediain:
|
210 |
-
replfile = await con.convert(replfile, convert_to="mp4")
|
211 |
-
else:
|
212 |
-
replfile = await con.convert(
|
213 |
-
replfile, outname="chatphoto", allowed_formats=["jpg", "png", "mp4"]
|
214 |
-
)
|
215 |
-
file = await ult.client.upload_file(replfile)
|
216 |
-
try:
|
217 |
-
if "pic" not in mediain:
|
218 |
-
file = types.InputChatUploadedPhoto(video=file)
|
219 |
-
await ult.client(EditPhotoRequest(chat, file))
|
220 |
-
await ult.eor("`Group Photo has Successfully Changed !`", time=5)
|
221 |
-
except Exception as ex:
|
222 |
-
await ult.eor(f"Error occured.\n`{str(ex)}`", time=5)
|
223 |
-
os.remove(replfile)
|
224 |
-
|
225 |
-
|
226 |
-
@ultroid_cmd(
|
227 |
-
pattern="delgpic( (.*)|$)", admins_only=True, manager=True, require="change_info"
|
228 |
-
)
|
229 |
-
async def _(ult):
|
230 |
-
match = ult.pattern_match.group(1).strip()
|
231 |
-
chat = ult.chat_id
|
232 |
-
if not ult.client._bot and match:
|
233 |
-
chat = match
|
234 |
-
try:
|
235 |
-
await ult.client(EditPhotoRequest(chat, types.InputChatPhotoEmpty()))
|
236 |
-
text = "`Removed Chat Photo..`"
|
237 |
-
except Exception as E:
|
238 |
-
text = str(E)
|
239 |
-
return await ult.eor(text, time=5)
|
240 |
-
|
241 |
-
|
242 |
-
@ultroid_cmd(pattern="unbanall$", manager=True, admins_only=True, require="ban_users")
|
243 |
-
async def _(event):
|
244 |
-
xx = await event.eor("Searching Participant Lists.")
|
245 |
-
p = 0
|
246 |
-
title = (await event.get_chat()).title
|
247 |
-
async for i in event.client.iter_participants(
|
248 |
-
event.chat_id,
|
249 |
-
filter=ChannelParticipantsKicked,
|
250 |
-
aggressive=True,
|
251 |
-
):
|
252 |
-
try:
|
253 |
-
await event.client.edit_permissions(event.chat_id, i, view_messages=True)
|
254 |
-
p += 1
|
255 |
-
except no_admin:
|
256 |
-
pass
|
257 |
-
except BaseException as er:
|
258 |
-
LOGS.exception(er)
|
259 |
-
await xx.eor(f"{title}: {p} unbanned", time=5)
|
260 |
-
|
261 |
-
|
262 |
-
@ultroid_cmd(
|
263 |
-
pattern="rmusers( (.*)|$)",
|
264 |
-
groups_only=True,
|
265 |
-
admins_only=True,
|
266 |
-
fullsudo=True,
|
267 |
-
)
|
268 |
-
async def _(event):
|
269 |
-
xx = await event.eor(get_string("com_1"))
|
270 |
-
input_str = event.pattern_match.group(1).strip()
|
271 |
-
p, a, b, c, d, m, n, y, w, o, q, r = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
272 |
-
async for i in event.client.iter_participants(event.chat_id):
|
273 |
-
p += 1 # Total Count
|
274 |
-
if isinstance(i.status, UserStatusEmpty):
|
275 |
-
if "empty" in input_str:
|
276 |
-
try:
|
277 |
-
await event.client.kick_participant(event.chat_id, i)
|
278 |
-
c += 1
|
279 |
-
except BaseException:
|
280 |
-
pass
|
281 |
-
else:
|
282 |
-
y += 1
|
283 |
-
if isinstance(i.status, UserStatusLastMonth):
|
284 |
-
if "month" in input_str:
|
285 |
-
try:
|
286 |
-
await event.client.kick_participant(event.chat_id, i)
|
287 |
-
c += 1
|
288 |
-
except BaseException:
|
289 |
-
pass
|
290 |
-
else:
|
291 |
-
m += 1
|
292 |
-
if isinstance(i.status, UserStatusLastWeek):
|
293 |
-
if "week" in input_str:
|
294 |
-
try:
|
295 |
-
await event.client.kick_participant(event.chat_id, i)
|
296 |
-
c += 1
|
297 |
-
except BaseException:
|
298 |
-
pass
|
299 |
-
else:
|
300 |
-
w += 1
|
301 |
-
if isinstance(i.status, UserStatusOffline):
|
302 |
-
if "offline" in input_str:
|
303 |
-
try:
|
304 |
-
await event.client.kick_participant(event.chat_id, i)
|
305 |
-
c += 1
|
306 |
-
except BaseException:
|
307 |
-
pass
|
308 |
-
else:
|
309 |
-
o += 1
|
310 |
-
if isinstance(i.status, UserStatusOnline):
|
311 |
-
if "online" in input_str:
|
312 |
-
try:
|
313 |
-
await event.client.kick_participant(event.chat_id, i)
|
314 |
-
c += 1
|
315 |
-
except BaseException:
|
316 |
-
pass
|
317 |
-
else:
|
318 |
-
q += 1
|
319 |
-
if isinstance(i.status, UserStatusRecently):
|
320 |
-
if "recently" in input_str:
|
321 |
-
try:
|
322 |
-
await event.client.kick_participant(event.chat_id, i)
|
323 |
-
c += 1
|
324 |
-
except BaseException:
|
325 |
-
pass
|
326 |
-
else:
|
327 |
-
r += 1
|
328 |
-
if i.bot:
|
329 |
-
if "bot" in input_str:
|
330 |
-
try:
|
331 |
-
await event.client.kick_participant(event.chat_id, i)
|
332 |
-
c += 1
|
333 |
-
except BaseException:
|
334 |
-
pass
|
335 |
-
else:
|
336 |
-
b += 1
|
337 |
-
elif i.deleted:
|
338 |
-
if "deleted" in input_str:
|
339 |
-
try:
|
340 |
-
await event.client.kick_participant(event.chat_id, i)
|
341 |
-
c += 1
|
342 |
-
except BaseException:
|
343 |
-
pass
|
344 |
-
else:
|
345 |
-
d += 1
|
346 |
-
elif i.status is None:
|
347 |
-
if "none" in input_str:
|
348 |
-
try:
|
349 |
-
await event.client.kick_participant(event.chat_id, i)
|
350 |
-
c += 1
|
351 |
-
except BaseException:
|
352 |
-
pass
|
353 |
-
else:
|
354 |
-
n += 1
|
355 |
-
if input_str:
|
356 |
-
required_string = f"**>> Kicked** `{c} / {p}` **users**\n\n"
|
357 |
-
else:
|
358 |
-
required_string = f"**>> Total** `{p}` **users**\n\n"
|
359 |
-
required_string += f" `{HNDLR}rmusers deleted` **••** `{d}`\n"
|
360 |
-
required_string += f" `{HNDLR}rmusers empty` **••** `{y}`\n"
|
361 |
-
required_string += f" `{HNDLR}rmusers month` **••** `{m}`\n"
|
362 |
-
required_string += f" `{HNDLR}rmusers week` **••** `{w}`\n"
|
363 |
-
required_string += f" `{HNDLR}rmusers offline` **••** `{o}`\n"
|
364 |
-
required_string += f" `{HNDLR}rmusers online` **••** `{q}`\n"
|
365 |
-
required_string += f" `{HNDLR}rmusers recently` **••** `{r}`\n"
|
366 |
-
required_string += f" `{HNDLR}rmusers bot` **••** `{b}`\n"
|
367 |
-
required_string += f" `{HNDLR}rmusers none` **••** `{n}`"
|
368 |
-
await xx.eor(required_string)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/cleanaction.py
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_cleanaction")
|
11 |
-
|
12 |
-
|
13 |
-
from telethon.utils import get_display_name
|
14 |
-
|
15 |
-
from . import get_string, udB, ultroid_cmd
|
16 |
-
|
17 |
-
|
18 |
-
@ultroid_cmd(pattern="addclean$", admins_only=True)
|
19 |
-
async def _(e):
|
20 |
-
key = udB.get_key("CLEANCHAT") or []
|
21 |
-
if e.chat_id in key:
|
22 |
-
return await eod(e, get_string("clan_5"))
|
23 |
-
key.append(e.chat_id)
|
24 |
-
udB.set_key("CLEANCHAT", key)
|
25 |
-
await e.eor(get_string("clan_1"), time=5)
|
26 |
-
|
27 |
-
|
28 |
-
@ultroid_cmd(pattern="remclean$")
|
29 |
-
async def _(e):
|
30 |
-
key = udB.get_key("CLEANCHAT") or []
|
31 |
-
if e.chat_id in key:
|
32 |
-
key.remove(e.chat_id)
|
33 |
-
udB.set_key("CLEANCHAT", key)
|
34 |
-
await e.eor(get_string("clan_2"), time=5)
|
35 |
-
|
36 |
-
|
37 |
-
@ultroid_cmd(pattern="listclean$")
|
38 |
-
async def _(e):
|
39 |
-
if k := udB.get_key("CLEANCHAT"):
|
40 |
-
o = ""
|
41 |
-
for x in k:
|
42 |
-
try:
|
43 |
-
title = get_display_name(await e.client.get_entity(x))
|
44 |
-
except BaseException:
|
45 |
-
title = get_string("clan_3")
|
46 |
-
o += f"{x} {title}\n"
|
47 |
-
return await e.eor(o)
|
48 |
-
await e.eor(get_string("clan_4"), time=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/codefix.py
DELETED
@@ -1,241 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
from collections import deque
|
3 |
-
from io import BytesIO
|
4 |
-
|
5 |
-
from . import (
|
6 |
-
ultroid_cmd,
|
7 |
-
async_searcher,
|
8 |
-
udB,
|
9 |
-
LOGS,
|
10 |
-
get_paste,
|
11 |
-
)
|
12 |
-
|
13 |
-
CR_O_CHAT_HISTORY = deque(maxlen=30)
|
14 |
-
|
15 |
-
TELEGRAM_CHAR_LIMIT = 4096 # Telegram's message character limit
|
16 |
-
|
17 |
-
initprompt = """
|
18 |
-
You are an expert coding assistant. Your primary goal is to analyze, repair, and enhance the code provided by the user.
|
19 |
-
|
20 |
-
Follow this structured approach:
|
21 |
-
|
22 |
-
1. **Clarify Code Intent:**
|
23 |
-
* If the purpose of the code is unclear, ask the user for clarification.
|
24 |
-
* Understand what the code is supposed to achieve.
|
25 |
-
|
26 |
-
2. **Analyze and Diagnose:**
|
27 |
-
* Identify errors, bugs, security vulnerabilities, or logical flaws.
|
28 |
-
* Look for performance inefficiencies and suggest improvements.
|
29 |
-
* Ensure adherence to coding standards and best practices (e.g., PEP 8 for Python).
|
30 |
-
|
31 |
-
3. **Repair and Optimize:**
|
32 |
-
* Correct bugs, errors, and vulnerabilities, providing explanations for each fix.
|
33 |
-
* Optimize the code for speed, memory usage, or overall efficiency.
|
34 |
-
* Recommend alternative libraries or methods where they might offer better solutions.
|
35 |
-
|
36 |
-
4. **Enhance Readability and Maintainability:**
|
37 |
-
* Apply consistent formatting and clean coding practices.
|
38 |
-
* Add meaningful comments to clarify complex logic or structures.
|
39 |
-
|
40 |
-
5. **Summarize Improvements:**
|
41 |
-
* Present the corrected, optimized code.
|
42 |
-
* Provide a brief summary of the changes made and explain the benefits of each.
|
43 |
-
"""
|
44 |
-
|
45 |
-
initset = False
|
46 |
-
|
47 |
-
async def pastee(data):
|
48 |
-
err, linky = await get_paste(data)
|
49 |
-
if err:
|
50 |
-
return f">> [Raw Code Pasted Here](https://spaceb.in/{linky})\n"
|
51 |
-
else:
|
52 |
-
LOGS.error(linky)
|
53 |
-
return ""
|
54 |
-
|
55 |
-
|
56 |
-
@ultroid_cmd(
|
57 |
-
pattern=r"codefix( ([\s\S]*))?$",
|
58 |
-
)
|
59 |
-
async def openai_chat_gpt(e):
|
60 |
-
global initset
|
61 |
-
api_key = "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"
|
62 |
-
if not api_key:
|
63 |
-
return await e.eor("`OPENAI_API` key missing..", time=10)
|
64 |
-
|
65 |
-
query = e.pattern_match.group(2)
|
66 |
-
reply = await e.get_reply_message()
|
67 |
-
|
68 |
-
file_content = None
|
69 |
-
|
70 |
-
if query:
|
71 |
-
# Check if query contains 'from filename'
|
72 |
-
if ' from ' in query:
|
73 |
-
query_text, filename = query.split(' from ', 1)
|
74 |
-
query_text = query_text.strip()
|
75 |
-
filename = filename.strip()
|
76 |
-
# Attempt to find and read the file from media in chat
|
77 |
-
file_found = False
|
78 |
-
async for message in e.client.iter_messages(e.chat_id, reverse=True, limit=50):
|
79 |
-
if message.media and message.file.name == filename:
|
80 |
-
if (message.file.name.endswith(".txt") or message.file.name.endswith(".py")):
|
81 |
-
file = await e.client.download_media(message)
|
82 |
-
try:
|
83 |
-
with open(file, "r", encoding='utf-8') as f:
|
84 |
-
file_content = f.read()
|
85 |
-
except Exception as exc:
|
86 |
-
LOGS.error(f"Error reading file: {exc}")
|
87 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
88 |
-
finally:
|
89 |
-
os.remove(file)
|
90 |
-
file_found = True
|
91 |
-
break
|
92 |
-
if not file_found:
|
93 |
-
return await e.eor(f"`File {filename} not found in recent messages.`", time=5)
|
94 |
-
if file_content:
|
95 |
-
query = f"{query_text}\n\n{file_content}" if query_text else file_content
|
96 |
-
else:
|
97 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
98 |
-
else:
|
99 |
-
if reply and reply.media and (reply.file.name.endswith(".txt") or reply.file.name.endswith(".py")):
|
100 |
-
# Use the query and the replied file content
|
101 |
-
file = await e.client.download_media(reply)
|
102 |
-
try:
|
103 |
-
with open(file, "r", encoding='utf-8') as f:
|
104 |
-
file_content = f.read()
|
105 |
-
except Exception as exc:
|
106 |
-
LOGS.error(f"Error reading file: {exc}")
|
107 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
108 |
-
finally:
|
109 |
-
os.remove(file)
|
110 |
-
query = f"{query}\n\n{file_content}"
|
111 |
-
elif reply and reply.message:
|
112 |
-
# Use the query and the replied text message content
|
113 |
-
query = f"{query}\n\n{reply.message}"
|
114 |
-
# Else, use query as is
|
115 |
-
else:
|
116 |
-
if reply and reply.media and (reply.file.name.endswith(".txt") or reply.file.name.endswith(".py")):
|
117 |
-
# Use the replied file content
|
118 |
-
file = await e.client.download_media(reply)
|
119 |
-
try:
|
120 |
-
with open(file, "r", encoding='utf-8') as f:
|
121 |
-
file_content = f.read()
|
122 |
-
except Exception as exc:
|
123 |
-
LOGS.error(f"Error reading file: {exc}")
|
124 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
125 |
-
finally:
|
126 |
-
os.remove(file)
|
127 |
-
query = file_content
|
128 |
-
elif reply and reply.message:
|
129 |
-
# Use the replied text message content
|
130 |
-
query = reply.message
|
131 |
-
else:
|
132 |
-
return await e.eor("`Please provide a question or reply to a message or .txt/.py file.`", time=5)
|
133 |
-
|
134 |
-
if query.strip() == "-c":
|
135 |
-
initset = False
|
136 |
-
CR_O_CHAT_HISTORY.clear()
|
137 |
-
return await e.eor("__Cleared o1-mini Chat History!__", time=6)
|
138 |
-
|
139 |
-
if initset == False:
|
140 |
-
CR_O_CHAT_HISTORY.append({"role": "user", "content": initprompt})
|
141 |
-
try:
|
142 |
-
data = {
|
143 |
-
"model": "o1-mini",
|
144 |
-
"messages": list(CR_O_CHAT_HISTORY),
|
145 |
-
}
|
146 |
-
request = await async_searcher(
|
147 |
-
"https://api.openai.com/v1/chat/completions",
|
148 |
-
headers={
|
149 |
-
"Content-Type": "application/json",
|
150 |
-
"Authorization": f"Bearer {api_key}",
|
151 |
-
},
|
152 |
-
json=data,
|
153 |
-
re_json=True,
|
154 |
-
post=True,
|
155 |
-
)
|
156 |
-
response = request["choices"][0]["message"]["content"]
|
157 |
-
CR_O_CHAT_HISTORY.append({"role": "assistant", "content": response})
|
158 |
-
initset = True
|
159 |
-
except Exception as exc:
|
160 |
-
LOGS.warning(exc, exc_info=True)
|
161 |
-
CR_O_CHAT_HISTORY.pop()
|
162 |
-
return await e.edit(
|
163 |
-
f"**Error while requesting data from OpenAI:** \n> `{exc}`"
|
164 |
-
)
|
165 |
-
|
166 |
-
eris = await e.eor(f"__Generating answer for:__\n`{query[:20]} ...`")
|
167 |
-
CR_O_CHAT_HISTORY.append({"role": "user", "content": query})
|
168 |
-
|
169 |
-
try:
|
170 |
-
data = {
|
171 |
-
"model": "o1-mini",
|
172 |
-
"messages": list(CR_O_CHAT_HISTORY),
|
173 |
-
}
|
174 |
-
request = await async_searcher(
|
175 |
-
"https://api.openai.com/v1/chat/completions",
|
176 |
-
headers={
|
177 |
-
"Content-Type": "application/json",
|
178 |
-
"Authorization": f"Bearer {api_key}",
|
179 |
-
},
|
180 |
-
json=data,
|
181 |
-
re_json=True,
|
182 |
-
post=True,
|
183 |
-
)
|
184 |
-
response = request["choices"][0]["message"]["content"]
|
185 |
-
CR_O_CHAT_HISTORY.append({"role": "assistant", "content": response})
|
186 |
-
except Exception as exc:
|
187 |
-
LOGS.warning(exc, exc_info=True)
|
188 |
-
CR_O_CHAT_HISTORY.pop()
|
189 |
-
return await eris.edit(
|
190 |
-
f"**Error while requesting data from OpenAI:** \n> `{exc}`"
|
191 |
-
)
|
192 |
-
|
193 |
-
LOGS.debug(f'Tokens Used on query: {request["usage"]["completion_tokens"]}')
|
194 |
-
|
195 |
-
# Truncate query to 50 characters for display
|
196 |
-
truncated_query = query[:100]
|
197 |
-
|
198 |
-
# Prepare the full message
|
199 |
-
full_message = f"**Query:**\n~ __{truncated_query}__\n\n**o1-mini:**\n~ {response}"
|
200 |
-
|
201 |
-
# Check if response contains code blocks
|
202 |
-
code_blocks = []
|
203 |
-
in_code_block = False
|
204 |
-
code_block_lines = []
|
205 |
-
for line in response.split('\n'):
|
206 |
-
if line.strip().startswith('```'):
|
207 |
-
if in_code_block:
|
208 |
-
# End of code block
|
209 |
-
in_code_block = False
|
210 |
-
code_blocks.append('\n'.join(code_block_lines))
|
211 |
-
code_block_lines = []
|
212 |
-
else:
|
213 |
-
# Start of code block
|
214 |
-
in_code_block = True
|
215 |
-
elif in_code_block:
|
216 |
-
code_block_lines.append(line)
|
217 |
-
|
218 |
-
# If the response contains code blocks, select the largest one and paste it
|
219 |
-
if code_blocks:
|
220 |
-
# Select the largest code block based on length
|
221 |
-
largest_code_block = max(code_blocks, key=lambda block: len(block))
|
222 |
-
# Upload the largest code block to spaceb.in and get the link
|
223 |
-
paste_link = await pastee(largest_code_block)
|
224 |
-
else:
|
225 |
-
paste_link = ""
|
226 |
-
|
227 |
-
if len(full_message) <= TELEGRAM_CHAR_LIMIT:
|
228 |
-
# If it fits within the limit, send as a message
|
229 |
-
await eris.edit(full_message + f"\n\n{paste_link}")
|
230 |
-
else:
|
231 |
-
# If it exceeds the limit, send as a file and include paste link
|
232 |
-
file = BytesIO(full_message.encode('utf-8'))
|
233 |
-
file.name = "o1-mini-output.txt"
|
234 |
-
await eris.respond(
|
235 |
-
"__The query and response were too long, so they have been sent as a file.__\n\n" + paste_link,
|
236 |
-
file=file,
|
237 |
-
reply_to=e.reply_to_msg_id or e.id,
|
238 |
-
link_preview=False
|
239 |
-
)
|
240 |
-
await eris.delete()
|
241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/codegpt.py
DELETED
@@ -1,302 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
from collections import deque
|
3 |
-
from io import BytesIO
|
4 |
-
|
5 |
-
from . import (
|
6 |
-
ultroid_cmd,
|
7 |
-
async_searcher,
|
8 |
-
udB,
|
9 |
-
LOGS,
|
10 |
-
get_paste,
|
11 |
-
)
|
12 |
-
|
13 |
-
CG_GPT_CHAT_HISTORY = deque(maxlen=30)
|
14 |
-
|
15 |
-
TELEGRAM_CHAR_LIMIT = 4096 # Telegram's message character limit
|
16 |
-
|
17 |
-
initprompt = """
|
18 |
-
Your name is User Coding Helper. Your task is to create plugins for the Ultroid Telegram userbot. Follow these guidelines:
|
19 |
-
1. Imports: Include all necessary imports as demonstrated in the example code provided below.
|
20 |
-
2. Command Creation: Generate a random, suitable Ultroid command. Ensure that this command can either:
|
21 |
-
- Process a query, or
|
22 |
-
- Be used directly with the command.
|
23 |
-
3. Code Submission: Do not send any code without a corresponding post request or without the user providing a code snippet.
|
24 |
-
|
25 |
-
Example Code:
|
26 |
-
```
|
27 |
-
from os import system, remove
|
28 |
-
from io import BytesIO
|
29 |
-
|
30 |
-
try:
|
31 |
-
import openai
|
32 |
-
except ImportError:
|
33 |
-
system("pip install -q openai")
|
34 |
-
import openai
|
35 |
-
|
36 |
-
from . import ultroid_cmd, check_filename, udB, LOGS, fast_download, run_async
|
37 |
-
|
38 |
-
@run_async
|
39 |
-
def get_gpt_answer(gen_image, question, api_key):
|
40 |
-
openai.api_key = api_key
|
41 |
-
if gen_image:
|
42 |
-
x = openai.Image.create(
|
43 |
-
prompt=question,
|
44 |
-
n=1,
|
45 |
-
size="1024x1024",
|
46 |
-
user="arc",
|
47 |
-
)
|
48 |
-
return x["data"][0]["url"]
|
49 |
-
x = openai.ChatCompletion.create(
|
50 |
-
model="gpt-3.5-turbo",
|
51 |
-
messages=[{"role": "user", "content": question}],
|
52 |
-
)
|
53 |
-
LOGS.debug(f'Token Used on ({question}) > {x["usage"]["total_tokens"]}')
|
54 |
-
return x["choices"][0]["message"]["content"].lstrip("+AFw-n")
|
55 |
-
|
56 |
-
@ultroid_cmd(pattern="(chat)?gpt( (.*)|$)")
|
57 |
-
async def openai_chat_gpt(e):
|
58 |
-
api_key = udB.get_key("OPENAI_API")
|
59 |
-
gen_image = False
|
60 |
-
if not api_key:
|
61 |
-
return await e.eor("OPENAI_API key missing..")
|
62 |
-
|
63 |
-
args = e.pattern_match.group(3)
|
64 |
-
reply = await e.get_reply_message()
|
65 |
-
if not args:
|
66 |
-
if reply and reply.text:
|
67 |
-
args = reply.message
|
68 |
-
if not args:
|
69 |
-
return await e.eor("Gimme a Question to ask from ChatGPT")
|
70 |
-
|
71 |
-
moi = await e.eor(f"+2D3cIw")
|
72 |
-
if args.startswith("-i"):
|
73 |
-
gen_image = True
|
74 |
-
args = args[2:].strip()
|
75 |
-
try:
|
76 |
-
response = await get_gpt_answer(gen_image, args, api_key)
|
77 |
-
except Exception as exc:
|
78 |
-
LOGS.warning(exc, exc_info=True)
|
79 |
-
return await moi.edit(f"Error: +AFw-n> {exc}")
|
80 |
-
else:
|
81 |
-
if gen_image:
|
82 |
-
path, _ = await fast_download(
|
83 |
-
response, filename=check_filename("dall-e.png")
|
84 |
-
)
|
85 |
-
await e.client.send_file(
|
86 |
-
e.chat_id,
|
87 |
-
path,
|
88 |
-
caption=f"{args[:1020]}",
|
89 |
-
reply_to=e.reply_to_msg_id,
|
90 |
-
)
|
91 |
-
await moi.delete()
|
92 |
-
return remove(path)
|
93 |
-
if len(response) < 4095:
|
94 |
-
answer = f"<b></b>+AFw-n <i>{response}</i>"
|
95 |
-
return await moi.edit(answer, parse_mode="html")
|
96 |
-
with BytesIO(response.encode()) as file:
|
97 |
-
file.name = "gpt_response.txt"
|
98 |
-
await e.client.send_file(
|
99 |
-
e.chat_id, file, caption=f"{args[:1020]}", reply_to=e.reply_to_msg_id
|
100 |
-
)
|
101 |
-
await moi.delete()
|
102 |
-
```
|
103 |
-
|
104 |
-
Based on this template, whenever a new prompt is given, create a suitable Ultroid plugin code snippet that includes a POST request, handles the query, and assigns a new command.
|
105 |
-
"""
|
106 |
-
|
107 |
-
initset = False
|
108 |
-
|
109 |
-
async def pastee(data):
|
110 |
-
err, linky = await get_paste(data)
|
111 |
-
if err:
|
112 |
-
return f">> [Raw Code Pasted Here](https://spaceb.in/{linky})\n"
|
113 |
-
else:
|
114 |
-
LOGS.error(linky)
|
115 |
-
return ""
|
116 |
-
|
117 |
-
|
118 |
-
@ultroid_cmd(
|
119 |
-
pattern=r"codegen( ([\s\S]*))?$",
|
120 |
-
)
|
121 |
-
async def openai_chat_gpt(e):
|
122 |
-
global initset
|
123 |
-
api_key = "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"
|
124 |
-
if not api_key:
|
125 |
-
return await e.eor("`OPENAI_API` key missing..", time=10)
|
126 |
-
|
127 |
-
query = e.pattern_match.group(2)
|
128 |
-
reply = await e.get_reply_message()
|
129 |
-
|
130 |
-
file_content = None
|
131 |
-
|
132 |
-
if query:
|
133 |
-
# Check if query contains 'from filename'
|
134 |
-
if ' from ' in query:
|
135 |
-
query_text, filename = query.split(' from ', 1)
|
136 |
-
query_text = query_text.strip()
|
137 |
-
filename = filename.strip()
|
138 |
-
# Attempt to find and read the file from media in chat
|
139 |
-
file_found = False
|
140 |
-
async for message in e.client.iter_messages(e.chat_id, reverse=True, limit=50):
|
141 |
-
if message.media and message.file.name == filename:
|
142 |
-
if (message.file.name.endswith(".txt") or message.file.name.endswith(".py")):
|
143 |
-
file = await e.client.download_media(message)
|
144 |
-
try:
|
145 |
-
with open(file, "r", encoding='utf-8') as f:
|
146 |
-
file_content = f.read()
|
147 |
-
except Exception as exc:
|
148 |
-
LOGS.error(f"Error reading file: {exc}")
|
149 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
150 |
-
finally:
|
151 |
-
os.remove(file)
|
152 |
-
file_found = True
|
153 |
-
break
|
154 |
-
if not file_found:
|
155 |
-
return await e.eor(f"`File {filename} not found in recent messages.`", time=5)
|
156 |
-
if file_content:
|
157 |
-
query = f"{query_text}\n\n{file_content}" if query_text else file_content
|
158 |
-
else:
|
159 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
160 |
-
else:
|
161 |
-
if reply and reply.media and (reply.file.name.endswith(".txt") or reply.file.name.endswith(".py")):
|
162 |
-
# Use the query and the replied file content
|
163 |
-
file = await e.client.download_media(reply)
|
164 |
-
try:
|
165 |
-
with open(file, "r", encoding='utf-8') as f:
|
166 |
-
file_content = f.read()
|
167 |
-
except Exception as exc:
|
168 |
-
LOGS.error(f"Error reading file: {exc}")
|
169 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
170 |
-
finally:
|
171 |
-
os.remove(file)
|
172 |
-
query = f"{query}\n\n{file_content}"
|
173 |
-
elif reply and reply.message:
|
174 |
-
# Use the query and the replied text message content
|
175 |
-
query = f"{query}\n\n{reply.message}"
|
176 |
-
# Else, use query as is
|
177 |
-
else:
|
178 |
-
if reply and reply.media and (reply.file.name.endswith(".txt") or reply.file.name.endswith(".py")):
|
179 |
-
# Use the replied file content
|
180 |
-
file = await e.client.download_media(reply)
|
181 |
-
try:
|
182 |
-
with open(file, "r", encoding='utf-8') as f:
|
183 |
-
file_content = f.read()
|
184 |
-
except Exception as exc:
|
185 |
-
LOGS.error(f"Error reading file: {exc}")
|
186 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
187 |
-
finally:
|
188 |
-
os.remove(file)
|
189 |
-
query = file_content
|
190 |
-
elif reply and reply.message:
|
191 |
-
# Use the replied text message content
|
192 |
-
query = reply.message
|
193 |
-
else:
|
194 |
-
return await e.eor("`Please provide a question or reply to a message or .txt/.py file.`", time=5)
|
195 |
-
|
196 |
-
if query.strip() == "-c":
|
197 |
-
CG_GPT_CHAT_HISTORY.clear()
|
198 |
-
return await e.eor("__Cleared o1-mini Chat History!__", time=6)
|
199 |
-
|
200 |
-
if initset == False:
|
201 |
-
CG_GPT_CHAT_HISTORY.append({"role": "user", "content": initprompt})
|
202 |
-
try:
|
203 |
-
data = {
|
204 |
-
"model": "o1-mini",
|
205 |
-
"messages": list(CG_GPT_CHAT_HISTORY),
|
206 |
-
}
|
207 |
-
request = await async_searcher(
|
208 |
-
"https://api.openai.com/v1/chat/completions",
|
209 |
-
headers={
|
210 |
-
"Content-Type": "application/json",
|
211 |
-
"Authorization": f"Bearer {api_key}",
|
212 |
-
},
|
213 |
-
json=data,
|
214 |
-
re_json=True,
|
215 |
-
post=True,
|
216 |
-
)
|
217 |
-
response = request["choices"][0]["message"]["content"]
|
218 |
-
CG_GPT_CHAT_HISTORY.append({"role": "assistant", "content": response})
|
219 |
-
initset = True
|
220 |
-
except Exception as exc:
|
221 |
-
LOGS.warning(exc, exc_info=True)
|
222 |
-
CG_GPT_CHAT_HISTORY.pop()
|
223 |
-
return await eris.edit(
|
224 |
-
f"**Error while requesting data from OpenAI:** \n> `{exc}`"
|
225 |
-
)
|
226 |
-
|
227 |
-
eris = await e.eor(f"__Generating answer for:__\n`{query[:20]} ...`")
|
228 |
-
CG_GPT_CHAT_HISTORY.append({"role": "user", "content": query})
|
229 |
-
|
230 |
-
try:
|
231 |
-
data = {
|
232 |
-
"model": "o1-mini",
|
233 |
-
"messages": list(CG_GPT_CHAT_HISTORY),
|
234 |
-
}
|
235 |
-
request = await async_searcher(
|
236 |
-
"https://api.openai.com/v1/chat/completions",
|
237 |
-
headers={
|
238 |
-
"Content-Type": "application/json",
|
239 |
-
"Authorization": f"Bearer {api_key}",
|
240 |
-
},
|
241 |
-
json=data,
|
242 |
-
re_json=True,
|
243 |
-
post=True,
|
244 |
-
)
|
245 |
-
response = request["choices"][0]["message"]["content"]
|
246 |
-
CG_GPT_CHAT_HISTORY.append({"role": "assistant", "content": response})
|
247 |
-
except Exception as exc:
|
248 |
-
LOGS.warning(exc, exc_info=True)
|
249 |
-
CG_GPT_CHAT_HISTORY.pop()
|
250 |
-
return await eris.edit(
|
251 |
-
f"**Error while requesting data from OpenAI:** \n> `{exc}`"
|
252 |
-
)
|
253 |
-
|
254 |
-
LOGS.debug(f'Tokens Used on query: {request["usage"]["completion_tokens"]}')
|
255 |
-
|
256 |
-
# Truncate query to 50 characters for display
|
257 |
-
truncated_query = query[:100]
|
258 |
-
|
259 |
-
# Prepare the full message
|
260 |
-
full_message = f"**Query:**\n~ __{truncated_query}__\n\n**o1-mini:**\n~ {response}"
|
261 |
-
|
262 |
-
# Check if response contains code blocks
|
263 |
-
code_blocks = []
|
264 |
-
in_code_block = False
|
265 |
-
code_block_lines = []
|
266 |
-
for line in response.split('\n'):
|
267 |
-
if line.strip().startswith('```'):
|
268 |
-
if in_code_block:
|
269 |
-
# End of code block
|
270 |
-
in_code_block = False
|
271 |
-
code_blocks.append('\n'.join(code_block_lines))
|
272 |
-
code_block_lines = []
|
273 |
-
else:
|
274 |
-
# Start of code block
|
275 |
-
in_code_block = True
|
276 |
-
elif in_code_block:
|
277 |
-
code_block_lines.append(line)
|
278 |
-
|
279 |
-
# If the response contains code blocks, select the largest one and paste it
|
280 |
-
if code_blocks:
|
281 |
-
# Select the largest code block based on length
|
282 |
-
largest_code_block = max(code_blocks, key=lambda block: len(block))
|
283 |
-
# Upload the largest code block to spaceb.in and get the link
|
284 |
-
paste_link = await pastee(largest_code_block)
|
285 |
-
else:
|
286 |
-
paste_link = ""
|
287 |
-
|
288 |
-
if len(full_message) <= TELEGRAM_CHAR_LIMIT:
|
289 |
-
# If it fits within the limit, send as a message
|
290 |
-
await eris.edit(full_message + f"\n\n{paste_link}")
|
291 |
-
else:
|
292 |
-
# If it exceeds the limit, send as a file and include paste link
|
293 |
-
file = BytesIO(full_message.encode('utf-8'))
|
294 |
-
file.name = "o1-mini-output.txt"
|
295 |
-
await eris.respond(
|
296 |
-
"__The query and response were too long, so they have been sent as a file.__\n\n" + paste_link,
|
297 |
-
file=file,
|
298 |
-
reply_to=e.reply_to_msg_id or e.id,
|
299 |
-
link_preview=False
|
300 |
-
)
|
301 |
-
await eris.delete()
|
302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/compressor.py
DELETED
@@ -1,175 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_compressor")
|
11 |
-
|
12 |
-
|
13 |
-
import asyncio
|
14 |
-
import os
|
15 |
-
import re
|
16 |
-
import time
|
17 |
-
from datetime import datetime as dt
|
18 |
-
|
19 |
-
from telethon.errors.rpcerrorlist import MessageNotModifiedError
|
20 |
-
from telethon.tl.types import DocumentAttributeVideo
|
21 |
-
|
22 |
-
from pyUltroid.fns.tools import metadata
|
23 |
-
|
24 |
-
from . import (
|
25 |
-
ULTConfig,
|
26 |
-
bash,
|
27 |
-
downloader,
|
28 |
-
get_string,
|
29 |
-
humanbytes,
|
30 |
-
math,
|
31 |
-
mediainfo,
|
32 |
-
time_formatter,
|
33 |
-
ultroid_cmd,
|
34 |
-
uploader,
|
35 |
-
)
|
36 |
-
|
37 |
-
|
38 |
-
@ultroid_cmd(pattern="compress( (.*)|$)")
|
39 |
-
async def _(e):
|
40 |
-
cr = e.pattern_match.group(1).strip()
|
41 |
-
crf = 27
|
42 |
-
to_stream = False
|
43 |
-
if cr:
|
44 |
-
k = e.text.split()
|
45 |
-
if len(k) == 2:
|
46 |
-
crf = int(k[1]) if k[1].isdigit() else 27
|
47 |
-
elif len(k) > 2:
|
48 |
-
crf = int(k[1]) if k[1].isdigit() else 27
|
49 |
-
to_stream = "stream" in k[2]
|
50 |
-
vido = await e.get_reply_message()
|
51 |
-
if vido and vido.media and "video" in mediainfo(vido.media):
|
52 |
-
if hasattr(vido.media, "document"):
|
53 |
-
vfile = vido.media.document
|
54 |
-
name = vido.file.name
|
55 |
-
else:
|
56 |
-
vfile = vido.media
|
57 |
-
name = ""
|
58 |
-
if not name:
|
59 |
-
name = "video_" + dt.now().isoformat("_", "seconds") + ".mp4"
|
60 |
-
xxx = await e.eor(get_string("audiotools_5"))
|
61 |
-
c_time = time.time()
|
62 |
-
file = await downloader(
|
63 |
-
f"resources/downloads/{name}",
|
64 |
-
vfile,
|
65 |
-
xxx,
|
66 |
-
c_time,
|
67 |
-
f"Downloading {name}...",
|
68 |
-
)
|
69 |
-
|
70 |
-
o_size = os.path.getsize(file.name)
|
71 |
-
d_time = time.time()
|
72 |
-
diff = time_formatter((d_time - c_time) * 1000)
|
73 |
-
file_name = (file.name).split("/")[-1]
|
74 |
-
out = file_name.replace(file_name.split(".")[-1], "compressed.mkv")
|
75 |
-
await xxx.edit(
|
76 |
-
f"`Downloaded {file.name} of {humanbytes(o_size)} in {diff}.\nNow Compressing...`"
|
77 |
-
)
|
78 |
-
x, y = await bash(
|
79 |
-
f'mediainfo --fullscan """{file.name}""" | grep "Frame count"'
|
80 |
-
)
|
81 |
-
if y and y.endswith("NOT_FOUND"):
|
82 |
-
return await xxx.edit(f"ERROR: `{y}`")
|
83 |
-
total_frames = x.split(":")[1].split("\n")[0]
|
84 |
-
progress = f"progress-{c_time}.txt"
|
85 |
-
with open(progress, "w"):
|
86 |
-
pass
|
87 |
-
proce = await asyncio.create_subprocess_shell(
|
88 |
-
f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{file.name}""" -preset ultrafast -vcodec libx265 -crf {crf} -c:a copy """{out}""" -y',
|
89 |
-
stdout=asyncio.subprocess.PIPE,
|
90 |
-
stderr=asyncio.subprocess.PIPE,
|
91 |
-
)
|
92 |
-
while proce.returncode != 0:
|
93 |
-
await asyncio.sleep(3)
|
94 |
-
with open(progress, "r+") as fil:
|
95 |
-
text = fil.read()
|
96 |
-
frames = re.findall("frame=(\\d+)", text)
|
97 |
-
size = re.findall("total_size=(\\d+)", text)
|
98 |
-
speed = 0
|
99 |
-
if len(frames):
|
100 |
-
elapse = int(frames[-1])
|
101 |
-
if len(size):
|
102 |
-
size = int(size[-1])
|
103 |
-
per = elapse * 100 / int(total_frames)
|
104 |
-
time_diff = time.time() - int(d_time)
|
105 |
-
speed = round(elapse / time_diff, 2)
|
106 |
-
if int(speed) != 0:
|
107 |
-
some_eta = ((int(total_frames) - elapse) / speed) * 1000
|
108 |
-
text = f"`Compressing {file_name} at {crf} CRF.\n`"
|
109 |
-
progress_str = "`[{0}{1}] {2}%\n\n`".format(
|
110 |
-
"".join("●" for _ in range(math.floor(per / 5))),
|
111 |
-
"".join("" for _ in range(20 - math.floor(per / 5))),
|
112 |
-
round(per, 2),
|
113 |
-
)
|
114 |
-
|
115 |
-
e_size = f"{humanbytes(size)} of ~{humanbytes((size / per) * 100)}"
|
116 |
-
eta = f"~{time_formatter(some_eta)}"
|
117 |
-
try:
|
118 |
-
await xxx.edit(
|
119 |
-
text
|
120 |
-
+ progress_str
|
121 |
-
+ "`"
|
122 |
-
+ e_size
|
123 |
-
+ "`"
|
124 |
-
+ "\n\n`"
|
125 |
-
+ eta
|
126 |
-
+ "`"
|
127 |
-
)
|
128 |
-
except MessageNotModifiedError:
|
129 |
-
pass
|
130 |
-
os.remove(file.name)
|
131 |
-
c_size = os.path.getsize(out)
|
132 |
-
f_time = time.time()
|
133 |
-
difff = time_formatter((f_time - d_time) * 1000)
|
134 |
-
await xxx.edit(
|
135 |
-
f"`Compressed {humanbytes(o_size)} to {humanbytes(c_size)} in {difff}\nTrying to Upload...`"
|
136 |
-
)
|
137 |
-
differ = 100 - ((c_size / o_size) * 100)
|
138 |
-
caption = f"**Original Size: **`{humanbytes(o_size)}`\n"
|
139 |
-
caption += f"**Compressed Size: **`{humanbytes(c_size)}`\n"
|
140 |
-
caption += f"**Compression Ratio: **`{differ:.2f}%`\n"
|
141 |
-
caption += f"\n**Time Taken To Compress: **`{difff}`"
|
142 |
-
mmmm = await uploader(out, out, f_time, xxx, f"Uploading {out}...")
|
143 |
-
if to_stream:
|
144 |
-
data = await metadata(out)
|
145 |
-
width = data["width"]
|
146 |
-
height = data["height"]
|
147 |
-
duration = data["duration"]
|
148 |
-
attributes = [
|
149 |
-
DocumentAttributeVideo(
|
150 |
-
duration=duration, w=width, h=height, supports_streaming=True
|
151 |
-
)
|
152 |
-
]
|
153 |
-
await e.client.send_file(
|
154 |
-
e.chat_id,
|
155 |
-
mmmm,
|
156 |
-
thumb=ULTConfig.thumb,
|
157 |
-
caption=caption,
|
158 |
-
attributes=attributes,
|
159 |
-
force_document=False,
|
160 |
-
reply_to=e.reply_to_msg_id,
|
161 |
-
)
|
162 |
-
else:
|
163 |
-
await e.client.send_file(
|
164 |
-
e.chat_id,
|
165 |
-
mmmm,
|
166 |
-
thumb=ULTConfig.thumb,
|
167 |
-
caption=caption,
|
168 |
-
force_document=True,
|
169 |
-
reply_to=e.reply_to_msg_id,
|
170 |
-
)
|
171 |
-
await xxx.delete()
|
172 |
-
os.remove(out)
|
173 |
-
os.remove(progress)
|
174 |
-
else:
|
175 |
-
await e.eor(get_string("audiotools_8"), time=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/converter.py
DELETED
@@ -1,191 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_converter")
|
11 |
-
|
12 |
-
import os
|
13 |
-
import time
|
14 |
-
|
15 |
-
from . import LOGS
|
16 |
-
|
17 |
-
try:
|
18 |
-
import cv2
|
19 |
-
except ImportError:
|
20 |
-
cv2 = None
|
21 |
-
|
22 |
-
try:
|
23 |
-
from PIL import Image
|
24 |
-
except ImportError:
|
25 |
-
LOGS.info(f"{__file__}: PIL not Installed.")
|
26 |
-
Image = None
|
27 |
-
|
28 |
-
from telegraph import upload_file as uf
|
29 |
-
|
30 |
-
from . import (
|
31 |
-
ULTConfig,
|
32 |
-
bash,
|
33 |
-
con,
|
34 |
-
downloader,
|
35 |
-
get_paste,
|
36 |
-
get_string,
|
37 |
-
udB,
|
38 |
-
ultroid_cmd,
|
39 |
-
uploader,
|
40 |
-
)
|
41 |
-
|
42 |
-
opn = []
|
43 |
-
|
44 |
-
|
45 |
-
@ultroid_cmd(
|
46 |
-
pattern="thumbnail$",
|
47 |
-
)
|
48 |
-
async def _(e):
|
49 |
-
r = await e.get_reply_message()
|
50 |
-
if r.photo:
|
51 |
-
dl = await r.download_media()
|
52 |
-
elif r.document and r.document.thumbs:
|
53 |
-
dl = await r.download_media(thumb=-1)
|
54 |
-
else:
|
55 |
-
return await e.eor("`Reply to Photo or media with thumb...`")
|
56 |
-
variable = uf(dl)
|
57 |
-
os.remove(dl)
|
58 |
-
nn = f"https://graph.org{variable[0]}"
|
59 |
-
udB.set_key("CUSTOM_THUMBNAIL", str(nn))
|
60 |
-
await bash(f"wget {nn} -O resources/extras/ultroid.jpg")
|
61 |
-
await e.eor(get_string("cvt_6").format(nn), link_preview=False)
|
62 |
-
|
63 |
-
|
64 |
-
@ultroid_cmd(
|
65 |
-
pattern="rename( (.*)|$)",
|
66 |
-
)
|
67 |
-
async def imak(event):
|
68 |
-
reply = await event.get_reply_message()
|
69 |
-
t = time.time()
|
70 |
-
if not reply:
|
71 |
-
return await event.eor(get_string("cvt_1"))
|
72 |
-
inp = event.pattern_match.group(1).strip()
|
73 |
-
if not inp:
|
74 |
-
return await event.eor(get_string("cvt_2"))
|
75 |
-
xx = await event.eor(get_string("com_1"))
|
76 |
-
if reply.media:
|
77 |
-
if hasattr(reply.media, "document"):
|
78 |
-
file = reply.media.document
|
79 |
-
image = await downloader(
|
80 |
-
reply.file.name or str(time.time()),
|
81 |
-
reply.media.document,
|
82 |
-
xx,
|
83 |
-
t,
|
84 |
-
get_string("com_5"),
|
85 |
-
)
|
86 |
-
|
87 |
-
file = image.name
|
88 |
-
else:
|
89 |
-
file = await event.client.download_media(reply.media)
|
90 |
-
if os.path.exists(inp):
|
91 |
-
os.remove(inp)
|
92 |
-
await bash(f'mv """{file}""" """{inp}"""')
|
93 |
-
if not os.path.exists(inp) or os.path.exists(inp) and not os.path.getsize(inp):
|
94 |
-
os.rename(file, inp)
|
95 |
-
k = time.time()
|
96 |
-
xxx = await uploader(inp, inp, k, xx, get_string("com_6"))
|
97 |
-
await event.reply(
|
98 |
-
f"`{xxx.name}`",
|
99 |
-
file=xxx,
|
100 |
-
force_document=True,
|
101 |
-
thumb=ULTConfig.thumb,
|
102 |
-
)
|
103 |
-
os.remove(inp)
|
104 |
-
await xx.delete()
|
105 |
-
|
106 |
-
|
107 |
-
conv_keys = {
|
108 |
-
"img": "png",
|
109 |
-
"sticker": "webp",
|
110 |
-
"webp": "webp",
|
111 |
-
"image": "png",
|
112 |
-
"webm": "webm",
|
113 |
-
"gif": "gif",
|
114 |
-
"json": "json",
|
115 |
-
"tgs": "tgs",
|
116 |
-
}
|
117 |
-
|
118 |
-
|
119 |
-
@ultroid_cmd(
|
120 |
-
pattern="convert( (.*)|$)",
|
121 |
-
)
|
122 |
-
async def uconverter(event):
|
123 |
-
xx = await event.eor(get_string("com_1"))
|
124 |
-
a = await event.get_reply_message()
|
125 |
-
if a is None:
|
126 |
-
return await event.eor("`Reply to Photo or media with thumb...`")
|
127 |
-
input_ = event.pattern_match.group(1).strip()
|
128 |
-
b = await a.download_media("resources/downloads/")
|
129 |
-
if not b and (a.document and a.document.thumbs):
|
130 |
-
b = await a.download_media(thumb=-1)
|
131 |
-
if not b:
|
132 |
-
return await xx.edit(get_string("cvt_3"))
|
133 |
-
try:
|
134 |
-
convert = conv_keys[input_]
|
135 |
-
except KeyError:
|
136 |
-
return await xx.edit(get_string("sts_3").format("gif/img/sticker/webm"))
|
137 |
-
file = await con.convert(b, outname="ultroid", convert_to=convert)
|
138 |
-
if file:
|
139 |
-
await event.client.send_file(
|
140 |
-
event.chat_id, file, reply_to=event.reply_to_msg_id or event.id
|
141 |
-
)
|
142 |
-
os.remove(file)
|
143 |
-
await xx.delete()
|
144 |
-
|
145 |
-
|
146 |
-
@ultroid_cmd(
|
147 |
-
pattern="doc( (.*)|$)",
|
148 |
-
)
|
149 |
-
async def _(event):
|
150 |
-
input_str = event.pattern_match.group(1).strip()
|
151 |
-
if not (input_str and event.is_reply):
|
152 |
-
return await event.eor(get_string("cvt_1"), time=5)
|
153 |
-
xx = await event.eor(get_string("com_1"))
|
154 |
-
a = await event.get_reply_message()
|
155 |
-
if not a.message:
|
156 |
-
return await xx.edit(get_string("ex_1"))
|
157 |
-
with open(input_str, "w") as b:
|
158 |
-
b.write(str(a.message))
|
159 |
-
await xx.edit(f"**Packing into** `{input_str}`")
|
160 |
-
await event.reply(file=input_str, thumb=ULTConfig.thumb)
|
161 |
-
await xx.delete()
|
162 |
-
os.remove(input_str)
|
163 |
-
|
164 |
-
|
165 |
-
@ultroid_cmd(
|
166 |
-
pattern="open( (.*)|$)",
|
167 |
-
)
|
168 |
-
async def _(event):
|
169 |
-
a = await event.get_reply_message()
|
170 |
-
b = event.pattern_match.group(1).strip()
|
171 |
-
if not ((a and a.media) or (b and os.path.exists(b))):
|
172 |
-
return await event.eor(get_string("cvt_7"), time=5)
|
173 |
-
xx = await event.eor(get_string("com_1"))
|
174 |
-
rem = None
|
175 |
-
if not b:
|
176 |
-
b = await a.download_media()
|
177 |
-
rem = True
|
178 |
-
try:
|
179 |
-
with open(b) as c:
|
180 |
-
d = c.read()
|
181 |
-
except UnicodeDecodeError:
|
182 |
-
return await xx.eor(get_string("cvt_8"), time=5)
|
183 |
-
try:
|
184 |
-
await xx.edit(f"```{d}```")
|
185 |
-
except BaseException:
|
186 |
-
what, key = await get_paste(d)
|
187 |
-
await xx.edit(
|
188 |
-
f"**MESSAGE EXCEEDS TELEGRAM LIMITS**\n\nSo Pasted It On [SPACEBIN](https://spaceb.in/{key})"
|
189 |
-
)
|
190 |
-
if rem:
|
191 |
-
os.remove(b)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/core.py
DELETED
@@ -1,124 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
|
9 |
-
from . import get_help
|
10 |
-
|
11 |
-
__doc__ = get_help("help_core")
|
12 |
-
|
13 |
-
|
14 |
-
import os
|
15 |
-
|
16 |
-
from pyUltroid.startup.loader import load_addons
|
17 |
-
|
18 |
-
from . import LOGS, async_searcher, eod, get_string, safeinstall, ultroid_cmd, un_plug
|
19 |
-
|
20 |
-
|
21 |
-
@ultroid_cmd(pattern="install", fullsudo=True)
|
22 |
-
async def install(event):
|
23 |
-
await safeinstall(event)
|
24 |
-
|
25 |
-
|
26 |
-
@ultroid_cmd(
|
27 |
-
pattern=r"unload( (.*)|$)",
|
28 |
-
)
|
29 |
-
async def unload(event):
|
30 |
-
shortname = event.pattern_match.group(1).strip()
|
31 |
-
if not shortname:
|
32 |
-
await event.eor(get_string("core_9"))
|
33 |
-
return
|
34 |
-
lsd = os.listdir("addons")
|
35 |
-
zym = f"{shortname}.py"
|
36 |
-
if zym in lsd:
|
37 |
-
try:
|
38 |
-
un_plug(shortname)
|
39 |
-
await event.eor(f"**Uɴʟᴏᴀᴅᴇᴅ** `{shortname}` **Sᴜᴄᴄᴇssғᴜʟʟʏ.**", time=3)
|
40 |
-
except Exception as ex:
|
41 |
-
LOGS.exception(ex)
|
42 |
-
return await event.eor(str(ex))
|
43 |
-
elif zym in os.listdir("plugins"):
|
44 |
-
return await event.eor(get_string("core_11"), time=3)
|
45 |
-
else:
|
46 |
-
await event.eor(f"**Nᴏ Pʟᴜɢɪɴ Nᴀᴍᴇᴅ** `{shortname}`", time=3)
|
47 |
-
|
48 |
-
|
49 |
-
@ultroid_cmd(
|
50 |
-
pattern=r"uninstall( (.*)|$)",
|
51 |
-
)
|
52 |
-
async def uninstall(event):
|
53 |
-
shortname = event.pattern_match.group(1).strip()
|
54 |
-
if not shortname:
|
55 |
-
await event.eor(get_string("core_13"))
|
56 |
-
return
|
57 |
-
lsd = os.listdir("addons")
|
58 |
-
zym = f"{shortname}.py"
|
59 |
-
if zym in lsd:
|
60 |
-
try:
|
61 |
-
un_plug(shortname)
|
62 |
-
await event.eor(f"**Uɴɪɴsᴛᴀʟʟᴇᴅ** `{shortname}` **Sᴜᴄᴄᴇssғᴜʟʟʏ.**", time=3)
|
63 |
-
os.remove(f"addons/{shortname}.py")
|
64 |
-
except Exception as ex:
|
65 |
-
return await event.eor(str(ex))
|
66 |
-
elif zym in os.listdir("plugins"):
|
67 |
-
return await event.eor(get_string("core_15"), time=3)
|
68 |
-
else:
|
69 |
-
return await event.eor(f"**Nᴏ Pʟᴜɢɪɴ Nᴀᴍᴇᴅ** `{shortname}`", time=3)
|
70 |
-
|
71 |
-
|
72 |
-
@ultroid_cmd(
|
73 |
-
pattern=r"load( (.*)|$)",
|
74 |
-
fullsudo=True,
|
75 |
-
)
|
76 |
-
async def load(event):
|
77 |
-
shortname = event.pattern_match.group(1).strip()
|
78 |
-
if not shortname:
|
79 |
-
await event.eor(get_string("core_16"))
|
80 |
-
return
|
81 |
-
try:
|
82 |
-
try:
|
83 |
-
un_plug(shortname)
|
84 |
-
except BaseException:
|
85 |
-
pass
|
86 |
-
load_addons(f"addons/{shortname}.py")
|
87 |
-
await event.eor(get_string("core_17").format(shortname), time=3)
|
88 |
-
except Exception as e:
|
89 |
-
LOGS.exception(e)
|
90 |
-
await eod(
|
91 |
-
event,
|
92 |
-
get_string("core_18").format(shortname, e),
|
93 |
-
time=3,
|
94 |
-
)
|
95 |
-
|
96 |
-
|
97 |
-
@ultroid_cmd(pattern="getaddons( (.*)|$)", fullsudo=True)
|
98 |
-
async def get_the_addons_lol(event):
|
99 |
-
thelink = event.pattern_match.group(1).strip()
|
100 |
-
xx = await event.eor(get_string("com_1"))
|
101 |
-
fool = get_string("gas_1")
|
102 |
-
if thelink is None:
|
103 |
-
return await xx.eor(fool, time=10)
|
104 |
-
split_thelink = thelink.split("/")
|
105 |
-
if not ("raw" in thelink and thelink.endswith(".py")):
|
106 |
-
return await xx.eor(fool, time=10)
|
107 |
-
name_of_it = split_thelink[-1]
|
108 |
-
plug = await async_searcher(thelink)
|
109 |
-
fil = f"addons/{name_of_it}"
|
110 |
-
await xx.edit("Packing the codes...")
|
111 |
-
with open(fil, "w", encoding="utf-8") as uult:
|
112 |
-
uult.write(plug)
|
113 |
-
await xx.edit("Packed. Now loading the plugin..")
|
114 |
-
shortname = name_of_it.split(".")[0]
|
115 |
-
try:
|
116 |
-
load_addons(fil)
|
117 |
-
await xx.eor(get_string("core_17").format(shortname), time=15)
|
118 |
-
except Exception as e:
|
119 |
-
LOGS.exception(e)
|
120 |
-
await eod(
|
121 |
-
xx,
|
122 |
-
get_string("core_18").format(shortname, e),
|
123 |
-
time=3,
|
124 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/database.py
DELETED
@@ -1,77 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
|
9 |
-
from . import get_help
|
10 |
-
|
11 |
-
__doc__ = get_help("help_database")
|
12 |
-
|
13 |
-
|
14 |
-
import re
|
15 |
-
|
16 |
-
from . import Redis, eor, get_string, udB, ultroid_cmd
|
17 |
-
|
18 |
-
|
19 |
-
@ultroid_cmd(pattern="setdb( (.*)|$)", fullsudo=True)
|
20 |
-
async def _(ult):
|
21 |
-
match = ult.pattern_match.group(1).strip()
|
22 |
-
if not match:
|
23 |
-
return await ult.eor("Provide key and value to set!")
|
24 |
-
try:
|
25 |
-
delim = " " if re.search("[|]", match) is None else " | "
|
26 |
-
data = match.split(delim, maxsplit=1)
|
27 |
-
if data[0] in ["--extend", "-e"]:
|
28 |
-
data = data[1].split(maxsplit=1)
|
29 |
-
data[1] = f"{str(udB.get_key(data[0]))} {data[1]}"
|
30 |
-
udB.set_key(data[0], data[1])
|
31 |
-
await ult.eor(
|
32 |
-
f"**DB Key Value Pair Updated\nKey :** `{data[0]}`\n**Value :** `{data[1]}`"
|
33 |
-
)
|
34 |
-
|
35 |
-
except BaseException:
|
36 |
-
await ult.eor(get_string("com_7"))
|
37 |
-
|
38 |
-
|
39 |
-
@ultroid_cmd(pattern="deldb( (.*)|$)", fullsudo=True)
|
40 |
-
async def _(ult):
|
41 |
-
key = ult.pattern_match.group(1).strip()
|
42 |
-
if not key:
|
43 |
-
return await ult.eor("Give me a key name to delete!", time=5)
|
44 |
-
_ = key.split(maxsplit=1)
|
45 |
-
try:
|
46 |
-
if _[0] == "-m":
|
47 |
-
for key in _[1].split():
|
48 |
-
k = udB.del_key(key)
|
49 |
-
key = _[1]
|
50 |
-
else:
|
51 |
-
k = udB.del_key(key)
|
52 |
-
if k == 0:
|
53 |
-
return await ult.eor("`No Such Key.`")
|
54 |
-
await ult.eor(f"`Successfully deleted key {key}`")
|
55 |
-
except BaseException:
|
56 |
-
await ult.eor(get_string("com_7"))
|
57 |
-
|
58 |
-
|
59 |
-
@ultroid_cmd(pattern="rendb( (.*)|$)", fullsudo=True)
|
60 |
-
async def _(ult):
|
61 |
-
match = ult.pattern_match.group(1).strip()
|
62 |
-
if not match:
|
63 |
-
return await ult.eor("`Provide Keys name to rename..`")
|
64 |
-
delim = " " if re.search("[|]", match) is None else " | "
|
65 |
-
data = match.split(delim)
|
66 |
-
if Redis(data[0]):
|
67 |
-
try:
|
68 |
-
udB.rename(data[0], data[1])
|
69 |
-
await eor(
|
70 |
-
ult,
|
71 |
-
f"**DB Key Rename Successful\nOld Key :** `{data[0]}`\n**New Key :** `{data[1]}`",
|
72 |
-
)
|
73 |
-
|
74 |
-
except BaseException:
|
75 |
-
await ult.eor(get_string("com_7"))
|
76 |
-
else:
|
77 |
-
await ult.eor("Key not found")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/dbx.py
DELETED
@@ -1,123 +0,0 @@
|
|
1 |
-
import dns.resolver
|
2 |
-
import re
|
3 |
-
|
4 |
-
from motor.motor_asyncio import AsyncIOMotorClient
|
5 |
-
from telethon import errors
|
6 |
-
|
7 |
-
from . import ultroid_cmd, LOGS, run_async
|
8 |
-
|
9 |
-
dns.resolver.default_resolver = dns.resolver.Resolver(configure=False)
|
10 |
-
dns.resolver.default_resolver.nameservers = ['8.8.8.8']
|
11 |
-
|
12 |
-
MONGO_URI = "mongodb+srv://xannychef:GlZdS1tZ4CiKDrcN@vouchdb.elfcz.mongodb.net/?retryWrites=true&w=majority&appName=vouchdb"
|
13 |
-
mongo_client = AsyncIOMotorClient(MONGO_URI)
|
14 |
-
db = mongo_client['vouchdata']
|
15 |
-
vouch_collection = db['vouches']
|
16 |
-
|
17 |
-
BATCH_SIZE = 1000
|
18 |
-
|
19 |
-
AUTHORIZED_USERS = [5575183435]
|
20 |
-
|
21 |
-
@ultroid_cmd(pattern=r"dbx(?: |$)(.*)", allow_sudo=True)
|
22 |
-
async def db_command_handler(event):
|
23 |
-
try:
|
24 |
-
args = event.pattern_match.group(1).split()
|
25 |
-
user_id = event.sender_id
|
26 |
-
|
27 |
-
if user_id not in AUTHORIZED_USERS:
|
28 |
-
await event.reply("❌ You are not authorized to use this command.")
|
29 |
-
return
|
30 |
-
|
31 |
-
if len(args) < 2:
|
32 |
-
await event.reply("❌ Invalid command. Usage:\n.db -index <channel_id>\n.db -update <channel_id> <from_message_id>")
|
33 |
-
return
|
34 |
-
|
35 |
-
command = args[0]
|
36 |
-
try:
|
37 |
-
channel_id = int(args[1])
|
38 |
-
except ValueError:
|
39 |
-
await event.reply("❌ Channel ID must be an integer.")
|
40 |
-
return
|
41 |
-
|
42 |
-
from_message_id = int(args[2]) if command == "-update" and len(args) > 2 else None
|
43 |
-
|
44 |
-
if command not in ["-index", "-update"]:
|
45 |
-
await event.reply("❌ Invalid flag. Use -index or -update.")
|
46 |
-
return
|
47 |
-
|
48 |
-
processing_msg = await event.reply("🔍 Starting to process messages from the channel...")
|
49 |
-
|
50 |
-
total_message_count = 0
|
51 |
-
batch_data = []
|
52 |
-
progress_update_interval = 10000
|
53 |
-
|
54 |
-
try:
|
55 |
-
channel = await event.client.get_entity(channel_id)
|
56 |
-
except errors.ChannelPrivateError:
|
57 |
-
await processing_msg.edit("❌ Cannot access the specified channel. It might be private or you lack permissions.")
|
58 |
-
return
|
59 |
-
except Exception as e:
|
60 |
-
await processing_msg.edit(f"❌ Error accessing the channel: {str(e)}")
|
61 |
-
return
|
62 |
-
|
63 |
-
try:
|
64 |
-
if command == "-index":
|
65 |
-
total_messages = (await event.client.get_messages(channel, limit=1)).total
|
66 |
-
await processing_msg.edit(f"🔍 Total messages to process: {total_messages}")
|
67 |
-
|
68 |
-
async for message in event.client.iter_messages(channel_id):
|
69 |
-
await process_message(message, batch_data, processing_msg, total_message_count, progress_update_interval)
|
70 |
-
total_message_count += 1
|
71 |
-
|
72 |
-
elif command == "-update":
|
73 |
-
if not from_message_id:
|
74 |
-
await processing_msg.edit("❌ For -update, you must provide a from_message_id.")
|
75 |
-
return
|
76 |
-
|
77 |
-
async for message in event.client.iter_messages(channel_id, min_id=from_message_id):
|
78 |
-
await process_message(message, batch_data, processing_msg, total_message_count, progress_update_interval)
|
79 |
-
total_message_count += 1
|
80 |
-
|
81 |
-
if batch_data:
|
82 |
-
await vouch_collection.insert_many(batch_data)
|
83 |
-
batch_data.clear()
|
84 |
-
|
85 |
-
await processing_msg.edit(f"✅ Completed {command[1:]}ing {total_message_count} messages.")
|
86 |
-
except Exception as e:
|
87 |
-
LOGS.error(f"Error during {command[1:]}ing: {str(e)}")
|
88 |
-
await processing_msg.edit(f"❌ Error during {command[1:]}ing: {str(e)}")
|
89 |
-
except Exception as e:
|
90 |
-
LOGS.error(f"Unexpected error: {str(e)}")
|
91 |
-
await event.reply(f"❌ An unexpected error occurred: {str(e)}")
|
92 |
-
|
93 |
-
async def process_message(message, batch_data, processing_msg, total_message_count, progress_update_interval):
|
94 |
-
if message.sender and message.sender.username and message.sender.username.lower().endswith('bot'):
|
95 |
-
return
|
96 |
-
|
97 |
-
vouched_by = message.sender.username if message.sender else "Unknown"
|
98 |
-
description = message.message or "No description"
|
99 |
-
message_id = message.id
|
100 |
-
|
101 |
-
vouched_user_match = re.search(r"@\w+", description)
|
102 |
-
vouched_user = vouched_user_match.group(0) if vouched_user_match else "Unknown"
|
103 |
-
|
104 |
-
vouch_data = {
|
105 |
-
"vouched_by": vouched_by,
|
106 |
-
"description": description,
|
107 |
-
"vouched_user": vouched_user,
|
108 |
-
"message_id": message_id,
|
109 |
-
"channel_id": message.chat_id
|
110 |
-
}
|
111 |
-
|
112 |
-
existing_document = await vouch_collection.find_one({"message_id": message_id, "channel_id": message.chat_id})
|
113 |
-
if existing_document:
|
114 |
-
await vouch_collection.update_one({"_id": existing_document["_id"]}, {"$set": vouch_data})
|
115 |
-
else:
|
116 |
-
batch_data.append(vouch_data)
|
117 |
-
|
118 |
-
if len(batch_data) >= BATCH_SIZE:
|
119 |
-
await vouch_collection.insert_many(batch_data)
|
120 |
-
batch_data.clear()
|
121 |
-
|
122 |
-
if total_message_count and total_message_count % progress_update_interval == 0:
|
123 |
-
await processing_msg.edit(f"🔄 Processed {total_message_count} messages...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/devtools.py
DELETED
@@ -1,404 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_devtools")
|
11 |
-
|
12 |
-
import inspect
|
13 |
-
import sys
|
14 |
-
import traceback
|
15 |
-
from io import BytesIO, StringIO
|
16 |
-
from os import remove
|
17 |
-
from pprint import pprint
|
18 |
-
|
19 |
-
from telethon.utils import get_display_name
|
20 |
-
|
21 |
-
from pyUltroid import _ignore_eval
|
22 |
-
|
23 |
-
from . import *
|
24 |
-
|
25 |
-
# Used for Formatting Eval Code, if installed
|
26 |
-
try:
|
27 |
-
import black
|
28 |
-
except ImportError:
|
29 |
-
black = None
|
30 |
-
from random import choice
|
31 |
-
|
32 |
-
try:
|
33 |
-
from yaml import safe_load
|
34 |
-
except ImportError:
|
35 |
-
from pyUltroid.fns.tools import safe_load
|
36 |
-
try:
|
37 |
-
from telegraph import upload_file as uf
|
38 |
-
except ImportError:
|
39 |
-
uf = None
|
40 |
-
from telethon.tl import functions
|
41 |
-
|
42 |
-
fn = functions
|
43 |
-
|
44 |
-
|
45 |
-
@ultroid_cmd(
|
46 |
-
pattern="sysinfo$",
|
47 |
-
)
|
48 |
-
async def _(e):
|
49 |
-
try:
|
50 |
-
remove("Dockerfile")
|
51 |
-
except Exception:
|
52 |
-
pass
|
53 |
-
xx = await e.eor(get_string("com_1"))
|
54 |
-
x, y = await bash("neofetch|sed 's/\x1B\\[[0-9;\\?]*[a-zA-Z]//g' >> neo.txt")
|
55 |
-
if y and y.endswith("NOT_FOUND"):
|
56 |
-
return await xx.edit(f"Error: `{y}`")
|
57 |
-
with open("neo.txt", "r", encoding="utf-8") as neo:
|
58 |
-
p = (neo.read()).replace("\n\n", "")
|
59 |
-
haa = await Carbon(code=p, file_name="neofetch", backgroundColor=choice(ATRA_COL))
|
60 |
-
if isinstance(haa, dict):
|
61 |
-
await xx.edit(f"`{haa}`")
|
62 |
-
else:
|
63 |
-
await e.reply(file=haa)
|
64 |
-
await xx.delete()
|
65 |
-
remove("neo.txt")
|
66 |
-
|
67 |
-
|
68 |
-
@ultroid_cmd(pattern="bash", fullsudo=True, only_devs=True)
|
69 |
-
async def _(event):
|
70 |
-
try:
|
71 |
-
remove("Dockerfile")
|
72 |
-
except Exception:
|
73 |
-
pass
|
74 |
-
carb, rayso, yamlf = None, None, False
|
75 |
-
try:
|
76 |
-
cmd = event.text.split(" ", maxsplit=1)[1]
|
77 |
-
if cmd.split()[0] in ["-c", "--carbon"]:
|
78 |
-
cmd = cmd.split(maxsplit=1)[1]
|
79 |
-
carb = True
|
80 |
-
if cmd.split()[0] in ["-r", "--rayso"]:
|
81 |
-
cmd = cmd.split(maxsplit=1)[1]
|
82 |
-
rayso = True
|
83 |
-
except IndexError:
|
84 |
-
return await event.eor(get_string("devs_1"), time=10)
|
85 |
-
xx = await event.eor(get_string("com_1"))
|
86 |
-
reply_to_id = event.reply_to_msg_id or event.id
|
87 |
-
stdout, stderr = await bash(cmd, run_code=1)
|
88 |
-
OUT = f"**[👩💻](emoji/5301083932211550593) Ⲃⲁⲋⲏ\n\n• COMMAND:**\n`{cmd}` \n\n"
|
89 |
-
err, out = "", ""
|
90 |
-
if stderr:
|
91 |
-
err = f"**[⚠️](emoji/5213205860498549992) Ⲉɴfⲟʀmⲁtⲓⲟɴ:** \n`{stderr}`\n\n"
|
92 |
-
if stdout:
|
93 |
-
if (carb or udB.get_key("CARBON_ON_BASH")) and (
|
94 |
-
event.is_private
|
95 |
-
or event.chat.admin_rights
|
96 |
-
or event.chat.creator
|
97 |
-
or event.chat.default_banned_rights.embed_links
|
98 |
-
):
|
99 |
-
li = await Carbon(
|
100 |
-
code=stdout,
|
101 |
-
file_name="bash",
|
102 |
-
download=True,
|
103 |
-
backgroundColor=choice(ATRA_COL),
|
104 |
-
)
|
105 |
-
if isinstance(li, dict):
|
106 |
-
await xx.edit(
|
107 |
-
f"Unknown Response from Carbon: `{li}`\n\nstdout`:{stdout}`\nstderr: `{stderr}`"
|
108 |
-
)
|
109 |
-
return
|
110 |
-
url = f"https://graph.org{uf(li)[-1]}"
|
111 |
-
OUT = f"[\xad]({url}){OUT}"
|
112 |
-
out = f"**[👨💻](emoji/5319161050128459957) Ⲟυⲧⲣυⲧ:**"
|
113 |
-
remove(li)
|
114 |
-
elif (rayso or udB.get_key("RAYSO_ON_BASH")) and (
|
115 |
-
event.is_private
|
116 |
-
or event.chat.admin_rights
|
117 |
-
or event.chat.creator
|
118 |
-
or event.chat.default_banned_rights.embed_links
|
119 |
-
):
|
120 |
-
li = await Carbon(
|
121 |
-
code=stdout,
|
122 |
-
file_name="bash",
|
123 |
-
download=True,
|
124 |
-
backgroundColor=choice(ATRA_COL),
|
125 |
-
rayso=True,
|
126 |
-
)
|
127 |
-
if isinstance(li, dict):
|
128 |
-
await xx.edit(
|
129 |
-
f"Unknown Response from Carbon: `{li}`\n\nstdout`:{stdout}`\nstderr: `{stderr}`"
|
130 |
-
)
|
131 |
-
return
|
132 |
-
url = f"https://graph.org{uf(li)[-1]}"
|
133 |
-
OUT = f"[\xad]({url}){OUT}"
|
134 |
-
out = f"**[👨💻](emoji/5319161050128459957) Ⲟυⲧⲣυⲧ:**"
|
135 |
-
remove(li)
|
136 |
-
else:
|
137 |
-
if "pip" in cmd and all(":" in line for line in stdout.split("\n")):
|
138 |
-
try:
|
139 |
-
load = safe_load(stdout)
|
140 |
-
stdout = ""
|
141 |
-
for data in list(load.keys()):
|
142 |
-
res = load[data] or ""
|
143 |
-
if res and "http" not in str(res):
|
144 |
-
res = f"`{res}`"
|
145 |
-
stdout += f"**{data}** : {res}\n"
|
146 |
-
yamlf = True
|
147 |
-
except Exception as er:
|
148 |
-
stdout = f"`{stdout}`"
|
149 |
-
LOGS.exception(er)
|
150 |
-
else:
|
151 |
-
stdout = f"`{stdout}`"
|
152 |
-
out = f"**[👨💻](emoji/5319161050128459957) Ⲟυⲧⲣυⲧ:**\n{stdout}"
|
153 |
-
if not stderr and not stdout:
|
154 |
-
out = f"**[👨💻](emoji/5319161050128459957) Ⲟυⲧⲣυⲧ:**\n`Ⲋυⲥⲥⲉⲋⲋ`"
|
155 |
-
OUT += err + out
|
156 |
-
if len(OUT) > 4096:
|
157 |
-
ultd = err + out
|
158 |
-
with BytesIO(str.encode(ultd)) as out_file:
|
159 |
-
out_file.name = "bash.txt"
|
160 |
-
await event.client.send_file(
|
161 |
-
event.chat_id,
|
162 |
-
out_file,
|
163 |
-
force_document=True,
|
164 |
-
thumb=ULTConfig.thumb,
|
165 |
-
allow_cache=False,
|
166 |
-
caption=f"`{cmd}`" if len(cmd) < 998 else None,
|
167 |
-
reply_to=reply_to_id,
|
168 |
-
)
|
169 |
-
|
170 |
-
await xx.delete()
|
171 |
-
else:
|
172 |
-
await xx.edit(OUT, link_preview=not yamlf)
|
173 |
-
|
174 |
-
|
175 |
-
pp = pprint # ignore: pylint
|
176 |
-
bot = ultroid = ultroid_bot
|
177 |
-
|
178 |
-
|
179 |
-
class u:
|
180 |
-
_ = ""
|
181 |
-
|
182 |
-
|
183 |
-
def _parse_eval(value=None):
|
184 |
-
if not value:
|
185 |
-
return value
|
186 |
-
if hasattr(value, "stringify"):
|
187 |
-
try:
|
188 |
-
return value.stringify()
|
189 |
-
except TypeError:
|
190 |
-
pass
|
191 |
-
elif isinstance(value, dict):
|
192 |
-
try:
|
193 |
-
return json_parser(value, indent=1)
|
194 |
-
except BaseException:
|
195 |
-
pass
|
196 |
-
elif isinstance(value, list):
|
197 |
-
newlist = "["
|
198 |
-
for index, child in enumerate(value):
|
199 |
-
newlist += "\n " + str(_parse_eval(child))
|
200 |
-
if index < len(value) - 1:
|
201 |
-
newlist += ","
|
202 |
-
newlist += "\n]"
|
203 |
-
return newlist
|
204 |
-
return str(value)
|
205 |
-
|
206 |
-
|
207 |
-
@ultroid_cmd(pattern="eval", fullsudo=True, only_devs=True)
|
208 |
-
async def _(event):
|
209 |
-
try:
|
210 |
-
remove("Dockerfile")
|
211 |
-
except Exception:
|
212 |
-
pass
|
213 |
-
try:
|
214 |
-
cmd = event.text.split(maxsplit=1)[1]
|
215 |
-
except IndexError:
|
216 |
-
return await event.eor(get_string("devs_2"), time=5)
|
217 |
-
xx = None
|
218 |
-
mode = ""
|
219 |
-
spli = cmd.split()
|
220 |
-
|
221 |
-
async def get_():
|
222 |
-
try:
|
223 |
-
cm = cmd.split(maxsplit=1)[1]
|
224 |
-
except IndexError:
|
225 |
-
await event.eor("->> Wrong Format <<-")
|
226 |
-
cm = None
|
227 |
-
return cm
|
228 |
-
|
229 |
-
if spli[0] in ["-s", "--silent"]:
|
230 |
-
await event.delete()
|
231 |
-
mode = "silent"
|
232 |
-
elif spli[0] in ["-n", "-noedit"]:
|
233 |
-
mode = "no-edit"
|
234 |
-
xx = await event.reply(get_string("com_1"))
|
235 |
-
elif spli[0] in ["-gs", "--source"]:
|
236 |
-
mode = "gsource"
|
237 |
-
elif spli[0] in ["-ga", "--args"]:
|
238 |
-
mode = "g-args"
|
239 |
-
if mode:
|
240 |
-
cmd = await get_()
|
241 |
-
if not cmd:
|
242 |
-
return
|
243 |
-
if mode != "silent" and not xx:
|
244 |
-
xx = await event.eor(get_string("com_1"))
|
245 |
-
if black:
|
246 |
-
try:
|
247 |
-
cmd = black.format_str(cmd, mode=black.Mode())
|
248 |
-
except BaseException:
|
249 |
-
# Consider it as Code Error, and move on to be shown ahead.
|
250 |
-
pass
|
251 |
-
reply_to_id = event.reply_to_msg_id or event
|
252 |
-
if (
|
253 |
-
any(item in cmd for item in KEEP_SAFE().All)
|
254 |
-
and not event.out
|
255 |
-
and event.sender_id != ultroid_bot.uid
|
256 |
-
):
|
257 |
-
warning = await event.forward_to(udB.get_key("LOG_CHANNEL"))
|
258 |
-
await warning.reply(
|
259 |
-
f"Malicious Activities suspected by {inline_mention(await event.get_sender())}"
|
260 |
-
)
|
261 |
-
_ignore_eval.append(event.sender_id)
|
262 |
-
return await xx.edit(
|
263 |
-
f"`Malicious Activities suspected![⚠️](emoji/5213205860498549992)\nReported to owner. Aborted this request!`"
|
264 |
-
)
|
265 |
-
old_stderr = sys.stderr
|
266 |
-
old_stdout = sys.stdout
|
267 |
-
redirected_output = sys.stdout = StringIO()
|
268 |
-
redirected_error = sys.stderr = StringIO()
|
269 |
-
stdout, stderr, exc, timeg = None, None, None, None
|
270 |
-
tima = time.time()
|
271 |
-
try:
|
272 |
-
value = await aexec(cmd, event)
|
273 |
-
except Exception:
|
274 |
-
value = None
|
275 |
-
exc = traceback.format_exc()
|
276 |
-
tima = time.time() - tima
|
277 |
-
stdout = redirected_output.getvalue()
|
278 |
-
stderr = redirected_error.getvalue()
|
279 |
-
sys.stdout = old_stdout
|
280 |
-
sys.stderr = old_stderr
|
281 |
-
if value:
|
282 |
-
try:
|
283 |
-
if mode == "gsource":
|
284 |
-
exc = inspect.getsource(value)
|
285 |
-
elif mode == "g-args":
|
286 |
-
args = inspect.signature(value).parameters.values()
|
287 |
-
name = ""
|
288 |
-
if hasattr(value, "__name__"):
|
289 |
-
name = value.__name__
|
290 |
-
exc = f"**{name}**\n\n" + "\n ".join([str(arg) for arg in args])
|
291 |
-
except Exception:
|
292 |
-
exc = traceback.format_exc()
|
293 |
-
evaluation = exc or stderr or stdout or _parse_eval(value) or get_string("instu_4")
|
294 |
-
if mode == "silent":
|
295 |
-
if exc:
|
296 |
-
msg = f"[⚠️](emoji/5213205860498549992) <b>EVAL Ⲉʀʀⲟʀ\n\n• CHAT:</b> <code>{get_display_name(event.chat)}</code> [<code>{event.chat_id}</code>]"
|
297 |
-
msg += f"\n\n∆ <b>CODE:</b>\n<code>{cmd}</code>\n\n∆ <b>Ⲉʀʀⲟʀ:</b>\n<code>{exc}</code>"
|
298 |
-
log_chat = udB.get_key("LOG_CHANNEL")
|
299 |
-
if len(msg) > 4000:
|
300 |
-
with BytesIO(msg.encode()) as out_file:
|
301 |
-
out_file.name = "Eval-Error.txt"
|
302 |
-
return await event.client.send_message(
|
303 |
-
log_chat, f"`{cmd}`", file=out_file
|
304 |
-
)
|
305 |
-
await event.client.send_message(log_chat, msg, parse_mode="html")
|
306 |
-
return
|
307 |
-
tmt = tima * 1000
|
308 |
-
timef = time_formatter(tmt)
|
309 |
-
timeform = timef if timef != "0s" else f"{tmt:.3f}ms"
|
310 |
-
final_output = (
|
311 |
-
"{} **Ⲉⳳⲁⳑ** (__in {}__)\n```{}``` \n\n{} **Ⲟυⲧⲣυⲧ**: \n```{}``` \n".format(
|
312 |
-
f"[👩💻](emoji/5300928913956938544)",
|
313 |
-
timeform,
|
314 |
-
cmd,
|
315 |
-
f"[👨💻](emoji/5319161050128459957)",
|
316 |
-
evaluation,
|
317 |
-
)
|
318 |
-
)
|
319 |
-
if len(final_output) > 4096:
|
320 |
-
final_output = evaluation
|
321 |
-
with BytesIO(str.encode(final_output)) as out_file:
|
322 |
-
out_file.name = "eval.txt"
|
323 |
-
await event.client.send_file(
|
324 |
-
event.chat_id,
|
325 |
-
out_file,
|
326 |
-
force_document=True,
|
327 |
-
thumb=ULTConfig.thumb,
|
328 |
-
allow_cache=False,
|
329 |
-
caption=f"```{cmd}```" if len(cmd) < 998 else None,
|
330 |
-
reply_to=reply_to_id,
|
331 |
-
)
|
332 |
-
return await xx.delete()
|
333 |
-
await xx.edit(final_output)
|
334 |
-
|
335 |
-
|
336 |
-
def _stringify(text=None, *args, **kwargs):
|
337 |
-
if text:
|
338 |
-
u._ = text
|
339 |
-
text = _parse_eval(text)
|
340 |
-
return print(text, *args, **kwargs)
|
341 |
-
|
342 |
-
|
343 |
-
async def aexec(code, event):
|
344 |
-
exec(
|
345 |
-
(
|
346 |
-
"async def __aexec(e, client): "
|
347 |
-
+ "\n print = p = _stringify"
|
348 |
-
+ "\n message = event = e"
|
349 |
-
+ "\n u.r = reply = await event.get_reply_message()"
|
350 |
-
+ "\n chat = event.chat_id"
|
351 |
-
+ "\n u.lr = locals()"
|
352 |
-
)
|
353 |
-
+ "".join(f"\n {l}" for l in code.split("\n"))
|
354 |
-
)
|
355 |
-
|
356 |
-
return await locals()["__aexec"](event, event.client)
|
357 |
-
|
358 |
-
|
359 |
-
DUMMY_CPP = """#include <iostream>
|
360 |
-
using namespace std;
|
361 |
-
|
362 |
-
int main(){
|
363 |
-
!code
|
364 |
-
}
|
365 |
-
"""
|
366 |
-
|
367 |
-
|
368 |
-
@ultroid_cmd(pattern="cpp", only_devs=True)
|
369 |
-
async def doie(e):
|
370 |
-
match = e.text.split(" ", maxsplit=1)
|
371 |
-
try:
|
372 |
-
match = match[1]
|
373 |
-
except IndexError:
|
374 |
-
return await e.eor(get_string("devs_3"))
|
375 |
-
msg = await e.eor(get_string("com_1"))
|
376 |
-
if "main(" not in match:
|
377 |
-
new_m = "".join(" " * 4 + i + "\n" for i in match.split("\n"))
|
378 |
-
match = DUMMY_CPP.replace("!code", new_m)
|
379 |
-
open("cpp-ultroid.cpp", "w").write(match)
|
380 |
-
m = await bash("g++ -o CppUltroid cpp-ultroid.cpp")
|
381 |
-
o_cpp = f"• **Eval-Cpp**\n`{match}`"
|
382 |
-
if m[1]:
|
383 |
-
o_cpp += f"\n\n**• Error :**\n`{m[1]}`"
|
384 |
-
if len(o_cpp) > 3000:
|
385 |
-
os.remove("cpp-ultroid.cpp")
|
386 |
-
if os.path.exists("CppUltroid"):
|
387 |
-
os.remove("CppUltroid")
|
388 |
-
with BytesIO(str.encode(o_cpp)) as out_file:
|
389 |
-
out_file.name = "error.txt"
|
390 |
-
return await msg.reply(f"`{match}`", file=out_file)
|
391 |
-
return await eor(msg, o_cpp)
|
392 |
-
m = await bash("./CppUltroid")
|
393 |
-
if m[0] != "":
|
394 |
-
o_cpp += f"\n\n**• Output :**\n`{m[0]}`"
|
395 |
-
if m[1]:
|
396 |
-
o_cpp += f"\n\n**• Error :**\n`{m[1]}`"
|
397 |
-
if len(o_cpp) > 3000:
|
398 |
-
with BytesIO(str.encode(o_cpp)) as out_file:
|
399 |
-
out_file.name = "eval.txt"
|
400 |
-
await msg.reply(f"`{match}`", file=out_file)
|
401 |
-
else:
|
402 |
-
await eor(msg, o_cpp)
|
403 |
-
os.remove("CppUltroid")
|
404 |
-
os.remove("cpp-ultroid.cpp")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/downloadupload.py
DELETED
@@ -1,222 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_downloadupload")
|
11 |
-
|
12 |
-
import asyncio
|
13 |
-
import glob
|
14 |
-
import os
|
15 |
-
import time
|
16 |
-
from datetime import datetime as dt
|
17 |
-
|
18 |
-
from aiohttp.client_exceptions import InvalidURL
|
19 |
-
from telethon.errors.rpcerrorlist import MessageNotModifiedError
|
20 |
-
|
21 |
-
from pyUltroid.fns.helper import time_formatter
|
22 |
-
from pyUltroid.fns.tools import get_chat_and_msgid, set_attributes
|
23 |
-
|
24 |
-
from . import (
|
25 |
-
LOGS,
|
26 |
-
ULTConfig,
|
27 |
-
downloader,
|
28 |
-
eor,
|
29 |
-
fast_download,
|
30 |
-
get_all_files,
|
31 |
-
get_string,
|
32 |
-
progress,
|
33 |
-
time_formatter,
|
34 |
-
ultroid_cmd,
|
35 |
-
)
|
36 |
-
|
37 |
-
|
38 |
-
@ultroid_cmd(
|
39 |
-
pattern="download( (.*)|$)",
|
40 |
-
)
|
41 |
-
async def down(event):
|
42 |
-
matched = event.pattern_match.group(1).strip()
|
43 |
-
msg = await event.eor(get_string("udl_4"))
|
44 |
-
if not matched:
|
45 |
-
return await eor(msg, get_string("udl_5"), time=5)
|
46 |
-
try:
|
47 |
-
splited = matched.split(" | ")
|
48 |
-
link = splited[0]
|
49 |
-
filename = splited[1]
|
50 |
-
except IndexError:
|
51 |
-
filename = None
|
52 |
-
s_time = time.time()
|
53 |
-
try:
|
54 |
-
filename, d = await fast_download(
|
55 |
-
link,
|
56 |
-
filename,
|
57 |
-
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
|
58 |
-
progress(
|
59 |
-
d,
|
60 |
-
t,
|
61 |
-
msg,
|
62 |
-
s_time,
|
63 |
-
f"Downloading from {link}",
|
64 |
-
)
|
65 |
-
),
|
66 |
-
)
|
67 |
-
except InvalidURL:
|
68 |
-
return await msg.eor("`Invalid URL provided :(`", time=5)
|
69 |
-
await msg.eor(f"`{filename}` `downloaded in {time_formatter(d*1000)}.`")
|
70 |
-
|
71 |
-
|
72 |
-
@ultroid_cmd(
|
73 |
-
pattern="dl( (.*)|$)",
|
74 |
-
)
|
75 |
-
async def download(event):
|
76 |
-
match = event.pattern_match.group(1).strip()
|
77 |
-
if match and "t.me/" in match:
|
78 |
-
chat, msg = get_chat_and_msgid(match)
|
79 |
-
if not (chat and msg):
|
80 |
-
return await event.eor(get_string("gms_1"))
|
81 |
-
match = ""
|
82 |
-
ok = await event.client.get_messages(chat, ids=msg)
|
83 |
-
elif event.reply_to_msg_id:
|
84 |
-
ok = await event.get_reply_message()
|
85 |
-
else:
|
86 |
-
return await event.eor(get_string("cvt_3"), time=8)
|
87 |
-
xx = await event.eor(get_string("com_1"))
|
88 |
-
if not (ok and ok.media):
|
89 |
-
return await xx.eor(get_string("udl_1"), time=5)
|
90 |
-
s = dt.now()
|
91 |
-
k = time.time()
|
92 |
-
if hasattr(ok.media, "document"):
|
93 |
-
file = ok.media.document
|
94 |
-
mime_type = file.mime_type
|
95 |
-
filename = match or ok.file.name
|
96 |
-
if not filename:
|
97 |
-
if "audio" in mime_type:
|
98 |
-
filename = "audio_" + dt.now().isoformat("_", "seconds") + ".ogg"
|
99 |
-
elif "video" in mime_type:
|
100 |
-
filename = "video_" + dt.now().isoformat("_", "seconds") + ".mp4"
|
101 |
-
try:
|
102 |
-
result = await downloader(
|
103 |
-
f"resources/downloads/{filename}",
|
104 |
-
file,
|
105 |
-
xx,
|
106 |
-
k,
|
107 |
-
f"Downloading {filename}...",
|
108 |
-
)
|
109 |
-
|
110 |
-
except MessageNotModifiedError as err:
|
111 |
-
return await xx.edit(str(err))
|
112 |
-
file_name = result.name
|
113 |
-
else:
|
114 |
-
d = "resources/downloads/"
|
115 |
-
file_name = await event.client.download_media(
|
116 |
-
ok,
|
117 |
-
d,
|
118 |
-
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
|
119 |
-
progress(
|
120 |
-
d,
|
121 |
-
t,
|
122 |
-
xx,
|
123 |
-
k,
|
124 |
-
get_string("com_5"),
|
125 |
-
),
|
126 |
-
),
|
127 |
-
)
|
128 |
-
e = dt.now()
|
129 |
-
t = time_formatter(((e - s).seconds) * 1000)
|
130 |
-
await xx.eor(get_string("udl_2").format(file_name, t))
|
131 |
-
|
132 |
-
|
133 |
-
@ultroid_cmd(
|
134 |
-
pattern="ul( (.*)|$)",
|
135 |
-
)
|
136 |
-
async def _(event):
|
137 |
-
msg = await event.eor(get_string("com_1"))
|
138 |
-
match = event.pattern_match.group(1)
|
139 |
-
if match:
|
140 |
-
match = match.strip()
|
141 |
-
if not event.out and match == ".env":
|
142 |
-
return await event.reply("`You can't do this...`")
|
143 |
-
stream, force_doc, delete, thumb = (
|
144 |
-
False,
|
145 |
-
True,
|
146 |
-
False,
|
147 |
-
ULTConfig.thumb,
|
148 |
-
)
|
149 |
-
if "--stream" in match:
|
150 |
-
stream = True
|
151 |
-
force_doc = False
|
152 |
-
if "--delete" in match:
|
153 |
-
delete = True
|
154 |
-
if "--no-thumb" in match:
|
155 |
-
thumb = None
|
156 |
-
arguments = ["--stream", "--delete", "--no-thumb"]
|
157 |
-
if any(item in match for item in arguments):
|
158 |
-
match = (
|
159 |
-
match.replace("--stream", "")
|
160 |
-
.replace("--delete", "")
|
161 |
-
.replace("--no-thumb", "")
|
162 |
-
.strip()
|
163 |
-
)
|
164 |
-
if match.endswith("/"):
|
165 |
-
match += "*"
|
166 |
-
results = glob.glob(match)
|
167 |
-
if not results and os.path.exists(match):
|
168 |
-
results = [match]
|
169 |
-
if not results:
|
170 |
-
try:
|
171 |
-
await event.reply(file=match)
|
172 |
-
return await event.try_delete()
|
173 |
-
except Exception as er:
|
174 |
-
LOGS.exception(er)
|
175 |
-
return await msg.eor(get_string("ls1"))
|
176 |
-
for result in results:
|
177 |
-
if os.path.isdir(result):
|
178 |
-
c, s = 0, 0
|
179 |
-
for files in get_all_files(result):
|
180 |
-
attributes = None
|
181 |
-
if stream:
|
182 |
-
try:
|
183 |
-
attributes = await set_attributes(files)
|
184 |
-
except KeyError as er:
|
185 |
-
LOGS.exception(er)
|
186 |
-
try:
|
187 |
-
file, _ = await event.client.fast_uploader(
|
188 |
-
files, show_progress=True, event=msg, to_delete=delete
|
189 |
-
)
|
190 |
-
await event.client.send_file(
|
191 |
-
event.chat_id,
|
192 |
-
file,
|
193 |
-
supports_streaming=stream,
|
194 |
-
force_document=force_doc,
|
195 |
-
thumb=thumb,
|
196 |
-
attributes=attributes,
|
197 |
-
caption=f"`Uploaded` `{files}` `in {time_formatter(_*1000)}`",
|
198 |
-
reply_to=event.reply_to_msg_id or event,
|
199 |
-
)
|
200 |
-
s += 1
|
201 |
-
except (ValueError, IsADirectoryError):
|
202 |
-
c += 1
|
203 |
-
break
|
204 |
-
attributes = None
|
205 |
-
if stream:
|
206 |
-
try:
|
207 |
-
attributes = await set_attributes(result)
|
208 |
-
except KeyError as er:
|
209 |
-
LOGS.exception(er)
|
210 |
-
file, _ = await event.client.fast_uploader(
|
211 |
-
result, show_progress=True, event=msg, to_delete=delete
|
212 |
-
)
|
213 |
-
await event.client.send_file(
|
214 |
-
event.chat_id,
|
215 |
-
file,
|
216 |
-
supports_streaming=stream,
|
217 |
-
force_document=force_doc,
|
218 |
-
thumb=thumb,
|
219 |
-
attributes=attributes,
|
220 |
-
caption=f"`Uploaded` `{result}` `in {time_formatter(_*1000)}`",
|
221 |
-
)
|
222 |
-
await msg.try_delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/echo.py
DELETED
@@ -1,76 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_echo")
|
11 |
-
|
12 |
-
|
13 |
-
from telethon.utils import get_display_name
|
14 |
-
|
15 |
-
from pyUltroid.dB.echo_db import add_echo, check_echo, list_echo, rem_echo
|
16 |
-
|
17 |
-
from . import inline_mention, ultroid_cmd
|
18 |
-
|
19 |
-
|
20 |
-
@ultroid_cmd(pattern="addecho( (.*)|$)")
|
21 |
-
async def echo(e):
|
22 |
-
r = await e.get_reply_message()
|
23 |
-
if r:
|
24 |
-
user = r.sender_id
|
25 |
-
else:
|
26 |
-
try:
|
27 |
-
user = e.text.split()[1]
|
28 |
-
if user.startswith("@"):
|
29 |
-
ok = await e.client.get_entity(user)
|
30 |
-
user = ok.id
|
31 |
-
else:
|
32 |
-
user = int(user)
|
33 |
-
except BaseException:
|
34 |
-
return await e.eor("Reply To A user.", time=5)
|
35 |
-
if check_echo(e.chat_id, user):
|
36 |
-
return await e.eor("Echo already activated for this user.", time=5)
|
37 |
-
add_echo(e.chat_id, user)
|
38 |
-
ok = await e.client.get_entity(user)
|
39 |
-
user = inline_mention(ok)
|
40 |
-
await e.eor(f"Activated Echo For {user}.")
|
41 |
-
|
42 |
-
|
43 |
-
@ultroid_cmd(pattern="remecho( (.*)|$)")
|
44 |
-
async def rm(e):
|
45 |
-
r = await e.get_reply_message()
|
46 |
-
if r:
|
47 |
-
user = r.sender_id
|
48 |
-
else:
|
49 |
-
try:
|
50 |
-
user = e.text.split()[1]
|
51 |
-
if user.startswith("@"):
|
52 |
-
ok = await e.client.get_entity(user)
|
53 |
-
user = ok.id
|
54 |
-
else:
|
55 |
-
user = int(user)
|
56 |
-
except BaseException:
|
57 |
-
return await e.eor("Reply To A User.", time=5)
|
58 |
-
if check_echo(e.chat_id, user):
|
59 |
-
rem_echo(e.chat_id, user)
|
60 |
-
ok = await e.client.get_entity(user)
|
61 |
-
user = f"[{get_display_name(ok)}](tg://user?id={ok.id})"
|
62 |
-
return await e.eor(f"Deactivated Echo For {user}.")
|
63 |
-
await e.eor("Echo not activated for this user")
|
64 |
-
|
65 |
-
|
66 |
-
@ultroid_cmd(pattern="listecho$")
|
67 |
-
async def lstecho(e):
|
68 |
-
if k := list_echo(e.chat_id):
|
69 |
-
user = "**Activated Echo For Users:**\n\n"
|
70 |
-
for x in k:
|
71 |
-
ok = await e.client.get_entity(int(x))
|
72 |
-
kk = f"[{get_display_name(ok)}](tg://user?id={ok.id})"
|
73 |
-
user += f"•{kk}" + "\n"
|
74 |
-
await e.eor(user)
|
75 |
-
else:
|
76 |
-
await e.eor("`List is Empty, For echo`", time=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/extra.py
DELETED
@@ -1,85 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("extra")
|
11 |
-
|
12 |
-
import asyncio
|
13 |
-
|
14 |
-
from . import get_string, ultroid_cmd
|
15 |
-
|
16 |
-
|
17 |
-
@ultroid_cmd(
|
18 |
-
pattern="del$",
|
19 |
-
manager=True,
|
20 |
-
)
|
21 |
-
async def delete_it(delme):
|
22 |
-
msg_src = await delme.get_reply_message()
|
23 |
-
if not msg_src:
|
24 |
-
return
|
25 |
-
await msg_src.try_delete()
|
26 |
-
await delme.try_delete()
|
27 |
-
|
28 |
-
|
29 |
-
@ultroid_cmd(
|
30 |
-
pattern="copy$",
|
31 |
-
)
|
32 |
-
async def copy(e):
|
33 |
-
reply = await e.get_reply_message()
|
34 |
-
if reply:
|
35 |
-
await reply.reply(reply)
|
36 |
-
return await e.try_delete()
|
37 |
-
await e.eor(get_string("ex_1"), time=5)
|
38 |
-
|
39 |
-
|
40 |
-
@ultroid_cmd(
|
41 |
-
pattern="edit",
|
42 |
-
)
|
43 |
-
async def editer(edit):
|
44 |
-
message = edit.text
|
45 |
-
chat = await edit.get_input_chat()
|
46 |
-
string = str(message[6:])
|
47 |
-
reply = await edit.get_reply_message()
|
48 |
-
if reply and reply.text:
|
49 |
-
try:
|
50 |
-
await reply.edit(string)
|
51 |
-
await edit.delete()
|
52 |
-
except BaseException:
|
53 |
-
pass
|
54 |
-
else:
|
55 |
-
i = 1
|
56 |
-
async for message in edit.client.iter_messages(chat, from_user="me", limit=2):
|
57 |
-
if i == 2:
|
58 |
-
await message.edit(string)
|
59 |
-
await edit.delete()
|
60 |
-
break
|
61 |
-
i += 1
|
62 |
-
|
63 |
-
|
64 |
-
@ultroid_cmd(
|
65 |
-
pattern="reply$",
|
66 |
-
)
|
67 |
-
async def _(e):
|
68 |
-
if e.reply_to_msg_id:
|
69 |
-
chat = e.chat_id
|
70 |
-
try:
|
71 |
-
msg = (await e.client.get_messages(e.chat_id, limit=1, max_id=e.id))[0]
|
72 |
-
except IndexError:
|
73 |
-
return await e.eor(
|
74 |
-
"`You have previously sent no message to reply again...`", time=5
|
75 |
-
)
|
76 |
-
except BaseException as er:
|
77 |
-
return await e.eor(f"**ERROR:** `{er}`")
|
78 |
-
await asyncio.wait(
|
79 |
-
[
|
80 |
-
e.client.delete_messages(chat, [e.id, msg.id]),
|
81 |
-
e.client.send_message(chat, msg, reply_to=e.reply_to_msg_id),
|
82 |
-
]
|
83 |
-
)
|
84 |
-
else:
|
85 |
-
await e.try_delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/fakeaction.py
DELETED
@@ -1,36 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_fakeaction")
|
11 |
-
|
12 |
-
import math
|
13 |
-
import time
|
14 |
-
|
15 |
-
from pyUltroid.fns.admins import ban_time
|
16 |
-
|
17 |
-
from . import asyncio, get_string, ultroid_cmd
|
18 |
-
|
19 |
-
|
20 |
-
@ultroid_cmd(
|
21 |
-
pattern="f(typing|audio|contact|document|game|location|sticker|photo|round|video)( (.*)|$)"
|
22 |
-
)
|
23 |
-
async def _(e):
|
24 |
-
act = e.pattern_match.group(1).strip()
|
25 |
-
t = e.pattern_match.group(2)
|
26 |
-
if act in ["audio", "round", "video"]:
|
27 |
-
act = f"record-{act}"
|
28 |
-
if t.isdigit():
|
29 |
-
t = int(t)
|
30 |
-
elif t.endswith(("s", "h", "d", "m")):
|
31 |
-
t = math.ceil((ban_time(t)) - time.time())
|
32 |
-
else:
|
33 |
-
t = 60
|
34 |
-
await e.eor(get_string("fka_1").format(str(t)), time=5)
|
35 |
-
async with e.client.action(e.chat_id, act):
|
36 |
-
await asyncio.sleep(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/fileshare.py
DELETED
@@ -1,95 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_fileshare")
|
11 |
-
|
12 |
-
import os
|
13 |
-
|
14 |
-
from pyUltroid.dB.filestore_db import del_stored, get_stored_msg, list_all_stored_msgs
|
15 |
-
from pyUltroid.fns.tools import get_file_link
|
16 |
-
|
17 |
-
from . import HNDLR, asst, get_string, in_pattern, udB, ultroid_bot, ultroid_cmd
|
18 |
-
|
19 |
-
|
20 |
-
@ultroid_cmd(pattern="store$")
|
21 |
-
async def filestoreplg(event):
|
22 |
-
msg = await event.get_reply_message()
|
23 |
-
if not msg:
|
24 |
-
return await event.eor(get_string("fsh_3"), time=10)
|
25 |
-
# allow storing both messages and media.
|
26 |
-
filehash = await get_file_link(msg)
|
27 |
-
link_to_file = f"https://t.me/{asst.me.username}?start={filehash}"
|
28 |
-
await event.eor(
|
29 |
-
get_string("fsh_2").format(link_to_file),
|
30 |
-
link_preview=False,
|
31 |
-
)
|
32 |
-
|
33 |
-
|
34 |
-
@ultroid_cmd("delstored ?(.*)")
|
35 |
-
async def _(event):
|
36 |
-
match = event.pattern_match.group(1)
|
37 |
-
if not match:
|
38 |
-
return await event.eor("`Give stored film's link to delete.`", time=5)
|
39 |
-
match = match.split("?start=")
|
40 |
-
botusername = match[0].split("/")[-1]
|
41 |
-
if botusername != asst.me.username:
|
42 |
-
return await event.eor(
|
43 |
-
"`Message/Media of provided link was not stored by this bot.`", time=5
|
44 |
-
)
|
45 |
-
msg_id = get_stored_msg(match[1])
|
46 |
-
if not msg_id:
|
47 |
-
return await event.eor(
|
48 |
-
"`Message/Media of provided link was already deleted.`", time=5
|
49 |
-
)
|
50 |
-
del_stored(match[1])
|
51 |
-
await ultroid_bot.delete_messages(udB.get_key("LOG_CHANNEL"), int(msg_id))
|
52 |
-
await event.eor("__Deleted__")
|
53 |
-
|
54 |
-
|
55 |
-
@ultroid_cmd("liststored$")
|
56 |
-
async def liststored(event):
|
57 |
-
files = list_all_stored_msgs()
|
58 |
-
if not files:
|
59 |
-
return await event.eor(get_string("fsh_4"), time=5)
|
60 |
-
msg = "**Stored files:**\n"
|
61 |
-
for c, i in enumerate(files, start=1):
|
62 |
-
msg += f"`{c}`. https://t.me/{asst.me.username}?start={i}\n"
|
63 |
-
if len(msg) > 4095:
|
64 |
-
with open("liststored.txt", "w") as f:
|
65 |
-
f.write(msg.replace("**", "").replace("`", ""))
|
66 |
-
await event.reply(get_string("fsh_1"), file="liststored.txt")
|
67 |
-
os.remove("liststored.txt")
|
68 |
-
return
|
69 |
-
await event.eor(msg, link_preview=False)
|
70 |
-
|
71 |
-
|
72 |
-
@in_pattern("filestore", owner=True)
|
73 |
-
async def file_short(event):
|
74 |
-
all_ = list_all_stored_msgs()
|
75 |
-
res = []
|
76 |
-
if all_:
|
77 |
-
LOG_CHA = udB.get_key("LOG_CHANNEL")
|
78 |
-
for msg in all_[:50]:
|
79 |
-
m_id = get_stored_msg(msg)
|
80 |
-
if not m_id:
|
81 |
-
continue
|
82 |
-
message = await asst.get_messages(LOG_CHA, ids=m_id)
|
83 |
-
if not message:
|
84 |
-
continue
|
85 |
-
if message.media:
|
86 |
-
res.append(await event.builder.document(title=msg, file=message.media))
|
87 |
-
elif message.text:
|
88 |
-
res.append(
|
89 |
-
await event.builder.article(title=message.text, text=message.text)
|
90 |
-
)
|
91 |
-
if not res:
|
92 |
-
title = "You have no stored file :("
|
93 |
-
text = f"{title}\n\nRead `{HNDLR}help fileshare` to know how to store."
|
94 |
-
return await event.answer([await event.builder.article(title=title, text=text)])
|
95 |
-
await event.answer(res, switch_pm="• File Store •", switch_pm_param="start")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/filter.py
DELETED
@@ -1,102 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_filter")
|
11 |
-
|
12 |
-
import os
|
13 |
-
import re
|
14 |
-
|
15 |
-
from telegraph import upload_file as uf
|
16 |
-
from telethon.tl.types import User
|
17 |
-
from telethon.utils import pack_bot_file_id
|
18 |
-
|
19 |
-
from pyUltroid.dB.filter_db import add_filter, get_filter, list_filter, rem_filter
|
20 |
-
from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
|
21 |
-
|
22 |
-
from . import events, get_string, mediainfo, udB, ultroid_bot, ultroid_cmd
|
23 |
-
from ._inline import something
|
24 |
-
|
25 |
-
|
26 |
-
@ultroid_cmd(pattern="addfilter( (.*)|$)")
|
27 |
-
async def af(e):
|
28 |
-
wrd = (e.pattern_match.group(1).strip()).lower()
|
29 |
-
wt = await e.get_reply_message()
|
30 |
-
chat = e.chat_id
|
31 |
-
if not (wt and wrd):
|
32 |
-
return await e.eor(get_string("flr_1"))
|
33 |
-
btn = format_btn(wt.buttons) if wt.buttons else None
|
34 |
-
if wt and wt.media:
|
35 |
-
wut = mediainfo(wt.media)
|
36 |
-
if wut.startswith(("pic", "gif")):
|
37 |
-
dl = await wt.download_media()
|
38 |
-
variable = uf(dl)
|
39 |
-
m = f"https://graph.org{variable[0]}"
|
40 |
-
elif wut == "video":
|
41 |
-
if wt.media.document.size > 8 * 1000 * 1000:
|
42 |
-
return await e.eor(get_string("com_4"), time=5)
|
43 |
-
dl = await wt.download_media()
|
44 |
-
variable = uf(dl)
|
45 |
-
os.remove(dl)
|
46 |
-
m = f"https://graph.org{variable[0]}"
|
47 |
-
else:
|
48 |
-
m = pack_bot_file_id(wt.media)
|
49 |
-
if wt.text:
|
50 |
-
txt = wt.text
|
51 |
-
if not btn:
|
52 |
-
txt, btn = get_msg_button(wt.text)
|
53 |
-
add_filter(chat, wrd, txt, m, btn)
|
54 |
-
else:
|
55 |
-
add_filter(chat, wrd, None, m, btn)
|
56 |
-
else:
|
57 |
-
txt = wt.text
|
58 |
-
if not btn:
|
59 |
-
txt, btn = get_msg_button(wt.text)
|
60 |
-
add_filter(chat, wrd, txt, None, btn)
|
61 |
-
await e.eor(get_string("flr_4").format(wrd))
|
62 |
-
ultroid_bot.add_handler(filter_func, events.NewMessage())
|
63 |
-
|
64 |
-
|
65 |
-
@ultroid_cmd(pattern="remfilter( (.*)|$)")
|
66 |
-
async def rf(e):
|
67 |
-
wrd = (e.pattern_match.group(1).strip()).lower()
|
68 |
-
chat = e.chat_id
|
69 |
-
if not wrd:
|
70 |
-
return await e.eor(get_string("flr_3"))
|
71 |
-
rem_filter(int(chat), wrd)
|
72 |
-
await e.eor(get_string("flr_5").format(wrd))
|
73 |
-
|
74 |
-
|
75 |
-
@ultroid_cmd(pattern="listfilter$")
|
76 |
-
async def lsnote(e):
|
77 |
-
if x := list_filter(e.chat_id):
|
78 |
-
sd = "Filters Found In This Chats Are\n\n"
|
79 |
-
return await e.eor(sd + x)
|
80 |
-
await e.eor(get_string("flr_6"))
|
81 |
-
|
82 |
-
|
83 |
-
async def filter_func(e):
|
84 |
-
if isinstance(e.sender, User) and e.sender.bot:
|
85 |
-
return
|
86 |
-
xx = (e.text).lower()
|
87 |
-
chat = e.chat_id
|
88 |
-
if x := get_filter(chat):
|
89 |
-
for c in x:
|
90 |
-
pat = r"( |^|[^\w])" + re.escape(c) + r"( |$|[^\w])"
|
91 |
-
if re.search(pat, xx):
|
92 |
-
if k := x.get(c):
|
93 |
-
msg = k["msg"]
|
94 |
-
media = k["media"]
|
95 |
-
if k.get("button"):
|
96 |
-
btn = create_tl_btn(k["button"])
|
97 |
-
return await something(e, msg, media, btn)
|
98 |
-
await e.reply(msg, file=media)
|
99 |
-
|
100 |
-
|
101 |
-
if udB.get_key("FILTERS"):
|
102 |
-
ultroid_bot.add_handler(filter_func, events.NewMessage())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/flux2.py
DELETED
@@ -1,95 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
import os
|
3 |
-
import json
|
4 |
-
from . import ultroid_cmd, LOGS, fast_download
|
5 |
-
|
6 |
-
@ultroid_cmd(pattern="flux2(?:\s+(-p1|-p2|-l1|-l2|-s1|-s2|-hd)\s+(.*))?$")
|
7 |
-
async def codegen(e):
|
8 |
-
# Default to "portrait_16_9" if no specific command is provided
|
9 |
-
args = e.pattern_match.group(2)
|
10 |
-
size_option = e.pattern_match.group(1) or "portrait_16_9"
|
11 |
-
|
12 |
-
# Map the size_option to the corresponding image size
|
13 |
-
size_mapping = {
|
14 |
-
"-p1": "portrait_4_3",
|
15 |
-
"-p2": "portrait_16_9",
|
16 |
-
"-l1": "landscape_4_3",
|
17 |
-
"-l2": "landscape_16_9",
|
18 |
-
"-s1": "square",
|
19 |
-
"-s2": "square_hd",
|
20 |
-
"-hd": "square_hd"
|
21 |
-
}
|
22 |
-
image_size = size_mapping.get(size_option, "portrait_16_9")
|
23 |
-
|
24 |
-
# Handle when no prompt is provided
|
25 |
-
if not args:
|
26 |
-
reply = await e.get_reply_message()
|
27 |
-
if reply and reply.text:
|
28 |
-
args = reply.text
|
29 |
-
if not args:
|
30 |
-
return await e.eor("Please provide a prompt to generate images.")
|
31 |
-
|
32 |
-
# Prepare the request
|
33 |
-
API_URL = "http://fal.run/fal-ai/flux/schnell"
|
34 |
-
headers = {
|
35 |
-
"user-agent": "Python/3.x",
|
36 |
-
"content-type": "application/json; charset=utf-8",
|
37 |
-
"accept-encoding": "gzip",
|
38 |
-
"authorization": "Key f2438e21-b687-46c3-998f-0ed0deed8778:6a073a3d9bb73a9ed1c7aa8e8d905ced"
|
39 |
-
}
|
40 |
-
data = {
|
41 |
-
"prompt": args,
|
42 |
-
"image_size": image_size,
|
43 |
-
"num_inference_steps": 4,
|
44 |
-
"num_images": 4,
|
45 |
-
"embeddings": [],
|
46 |
-
"format": "jpeg",
|
47 |
-
"sync_mode": False,
|
48 |
-
"seed": "0",
|
49 |
-
"enable_safety_checker": False
|
50 |
-
}
|
51 |
-
|
52 |
-
# Notify the user that image generation is in progress
|
53 |
-
moi = await e.eor("🔄 Generating images, please wait...")
|
54 |
-
|
55 |
-
try:
|
56 |
-
response = requests.post(API_URL, headers=headers, json=data)
|
57 |
-
|
58 |
-
if response.status_code != 200:
|
59 |
-
LOGS.error(f"Request failed with status code {response.status_code}")
|
60 |
-
return await moi.edit("Failed to generate images. Please try again later.")
|
61 |
-
|
62 |
-
images = response.json().get("images", [])
|
63 |
-
if not images:
|
64 |
-
return await moi.edit("No images were generated.")
|
65 |
-
|
66 |
-
# Download images
|
67 |
-
image_paths = await download_images([img["url"] for img in images])
|
68 |
-
|
69 |
-
# Send images as a group
|
70 |
-
await send_images_as_group(e, args, image_paths)
|
71 |
-
|
72 |
-
# Clean up the files after sending
|
73 |
-
for path in image_paths:
|
74 |
-
os.remove(path)
|
75 |
-
|
76 |
-
await moi.delete()
|
77 |
-
|
78 |
-
except Exception as exc:
|
79 |
-
LOGS.error(f"Error: {exc}")
|
80 |
-
await moi.edit(f"An error occurred: {exc}")
|
81 |
-
|
82 |
-
async def download_images(image_urls):
|
83 |
-
downloaded_paths = []
|
84 |
-
for i, url in enumerate(image_urls, start=1):
|
85 |
-
filename = f"image_{i}.png"
|
86 |
-
path, _ = await fast_download(url, filename=filename)
|
87 |
-
downloaded_paths.append(path)
|
88 |
-
return downloaded_paths
|
89 |
-
|
90 |
-
async def send_images_as_group(e, query, image_paths):
|
91 |
-
caption = f"^^{query}^^"
|
92 |
-
media = [await e.client.upload_file(path) for path in image_paths]
|
93 |
-
await e.client.send_message(
|
94 |
-
e.chat_id, caption, file=media, parse_mode="markdown", reply_to=e.reply_to_msg_id
|
95 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/fontgen.py
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
|
8 |
-
from . import get_help
|
9 |
-
|
10 |
-
__doc__ = get_help("help_fontgen")
|
11 |
-
|
12 |
-
import string
|
13 |
-
|
14 |
-
from . import eod, ultroid_cmd
|
15 |
-
|
16 |
-
_default = string.ascii_letters
|
17 |
-
Fonts = {
|
18 |
-
"small caps": "ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘϙʀsᴛᴜᴠᴡxʏᴢABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
19 |
-
"monospace": "𝚊𝚋𝚌𝚍𝚎𝚏𝚐𝚑𝚒𝚓𝚔𝚕𝚖𝚗𝚘𝚙𝚚𝚛𝚜𝚝𝚞𝚟𝚠𝚡𝚢𝚣𝙰𝙱𝙲𝙳𝙴𝙵𝙶𝙷𝙸𝙹𝙺𝙻𝙼𝙽𝙾𝙿𝚀𝚁𝚂𝚃𝚄𝚅𝚆𝚇𝚈𝚉",
|
20 |
-
"double stroke": "𝕒𝕓𝕔𝕕𝕖𝕗𝕘𝕙𝕚𝕛𝕜𝕝𝕞𝕟𝕠𝕡𝕢𝕣𝕤𝕥𝕦𝕧𝕨𝕩𝕪𝕫𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ",
|
21 |
-
"script royal": "𝒶𝒷𝒸𝒹𝑒𝒻𝑔𝒽𝒾𝒿𝓀𝓁𝓂𝓃𝑜𝓅𝓆𝓇𝓈𝓉𝓊𝓋𝓌𝓍𝓎𝓏𝒜ℬ𝒞𝒟ℰℱ𝒢ℋℐ𝒥𝒦ℒℳ𝒩𝒪𝒫𝒬ℛ𝒮𝒯𝒰𝒱𝒲𝒳𝒴𝒵",
|
22 |
-
}
|
23 |
-
|
24 |
-
|
25 |
-
@ultroid_cmd(
|
26 |
-
pattern="font( (.*)|$)",
|
27 |
-
)
|
28 |
-
async def _(e):
|
29 |
-
input = e.pattern_match.group(1).strip()
|
30 |
-
reply = await e.get_reply_message()
|
31 |
-
if not input:
|
32 |
-
m = "**Available Fonts**\n\n"
|
33 |
-
for x in Fonts.keys():
|
34 |
-
m += f"• `{x}`\n"
|
35 |
-
return await e.eor(m, time=5)
|
36 |
-
if not reply:
|
37 |
-
try:
|
38 |
-
_ = input.split(":", maxsplit=1)
|
39 |
-
font = _[0][:-1]
|
40 |
-
text = _[1]
|
41 |
-
except IndexError:
|
42 |
-
return await eod(e, help)
|
43 |
-
elif not input:
|
44 |
-
return await eod(e, "`Give font dude :/`")
|
45 |
-
else:
|
46 |
-
font = input
|
47 |
-
text = reply.message
|
48 |
-
if font not in Fonts.keys():
|
49 |
-
return await e.eor(f"`{font} not in font list`.", time=5)
|
50 |
-
msg = gen_font(text, Fonts[font])
|
51 |
-
await e.eor(msg)
|
52 |
-
|
53 |
-
|
54 |
-
def gen_font(text, new_font):
|
55 |
-
new_font = " ".join(new_font).split()
|
56 |
-
for q in text:
|
57 |
-
if q in _default:
|
58 |
-
new = new_font[_default.index(q)]
|
59 |
-
text = text.replace(q, new)
|
60 |
-
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/forcesubscribe.py
DELETED
@@ -1,179 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
"""
|
8 |
-
✘ Commands Available -
|
9 |
-
|
10 |
-
• `{i}fsub <chat username><id>`
|
11 |
-
Enable ForceSub in Used Chat !
|
12 |
-
|
13 |
-
• `{i}checkfsub`
|
14 |
-
Check/Get Active ForceSub Setting of Used Chat.
|
15 |
-
|
16 |
-
• `{i}remfsub`
|
17 |
-
Remove ForceSub from Used Chat !
|
18 |
-
|
19 |
-
Note - You Need to be Admin in Both Channel/Chats
|
20 |
-
in order to Use ForceSubscribe.
|
21 |
-
"""
|
22 |
-
|
23 |
-
import re
|
24 |
-
|
25 |
-
from telethon.errors.rpcerrorlist import ChatAdminRequiredError, UserNotParticipantError
|
26 |
-
from telethon.tl.custom import Button
|
27 |
-
from telethon.tl.functions.channels import GetParticipantRequest
|
28 |
-
from telethon.tl.functions.messages import ExportChatInviteRequest
|
29 |
-
from telethon.tl.types import (
|
30 |
-
Channel,
|
31 |
-
ChannelParticipantBanned,
|
32 |
-
ChannelParticipantLeft,
|
33 |
-
User,
|
34 |
-
)
|
35 |
-
|
36 |
-
from pyUltroid.dB.forcesub_db import add_forcesub, get_forcesetting, rem_forcesub
|
37 |
-
|
38 |
-
from . import (
|
39 |
-
LOGS,
|
40 |
-
asst,
|
41 |
-
callback,
|
42 |
-
events,
|
43 |
-
get_string,
|
44 |
-
in_pattern,
|
45 |
-
inline_mention,
|
46 |
-
udB,
|
47 |
-
ultroid_bot,
|
48 |
-
ultroid_cmd,
|
49 |
-
)
|
50 |
-
|
51 |
-
CACHE = {}
|
52 |
-
|
53 |
-
|
54 |
-
@ultroid_cmd(pattern="fsub( (.*)|$)", admins_only=True, groups_only=True)
|
55 |
-
async def addfor(e):
|
56 |
-
match = e.pattern_match.group(1).strip()
|
57 |
-
if not match:
|
58 |
-
return await e.eor(get_string("fsub_1"), time=5)
|
59 |
-
try:
|
60 |
-
match = await e.client.parse_id(match)
|
61 |
-
except BaseException:
|
62 |
-
return await e.eor(get_string("fsub_2"), time=5)
|
63 |
-
add_forcesub(e.chat_id, match)
|
64 |
-
await e.eor("Added ForceSub in This Chat !")
|
65 |
-
ultroid_bot.add_handler(force_sub, events.NewMessage(incoming=True))
|
66 |
-
|
67 |
-
|
68 |
-
@ultroid_cmd(pattern="remfsub$")
|
69 |
-
async def remor(e):
|
70 |
-
res = rem_forcesub(e.chat_id)
|
71 |
-
if not res:
|
72 |
-
return await e.eor(get_string("fsub_3"), time=5)
|
73 |
-
await e.eor("Removed ForceSub...")
|
74 |
-
|
75 |
-
|
76 |
-
@ultroid_cmd(pattern="checkfsub$")
|
77 |
-
async def getfsr(e):
|
78 |
-
res = get_forcesetting(e.chat_id)
|
79 |
-
if not res:
|
80 |
-
return await e.eor("ForceSub is Not Active In This Chat !", time=5)
|
81 |
-
cha = await e.client.get_entity(int(res))
|
82 |
-
await e.eor(f"**ForceSub Status** : `Active`\n- **{cha.title}** `({res})`")
|
83 |
-
|
84 |
-
|
85 |
-
@in_pattern("fsub( (.*)|$)", owner=True)
|
86 |
-
async def fcall(e):
|
87 |
-
match = e.pattern_match.group(1).strip()
|
88 |
-
spli = match.split("_")
|
89 |
-
user = await ultroid_bot.get_entity(int(spli[0]))
|
90 |
-
cl = await ultroid_bot.get_entity(int(spli[1]))
|
91 |
-
text = f"Hi {inline_mention(user)}, You Need to Join"
|
92 |
-
text += f" {cl.title} in order to Chat in this Group."
|
93 |
-
el = (
|
94 |
-
f"https://t.me/{cl.username}"
|
95 |
-
if cl.username
|
96 |
-
else (await ultroid_bot(ExportChatInviteRequest(cl))).link
|
97 |
-
)
|
98 |
-
|
99 |
-
res = [
|
100 |
-
await e.builder.article(
|
101 |
-
title="forcesub",
|
102 |
-
text=text,
|
103 |
-
buttons=[
|
104 |
-
[Button.url(text=get_string("fsub_4"), url=el)],
|
105 |
-
[Button.inline(get_string("fsub_5"), data=f"unm_{match}")],
|
106 |
-
],
|
107 |
-
)
|
108 |
-
]
|
109 |
-
await e.answer(res)
|
110 |
-
|
111 |
-
|
112 |
-
@callback(re.compile("unm_(.*)"))
|
113 |
-
async def diesoon(e):
|
114 |
-
match = (e.data_match.group(1)).decode("UTF-8")
|
115 |
-
spli = match.split("_")
|
116 |
-
if e.sender_id != int(spli[0]):
|
117 |
-
return await e.answer(get_string("fsub_7"), alert=True)
|
118 |
-
try:
|
119 |
-
values = await ultroid_bot(GetParticipantRequest(int(spli[1]), int(spli[0])))
|
120 |
-
if isinstance(values.participant, ChannelParticipantLeft) or (
|
121 |
-
isinstance(values.participant, ChannelParticipantBanned) and values.left
|
122 |
-
):
|
123 |
-
raise UserNotParticipantError("")
|
124 |
-
except UserNotParticipantError:
|
125 |
-
return await e.answer(
|
126 |
-
"Please Join That Channel !\nThen Click This Button !", alert=True
|
127 |
-
)
|
128 |
-
await ultroid_bot.edit_permissions(
|
129 |
-
e.chat_id, int(spli[0]), send_messages=True, until_date=None
|
130 |
-
)
|
131 |
-
await e.edit(get_string("fsub_8"))
|
132 |
-
|
133 |
-
|
134 |
-
async def force_sub(ult):
|
135 |
-
if not udB.get_key("FORCESUB"):
|
136 |
-
return
|
137 |
-
user = await ult.get_sender()
|
138 |
-
joinchat = get_forcesetting(ult.chat_id)
|
139 |
-
if (not joinchat) or (isinstance(user, User) and user.bot):
|
140 |
-
return
|
141 |
-
if CACHE.get(ult.chat_id):
|
142 |
-
if CACHE[ult.chat_id].get(user.id):
|
143 |
-
CACHE[ult.chat_id].update({user.id: CACHE[ult.chat_id][user.id] + 1})
|
144 |
-
else:
|
145 |
-
CACHE[ult.chat_id].update({user.id: 1})
|
146 |
-
else:
|
147 |
-
CACHE.update({ult.chat_id: {user.id: 1}})
|
148 |
-
count = CACHE[ult.chat_id][user.id]
|
149 |
-
if count == 11:
|
150 |
-
CACHE[ult.chat_id][user.id] = 1
|
151 |
-
return
|
152 |
-
if count in range(2, 11):
|
153 |
-
return
|
154 |
-
try:
|
155 |
-
await ultroid_bot.get_permissions(int(joinchat), user.id)
|
156 |
-
return
|
157 |
-
except UserNotParticipantError:
|
158 |
-
pass
|
159 |
-
if isinstance(user, Channel):
|
160 |
-
try:
|
161 |
-
await ultroid_bot.edit_permissions(
|
162 |
-
ult.chat_id, user.id, view_messages=False
|
163 |
-
)
|
164 |
-
return
|
165 |
-
except BaseException as er:
|
166 |
-
LOGS.exception(er)
|
167 |
-
try:
|
168 |
-
await ultroid_bot.edit_permissions(ult.chat_id, user.id, send_messages=False)
|
169 |
-
except ChatAdminRequiredError:
|
170 |
-
return
|
171 |
-
except Exception as e:
|
172 |
-
await ult.delete()
|
173 |
-
LOGS.info(e)
|
174 |
-
res = await ultroid_bot.inline_query(asst.me.username, f"fsub {user.id}_{joinchat}")
|
175 |
-
await res[0].click(ult.chat_id, reply_to=ult.id)
|
176 |
-
|
177 |
-
|
178 |
-
if udB.get_key("FORCESUB"):
|
179 |
-
ultroid_bot.add_handler(force_sub, events.NewMessage(incoming=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/gdrive.py
DELETED
@@ -1,232 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
"""
|
8 |
-
✘ Commands Available
|
9 |
-
|
10 |
-
• `{i}gdul <reply/file name>`
|
11 |
-
Reply to file to upload on Google Drive.
|
12 |
-
Add file name to upload on Google Drive.
|
13 |
-
|
14 |
-
• `{i}gdown <file id/link> | <filename>`
|
15 |
-
Download from Gdrive link or file id.
|
16 |
-
|
17 |
-
• `{i}gdsearch <file name>`
|
18 |
-
Search file name on Google Drive and get link.
|
19 |
-
|
20 |
-
• `{i}gdlist`
|
21 |
-
List all GDrive files.
|
22 |
-
|
23 |
-
• `{i}gdfolder`
|
24 |
-
Link to your Google Drive Folder.
|
25 |
-
If added then all files will be uploaded in this folder.
|
26 |
-
"""
|
27 |
-
|
28 |
-
import os
|
29 |
-
import time
|
30 |
-
|
31 |
-
from telethon.tl.types import Message
|
32 |
-
|
33 |
-
from pyUltroid.fns.gDrive import GDriveManager
|
34 |
-
from pyUltroid.fns.helper import time_formatter
|
35 |
-
|
36 |
-
from . import ULTConfig, asst, eod, eor, get_string, ultroid_cmd
|
37 |
-
|
38 |
-
|
39 |
-
@ultroid_cmd(
|
40 |
-
pattern="gdown( (.*)|$)",
|
41 |
-
fullsudo=True,
|
42 |
-
)
|
43 |
-
async def gdown(event):
|
44 |
-
GDrive = GDriveManager()
|
45 |
-
match = event.pattern_match.group(1).strip()
|
46 |
-
if not match:
|
47 |
-
return await eod(event, "`Give file id or Gdrive link to download from!`")
|
48 |
-
filename = match.split(" | ")[1].strip() if " | " in match else None
|
49 |
-
eve = await event.eor(get_string("com_1"))
|
50 |
-
_start = time.time()
|
51 |
-
status, response = await GDrive._download_file(eve, match, filename)
|
52 |
-
if not status:
|
53 |
-
return await eve.edit(response)
|
54 |
-
await eve.edit(
|
55 |
-
f"`Downloaded ``{response}`` in {time_formatter((time.time() - _start)*1000)}`"
|
56 |
-
)
|
57 |
-
|
58 |
-
|
59 |
-
@ultroid_cmd(
|
60 |
-
pattern="gdlist$",
|
61 |
-
fullsudo=True,
|
62 |
-
)
|
63 |
-
async def files(event):
|
64 |
-
GDrive = GDriveManager()
|
65 |
-
if not os.path.exists(GDrive.token_file):
|
66 |
-
return await event.eor(get_string("gdrive_6").format(asst.me.username))
|
67 |
-
eve = await event.eor(get_string("com_1"))
|
68 |
-
msg = ""
|
69 |
-
if files := GDrive._list_files:
|
70 |
-
msg += f"{len(files.keys())} files found in gdrive.\n\n"
|
71 |
-
for _ in files:
|
72 |
-
msg += f"> [{files[_]}]({_})\n"
|
73 |
-
else:
|
74 |
-
msg += "Nothing in Gdrive"
|
75 |
-
if len(msg) < 4096:
|
76 |
-
await eve.edit(msg, link_preview=False)
|
77 |
-
else:
|
78 |
-
with open("drive-files.txt", "w") as f:
|
79 |
-
f.write(
|
80 |
-
msg.replace("[", "File Name: ")
|
81 |
-
.replace("](", "\n» Link: ")
|
82 |
-
.replace(")\n", "\n\n")
|
83 |
-
)
|
84 |
-
try:
|
85 |
-
await eve.delete()
|
86 |
-
except BaseException:
|
87 |
-
pass
|
88 |
-
await event.client.send_file(
|
89 |
-
event.chat_id,
|
90 |
-
"drive-files.txt",
|
91 |
-
thumb=ULTConfig.thumb,
|
92 |
-
reply_to=event,
|
93 |
-
)
|
94 |
-
os.remove("drive-files.txt")
|
95 |
-
|
96 |
-
|
97 |
-
@ultroid_cmd(
|
98 |
-
pattern="gdul( (.*)|$)",
|
99 |
-
fullsudo=True,
|
100 |
-
)
|
101 |
-
async def _(event):
|
102 |
-
GDrive = GDriveManager()
|
103 |
-
if not os.path.exists(GDrive.token_file):
|
104 |
-
return await eod(event, get_string("gdrive_6").format(asst.me.username))
|
105 |
-
input_file = event.pattern_match.group(1).strip() or await event.get_reply_message()
|
106 |
-
if not input_file:
|
107 |
-
return await eod(event, "`Reply to file or give its location.`")
|
108 |
-
mone = await event.eor(get_string("com_1"))
|
109 |
-
if isinstance(input_file, Message):
|
110 |
-
location = "resources/downloads"
|
111 |
-
if input_file.photo:
|
112 |
-
filename = await input_file.download_media(location)
|
113 |
-
else:
|
114 |
-
filename = input_file.file.name
|
115 |
-
if not filename:
|
116 |
-
filename = str(round(time.time()))
|
117 |
-
filename = f"{location}/{filename}"
|
118 |
-
try:
|
119 |
-
filename, downloaded_in = await event.client.fast_downloader(
|
120 |
-
file=input_file.media.document,
|
121 |
-
filename=filename,
|
122 |
-
show_progress=True,
|
123 |
-
event=mone,
|
124 |
-
message=get_string("com_5"),
|
125 |
-
)
|
126 |
-
filename = filename.name
|
127 |
-
except Exception as e:
|
128 |
-
return await eor(mone, str(e), time=10)
|
129 |
-
await mone.edit(
|
130 |
-
f"`Downloaded to ``{filename}`.`",
|
131 |
-
)
|
132 |
-
else:
|
133 |
-
filename = input_file.strip()
|
134 |
-
if not os.path.exists(filename):
|
135 |
-
return await eod(
|
136 |
-
mone,
|
137 |
-
"File Not found in local server. Give me a file path :((",
|
138 |
-
time=5,
|
139 |
-
)
|
140 |
-
folder_id = None
|
141 |
-
if os.path.isdir(filename):
|
142 |
-
files = os.listdir(filename)
|
143 |
-
if not files:
|
144 |
-
return await eod(
|
145 |
-
mone, "`Requested directory is empty. Can't create empty directory.`"
|
146 |
-
)
|
147 |
-
folder_id = GDrive.create_directory(filename)
|
148 |
-
c = 0
|
149 |
-
for files in sorted(files):
|
150 |
-
file = f"{filename}/{files}"
|
151 |
-
if not os.path.isdir(file):
|
152 |
-
try:
|
153 |
-
await GDrive._upload_file(mone, path=file, folder_id=folder_id)
|
154 |
-
c += 1
|
155 |
-
except Exception as e:
|
156 |
-
return await mone.edit(
|
157 |
-
f"Exception occurred while uploading to gDrive {e}"
|
158 |
-
)
|
159 |
-
return await mone.edit(
|
160 |
-
f"`Uploaded `[{filename}](https://drive.google.com/folderview?id={folder_id})` with {c} files.`"
|
161 |
-
)
|
162 |
-
try:
|
163 |
-
g_drive_link = await GDrive._upload_file(
|
164 |
-
mone,
|
165 |
-
filename,
|
166 |
-
)
|
167 |
-
await mone.edit(
|
168 |
-
get_string("gdrive_7").format(filename.split("/")[-1], g_drive_link)
|
169 |
-
)
|
170 |
-
except Exception as e:
|
171 |
-
await mone.edit(f"Exception occurred while uploading to gDrive {e}")
|
172 |
-
|
173 |
-
|
174 |
-
@ultroid_cmd(
|
175 |
-
pattern="gdsearch( (.*)|$)",
|
176 |
-
fullsudo=True,
|
177 |
-
)
|
178 |
-
async def _(event):
|
179 |
-
GDrive = GDriveManager()
|
180 |
-
if not os.path.exists(GDrive.token_file):
|
181 |
-
return await event.eor(get_string("gdrive_6").format(asst.me.username))
|
182 |
-
input_str = event.pattern_match.group(1).strip()
|
183 |
-
if not input_str:
|
184 |
-
return await event.eor("`Give filename to search on GDrive...`")
|
185 |
-
eve = await event.eor(f"`Searching for {input_str} in G-Drive...`")
|
186 |
-
files = GDrive.search(input_str)
|
187 |
-
msg = ""
|
188 |
-
if files:
|
189 |
-
msg += (
|
190 |
-
f"{len(files.keys())} files with {input_str} in title found in GDrive.\n\n"
|
191 |
-
)
|
192 |
-
for _ in files:
|
193 |
-
msg += f"> [{files[_]}]({_})\n"
|
194 |
-
else:
|
195 |
-
msg += f"`No files with title {input_str}`"
|
196 |
-
if len(msg) < 4096:
|
197 |
-
await eve.eor(msg, link_preview=False)
|
198 |
-
else:
|
199 |
-
with open("drive-files.txt", "w") as f:
|
200 |
-
f.write(
|
201 |
-
msg.replace("[", "File Name: ")
|
202 |
-
.replace("](", "\n» Link: ")
|
203 |
-
.replace(")\n", "\n\n")
|
204 |
-
)
|
205 |
-
try:
|
206 |
-
await eve.delete()
|
207 |
-
except BaseException:
|
208 |
-
pass
|
209 |
-
await event.client.send_file(
|
210 |
-
event.chat_id,
|
211 |
-
f"{input_str}.txt",
|
212 |
-
thumb=ULTConfig.thumb,
|
213 |
-
reply_to=event,
|
214 |
-
)
|
215 |
-
os.remove(f"{input_str}.txt")
|
216 |
-
|
217 |
-
|
218 |
-
@ultroid_cmd(
|
219 |
-
pattern="gdfolder$",
|
220 |
-
fullsudo=True,
|
221 |
-
)
|
222 |
-
async def _(event):
|
223 |
-
GDrive = GDriveManager()
|
224 |
-
if not os.path.exists(GDrive.token_file):
|
225 |
-
return await event.eor(get_string("gdrive_6").format(asst.me.username))
|
226 |
-
if GDrive.folder_id:
|
227 |
-
await event.eor(
|
228 |
-
"`Your G-Drive Folder link : `\n"
|
229 |
-
+ GDrive._create_folder_link(GDrive.folder_id)
|
230 |
-
)
|
231 |
-
else:
|
232 |
-
await eod(event, "Set FOLDERID from your Assistant bot's Settings ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/gemi.py
DELETED
@@ -1,413 +0,0 @@
|
|
1 |
-
# Nimbus ~ UserBot
|
2 |
-
# Copyright (C) 2023 NimbusTheCloud
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/ufoptg/Nimbus/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/ufoptg/Nimbus/blob/main/LICENSE/>.
|
7 |
-
# by @SoulOfSukuna
|
8 |
-
"""
|
9 |
-
Gemini Command Handler
|
10 |
-
|
11 |
-
This script provides the `.gemini` command to interact with Google's Gemini AI for generating content, selecting models, and managing chat history.
|
12 |
-
|
13 |
-
Available Gemini Models:
|
14 |
-
- `gemini-2.0-flash-exp` ➔ Trait: `g2f-exp` (Default model)
|
15 |
-
- `gemini-1.5-flash` ➔ Trait: `g1f`
|
16 |
-
- `gemini-1.5-flash-8b` ➔ Trait: `g1f8b`
|
17 |
-
- `gemini-1.5-pro` ➔ Trait: `g1p`
|
18 |
-
|
19 |
-
Features:
|
20 |
-
1. Query Gemini AI:
|
21 |
-
- `.gemini <your query>` ➔ Generates a response using the currently selected model.
|
22 |
-
- Example: `.gemini Write a poem about the stars.`
|
23 |
-
|
24 |
-
2. Select a Model:
|
25 |
-
- `.gemini -m <trait>` ➔ Selects a specific model based on its trait.
|
26 |
-
- Example: `.gemini -m g1f` ➔ Switches to the `gemini-1.5-flash` model.
|
27 |
-
- If an invalid trait is provided, an error message will be returned.
|
28 |
-
|
29 |
-
3. Clear Chat History:
|
30 |
-
- `.gemini -c` ➔ Clears the chat history stored in memory.
|
31 |
-
- Example: `.gemini -c` ➔ Removes all previous queries and responses.
|
32 |
-
|
33 |
-
4. Handle Long Responses:
|
34 |
-
- If the response exceeds Telegram's character limit (4096 characters), it will be sent as a `.txt` file.
|
35 |
-
|
36 |
-
5. Reply-Based Query:
|
37 |
-
- Reply to a message with `.gemini write a cool caption for this image` ➔ Uses the replied message's content as the query and processes the image.
|
38 |
-
|
39 |
-
Examples:
|
40 |
-
- `.gemini Tell me a joke about programmers.`
|
41 |
-
- `.gemini -m g2f-exp`
|
42 |
-
- `.gemini -c`
|
43 |
-
- Reply to an image with `.gemini write a cool caption for this image`
|
44 |
-
"""
|
45 |
-
|
46 |
-
import asyncio
|
47 |
-
import mimetypes
|
48 |
-
from collections import deque, defaultdict
|
49 |
-
from io import BytesIO
|
50 |
-
from os import system, path, remove
|
51 |
-
from googleapiclient.discovery import build
|
52 |
-
import time
|
53 |
-
import logging
|
54 |
-
from bs4 import BeautifulSoup
|
55 |
-
|
56 |
-
try:
|
57 |
-
import google.generativeai as genai
|
58 |
-
except ImportError:
|
59 |
-
system("pip install -q google-generativeai")
|
60 |
-
import google.generativeai as genai
|
61 |
-
|
62 |
-
try:
|
63 |
-
from PIL import Image
|
64 |
-
except ImportError:
|
65 |
-
system("pip install -q Pillow")
|
66 |
-
from PIL import Image
|
67 |
-
|
68 |
-
from typing import Optional
|
69 |
-
|
70 |
-
from . import (
|
71 |
-
ultroid_cmd,
|
72 |
-
async_searcher,
|
73 |
-
check_filename,
|
74 |
-
udB,
|
75 |
-
LOGS,
|
76 |
-
download_file,
|
77 |
-
run_async,
|
78 |
-
)
|
79 |
-
|
80 |
-
MODELS = [
|
81 |
-
{"id": "gemini-2.0-flash-exp", "traits": ["g2f-exp"]},
|
82 |
-
{"id": "gemini-1.5-flash", "traits": ["g1f"]},
|
83 |
-
{"id": "gemini-1.5-flash-8b", "traits": ["g1f8b"]},
|
84 |
-
{"id": "gemini-1.5-pro", "traits": ["g1p"]},
|
85 |
-
]
|
86 |
-
|
87 |
-
|
88 |
-
def select_model(trait: str) -> Optional[str]:
|
89 |
-
"""Selects the Gemini model ID based on the provided trait."""
|
90 |
-
for model in MODELS:
|
91 |
-
if trait in model["traits"]:
|
92 |
-
return model["id"]
|
93 |
-
return None
|
94 |
-
|
95 |
-
logging.getLogger("googleapiclient.discovery_cache").setLevel(logging.WARNING)
|
96 |
-
|
97 |
-
CONFIG = {"model": select_model("g2f-exp")}
|
98 |
-
|
99 |
-
GEMINI_CHAT_HISTORY = defaultdict(lambda: deque(maxlen=80))
|
100 |
-
|
101 |
-
async def generate_content_with_search(prompt, model):
|
102 |
-
try:
|
103 |
-
search_results = await google_search(prompt)
|
104 |
-
|
105 |
-
search_summary = "\n".join(
|
106 |
-
[f"{idx + 1}. {res['title']} - {res['snippet']}" for idx, res in enumerate(search_results)]
|
107 |
-
)
|
108 |
-
|
109 |
-
|
110 |
-
enhanced_prompt = (
|
111 |
-
f"Use the following search results to create a comprehensive response:\n\n"
|
112 |
-
f"{search_summary}\n\n"
|
113 |
-
f"Original Query: {prompt}"
|
114 |
-
)
|
115 |
-
|
116 |
-
response = await model.generate_content_async(enhanced_prompt)
|
117 |
-
return response.text.strip()
|
118 |
-
|
119 |
-
except Exception as e:
|
120 |
-
return f"An error occurred while including search results: {e}. Generating content...\n\n{model.generate_content(prompt).text.strip()}"
|
121 |
-
|
122 |
-
async def fetch_full_content(url):
|
123 |
-
try:
|
124 |
-
api_url = f"https://scraper.api.airforce/scrape?url={url}"
|
125 |
-
response = await async_searcher(api_url)
|
126 |
-
|
127 |
-
soup = BeautifulSoup(response, "html.parser")
|
128 |
-
main_content = soup.select_one("article") or soup.select_one("main") or soup
|
129 |
-
paragraphs = [
|
130 |
-
para.get_text(separator=" ").strip()
|
131 |
-
for para in main_content.find_all("p")
|
132 |
-
if len(para.get_text(strip=True)) > 30
|
133 |
-
and not any(
|
134 |
-
keyword in para.get_text().lower()
|
135 |
-
for keyword in [
|
136 |
-
"privacy",
|
137 |
-
"cookie",
|
138 |
-
"subscribe",
|
139 |
-
"sign up",
|
140 |
-
"terms",
|
141 |
-
"all rights reserved",
|
142 |
-
"see all",
|
143 |
-
"see more",
|
144 |
-
]
|
145 |
-
)
|
146 |
-
]
|
147 |
-
full_text = (
|
148 |
-
" ".join(paragraphs[:5]) if paragraphs else "No main content available."
|
149 |
-
)
|
150 |
-
return full_text
|
151 |
-
|
152 |
-
except Exception as e:
|
153 |
-
return f"Error fetching content: {e}"
|
154 |
-
|
155 |
-
async def google_search(query):
|
156 |
-
api_key = "AIzaSyAOhKEVXRX-DJbxjyUz5Ol54qCygeRQRTA"
|
157 |
-
cse_id = "a44275f02ca2946da"
|
158 |
-
service = build("customsearch", "v1", developerKey=api_key)
|
159 |
-
|
160 |
-
results = service.cse().list(q=query, cx=cse_id, gl="AU").execute()
|
161 |
-
search_items = results.get("items", [])
|
162 |
-
|
163 |
-
search_results = await asyncio.gather(
|
164 |
-
*(fetch_search_result(item) for item in search_items)
|
165 |
-
)
|
166 |
-
|
167 |
-
return search_results
|
168 |
-
|
169 |
-
async def fetch_search_result(item):
|
170 |
-
title = item.get("title")
|
171 |
-
link = item.get("link")
|
172 |
-
snippet = item.get("snippet")
|
173 |
-
full_content = await fetch_full_content(link)
|
174 |
-
return {
|
175 |
-
"title": title,
|
176 |
-
"link": link,
|
177 |
-
"snippet": snippet,
|
178 |
-
"full_content": full_content or "No additional content available."
|
179 |
-
}
|
180 |
-
|
181 |
-
async def process_file(file_path: str) -> str:
|
182 |
-
"""
|
183 |
-
Uploads a file to Gemini and returns the file URL.
|
184 |
-
"""
|
185 |
-
try:
|
186 |
-
mime_type, _ = mimetypes.guess_type(file_path)
|
187 |
-
if not mime_type:
|
188 |
-
mime_type = 'application/octet-stream'
|
189 |
-
file_url = await asyncio.to_thread(genai.upload_file, file_path, mime_type=mime_type)
|
190 |
-
return file_url
|
191 |
-
except Exception as exc:
|
192 |
-
LOGS.error(f"File upload failed: {exc}")
|
193 |
-
raise
|
194 |
-
|
195 |
-
async def process_video_file(file_path: str) -> str:
|
196 |
-
"""
|
197 |
-
Uploads a video to Gemini and returns the file URL.
|
198 |
-
"""
|
199 |
-
try:
|
200 |
-
video_file = await asyncio.to_thread(genai.upload_file, path=file_path)
|
201 |
-
while video_file.state.name == "PROCESSING":
|
202 |
-
await asyncio.sleep(10)
|
203 |
-
video_file = genai.get_file(video_file.name)
|
204 |
-
|
205 |
-
if video_file.state.name == "FAILED":
|
206 |
-
raise ValueError(video_file.state.name)
|
207 |
-
return video_file
|
208 |
-
except Exception as exc:
|
209 |
-
LOGS.error(f"File upload failed: {exc}")
|
210 |
-
raise
|
211 |
-
|
212 |
-
async def process_image_with_pillow(file_path: str) -> Optional[str]:
|
213 |
-
"""
|
214 |
-
Processes an image file using PIL.Image, saves it temporarily,
|
215 |
-
uploads it to Gemini, and returns the file URL.
|
216 |
-
"""
|
217 |
-
try:
|
218 |
-
with Image.open(file_path) as img:
|
219 |
-
img = img.convert("RGB")
|
220 |
-
buffer = BytesIO()
|
221 |
-
buffer.name = "processed_image.jpeg"
|
222 |
-
img.save(buffer, format="JPEG", quality=90)
|
223 |
-
buffer.seek(0)
|
224 |
-
|
225 |
-
temp_image_path = "temp_processed_image.jpeg"
|
226 |
-
with open(temp_image_path, "wb") as temp_file:
|
227 |
-
temp_file.write(buffer.read())
|
228 |
-
|
229 |
-
file_url = await process_file(temp_image_path)
|
230 |
-
|
231 |
-
remove(temp_image_path)
|
232 |
-
|
233 |
-
return file_url
|
234 |
-
except Exception as exc:
|
235 |
-
LOGS.error(f"Image processing failed: {exc}")
|
236 |
-
return None
|
237 |
-
|
238 |
-
|
239 |
-
async def handle_multimodal_input(event, e) -> Optional[str]:
|
240 |
-
"""
|
241 |
-
Checks and processes images, audio, or video in a replied message.
|
242 |
-
Ensures cleanup of downloaded files.
|
243 |
-
Returns the file URL or None if processing fails.
|
244 |
-
"""
|
245 |
-
temp_file = None
|
246 |
-
try:
|
247 |
-
if event.photo:
|
248 |
-
temp_file = await event.download_media()
|
249 |
-
await e.eor("Processing image with Pillow...")
|
250 |
-
return await process_image_with_pillow(temp_file)
|
251 |
-
elif event.voice or event.audio:
|
252 |
-
temp_file = await event.download_media()
|
253 |
-
await e.eor("Uploading audio...")
|
254 |
-
return await process_file(temp_file)
|
255 |
-
elif event.video:
|
256 |
-
temp_file = await event.download_media()
|
257 |
-
await e.eor("Uploading video...")
|
258 |
-
return await process_video_file(temp_file)
|
259 |
-
except Exception as exc:
|
260 |
-
LOGS.error(f"Error processing media: {exc}")
|
261 |
-
finally:
|
262 |
-
if temp_file and path.exists(temp_file):
|
263 |
-
try:
|
264 |
-
remove(temp_file)
|
265 |
-
LOGS.info(f"Cleaned up temporary file: {temp_file}")
|
266 |
-
except Exception as cleanup_exc:
|
267 |
-
LOGS.warning(f"Failed to clean up temporary file: {cleanup_exc}")
|
268 |
-
return None
|
269 |
-
|
270 |
-
|
271 |
-
async def get_gemini_response(user_id: int, query: str, api_key: str, file_url: Optional[str] = None) -> str:
|
272 |
-
"""
|
273 |
-
Generates a response from the selected Gemini model based on the user query.
|
274 |
-
Includes the user's chat history in the request.
|
275 |
-
If a file URL is provided, it is included in the content generation.
|
276 |
-
"""
|
277 |
-
try:
|
278 |
-
genai.configure(api_key=api_key)
|
279 |
-
model = genai.GenerativeModel(CONFIG["model"])
|
280 |
-
|
281 |
-
chat_history = GEMINI_CHAT_HISTORY[user_id]
|
282 |
-
|
283 |
-
if chat_history:
|
284 |
-
formatted_history = "\n".join(
|
285 |
-
[f"{msg['role']}: {msg['content']}" for msg in chat_history]
|
286 |
-
)
|
287 |
-
if file_url:
|
288 |
-
content = [file_url, "\n\n", f"{formatted_history}\nuser: {query}"]
|
289 |
-
else:
|
290 |
-
content = f"{formatted_history}\nuser: {query}"
|
291 |
-
else:
|
292 |
-
if file_url:
|
293 |
-
content = [file_url, "\n\n", query]
|
294 |
-
else:
|
295 |
-
content = query
|
296 |
-
|
297 |
-
# Key Addition: Handle queries without file_url using Google Search
|
298 |
-
if not file_url:
|
299 |
-
response = await generate_content_with_search(query, model)
|
300 |
-
return response
|
301 |
-
|
302 |
-
response = await asyncio.to_thread(model.generate_content, content)
|
303 |
-
return response.text.strip()
|
304 |
-
except Exception as exc:
|
305 |
-
LOGS.error(f"Error generating response: {exc}")
|
306 |
-
raise
|
307 |
-
|
308 |
-
|
309 |
-
@ultroid_cmd(pattern=r"gemi(?:\s+([\s\S]*))?$")
|
310 |
-
async def gemini_handler(e):
|
311 |
-
"""
|
312 |
-
Handles the .gemini command with optional model selection.
|
313 |
-
"""
|
314 |
-
args = e.pattern_match.group(1)
|
315 |
-
|
316 |
-
trait = None
|
317 |
-
user_query = None
|
318 |
-
file_url = None
|
319 |
-
|
320 |
-
try:
|
321 |
-
user_id = e.sender.id
|
322 |
-
except AttributeError:
|
323 |
-
user_id = e.from_id.user_id
|
324 |
-
|
325 |
-
if args:
|
326 |
-
if args.startswith("-m"):
|
327 |
-
trait = args[3:].lower().strip()
|
328 |
-
selected_model = select_model(trait)
|
329 |
-
if not selected_model:
|
330 |
-
return await e.eor("❌ **Error:** Invalid model trait specified.", time=10)
|
331 |
-
CONFIG["model"] = selected_model
|
332 |
-
return await e.eor(f"✅ **Success:** Selected Model: `{CONFIG['model']}`", time=10)
|
333 |
-
elif args.strip().lower() == "-c":
|
334 |
-
GEMINI_CHAT_HISTORY[user_id].clear()
|
335 |
-
return await e.eor("🧹 **Success:** Cleared your Gemini Chat History!", time=6)
|
336 |
-
else:
|
337 |
-
user_query = args.strip()
|
338 |
-
|
339 |
-
api_key = udB.get_key("GEMINI_API")
|
340 |
-
if not api_key:
|
341 |
-
return await e.eor(
|
342 |
-
"⚠️ **Error:** `GEMINI_API` key missing. Please set it using `.setvar GEMINI_API your_api_key_here`.",
|
343 |
-
time=10,
|
344 |
-
)
|
345 |
-
|
346 |
-
query = user_query
|
347 |
-
file_url = None
|
348 |
-
|
349 |
-
reply = await e.get_reply_message()
|
350 |
-
if reply:
|
351 |
-
# New logic to handle file content
|
352 |
-
if (
|
353 |
-
reply.file
|
354 |
-
and reply.file.mime_type in ["text/x-python", "text/plain"]
|
355 |
-
):
|
356 |
-
# Download the file and read its content
|
357 |
-
file = await reply.download_media(BytesIO())
|
358 |
-
file.seek(0)
|
359 |
-
query = file.read().decode("utf-8")
|
360 |
-
|
361 |
-
multimodal_content = await handle_multimodal_input(reply, e)
|
362 |
-
if multimodal_content:
|
363 |
-
file_url = multimodal_content
|
364 |
-
if not query:
|
365 |
-
if reply.photo:
|
366 |
-
query = "Analyse this image"
|
367 |
-
elif reply.voice or reply.audio:
|
368 |
-
query = "Analyse this audio."
|
369 |
-
elif reply.video:
|
370 |
-
query = "Analyse this video"
|
371 |
-
elif reply.text and not query:
|
372 |
-
query = reply.text.strip()
|
373 |
-
|
374 |
-
if not query and not file_url:
|
375 |
-
return await e.eor(
|
376 |
-
"💬 **Usage:** `.gemini <your query>`\n*Provide a query or reply with media to generate content using Gemini AI.*",
|
377 |
-
time=5,
|
378 |
-
)
|
379 |
-
|
380 |
-
processing_message = await e.eor(f"🔄 **Processing your request using `{CONFIG['model']}`...**")
|
381 |
-
|
382 |
-
GEMINI_CHAT_HISTORY[user_id].append({"role": "user", "content": query})
|
383 |
-
|
384 |
-
try:
|
385 |
-
response = await get_gemini_response(user_id, query, api_key, file_url=file_url)
|
386 |
-
GEMINI_CHAT_HISTORY[user_id].append({"role": "assistant", "content": response})
|
387 |
-
except Exception as exc:
|
388 |
-
LOGS.warning(f"Gemini response generation failed: {exc}", exc_info=True)
|
389 |
-
if query:
|
390 |
-
GEMINI_CHAT_HISTORY[user_id].pop()
|
391 |
-
return await processing_message.edit(f"❌ **Error:** {exc}")
|
392 |
-
|
393 |
-
if len(response) < 4096:
|
394 |
-
reply_text = f"📄 **Gemini Response:**\n\n{response}"
|
395 |
-
await processing_message.edit(reply_text, parse_mode="markdown")
|
396 |
-
else:
|
397 |
-
buffer = BytesIO()
|
398 |
-
try:
|
399 |
-
buffer.write(response.encode('utf-8'))
|
400 |
-
buffer.seek(0)
|
401 |
-
buffer.name = "gemini_response.txt"
|
402 |
-
await e.client.send_file(
|
403 |
-
e.chat_id,
|
404 |
-
buffer,
|
405 |
-
caption="📄 **Gemini Response:**",
|
406 |
-
reply_to=e.reply_to_msg_id,
|
407 |
-
)
|
408 |
-
except Exception as exc:
|
409 |
-
LOGS.error(f"Error sending file: {exc}")
|
410 |
-
await processing_message.edit("❌ **Error:** Failed to send the response as a file.")
|
411 |
-
finally:
|
412 |
-
buffer.close()
|
413 |
-
await processing_message.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/giftools.py
DELETED
@@ -1,128 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
"""
|
8 |
-
✘ Commands Available
|
9 |
-
|
10 |
-
•`{i}invertgif`
|
11 |
-
Make Gif Inverted(negative).
|
12 |
-
|
13 |
-
•`{i}bwgif`
|
14 |
-
Make Gif black and white
|
15 |
-
|
16 |
-
•`{i}rvgif`
|
17 |
-
Reverse a gif
|
18 |
-
|
19 |
-
•`{i}vtog`
|
20 |
-
Reply To Video , It will Create Gif
|
21 |
-
Video to Gif
|
22 |
-
|
23 |
-
•`{i}gif <query>`
|
24 |
-
Send video regarding to query.
|
25 |
-
"""
|
26 |
-
import os
|
27 |
-
import random
|
28 |
-
import time
|
29 |
-
from datetime import datetime as dt
|
30 |
-
|
31 |
-
from . import HNDLR, LOGS, bash, downloader, get_string, mediainfo, ultroid_cmd
|
32 |
-
|
33 |
-
|
34 |
-
@ultroid_cmd(pattern="(bw|invert)gif$")
|
35 |
-
async def igif(e):
|
36 |
-
match = e.pattern_match.group(1).strip()
|
37 |
-
a = await e.get_reply_message()
|
38 |
-
if not (a and a.media):
|
39 |
-
return await e.eor("`Reply To gif only`", time=5)
|
40 |
-
wut = mediainfo(a.media)
|
41 |
-
if "gif" not in wut:
|
42 |
-
return await e.eor("`Reply To Gif Only`", time=5)
|
43 |
-
xx = await e.eor(get_string("com_1"))
|
44 |
-
z = await a.download_media()
|
45 |
-
if match == "bw":
|
46 |
-
cmd = f'ffmpeg -i "{z}" -vf format=gray ult.gif -y'
|
47 |
-
else:
|
48 |
-
cmd = f'ffmpeg -i "{z}" -vf lutyuv="y=negval:u=negval:v=negval" ult.gif -y'
|
49 |
-
try:
|
50 |
-
await bash(cmd)
|
51 |
-
await e.client.send_file(e.chat_id, "ult.gif", supports_streaming=True)
|
52 |
-
os.remove(z)
|
53 |
-
os.remove("ult.gif")
|
54 |
-
await xx.delete()
|
55 |
-
except Exception as er:
|
56 |
-
LOGS.info(er)
|
57 |
-
|
58 |
-
|
59 |
-
@ultroid_cmd(pattern="rvgif$")
|
60 |
-
async def reverse_gif(event):
|
61 |
-
a = await event.get_reply_message()
|
62 |
-
if not (a and a.media) and "video" not in mediainfo(a.media):
|
63 |
-
return await event.eor("`Reply To Video only`", time=5)
|
64 |
-
msg = await event.eor(get_string("com_1"))
|
65 |
-
file = await a.download_media()
|
66 |
-
await bash(f'ffmpeg -i "{file}" -vf reverse -af areverse reversed.mp4 -y')
|
67 |
-
await event.respond("- **Reversed Video/GIF**", file="reversed.mp4")
|
68 |
-
await msg.delete()
|
69 |
-
os.remove(file)
|
70 |
-
os.remove("reversed.mp4")
|
71 |
-
|
72 |
-
|
73 |
-
@ultroid_cmd(pattern="gif( (.*)|$)")
|
74 |
-
async def gifs(ult):
|
75 |
-
get = ult.pattern_match.group(1).strip()
|
76 |
-
xx = random.randint(0, 5)
|
77 |
-
n = 0
|
78 |
-
if ";" in get:
|
79 |
-
try:
|
80 |
-
n = int(get.split(";")[-1])
|
81 |
-
except IndexError:
|
82 |
-
pass
|
83 |
-
if not get:
|
84 |
-
return await ult.eor(f"`{HNDLR}gif <query>`")
|
85 |
-
m = await ult.eor(get_string("com_2"))
|
86 |
-
gifs = await ult.client.inline_query("gif", get)
|
87 |
-
if not n:
|
88 |
-
await gifs[xx].click(
|
89 |
-
ult.chat_id, reply_to=ult.reply_to_msg_id, silent=True, hide_via=True
|
90 |
-
)
|
91 |
-
else:
|
92 |
-
for x in range(n):
|
93 |
-
await gifs[x].click(
|
94 |
-
ult.chat_id, reply_to=ult.reply_to_msg_id, silent=True, hide_via=True
|
95 |
-
)
|
96 |
-
await m.delete()
|
97 |
-
|
98 |
-
|
99 |
-
@ultroid_cmd(pattern="vtog$")
|
100 |
-
async def vtogif(e):
|
101 |
-
a = await e.get_reply_message()
|
102 |
-
if not (a and a.media):
|
103 |
-
return await e.eor("`Reply To video only`", time=5)
|
104 |
-
wut = mediainfo(a.media)
|
105 |
-
if "video" not in wut:
|
106 |
-
return await e.eor("`Reply To Video Only`", time=5)
|
107 |
-
xx = await e.eor(get_string("com_1"))
|
108 |
-
dur = a.media.document.attributes[0].duration
|
109 |
-
tt = time.time()
|
110 |
-
if int(dur) < 120:
|
111 |
-
z = await a.download_media()
|
112 |
-
await bash(
|
113 |
-
f'ffmpeg -i {z} -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 ult.gif -y'
|
114 |
-
)
|
115 |
-
else:
|
116 |
-
filename = a.file.name
|
117 |
-
if not filename:
|
118 |
-
filename = "video_" + dt.now().isoformat("_", "seconds") + ".mp4"
|
119 |
-
vid = await downloader(filename, a.media.document, xx, tt, get_string("com_5"))
|
120 |
-
z = vid.name
|
121 |
-
await bash(
|
122 |
-
f'ffmpeg -ss 3 -t 100 -i {z} -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 ult.gif'
|
123 |
-
)
|
124 |
-
|
125 |
-
await e.client.send_file(e.chat_id, "ult.gif", support_stream=True)
|
126 |
-
os.remove(z)
|
127 |
-
os.remove("ult.gif")
|
128 |
-
await xx.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/glitch.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
"""
|
8 |
-
✘ Commands Available -
|
9 |
-
|
10 |
-
•`{i}glitch <reply to media>`
|
11 |
-
gives a glitchy gif.
|
12 |
-
"""
|
13 |
-
import os
|
14 |
-
|
15 |
-
from . import bash, get_string, mediainfo, ultroid_cmd
|
16 |
-
|
17 |
-
|
18 |
-
@ultroid_cmd(pattern="glitch$")
|
19 |
-
async def _(e):
|
20 |
-
try:
|
21 |
-
import glitch_me # ignore :pylint
|
22 |
-
except ModuleNotFoundError:
|
23 |
-
await bash(
|
24 |
-
"pip install -e git+https://github.com/1Danish-00/glitch_me.git#egg=glitch_me"
|
25 |
-
)
|
26 |
-
reply = await e.get_reply_message()
|
27 |
-
if not reply or not reply.media:
|
28 |
-
return await e.eor(get_string("cvt_3"))
|
29 |
-
xx = await e.eor(get_string("glitch_1"))
|
30 |
-
wut = mediainfo(reply.media)
|
31 |
-
if wut.startswith(("pic", "sticker")):
|
32 |
-
ok = await reply.download_media()
|
33 |
-
elif reply.document and reply.document.thumbs:
|
34 |
-
ok = await reply.download_media(thumb=-1)
|
35 |
-
else:
|
36 |
-
return await xx.eor(get_string("com_4"))
|
37 |
-
cmd = f"glitch_me gif --line_count 200 -f 10 -d 50 '{ok}' ult.gif"
|
38 |
-
await bash(cmd)
|
39 |
-
await e.reply(file="ult.gif", force_document=False)
|
40 |
-
await xx.delete()
|
41 |
-
os.remove(ok)
|
42 |
-
os.remove("ult.gif")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/globaltools.py
DELETED
@@ -1,753 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
"""
|
8 |
-
✘ Commands Available -
|
9 |
-
|
10 |
-
• `{i}gban <reply user/ username>`
|
11 |
-
• `{i}ungban`
|
12 |
-
Ban/Unban Globally.
|
13 |
-
|
14 |
-
• `{i}gstat <reply to user/userid/username>`
|
15 |
-
Check if user is GBanned.
|
16 |
-
|
17 |
-
• `{i}listgban` : List all GBanned users.
|
18 |
-
|
19 |
-
• `{i}gmute` | `{i}ungmute` <reply user/ username>
|
20 |
-
Mute/UnMute Globally.
|
21 |
-
|
22 |
-
• `{i}gkick <reply/username>` `Globally Kick User`
|
23 |
-
• `{i}gcast <text/reply>` `Globally Send msg in all grps`
|
24 |
-
|
25 |
-
• `{i}gadmincast <text/reply>` `Globally broadcast in your admin chats`
|
26 |
-
• `{i}gucast <text/reply>` `Globally send msg in all pm users`
|
27 |
-
|
28 |
-
• `{i}gblacklist <chat id/username/nothing (for current chat)`
|
29 |
-
Add chat to blacklist and ignores global broadcast.
|
30 |
-
• `{i}ungblacklist` `Remove the chat from blacklist.`
|
31 |
-
|
32 |
-
• `{i}gpromote <reply to user> <channel/group/all> <rank>`
|
33 |
-
globally promote user where you are admin
|
34 |
-
- Set whether To promote only in groups/channels/all.
|
35 |
-
Eg- `gpromote group boss` ~ promotes user in all grps.
|
36 |
-
`gpromote @username all sar` ~ promote the user in all group & channel
|
37 |
-
• `{i}gdemote` - `demote user globally`
|
38 |
-
"""
|
39 |
-
import asyncio
|
40 |
-
import os
|
41 |
-
|
42 |
-
from telethon.errors.rpcerrorlist import ChatAdminRequiredError, FloodWaitError
|
43 |
-
from telethon.tl.functions.channels import EditAdminRequest
|
44 |
-
from telethon.tl.functions.contacts import BlockRequest, UnblockRequest
|
45 |
-
from telethon.tl.types import ChatAdminRights, User
|
46 |
-
|
47 |
-
from pyUltroid.dB import DEVLIST
|
48 |
-
from pyUltroid.dB.base import KeyManager
|
49 |
-
from pyUltroid.dB.gban_mute_db import (
|
50 |
-
gban,
|
51 |
-
gmute,
|
52 |
-
is_gbanned,
|
53 |
-
is_gmuted,
|
54 |
-
list_gbanned,
|
55 |
-
ungban,
|
56 |
-
ungmute,
|
57 |
-
)
|
58 |
-
from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
|
59 |
-
|
60 |
-
from . import (
|
61 |
-
HNDLR,
|
62 |
-
LOGS,
|
63 |
-
NOSPAM_CHAT,
|
64 |
-
OWNER_NAME,
|
65 |
-
eod,
|
66 |
-
eor,
|
67 |
-
get_string,
|
68 |
-
inline_mention,
|
69 |
-
ultroid_bot,
|
70 |
-
ultroid_cmd,
|
71 |
-
)
|
72 |
-
from ._inline import something
|
73 |
-
|
74 |
-
_gpromote_rights = ChatAdminRights(
|
75 |
-
add_admins=False,
|
76 |
-
invite_users=True,
|
77 |
-
change_info=False,
|
78 |
-
ban_users=True,
|
79 |
-
delete_messages=True,
|
80 |
-
pin_messages=True,
|
81 |
-
)
|
82 |
-
|
83 |
-
_gdemote_rights = ChatAdminRights(
|
84 |
-
add_admins=False,
|
85 |
-
invite_users=False,
|
86 |
-
change_info=False,
|
87 |
-
ban_users=False,
|
88 |
-
delete_messages=False,
|
89 |
-
pin_messages=False,
|
90 |
-
)
|
91 |
-
|
92 |
-
keym = KeyManager("GBLACKLISTS", cast=list)
|
93 |
-
|
94 |
-
|
95 |
-
@ultroid_cmd(pattern="gpromote( (.*)|$)", fullsudo=True)
|
96 |
-
async def _(e):
|
97 |
-
x = e.pattern_match.group(1).strip()
|
98 |
-
ultroid_bot = e.client
|
99 |
-
if not x:
|
100 |
-
return await e.eor(get_string("schdl_2"), time=5)
|
101 |
-
user = await e.get_reply_message()
|
102 |
-
if user:
|
103 |
-
ev = await e.eor("`Promoting Replied User Globally`")
|
104 |
-
ok = e.text.split()
|
105 |
-
key = "all"
|
106 |
-
if len(ok) > 1 and (("group" in ok[1]) or ("channel" in ok[1])):
|
107 |
-
key = ok[1]
|
108 |
-
rank = ok[2] if len(ok) > 2 else "AdMin"
|
109 |
-
c = 0
|
110 |
-
user.id = user.peer_id.user_id if e.is_private else user.from_id.user_id
|
111 |
-
async for x in e.client.iter_dialogs():
|
112 |
-
if (
|
113 |
-
"group" in key.lower()
|
114 |
-
and x.is_group
|
115 |
-
or "group" not in key.lower()
|
116 |
-
and "channel" in key.lower()
|
117 |
-
and x.is_channel
|
118 |
-
):
|
119 |
-
try:
|
120 |
-
await e.client(
|
121 |
-
EditAdminRequest(
|
122 |
-
x.id,
|
123 |
-
user.id,
|
124 |
-
_gpromote_rights,
|
125 |
-
rank,
|
126 |
-
),
|
127 |
-
)
|
128 |
-
c += 1
|
129 |
-
except BaseException:
|
130 |
-
pass
|
131 |
-
elif (
|
132 |
-
("group" not in key.lower() or x.is_group)
|
133 |
-
and (
|
134 |
-
"group" in key.lower()
|
135 |
-
or "channel" not in key.lower()
|
136 |
-
or x.is_channel
|
137 |
-
)
|
138 |
-
and (
|
139 |
-
"group" in key.lower()
|
140 |
-
or "channel" in key.lower()
|
141 |
-
or x.is_group
|
142 |
-
or x.is_channel
|
143 |
-
)
|
144 |
-
):
|
145 |
-
try:
|
146 |
-
await e.client(
|
147 |
-
EditAdminRequest(
|
148 |
-
x.id,
|
149 |
-
user.id,
|
150 |
-
_gpromote_rights,
|
151 |
-
rank,
|
152 |
-
),
|
153 |
-
)
|
154 |
-
c += 1
|
155 |
-
except Exception as er:
|
156 |
-
LOGS.info(er)
|
157 |
-
await eor(ev, f"Promoted The Replied Users in Total : {c} {key} chats")
|
158 |
-
else:
|
159 |
-
k = e.text.split()
|
160 |
-
if not k[1]:
|
161 |
-
return await eor(
|
162 |
-
e, "`Give someone's username/id or replied to user.", time=5
|
163 |
-
)
|
164 |
-
user = k[1]
|
165 |
-
if user.isdigit():
|
166 |
-
user = int(user)
|
167 |
-
try:
|
168 |
-
name = await e.client.get_entity(user)
|
169 |
-
except BaseException:
|
170 |
-
return await e.eor(f"`No User Found Regarding {user}`", time=5)
|
171 |
-
ev = await e.eor(f"`Promoting {name.first_name} globally.`")
|
172 |
-
key = "all"
|
173 |
-
if len(k) > 2 and (("group" in k[2]) or ("channel" in k[2])):
|
174 |
-
key = k[2]
|
175 |
-
rank = k[3] if len(k) > 3 else "AdMin"
|
176 |
-
c = 0
|
177 |
-
async for x in e.client.iter_dialogs():
|
178 |
-
if (
|
179 |
-
"group" in key.lower()
|
180 |
-
and x.is_group
|
181 |
-
or "group" not in key.lower()
|
182 |
-
and "channel" in key.lower()
|
183 |
-
and x.is_channel
|
184 |
-
or "group" not in key.lower()
|
185 |
-
and "channel" not in key.lower()
|
186 |
-
and (x.is_group or x.is_channel)
|
187 |
-
):
|
188 |
-
try:
|
189 |
-
await ultroid_bot(
|
190 |
-
EditAdminRequest(
|
191 |
-
x.id,
|
192 |
-
user,
|
193 |
-
_gpromote_rights,
|
194 |
-
rank,
|
195 |
-
),
|
196 |
-
)
|
197 |
-
c += 1
|
198 |
-
except BaseException:
|
199 |
-
pass
|
200 |
-
await eor(ev, f"Promoted {name.first_name} in Total : {c} {key} chats.")
|
201 |
-
|
202 |
-
|
203 |
-
@ultroid_cmd(pattern="gdemote( (.*)|$)", fullsudo=True)
|
204 |
-
async def _(e):
|
205 |
-
x = e.pattern_match.group(1).strip()
|
206 |
-
ultroid_bot = e.client
|
207 |
-
if not x:
|
208 |
-
return await e.eor(get_string("schdl_2"), time=5)
|
209 |
-
user = await e.get_reply_message()
|
210 |
-
if user:
|
211 |
-
user.id = user.peer_id.user_id if e.is_private else user.from_id.user_id
|
212 |
-
ev = await e.eor("`Demoting Replied User Globally`")
|
213 |
-
ok = e.text.split()
|
214 |
-
key = "all"
|
215 |
-
if len(ok) > 1 and (("group" in ok[1]) or ("channel" in ok[1])):
|
216 |
-
key = ok[1]
|
217 |
-
rank = "Not AdMin"
|
218 |
-
c = 0
|
219 |
-
async for x in e.client.iter_dialogs():
|
220 |
-
if (
|
221 |
-
"group" in key.lower()
|
222 |
-
and x.is_group
|
223 |
-
or "group" not in key.lower()
|
224 |
-
and "channel" in key.lower()
|
225 |
-
and x.is_channel
|
226 |
-
or "group" not in key.lower()
|
227 |
-
and "channel" not in key.lower()
|
228 |
-
and (x.is_group or x.is_channel)
|
229 |
-
):
|
230 |
-
try:
|
231 |
-
await ultroid_bot(
|
232 |
-
EditAdminRequest(
|
233 |
-
x.id,
|
234 |
-
user.id,
|
235 |
-
_gdemote_rights,
|
236 |
-
rank,
|
237 |
-
),
|
238 |
-
)
|
239 |
-
c += 1
|
240 |
-
except BaseException:
|
241 |
-
pass
|
242 |
-
await eor(ev, f"Demoted The Replied Users in Total : {c} {key} chats")
|
243 |
-
else:
|
244 |
-
k = e.text.split()
|
245 |
-
if not k[1]:
|
246 |
-
return await eor(
|
247 |
-
e, "`Give someone's username/id or replied to user.", time=5
|
248 |
-
)
|
249 |
-
user = k[1]
|
250 |
-
if user.isdigit():
|
251 |
-
user = int(user)
|
252 |
-
try:
|
253 |
-
name = await ultroid_bot.get_entity(user)
|
254 |
-
except BaseException:
|
255 |
-
return await e.eor(f"`No User Found Regarding {user}`", time=5)
|
256 |
-
ev = await e.eor(f"`Demoting {name.first_name} globally.`")
|
257 |
-
key = "all"
|
258 |
-
if len(k) > 2 and (("group" in k[2]) or ("channel" in k[2])):
|
259 |
-
key = k[2]
|
260 |
-
rank = "Not AdMin"
|
261 |
-
c = 0
|
262 |
-
async for x in ultroid_bot.iter_dialogs():
|
263 |
-
if (
|
264 |
-
"group" in key.lower()
|
265 |
-
and x.is_group
|
266 |
-
or "group" not in key.lower()
|
267 |
-
and "channel" in key.lower()
|
268 |
-
and x.is_channel
|
269 |
-
or "group" not in key.lower()
|
270 |
-
and "channel" not in key.lower()
|
271 |
-
and (x.is_group or x.is_channel)
|
272 |
-
):
|
273 |
-
try:
|
274 |
-
await ultroid_bot(
|
275 |
-
EditAdminRequest(
|
276 |
-
x.id,
|
277 |
-
user,
|
278 |
-
_gdemote_rights,
|
279 |
-
rank,
|
280 |
-
),
|
281 |
-
)
|
282 |
-
c += 1
|
283 |
-
except BaseException:
|
284 |
-
pass
|
285 |
-
await eor(ev, f"Demoted {name.first_name} in Total : {c} {key} chats.")
|
286 |
-
|
287 |
-
|
288 |
-
@ultroid_cmd(pattern="ungban( (.*)|$)", fullsudo=True)
|
289 |
-
async def _(e):
|
290 |
-
xx = await e.eor("`UnGbanning...`")
|
291 |
-
match = e.pattern_match.group(1).strip()
|
292 |
-
peer = None
|
293 |
-
if e.reply_to_msg_id:
|
294 |
-
userid = (await e.get_reply_message()).sender_id
|
295 |
-
elif match:
|
296 |
-
try:
|
297 |
-
userid = int(match)
|
298 |
-
except ValueError:
|
299 |
-
userid = match
|
300 |
-
try:
|
301 |
-
userid = (await e.client.get_entity(userid)).id
|
302 |
-
except Exception as er:
|
303 |
-
return await xx.edit(f"Failed to get User...\nError: {er}")
|
304 |
-
elif e.is_private:
|
305 |
-
userid = e.chat_id
|
306 |
-
else:
|
307 |
-
return await xx.eor("`Reply to some msg or add their id.`", time=5)
|
308 |
-
if not is_gbanned(userid):
|
309 |
-
return await xx.edit("`User/Channel is not Gbanned...`")
|
310 |
-
try:
|
311 |
-
if not peer:
|
312 |
-
peer = await e.client.get_entity(userid)
|
313 |
-
name = inline_mention(peer)
|
314 |
-
except BaseException:
|
315 |
-
userid = int(userid)
|
316 |
-
name = str(userid)
|
317 |
-
chats = 0
|
318 |
-
if e.client._dialogs:
|
319 |
-
dialog = e.client._dialogs
|
320 |
-
else:
|
321 |
-
dialog = await e.client.get_dialogs()
|
322 |
-
e.client._dialogs.extend(dialog)
|
323 |
-
for ggban in dialog:
|
324 |
-
if ggban.is_group or ggban.is_channel:
|
325 |
-
try:
|
326 |
-
await e.client.edit_permissions(ggban.id, userid, view_messages=True)
|
327 |
-
chats += 1
|
328 |
-
except FloodWaitError as fw:
|
329 |
-
LOGS.info(
|
330 |
-
f"[FLOOD_WAIT_ERROR] : on Ungban\nSleeping for {fw.seconds+10}"
|
331 |
-
)
|
332 |
-
await asyncio.sleep(fw.seconds + 10)
|
333 |
-
try:
|
334 |
-
await e.client.edit_permissions(
|
335 |
-
ggban.id, userid, view_messages=True
|
336 |
-
)
|
337 |
-
chats += 1
|
338 |
-
except BaseException as er:
|
339 |
-
LOGS.exception(er)
|
340 |
-
except (ChatAdminRequiredError, ValueError):
|
341 |
-
pass
|
342 |
-
except BaseException as er:
|
343 |
-
LOGS.exception(er)
|
344 |
-
ungban(userid)
|
345 |
-
if isinstance(peer, User):
|
346 |
-
await e.client(UnblockRequest(userid))
|
347 |
-
await xx.edit(
|
348 |
-
f"`Ungbaned` {name} in {chats} `chats.\nRemoved from gbanwatch.`",
|
349 |
-
)
|
350 |
-
|
351 |
-
|
352 |
-
@ultroid_cmd(pattern="gban( (.*)|$)", fullsudo=True)
|
353 |
-
async def _(e):
|
354 |
-
xx = await e.eor("`Gbanning...`")
|
355 |
-
reason = ""
|
356 |
-
if e.reply_to_msg_id:
|
357 |
-
userid = (await e.get_reply_message()).sender_id
|
358 |
-
try:
|
359 |
-
reason = e.text.split(" ", maxsplit=1)[1]
|
360 |
-
except IndexError:
|
361 |
-
pass
|
362 |
-
elif e.pattern_match.group(1).strip():
|
363 |
-
usr = e.text.split(maxsplit=2)[1]
|
364 |
-
try:
|
365 |
-
userid = await e.client.parse_id(usr)
|
366 |
-
except ValueError:
|
367 |
-
userid = usr
|
368 |
-
try:
|
369 |
-
reason = e.text.split(maxsplit=2)[2]
|
370 |
-
except IndexError:
|
371 |
-
pass
|
372 |
-
elif e.is_private:
|
373 |
-
userid = e.chat_id
|
374 |
-
try:
|
375 |
-
reason = e.text.split(" ", maxsplit=1)[1]
|
376 |
-
except IndexError:
|
377 |
-
pass
|
378 |
-
else:
|
379 |
-
return await xx.eor("`Reply to some msg or add their id.`", time=5)
|
380 |
-
user = None
|
381 |
-
try:
|
382 |
-
user = await e.client.get_entity(userid)
|
383 |
-
name = inline_mention(user)
|
384 |
-
except BaseException:
|
385 |
-
userid = int(userid)
|
386 |
-
name = str(userid)
|
387 |
-
chats = 0
|
388 |
-
if userid == ultroid_bot.uid:
|
389 |
-
return await xx.eor("`I can't gban myself.`", time=3)
|
390 |
-
elif userid in DEVLIST:
|
391 |
-
return await xx.eor("`I can't gban my Developers.`", time=3)
|
392 |
-
elif is_gbanned(userid):
|
393 |
-
return await eod(
|
394 |
-
xx,
|
395 |
-
"`User is already gbanned and added to gbanwatch.`",
|
396 |
-
time=4,
|
397 |
-
)
|
398 |
-
if e.client._dialogs:
|
399 |
-
dialog = e.client._dialogs
|
400 |
-
else:
|
401 |
-
dialog = await e.client.get_dialogs()
|
402 |
-
e.client._dialogs.extend(dialog)
|
403 |
-
for ggban in dialog:
|
404 |
-
if ggban.is_group or ggban.is_channel:
|
405 |
-
try:
|
406 |
-
await e.client.edit_permissions(ggban.id, userid, view_messages=False)
|
407 |
-
chats += 1
|
408 |
-
except FloodWaitError as fw:
|
409 |
-
LOGS.info(
|
410 |
-
f"[FLOOD_WAIT_ERROR] : on GBAN Command\nSleeping for {fw.seconds+10}"
|
411 |
-
)
|
412 |
-
await asyncio.sleep(fw.seconds + 10)
|
413 |
-
try:
|
414 |
-
await e.client.edit_permissions(
|
415 |
-
ggban.id, userid, view_messages=False
|
416 |
-
)
|
417 |
-
chats += 1
|
418 |
-
except BaseException as er:
|
419 |
-
LOGS.exception(er)
|
420 |
-
except (ChatAdminRequiredError, ValueError):
|
421 |
-
pass
|
422 |
-
except BaseException as er:
|
423 |
-
LOGS.exception(er)
|
424 |
-
gban(userid, reason)
|
425 |
-
if isinstance(user, User):
|
426 |
-
await e.client(BlockRequest(userid))
|
427 |
-
gb_msg = f"**#Gbanned** {name} `in {chats} chats and added to gbanwatch!`"
|
428 |
-
if reason:
|
429 |
-
gb_msg += f"\n**Reason** : {reason}"
|
430 |
-
await xx.edit(gb_msg)
|
431 |
-
|
432 |
-
|
433 |
-
@ultroid_cmd(pattern="g(admin|)cast( (.*)|$)", fullsudo=True)
|
434 |
-
async def gcast(event):
|
435 |
-
text, btn, reply = "", None, None
|
436 |
-
if xx := event.pattern_match.group(2):
|
437 |
-
msg, btn = get_msg_button(event.text.split(maxsplit=1)[1])
|
438 |
-
elif event.is_reply:
|
439 |
-
reply = await event.get_reply_message()
|
440 |
-
msg = reply.text
|
441 |
-
if reply.buttons:
|
442 |
-
btn = format_btn(reply.buttons)
|
443 |
-
else:
|
444 |
-
msg, btn = get_msg_button(msg)
|
445 |
-
else:
|
446 |
-
return await eor(
|
447 |
-
event, "`Give some text to Globally Broadcast or reply a message..`"
|
448 |
-
)
|
449 |
-
|
450 |
-
kk = await event.eor("`Globally Broadcasting Msg...`")
|
451 |
-
er = 0
|
452 |
-
done = 0
|
453 |
-
err = ""
|
454 |
-
if event.client._dialogs:
|
455 |
-
dialog = event.client._dialogs
|
456 |
-
else:
|
457 |
-
dialog = await event.client.get_dialogs()
|
458 |
-
event.client._dialogs.extend(dialog)
|
459 |
-
for x in dialog:
|
460 |
-
if x.is_group:
|
461 |
-
chat = x.entity.id
|
462 |
-
if (
|
463 |
-
not keym.contains(chat)
|
464 |
-
and int(f"-100{str(chat)}") not in NOSPAM_CHAT
|
465 |
-
and (
|
466 |
-
(
|
467 |
-
event.text[2:7] != "admin"
|
468 |
-
or (x.entity.admin_rights or x.entity.creator)
|
469 |
-
)
|
470 |
-
)
|
471 |
-
):
|
472 |
-
try:
|
473 |
-
if btn:
|
474 |
-
bt = create_tl_btn(btn)
|
475 |
-
await something(
|
476 |
-
event,
|
477 |
-
msg,
|
478 |
-
reply.media if reply else None,
|
479 |
-
bt,
|
480 |
-
chat=chat,
|
481 |
-
reply=False,
|
482 |
-
)
|
483 |
-
else:
|
484 |
-
await event.client.send_message(
|
485 |
-
chat, msg, file=reply.media if reply else None
|
486 |
-
)
|
487 |
-
done += 1
|
488 |
-
except FloodWaitError as fw:
|
489 |
-
await asyncio.sleep(fw.seconds + 10)
|
490 |
-
try:
|
491 |
-
if btn:
|
492 |
-
bt = create_tl_btn(btn)
|
493 |
-
await something(
|
494 |
-
event,
|
495 |
-
msg,
|
496 |
-
reply.media if reply else None,
|
497 |
-
bt,
|
498 |
-
chat=chat,
|
499 |
-
reply=False,
|
500 |
-
)
|
501 |
-
else:
|
502 |
-
await event.client.send_message(
|
503 |
-
chat, msg, file=reply.media if reply else None
|
504 |
-
)
|
505 |
-
done += 1
|
506 |
-
except Exception as rr:
|
507 |
-
err += f"• {rr}\n"
|
508 |
-
er += 1
|
509 |
-
except BaseException as h:
|
510 |
-
err += f"• {str(h)}" + "\n"
|
511 |
-
er += 1
|
512 |
-
text += f"Done in {done} chats, error in {er} chat(s)"
|
513 |
-
if err != "":
|
514 |
-
open("gcast-error.log", "w+").write(err)
|
515 |
-
text += f"\nYou can do `{HNDLR}ul gcast-error.log` to know error report."
|
516 |
-
await kk.edit(text)
|
517 |
-
|
518 |
-
|
519 |
-
@ultroid_cmd(pattern="gucast( (.*)|$)", fullsudo=True)
|
520 |
-
async def gucast(event):
|
521 |
-
msg, btn, reply = "", None, None
|
522 |
-
if xx := event.pattern_match.group(1).strip():
|
523 |
-
msg, btn = get_msg_button(event.text.split(maxsplit=1)[1])
|
524 |
-
elif event.is_reply:
|
525 |
-
reply = await event.get_reply_message()
|
526 |
-
msg = reply.text
|
527 |
-
if reply.buttons:
|
528 |
-
btn = format_btn(reply.buttons)
|
529 |
-
else:
|
530 |
-
msg, btn = get_msg_button(msg)
|
531 |
-
else:
|
532 |
-
return await eor(
|
533 |
-
event, "`Give some text to Globally Broadcast or reply a message..`"
|
534 |
-
)
|
535 |
-
kk = await event.eor("`Globally Broadcasting Msg...`")
|
536 |
-
er = 0
|
537 |
-
done = 0
|
538 |
-
if event.client._dialogs:
|
539 |
-
dialog = event.client._dialogs
|
540 |
-
else:
|
541 |
-
dialog = await event.client.get_dialogs()
|
542 |
-
event.client._dialogs.extend(dialog)
|
543 |
-
for x in dialog:
|
544 |
-
if x.is_user and not x.entity.bot:
|
545 |
-
chat = x.id
|
546 |
-
if not keym.contains(chat):
|
547 |
-
try:
|
548 |
-
if btn:
|
549 |
-
bt = create_tl_btn(btn)
|
550 |
-
await something(
|
551 |
-
event,
|
552 |
-
msg,
|
553 |
-
reply.media if reply else None,
|
554 |
-
bt,
|
555 |
-
chat=chat,
|
556 |
-
reply=False,
|
557 |
-
)
|
558 |
-
else:
|
559 |
-
await event.client.send_message(
|
560 |
-
chat, msg, file=reply.media if reply else None
|
561 |
-
)
|
562 |
-
done += 1
|
563 |
-
except BaseException:
|
564 |
-
er += 1
|
565 |
-
await kk.edit(f"Done in {done} chats, error in {er} chat(s)")
|
566 |
-
|
567 |
-
|
568 |
-
@ultroid_cmd(pattern="gkick( (.*)|$)", fullsudo=True)
|
569 |
-
async def gkick(e):
|
570 |
-
xx = await e.eor("`Gkicking...`")
|
571 |
-
if e.reply_to_msg_id:
|
572 |
-
userid = (await e.get_reply_message()).sender_id
|
573 |
-
elif e.pattern_match.group(1).strip():
|
574 |
-
userid = await e.client.parse_id(e.pattern_match.group(1).strip())
|
575 |
-
elif e.is_private:
|
576 |
-
userid = e.chat_id
|
577 |
-
else:
|
578 |
-
return await xx.edit("`Reply to some msg or add their id.`", time=5)
|
579 |
-
name = (await e.client.get_entity(userid)).first_name
|
580 |
-
chats = 0
|
581 |
-
if userid == ultroid_bot.uid:
|
582 |
-
return await xx.eor("`I can't gkick myself.`", time=3)
|
583 |
-
if userid in DEVLIST:
|
584 |
-
return await xx.eor("`I can't gkick my Developers.`", time=3)
|
585 |
-
if e.client._dialogs:
|
586 |
-
dialog = e.client._dialogs
|
587 |
-
else:
|
588 |
-
dialog = await e.client.get_dialogs()
|
589 |
-
e.client._dialogs.extend(dialog)
|
590 |
-
for gkick in dialog:
|
591 |
-
if gkick.is_group or gkick.is_channel:
|
592 |
-
try:
|
593 |
-
await e.client.kick_participant(gkick.id, userid)
|
594 |
-
chats += 1
|
595 |
-
except BaseException:
|
596 |
-
pass
|
597 |
-
await xx.edit(f"`Gkicked` [{name}](tg://user?id={userid}) `in {chats} chats.`")
|
598 |
-
|
599 |
-
|
600 |
-
@ultroid_cmd(pattern="gmute( (.*)|$)", fullsudo=True)
|
601 |
-
async def _(e):
|
602 |
-
xx = await e.eor("`Gmuting...`")
|
603 |
-
if e.reply_to_msg_id:
|
604 |
-
userid = (await e.get_reply_message()).sender_id
|
605 |
-
elif e.pattern_match.group(1).strip():
|
606 |
-
userid = await e.client.parse_id(e.pattern_match.group(1).strip())
|
607 |
-
elif e.is_private:
|
608 |
-
userid = e.chat_id
|
609 |
-
else:
|
610 |
-
return await xx.eor("`Reply to some msg or add their id.`", tome=5, time=5)
|
611 |
-
name = await e.client.get_entity(userid)
|
612 |
-
chats = 0
|
613 |
-
if userid == ultroid_bot.uid:
|
614 |
-
return await xx.eor("`I can't gmute myself.`", time=3)
|
615 |
-
if userid in DEVLIST:
|
616 |
-
return await xx.eor("`I can't gmute my Developers.`", time=3)
|
617 |
-
if is_gmuted(userid):
|
618 |
-
return await xx.eor("`User is already gmuted.`", time=4)
|
619 |
-
if e.client._dialogs:
|
620 |
-
dialog = e.client._dialogs
|
621 |
-
else:
|
622 |
-
dialog = await e.client.get_dialogs()
|
623 |
-
e.client._dialogs.extend(dialog)
|
624 |
-
for onmute in dialog:
|
625 |
-
if onmute.is_group:
|
626 |
-
try:
|
627 |
-
await e.client.edit_permissions(onmute.id, userid, send_messages=False)
|
628 |
-
chats += 1
|
629 |
-
except BaseException:
|
630 |
-
pass
|
631 |
-
gmute(userid)
|
632 |
-
await xx.edit(f"`Gmuted` {inline_mention(name)} `in {chats} chats.`")
|
633 |
-
|
634 |
-
|
635 |
-
@ultroid_cmd(pattern="ungmute( (.*)|$)", fullsudo=True)
|
636 |
-
async def _(e):
|
637 |
-
xx = await e.eor("`UnGmuting...`")
|
638 |
-
if e.reply_to_msg_id:
|
639 |
-
userid = (await e.get_reply_message()).sender_id
|
640 |
-
elif e.pattern_match.group(1).strip():
|
641 |
-
userid = await e.client.parse_id(e.pattern_match.group(1).strip())
|
642 |
-
elif e.is_private:
|
643 |
-
userid = e.chat_id
|
644 |
-
else:
|
645 |
-
return await xx.eor("`Reply to some msg or add their id.`", time=5)
|
646 |
-
name = (await e.client.get_entity(userid)).first_name
|
647 |
-
chats = 0
|
648 |
-
if not is_gmuted(userid):
|
649 |
-
return await xx.eor("`User is not gmuted.`", time=3)
|
650 |
-
if e.client._dialogs:
|
651 |
-
dialog = e.client._dialogs
|
652 |
-
else:
|
653 |
-
dialog = await e.client.get_dialogs()
|
654 |
-
e.client._dialogs.extend(dialog)
|
655 |
-
for hurr in dialog:
|
656 |
-
if hurr.is_group:
|
657 |
-
try:
|
658 |
-
await e.client.edit_permissions(hurr.id, userid, send_messages=True)
|
659 |
-
chats += 1
|
660 |
-
except BaseException:
|
661 |
-
pass
|
662 |
-
ungmute(userid)
|
663 |
-
await xx.edit(f"`Ungmuted` {inline_mention(name)} `in {chats} chats.`")
|
664 |
-
|
665 |
-
|
666 |
-
@ultroid_cmd(
|
667 |
-
pattern="listgban$",
|
668 |
-
)
|
669 |
-
async def list_gengbanned(event):
|
670 |
-
users = list_gbanned()
|
671 |
-
x = await event.eor(get_string("com_1"))
|
672 |
-
msg = ""
|
673 |
-
if not users:
|
674 |
-
return await x.edit("`You haven't GBanned anyone!`")
|
675 |
-
for i in users:
|
676 |
-
try:
|
677 |
-
name = await event.client.get_entity(int(i))
|
678 |
-
except BaseException:
|
679 |
-
name = i
|
680 |
-
msg += f"<strong>User</strong>: {inline_mention(name, html=True)}\n"
|
681 |
-
reason = users[i]
|
682 |
-
msg += f"<strong>Reason</strong>: {reason}\n\n" if reason is not None else "\n"
|
683 |
-
gbanned_users = f"<strong>List of users GBanned by {OWNER_NAME}</strong>:\n\n{msg}"
|
684 |
-
if len(gbanned_users) > 4096:
|
685 |
-
with open("gbanned.txt", "w") as f:
|
686 |
-
f.write(
|
687 |
-
gbanned_users.replace("<strong>", "")
|
688 |
-
.replace("</strong>", "")
|
689 |
-
.replace("<a href=tg://user?id=", "")
|
690 |
-
.replace("</a>", "")
|
691 |
-
)
|
692 |
-
await x.reply(
|
693 |
-
file="gbanned.txt",
|
694 |
-
message=f"List of users GBanned by {inline_mention(ultroid_bot.me)}",
|
695 |
-
)
|
696 |
-
os.remove("gbanned.txt")
|
697 |
-
await x.delete()
|
698 |
-
else:
|
699 |
-
await x.edit(gbanned_users, parse_mode="html")
|
700 |
-
|
701 |
-
|
702 |
-
@ultroid_cmd(
|
703 |
-
pattern="gstat( (.*)|$)",
|
704 |
-
)
|
705 |
-
async def gstat_(e):
|
706 |
-
xx = await e.eor(get_string("com_1"))
|
707 |
-
if e.is_private:
|
708 |
-
userid = (await e.get_chat()).id
|
709 |
-
elif e.reply_to_msg_id:
|
710 |
-
userid = (await e.get_reply_message()).sender_id
|
711 |
-
elif e.pattern_match.group(1).strip():
|
712 |
-
try:
|
713 |
-
userid = await e.client.parse_id(e.pattern_match.group(1).strip())
|
714 |
-
except Exception as err:
|
715 |
-
return await xx.eor(f"{err}", time=10)
|
716 |
-
else:
|
717 |
-
return await xx.eor("`Reply to some msg or add their id.`", time=5)
|
718 |
-
name = (await e.client.get_entity(userid)).first_name
|
719 |
-
msg = f"**{name} is "
|
720 |
-
is_banned = is_gbanned(userid)
|
721 |
-
reason = list_gbanned().get(userid)
|
722 |
-
if is_banned:
|
723 |
-
msg += "Globally Banned"
|
724 |
-
msg += f" with reason** `{reason}`" if reason else ".**"
|
725 |
-
else:
|
726 |
-
msg += "not Globally Banned.**"
|
727 |
-
await xx.edit(msg)
|
728 |
-
|
729 |
-
|
730 |
-
@ultroid_cmd(pattern="gblacklist$")
|
731 |
-
async def blacklist_(event):
|
732 |
-
await gblacker(event, "add")
|
733 |
-
|
734 |
-
|
735 |
-
@ultroid_cmd(pattern="ungblacklist$")
|
736 |
-
async def ungblacker(event):
|
737 |
-
await gblacker(event, "remove")
|
738 |
-
|
739 |
-
|
740 |
-
async def gblacker(event, type_):
|
741 |
-
try:
|
742 |
-
chat_id = int(event.text.split(maxsplit=1)[1])
|
743 |
-
try:
|
744 |
-
chat_id = (await event.client.get_entity(chat_id)).id
|
745 |
-
except Exception as e:
|
746 |
-
return await event.eor(f"**ERROR**\n`{str(e)}`")
|
747 |
-
except IndexError:
|
748 |
-
chat_id = event.chat_id
|
749 |
-
if type_ == "add":
|
750 |
-
keym.add(chat_id)
|
751 |
-
elif type_ == "remove":
|
752 |
-
keym.remove(chat_id)
|
753 |
-
await event.eor(f"Global Broadcasts: \n{type_}ed {chat_id}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/gpt.py
DELETED
@@ -1,183 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
from collections import deque
|
3 |
-
from io import BytesIO
|
4 |
-
|
5 |
-
from . import (
|
6 |
-
ultroid_cmd,
|
7 |
-
async_searcher,
|
8 |
-
udB,
|
9 |
-
LOGS,
|
10 |
-
get_paste,
|
11 |
-
)
|
12 |
-
|
13 |
-
GPT_CHAT_HISTORY = deque(maxlen=30)
|
14 |
-
|
15 |
-
TELEGRAM_CHAR_LIMIT = 4096 # Telegram's message character limit
|
16 |
-
|
17 |
-
|
18 |
-
async def pastee(data):
|
19 |
-
err, linky = await get_paste(data)
|
20 |
-
if err:
|
21 |
-
return f">> [Raw Code Pasted Here](https://spaceb.in/{linky})\n"
|
22 |
-
else:
|
23 |
-
LOGS.error(linky)
|
24 |
-
return ""
|
25 |
-
|
26 |
-
|
27 |
-
@ultroid_cmd(
|
28 |
-
pattern=r"gpt( ([\s\S]*))?$",
|
29 |
-
)
|
30 |
-
async def openai_chat_gpt(e):
|
31 |
-
api_key = "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"
|
32 |
-
if not api_key:
|
33 |
-
return await e.eor("`OPENAI_API` key missing..", time=10)
|
34 |
-
|
35 |
-
query = e.pattern_match.group(2)
|
36 |
-
reply = await e.get_reply_message()
|
37 |
-
|
38 |
-
file_content = None
|
39 |
-
|
40 |
-
if query:
|
41 |
-
# Check if query contains 'from filename'
|
42 |
-
if ' from ' in query:
|
43 |
-
query_text, filename = query.split(' from ', 1)
|
44 |
-
query_text = query_text.strip()
|
45 |
-
filename = filename.strip()
|
46 |
-
# Attempt to find and read the file from media in chat
|
47 |
-
file_found = False
|
48 |
-
async for message in e.client.iter_messages(e.chat_id, reverse=True, limit=50):
|
49 |
-
if message.media and message.file.name == filename:
|
50 |
-
if (message.file.name.endswith(".txt") or message.file.name.endswith(".py")):
|
51 |
-
file = await e.client.download_media(message)
|
52 |
-
try:
|
53 |
-
with open(file, "r", encoding='utf-8') as f:
|
54 |
-
file_content = f.read()
|
55 |
-
except Exception as exc:
|
56 |
-
LOGS.error(f"Error reading file: {exc}")
|
57 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
58 |
-
finally:
|
59 |
-
os.remove(file)
|
60 |
-
file_found = True
|
61 |
-
break
|
62 |
-
if not file_found:
|
63 |
-
return await e.eor(f"`File {filename} not found in recent messages.`", time=5)
|
64 |
-
if file_content:
|
65 |
-
query = f"{query_text}\n\n{file_content}" if query_text else file_content
|
66 |
-
else:
|
67 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
68 |
-
else:
|
69 |
-
if reply and reply.media and (reply.file.name.endswith(".txt") or reply.file.name.endswith(".py")):
|
70 |
-
# Use the query and the replied file content
|
71 |
-
file = await e.client.download_media(reply)
|
72 |
-
try:
|
73 |
-
with open(file, "r", encoding='utf-8') as f:
|
74 |
-
file_content = f.read()
|
75 |
-
except Exception as exc:
|
76 |
-
LOGS.error(f"Error reading file: {exc}")
|
77 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
78 |
-
finally:
|
79 |
-
os.remove(file)
|
80 |
-
query = f"{query}\n\n{file_content}"
|
81 |
-
elif reply and reply.message:
|
82 |
-
# Use the query and the replied text message content
|
83 |
-
query = f"{query}\n\n{reply.message}"
|
84 |
-
# Else, use query as is
|
85 |
-
else:
|
86 |
-
if reply and reply.media and (reply.file.name.endswith(".txt") or reply.file.name.endswith(".py")):
|
87 |
-
# Use the replied file content
|
88 |
-
file = await e.client.download_media(reply)
|
89 |
-
try:
|
90 |
-
with open(file, "r", encoding='utf-8') as f:
|
91 |
-
file_content = f.read()
|
92 |
-
except Exception as exc:
|
93 |
-
LOGS.error(f"Error reading file: {exc}")
|
94 |
-
return await e.eor("`Failed to read file content.`", time=5)
|
95 |
-
finally:
|
96 |
-
os.remove(file)
|
97 |
-
query = file_content
|
98 |
-
elif reply and reply.message:
|
99 |
-
# Use the replied text message content
|
100 |
-
query = reply.message
|
101 |
-
else:
|
102 |
-
return await e.eor("`Please provide a question or reply to a message or .txt/.py file.`", time=5)
|
103 |
-
|
104 |
-
if query.strip() == "-c":
|
105 |
-
GPT_CHAT_HISTORY.clear()
|
106 |
-
return await e.eor("__Cleared o1-mini Chat History!__", time=6)
|
107 |
-
|
108 |
-
eris = await e.eor(f"__Generating answer for:__\n`{query[:20]} ...`")
|
109 |
-
GPT_CHAT_HISTORY.append({"role": "user", "content": query})
|
110 |
-
|
111 |
-
try:
|
112 |
-
data = {
|
113 |
-
"model": "o1-mini",
|
114 |
-
"messages": list(GPT_CHAT_HISTORY),
|
115 |
-
}
|
116 |
-
request = await async_searcher(
|
117 |
-
"https://api.openai.com/v1/chat/completions",
|
118 |
-
headers={
|
119 |
-
"Content-Type": "application/json",
|
120 |
-
"Authorization": f"Bearer {api_key}",
|
121 |
-
},
|
122 |
-
json=data,
|
123 |
-
re_json=True,
|
124 |
-
post=True,
|
125 |
-
)
|
126 |
-
response = request["choices"][0]["message"]["content"]
|
127 |
-
GPT_CHAT_HISTORY.append({"role": "assistant", "content": response})
|
128 |
-
except Exception as exc:
|
129 |
-
LOGS.warning(exc, exc_info=True)
|
130 |
-
GPT_CHAT_HISTORY.pop()
|
131 |
-
return await eris.edit(
|
132 |
-
f"**Error while requesting data from OpenAI:** \n> `{exc}`"
|
133 |
-
)
|
134 |
-
|
135 |
-
LOGS.debug(f'Tokens Used on query: {request["usage"]["completion_tokens"]}')
|
136 |
-
|
137 |
-
# Truncate query to 50 characters for display
|
138 |
-
truncated_query = query[:100]
|
139 |
-
|
140 |
-
# Prepare the full message
|
141 |
-
full_message = f"**Query:**\n~ __{truncated_query}__\n\n**o1-mini:**\n~ {response}"
|
142 |
-
|
143 |
-
# Check if response contains code blocks
|
144 |
-
code_blocks = []
|
145 |
-
in_code_block = False
|
146 |
-
code_block_lines = []
|
147 |
-
for line in response.split('\n'):
|
148 |
-
if line.strip().startswith('```'):
|
149 |
-
if in_code_block:
|
150 |
-
# End of code block
|
151 |
-
in_code_block = False
|
152 |
-
code_blocks.append('\n'.join(code_block_lines))
|
153 |
-
code_block_lines = []
|
154 |
-
else:
|
155 |
-
# Start of code block
|
156 |
-
in_code_block = True
|
157 |
-
elif in_code_block:
|
158 |
-
code_block_lines.append(line)
|
159 |
-
|
160 |
-
# If the response contains code blocks, select the largest one and paste it
|
161 |
-
if code_blocks:
|
162 |
-
# Select the largest code block based on length
|
163 |
-
largest_code_block = max(code_blocks, key=lambda block: len(block))
|
164 |
-
# Upload the largest code block to spaceb.in and get the link
|
165 |
-
paste_link = await pastee(largest_code_block)
|
166 |
-
else:
|
167 |
-
paste_link = ""
|
168 |
-
|
169 |
-
if len(full_message) <= TELEGRAM_CHAR_LIMIT:
|
170 |
-
# If it fits within the limit, send as a message
|
171 |
-
await eris.edit(full_message + f"\n\n{paste_link}")
|
172 |
-
else:
|
173 |
-
# If it exceeds the limit, send as a file and include paste link
|
174 |
-
file = BytesIO(full_message.encode('utf-8'))
|
175 |
-
file.name = "o1-mini-output.txt"
|
176 |
-
await eris.respond(
|
177 |
-
"__The query and response were too long, so they have been sent as a file.__\n\n" + paste_link,
|
178 |
-
file=file,
|
179 |
-
reply_to=e.reply_to_msg_id or e.id,
|
180 |
-
link_preview=False
|
181 |
-
)
|
182 |
-
await eris.delete()
|
183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/greetings.py
DELETED
@@ -1,205 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
"""
|
8 |
-
✘ Commands Available -
|
9 |
-
|
10 |
-
---- Welcomes ----
|
11 |
-
• `{i}setwelcome <message/reply to message>`
|
12 |
-
Set welcome message in the current chat.
|
13 |
-
|
14 |
-
• `{i}clearwelcome`
|
15 |
-
Delete the welcome in the current chat.
|
16 |
-
|
17 |
-
• `{i}getwelcome`
|
18 |
-
Get the welcome message in the current chat.
|
19 |
-
|
20 |
-
---- GoodByes ----
|
21 |
-
• `{i}setgoodbye <message/reply to message>`
|
22 |
-
Set goodbye message in the current chat.
|
23 |
-
|
24 |
-
• `{i}cleargoodbye`
|
25 |
-
Delete the goodbye in the current chat.
|
26 |
-
|
27 |
-
• `{i}getgoodbye`
|
28 |
-
Get the goodbye message in the current chat.
|
29 |
-
|
30 |
-
• `{i}thankmembers on/off`
|
31 |
-
Send a thank you sticker on hitting a members count of 100*x in your groups.
|
32 |
-
"""
|
33 |
-
import os
|
34 |
-
|
35 |
-
from telegraph import upload_file as uf
|
36 |
-
from telethon.utils import pack_bot_file_id
|
37 |
-
|
38 |
-
from pyUltroid.dB.greetings_db import (
|
39 |
-
add_goodbye,
|
40 |
-
add_thanks,
|
41 |
-
add_welcome,
|
42 |
-
delete_goodbye,
|
43 |
-
delete_welcome,
|
44 |
-
get_goodbye,
|
45 |
-
get_welcome,
|
46 |
-
must_thank,
|
47 |
-
remove_thanks,
|
48 |
-
)
|
49 |
-
from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
|
50 |
-
|
51 |
-
from . import HNDLR, eor, get_string, mediainfo, ultroid_cmd
|
52 |
-
from ._inline import something
|
53 |
-
|
54 |
-
Note = "\n\nNote: `{mention}`, `{group}`, `{count}`, `{name}`, `{fullname}`, `{username}`, `{userid}` can be used as formatting parameters.\n\n"
|
55 |
-
|
56 |
-
|
57 |
-
@ultroid_cmd(pattern="setwelcome", groups_only=True)
|
58 |
-
async def setwel(event):
|
59 |
-
x = await event.eor(get_string("com_1"))
|
60 |
-
r = await event.get_reply_message()
|
61 |
-
btn = format_btn(r.buttons) if (r and r.buttons) else None
|
62 |
-
try:
|
63 |
-
text = event.text.split(maxsplit=1)[1]
|
64 |
-
except IndexError:
|
65 |
-
text = r.text if r else None
|
66 |
-
if r and r.media:
|
67 |
-
wut = mediainfo(r.media)
|
68 |
-
if wut.startswith(("pic", "gif")):
|
69 |
-
dl = await r.download_media()
|
70 |
-
variable = uf(dl)
|
71 |
-
os.remove(dl)
|
72 |
-
m = f"https://graph.org{variable[0]}"
|
73 |
-
elif wut == "video":
|
74 |
-
if r.media.document.size > 8 * 1000 * 1000:
|
75 |
-
return await eor(x, get_string("com_4"), time=5)
|
76 |
-
dl = await r.download_media()
|
77 |
-
variable = uf(dl)
|
78 |
-
os.remove(dl)
|
79 |
-
m = f"https://graph.org{variable[0]}"
|
80 |
-
elif wut == "web":
|
81 |
-
m = None
|
82 |
-
else:
|
83 |
-
m = pack_bot_file_id(r.media)
|
84 |
-
if r.text:
|
85 |
-
txt = r.text
|
86 |
-
if not btn:
|
87 |
-
txt, btn = get_msg_button(r.text)
|
88 |
-
add_welcome(event.chat_id, txt, m, btn)
|
89 |
-
else:
|
90 |
-
add_welcome(event.chat_id, None, m, btn)
|
91 |
-
await eor(x, get_string("grt_1"))
|
92 |
-
elif text:
|
93 |
-
if not btn:
|
94 |
-
txt, btn = get_msg_button(text)
|
95 |
-
add_welcome(event.chat_id, txt, None, btn)
|
96 |
-
await eor(x, get_string("grt_1"))
|
97 |
-
else:
|
98 |
-
await eor(x, get_string("grt_3"), time=5)
|
99 |
-
|
100 |
-
|
101 |
-
@ultroid_cmd(pattern="clearwelcome$", groups_only=True)
|
102 |
-
async def clearwel(event):
|
103 |
-
if not get_welcome(event.chat_id):
|
104 |
-
return await event.eor(get_string("grt_4"), time=5)
|
105 |
-
delete_welcome(event.chat_id)
|
106 |
-
await event.eor(get_string("grt_5"), time=5)
|
107 |
-
|
108 |
-
|
109 |
-
@ultroid_cmd(pattern="getwelcome$", groups_only=True)
|
110 |
-
async def listwel(event):
|
111 |
-
wel = get_welcome(event.chat_id)
|
112 |
-
if not wel:
|
113 |
-
return await event.eor(get_string("grt_4"), time=5)
|
114 |
-
msgg, med = wel["welcome"], wel["media"]
|
115 |
-
if wel.get("button"):
|
116 |
-
btn = create_tl_btn(wel["button"])
|
117 |
-
return await something(event, msgg, med, btn)
|
118 |
-
await event.reply(f"**Welcome Note in this chat**\n\n`{msgg}`", file=med)
|
119 |
-
await event.delete()
|
120 |
-
|
121 |
-
|
122 |
-
@ultroid_cmd(pattern="setgoodbye", groups_only=True)
|
123 |
-
async def setgb(event):
|
124 |
-
x = await event.eor(get_string("com_1"))
|
125 |
-
r = await event.get_reply_message()
|
126 |
-
btn = format_btn(r.buttons) if (r and r.buttons) else None
|
127 |
-
try:
|
128 |
-
text = event.text.split(maxsplit=1)[1]
|
129 |
-
except IndexError:
|
130 |
-
text = r.text if r else None
|
131 |
-
if r and r.media:
|
132 |
-
wut = mediainfo(r.media)
|
133 |
-
if wut.startswith(("pic", "gif")):
|
134 |
-
dl = await r.download_media()
|
135 |
-
variable = uf(dl)
|
136 |
-
os.remove(dl)
|
137 |
-
m = f"https://graph.org{variable[0]}"
|
138 |
-
elif wut == "video":
|
139 |
-
if r.media.document.size > 8 * 1000 * 1000:
|
140 |
-
return await eor(x, get_string("com_4"), time=5)
|
141 |
-
dl = await r.download_media()
|
142 |
-
variable = uf(dl)
|
143 |
-
os.remove(dl)
|
144 |
-
m = f"https://graph.org{variable[0]}"
|
145 |
-
elif wut == "web":
|
146 |
-
m = None
|
147 |
-
else:
|
148 |
-
m = pack_bot_file_id(r.media)
|
149 |
-
if r.text:
|
150 |
-
txt = r.text
|
151 |
-
if not btn:
|
152 |
-
txt, btn = get_msg_button(r.text)
|
153 |
-
add_goodbye(event.chat_id, txt, m, btn)
|
154 |
-
else:
|
155 |
-
add_goodbye(event.chat_id, None, m, btn)
|
156 |
-
await eor(x, "`Goodbye note saved`")
|
157 |
-
elif text:
|
158 |
-
if not btn:
|
159 |
-
txt, btn = get_msg_button(text)
|
160 |
-
add_goodbye(event.chat_id, txt, None, btn)
|
161 |
-
await eor(x, "`Goodbye note saved`")
|
162 |
-
else:
|
163 |
-
await eor(x, get_string("grt_7"), time=5)
|
164 |
-
|
165 |
-
|
166 |
-
@ultroid_cmd(pattern="cleargoodbye$", groups_only=True)
|
167 |
-
async def clearwgb(event):
|
168 |
-
if not get_goodbye(event.chat_id):
|
169 |
-
return await event.eor(get_string("grt_6"), time=5)
|
170 |
-
delete_goodbye(event.chat_id)
|
171 |
-
await event.eor("`Goodbye Note Deleted`", time=5)
|
172 |
-
|
173 |
-
|
174 |
-
@ultroid_cmd(pattern="getgoodbye$", groups_only=True)
|
175 |
-
async def listgd(event):
|
176 |
-
wel = get_goodbye(event.chat_id)
|
177 |
-
if not wel:
|
178 |
-
return await event.eor(get_string("grt_6"), time=5)
|
179 |
-
msgg = wel["goodbye"]
|
180 |
-
med = wel["media"]
|
181 |
-
if wel.get("button"):
|
182 |
-
btn = create_tl_btn(wel["button"])
|
183 |
-
return await something(event, msgg, med, btn)
|
184 |
-
await event.reply(f"**Goodbye Note in this chat**\n\n`{msgg}`", file=med)
|
185 |
-
await event.delete()
|
186 |
-
|
187 |
-
|
188 |
-
@ultroid_cmd(pattern="thankmembers (on|off)", groups_only=True)
|
189 |
-
async def thank_set(event):
|
190 |
-
type_ = event.pattern_match.group(1).strip()
|
191 |
-
if not type_ or type_ == "":
|
192 |
-
await eor(
|
193 |
-
event,
|
194 |
-
f"**Current Chat Settings:**\n**Thanking Members:** `{must_thank(event.chat_id)}`\n\nUse `{HNDLR}thankmembers on` or `{HNDLR}thankmembers off` to toggle current settings!",
|
195 |
-
)
|
196 |
-
return
|
197 |
-
chat = event.chat_id
|
198 |
-
if type_.lower() == "on":
|
199 |
-
add_thanks(chat)
|
200 |
-
elif type_.lower() == "off":
|
201 |
-
remove_thanks(chat)
|
202 |
-
await eor(
|
203 |
-
event,
|
204 |
-
f"**Done! Thank you members has been turned** `{type_.lower()}` **for this chat**!",
|
205 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins/imagetools.py
DELETED
@@ -1,292 +0,0 @@
|
|
1 |
-
# Ultroid - UserBot
|
2 |
-
# Copyright (C) 2021-2023 TeamUltroid
|
3 |
-
#
|
4 |
-
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
5 |
-
# PLease read the GNU Affero General Public License in
|
6 |
-
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
7 |
-
"""
|
8 |
-
✘ Commands Available -
|
9 |
-
|
10 |
-
• `{i}border <reply to photo/sticker>`
|
11 |
-
To create border around that media..
|
12 |
-
Ex - `{i}border 12,22,23`
|
13 |
-
- `{i}border 12,22,23 ; width (in number)`
|
14 |
-
|
15 |
-
• `{i}grey <reply to any media>`
|
16 |
-
To make it black nd white.
|
17 |
-
|
18 |
-
• `{i}color <reply to any Black nd White media>`
|
19 |
-
To make it Colorfull.
|
20 |
-
|
21 |
-
• `{i}toon <reply to any media>`
|
22 |
-
To make it toon.
|
23 |
-
|
24 |
-
• `{i}danger <reply to any media>`
|
25 |
-
To make it look Danger.
|
26 |
-
|
27 |
-
• `{i}negative <reply to any media>`
|
28 |
-
To make negative image.
|
29 |
-
|
30 |
-
• `{i}blur <reply to any media>`
|
31 |
-
To make it blurry.
|
32 |
-
|
33 |
-
• `{i}quad <reply to any media>`
|
34 |
-
create a Vortex.
|
35 |
-
|
36 |
-
• `{i}mirror <reply to any media>`
|
37 |
-
To create mirror pic.
|
38 |
-
|
39 |
-
• `{i}flip <reply to any media>`
|
40 |
-
To make it flip.
|
41 |
-
|
42 |
-
• `{i}sketch <reply to any media>`
|
43 |
-
To draw its sketch.
|
44 |
-
|
45 |
-
• `{i}blue <reply to any media>`
|
46 |
-
just cool.
|
47 |
-
|
48 |
-
• `{i}csample <color name /color code>`
|
49 |
-
example : `{i}csample red`
|
50 |
-
`{i}csample #ffffff`
|
51 |
-
|
52 |
-
• `{i}pixelator <reply image>`
|
53 |
-
Create a Pixelated Image..
|
54 |
-
"""
|
55 |
-
import os
|
56 |
-
|
57 |
-
from . import LOGS, con
|
58 |
-
|
59 |
-
try:
|
60 |
-
import cv2
|
61 |
-
except ImportError:
|
62 |
-
LOGS.error(f"{__file__}: OpenCv not Installed.")
|
63 |
-
|
64 |
-
import numpy as np
|
65 |
-
|
66 |
-
try:
|
67 |
-
from PIL import Image
|
68 |
-
except ImportError:
|
69 |
-
Image = None
|
70 |
-
LOGS.info(f"{__file__}: PIL not Installed.")
|
71 |
-
from telegraph import upload_file as upf
|
72 |
-
from telethon.errors.rpcerrorlist import (
|
73 |
-
ChatSendMediaForbiddenError,
|
74 |
-
MessageDeleteForbiddenError,
|
75 |
-
)
|
76 |
-
|
77 |
-
from . import (
|
78 |
-
Redis,
|
79 |
-
async_searcher,
|
80 |
-
download_file,
|
81 |
-
get_string,
|
82 |
-
requests,
|
83 |
-
udB,
|
84 |
-
ultroid_cmd,
|
85 |
-
)
|
86 |
-
|
87 |
-
|
88 |
-
@ultroid_cmd(pattern="color$")
|
89 |
-
async def _(event):
|
90 |
-
reply = await event.get_reply_message()
|
91 |
-
if not (reply and reply.media):
|
92 |
-
return await event.eor("`Reply To a Black and White Image`")
|
93 |
-
xx = await event.eor("`Coloring image 🎨🖌️...`")
|
94 |
-
image = await reply.download_media()
|
95 |
-
img = cv2.VideoCapture(image)
|
96 |
-
ret, frame = img.read()
|
97 |
-
cv2.imwrite("ult.jpg", frame)
|
98 |
-
if udB.get_key("DEEP_API"):
|
99 |
-
key = Redis("DEEP_API")
|
100 |
-
else:
|
101 |
-
key = "quickstart-QUdJIGlzIGNvbWluZy4uLi4K"
|
102 |
-
r = requests.post(
|
103 |
-
"https://api.deepai.org/api/colorizer",
|
104 |
-
files={"image": open("ult.jpg", "rb")},
|
105 |
-
headers={"api-key": key},
|
106 |
-
)
|
107 |
-
os.remove("ult.jpg")
|
108 |
-
os.remove(image)
|
109 |
-
if "status" in r.json():
|
110 |
-
return await event.edit(
|
111 |
-
r.json()["status"] + "\nGet api nd set `{i}setdb DEEP_API key`"
|
112 |
-
)
|
113 |
-
r_json = r.json()["output_url"]
|
114 |
-
await event.client.send_file(event.chat_id, r_json, reply_to=reply)
|
115 |
-
await xx.delete()
|
116 |
-
|
117 |
-
|
118 |
-
@ultroid_cmd(pattern="(grey|blur|negative|danger|mirror|quad|sketch|flip|toon)$")
|
119 |
-
async def ult_tools(event):
|
120 |
-
match = event.pattern_match.group(1)
|
121 |
-
ureply = await event.get_reply_message()
|
122 |
-
if not (ureply and (ureply.media)):
|
123 |
-
await event.eor(get_string("cvt_3"))
|
124 |
-
return
|
125 |
-
ultt = await ureply.download_media()
|
126 |
-
xx = await event.eor(get_string("com_1"))
|
127 |
-
if ultt.endswith(".tgs"):
|
128 |
-
xx = await xx.edit(get_string("sts_9"))
|
129 |
-
file = await con.convert(ultt, convert_to="png", outname="ult")
|
130 |
-
ult = cv2.imread(file)
|
131 |
-
if match == "grey":
|
132 |
-
ultroid = cv2.cvtColor(ult, cv2.COLOR_BGR2GRAY)
|
133 |
-
elif match == "blur":
|
134 |
-
ultroid = cv2.GaussianBlur(ult, (35, 35), 0)
|
135 |
-
elif match == "negative":
|
136 |
-
ultroid = cv2.bitwise_not(ult)
|
137 |
-
elif match == "danger":
|
138 |
-
dan = cv2.cvtColor(ult, cv2.COLOR_BGR2RGB)
|
139 |
-
ultroid = cv2.cvtColor(dan, cv2.COLOR_HSV2BGR)
|
140 |
-
elif match == "mirror":
|
141 |
-
ish = cv2.flip(ult, 1)
|
142 |
-
ultroid = cv2.hconcat([ult, ish])
|
143 |
-
elif match == "flip":
|
144 |
-
trn = cv2.flip(ult, 1)
|
145 |
-
ish = cv2.rotate(trn, cv2.ROTATE_180)
|
146 |
-
ultroid = cv2.vconcat([ult, ish])
|
147 |
-
elif match == "quad":
|
148 |
-
ult = cv2.imread(file)
|
149 |
-
roid = cv2.flip(ult, 1)
|
150 |
-
mici = cv2.hconcat([ult, roid])
|
151 |
-
fr = cv2.flip(mici, 1)
|
152 |
-
trn = cv2.rotate(fr, cv2.ROTATE_180)
|
153 |
-
ultroid = cv2.vconcat([mici, trn])
|
154 |
-
elif match == "sketch":
|
155 |
-
gray_image = cv2.cvtColor(ult, cv2.COLOR_BGR2GRAY)
|
156 |
-
inverted_gray_image = 255 - gray_image
|
157 |
-
blurred_img = cv2.GaussianBlur(inverted_gray_image, (21, 21), 0)
|
158 |
-
inverted_blurred_img = 255 - blurred_img
|
159 |
-
ultroid = cv2.divide(gray_image, inverted_blurred_img, scale=256.0)
|
160 |
-
elif match == "toon":
|
161 |
-
height, width, _ = ult.shape
|
162 |
-
samples = np.zeros([height * width, 3], dtype=np.float32)
|
163 |
-
count = 0
|
164 |
-
for x in range(height):
|
165 |
-
for y in range(width):
|
166 |
-
samples[count] = ult[x][y]
|
167 |
-
count += 1
|
168 |
-
_, labels, centers = cv2.kmeans(
|
169 |
-
samples,
|
170 |
-
12,
|
171 |
-
None,
|
172 |
-
(cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10000, 0.0001),
|
173 |
-
5,
|
174 |
-
cv2.KMEANS_PP_CENTERS,
|
175 |
-
)
|
176 |
-
centers = np.uint8(centers)
|
177 |
-
ish = centers[labels.flatten()]
|
178 |
-
ultroid = ish.reshape(ult.shape)
|
179 |
-
cv2.imwrite("ult.jpg", ultroid)
|
180 |
-
await ureply.reply(
|
181 |
-
file="ult.jpg",
|
182 |
-
force_document=False,
|
183 |
-
)
|
184 |
-
await xx.delete()
|
185 |
-
os.remove("ult.jpg")
|
186 |
-
os.remove(file)
|
187 |
-
|
188 |
-
|
189 |
-
@ultroid_cmd(pattern="csample (.*)")
|
190 |
-
async def sampl(ult):
|
191 |
-
if color := ult.pattern_match.group(1).strip():
|
192 |
-
img = Image.new("RGB", (200, 100), f"{color}")
|
193 |
-
img.save("csample.png")
|
194 |
-
try:
|
195 |
-
try:
|
196 |
-
await ult.delete()
|
197 |
-
await ult.respond(f"Colour Sample for `{color}` !", file="csample.png")
|
198 |
-
except MessageDeleteForbiddenError:
|
199 |
-
await ult.reply(f"Colour Sample for `{color}` !", file="csample.png")
|
200 |
-
except ChatSendMediaForbiddenError:
|
201 |
-
await ult.eor("Umm! Sending Media is disabled here!")
|
202 |
-
|
203 |
-
else:
|
204 |
-
await ult.eor("Wrong Color Name/Hex Code specified!")
|
205 |
-
|
206 |
-
|
207 |
-
@ultroid_cmd(
|
208 |
-
pattern="blue$",
|
209 |
-
)
|
210 |
-
async def ultd(event):
|
211 |
-
ureply = await event.get_reply_message()
|
212 |
-
xx = await event.eor("`...`")
|
213 |
-
if not (ureply and (ureply.media)):
|
214 |
-
await xx.edit(get_string("cvt_3"))
|
215 |
-
return
|
216 |
-
ultt = await ureply.download_media()
|
217 |
-
if ultt.endswith(".tgs"):
|
218 |
-
await xx.edit(get_string("sts_9"))
|
219 |
-
file = await con.convert(ultt, convert_to="png", outname="ult")
|
220 |
-
got = upf(file)
|
221 |
-
lnk = f"https://graph.org{got[0]}"
|
222 |
-
r = await async_searcher(
|
223 |
-
f"https://nekobot.xyz/api/imagegen?type=blurpify&image={lnk}", re_json=True
|
224 |
-
)
|
225 |
-
ms = r.get("message")
|
226 |
-
if not r["success"]:
|
227 |
-
return await xx.edit(ms)
|
228 |
-
await download_file(ms, "ult.png")
|
229 |
-
img = Image.open("ult.png").convert("RGB")
|
230 |
-
img.save("ult.webp", "webp")
|
231 |
-
await event.client.send_file(
|
232 |
-
event.chat_id,
|
233 |
-
"ult.webp",
|
234 |
-
force_document=False,
|
235 |
-
reply_to=event.reply_to_msg_id,
|
236 |
-
)
|
237 |
-
await xx.delete()
|
238 |
-
os.remove("ult.png")
|
239 |
-
os.remove("ult.webp")
|
240 |
-
os.remove(ultt)
|
241 |
-
|
242 |
-
|
243 |
-
@ultroid_cmd(pattern="border( (.*)|$)")
|
244 |
-
async def ok(event):
|
245 |
-
hm = await event.get_reply_message()
|
246 |
-
if not (hm and (hm.photo or hm.sticker)):
|
247 |
-
return await event.eor("`Reply to Sticker or Photo..`")
|
248 |
-
col = event.pattern_match.group(1).strip()
|
249 |
-
wh = 20
|
250 |
-
if not col:
|
251 |
-
col = [255, 255, 255]
|
252 |
-
else:
|
253 |
-
try:
|
254 |
-
if ";" in col:
|
255 |
-
col_ = col.split(";", maxsplit=1)
|
256 |
-
wh = int(col_[1])
|
257 |
-
col = col_[0]
|
258 |
-
col = [int(col) for col in col.split(",")[:2]]
|
259 |
-
except ValueError:
|
260 |
-
return await event.eor("`Not a Valid Input...`")
|
261 |
-
okla = await hm.download_media()
|
262 |
-
img1 = cv2.imread(okla)
|
263 |
-
constant = cv2.copyMakeBorder(img1, wh, wh, wh, wh, cv2.BORDER_CONSTANT, value=col)
|
264 |
-
cv2.imwrite("output.png", constant)
|
265 |
-
await event.client.send_file(event.chat.id, "output.png")
|
266 |
-
os.remove("output.png")
|
267 |
-
os.remove(okla)
|
268 |
-
await event.delete()
|
269 |
-
|
270 |
-
|
271 |
-
@ultroid_cmd(pattern="pixelator( (.*)|$)")
|
272 |
-
async def pixelator(event):
|
273 |
-
reply_message = await event.get_reply_message()
|
274 |
-
if not (reply_message and (reply_message.photo or reply_message.sticker)):
|
275 |
-
return await event.eor("`Reply to a photo`")
|
276 |
-
hw = 50
|
277 |
-
try:
|
278 |
-
hw = int(event.pattern_match.group(1).strip())
|
279 |
-
except (ValueError, TypeError):
|
280 |
-
pass
|
281 |
-
msg = await event.eor(get_string("com_1"))
|
282 |
-
image = await reply_message.download_media()
|
283 |
-
input_ = cv2.imread(image)
|
284 |
-
height, width = input_.shape[:2]
|
285 |
-
w, h = (hw, hw)
|
286 |
-
temp = cv2.resize(input_, (w, h), interpolation=cv2.INTER_LINEAR)
|
287 |
-
output = cv2.resize(temp, (width, height), interpolation=cv2.INTER_NEAREST)
|
288 |
-
cv2.imwrite("output.jpg", output)
|
289 |
-
await msg.respond("• Pixelated by Ultroid", file="output.jpg")
|
290 |
-
await msg.delete()
|
291 |
-
os.remove("output.jpg")
|
292 |
-
os.remove(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|