File size: 12,446 Bytes
f0f9ad9
cf6e83d
5fdc6b8
f0f9ad9
9db4ada
f0f9ad9
9db4ada
 
f0f9ad9
 
cbec4fb
f0f9ad9
af1662b
6d3c95d
6e5f67b
f0f9ad9
 
 
ca4eb6d
 
 
 
 
 
af1662b
 
 
ca4eb6d
 
 
 
 
 
 
5ec9c41
ca4eb6d
 
5ec9c41
ca4eb6d
 
 
 
 
 
 
5ec9c41
ca4eb6d
 
 
 
 
 
 
 
5ec9c41
ca4eb6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5fdc6b8
cf6e83d
ca4eb6d
 
 
 
 
11170eb
ca4eb6d
 
 
 
 
11170eb
ca4eb6d
af1662b
 
ca4eb6d
 
 
 
 
11170eb
ca4eb6d
11170eb
ca4eb6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1d601a
 
11170eb
ca4eb6d
 
c1d601a
11170eb
ca4eb6d
 
 
 
 
 
 
af1662b
 
 
 
ca4eb6d
11170eb
 
5ec9c41
ca4eb6d
 
 
 
 
af1662b
 
 
 
ca4eb6d
 
 
 
5ec9c41
ca4eb6d
c1d601a
af1662b
ca4eb6d
af1662b
ca4eb6d
cf6e83d
ca4eb6d
5fdc6b8
ca4eb6d
 
 
 
 
 
 
 
5ec9c41
ca4eb6d
 
11170eb
ca4eb6d
 
 
 
cf6e83d
ca4eb6d
cf6e83d
 
 
 
 
 
 
 
 
 
 
c664d1d
cf6e83d
 
d5348c6
c664d1d
d5348c6
cf6e83d
3c3977c
cf6e83d
 
 
 
 
 
 
 
3c3977c
 
 
 
 
 
 
 
 
6d3c95d
3c3977c
 
 
 
 
 
 
a8b7e55
 
 
3c3977c
 
 
81ba255
bd3e960
 
 
cf6e83d
c664d1d
af1662b
 
c664d1d
 
ca4eb6d
6e5f67b
c664d1d
 
 
ca4eb6d
c664d1d
ca4eb6d
 
c664d1d
 
 
 
af1662b
c664d1d
ca4eb6d
c664d1d
 
ca4eb6d
c664d1d
ca4eb6d
c664d1d
 
 
 
 
ca4eb6d
c664d1d
 
ca4eb6d
c664d1d
 
 
 
 
 
 
 
 
ca4eb6d
341e197
c664d1d
 
 
 
 
 
ca4eb6d
c664d1d
 
 
 
 
 
 
 
98371d5
 
af1662b
 
 
858a334
ca4eb6d
 
c664d1d
ca4eb6d
af1662b
 
 
c664d1d
ca4eb6d
 
c664d1d
 
 
ca4eb6d
c664d1d
ca4eb6d
c664d1d
 
 
ca4eb6d
 
c664d1d
 
ca4eb6d
 
 
 
c664d1d
ca4eb6d
c664d1d
ca4eb6d
 
 
 
 
5fdc6b8
ca4eb6d
9da6fea
709df35
096ee5f
709df35
 
9da6fea
d5348c6
 
 
 
 
 
 
9da6fea
 
d5348c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
import re
import asyncio
import aiofiles
from Powers import *
from os import remove
from io import BytesIO
from wikipedia import summary
from Powers.bot_class import Gojo
from gpytranslate import Translator
from pyrogram import enums, filters
from pyrogram.enums import ChatType
from Powers.utils.http_helper import *
from Powers.database.users_db import Users
from pyrogram.errors import MessageTooLong
from Powers.utils.custom_filters import command
from Powers.utils.clean_file import remove_markdown_and_html
from wikipedia.exceptions import PageError, DisambiguationError
from pyrogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup


@Gojo.on_message(command("wiki"))
async def wiki(_, m: Message):

    if len(m.text.split()) <= 1:
        return await m.reply_text(
            text="Please check help on how to use this this command."
        )

    search = m.text.split(None, 1)[1]
    try:
        res = summary(search)
    except DisambiguationError as de:
        return await m.reply_text(
            f"Disambiguated pages found! Adjust your query accordingly.\n<i>{de}</i>",
            parse_mode=enums.ParseMode.HTML,
        )
    except PageError as pe:
        return await m.reply_text(f"<code>{pe}</code>", parse_mode=enums.ParseMode.HTML)
    if res:
        result = f"<b>{search}</b>\n\n"
        result += f"<i>{res}</i>\n"
        result += f"""<a href="https://en.wikipedia.org/wiki/{search.replace(" ", "%20")}">Read more...</a>"""
        try:
            return await m.reply_text(
                result,
                parse_mode=enums.ParseMode.HTML,
                disable_web_page_preview=True,
            )
        except MessageTooLong:
            with BytesIO(str.encode(await remove_markdown_and_html(result))) as f:
                f.name = "result.txt"
                return await m.reply_document(
                    document=f,
                    quote=True,
                    parse_mode=enums.ParseMode.HTML,
                )
    await m.stop_propagation()


@Gojo.on_message(command("gdpr"))
async def gdpr_remove(_, m: Message):
    if m.from_user.id in SUPPORT_STAFF:
        await m.reply_text(
            "You're in my support staff, I cannot do that unless you are no longer a part of it!",
        )
        return

    Users(m.from_user.id).delete_user()
    await m.reply_text(
        "Your personal data has been deleted.\n"
        "Note that this will not unban you from any chats, as that is telegram data, not Gojo data."
        " Flooding, warns, and gbans are also preserved, as of "
        "[this](https://ico.org.uk/for-organisations/guide-to-the-general-data-protection-regulation-gdpr/individual-rights/right-to-erasure/),"
        " which clearly states that the right to erasure does not apply 'for the performance of a task carried out in the public interest', "
        "as is the case for the aforementioned pieces of data.",
        disable_web_page_preview=True,
    )
    await m.stop_propagation()


'''
@Gojo.on_message(
    command("lyrics") & (filters.group | filters.private),
)
async def get_lyrics(_, m: Message):
    if len(m.text.split()) <= 1:
        await m.reply_text(text="Please check help on how to use this this command.")
        return

    query = m.text.split(None, 1)[1]
    song = ""
    if not query:
        await m.edit_text(text="You haven't specified which song to look for!")
        return
    song_name = query
    em = await m.reply_text(text=f"Finding lyrics for <code>{song_name}<code>...")
    song = Song.find_song(query)
    if song:
        if song.lyrics:
            reply = song.format()
        else:
            reply = "Couldn't find any lyrics for that song!"
    else:
        reply = "Song not found!"
    try:
        await em.edit_text(reply)
    except MessageTooLong:
        with BytesIO(str.encode(await remove_markdown_and_html(reply))) as f:
            f.name = "lyrics.txt"
            await m.reply_document(
                document=f,
            )
        await em.delete()
    return


@Gojo.on_message(
    command("id") & (filters.group | filters.private),
)
async def id_info(c: Gojo, m: Message):


    if m.chat.type == ChatType.SUPERGROUP and not m.reply_to_message:
        await m.reply_text(text=f"This Group's ID is <code>{m.chat.id}</code>")
        return

    if m.chat.type == ChatType.PRIVATE and not m.reply_to_message:
        await m.reply_text(text=f"Your ID is <code>{m.chat.id}</code>.")
        return

    user_id, _, _ = await extract_user(c, m)
    if user_id:
        if m.reply_to_message and m.reply_to_message.forward_from:
            user1 = m.reply_to_message.from_user
            user2 = m.reply_to_message.forward_from
            orig_sender = ((await mention_html(user2.first_name, user2.id)),)
            orig_id = (f"<code>{user2.id}</code>",)
            fwd_sender = ((await mention_html(user1.first_name, user1.id)),)
            fwd_id = (f"<code>{user1.id}</code>",)
            await m.reply_text(
                text=f"""Original Sender - {orig_sender} (<code>{orig_id}</code>)
        Forwarder - {fwd_sender} (<code>{fwd_id}</code>)""",
                parse_mode=enums.ParseMode.HTML,
            )
        else:
            try:
                user = await c.get_users(user_id)
            except PeerIdInvalid:
                await m.reply_text(
                    text="""Failed to get user
      Peer ID invalid, I haven't seen this user anywhere earlier, maybe username would help to know them!"""
                )
                return

            await m.reply_text(
                f"{(await mention_html(user.first_name, user.id))}'s ID is <code>{user.id}</code>.",
                parse_mode=enums.ParseMode.HTML,
            )
    elif m.chat.type == ChatType.PRIVATE:
        await m.reply_text(text=f"Your ID is <code>{m.chat.id}</code>.")
    else:
        await m.reply_text(text=f"This Group's ID is <code>{m.chat.id}</code>")
    return
'''


@Gojo.on_message(
    command("gifid") & (filters.group | filters.private),
)
async def get_gifid(_, m: Message):
    if m.reply_to_message and m.reply_to_message.animation:
        LOGGER.info(f"{m.from_user.id} used gifid cmd in {m.chat.id}")
        await m.reply_text(
            f"Gif ID:\n<code>{m.reply_to_message.animation.file_id}</code>",
            parse_mode=enums.ParseMode.HTML,
        )
    else:
        await m.reply_text(text="Please reply to a gif to get it's ID.")
    return


@Gojo.on_message(
    command(["github", "git"]) & (filters.group | filters.private),
)
async def github(_, m: Message):
    if len(m.text.split()) == 2:
        username = m.text.split(maxsplit=1)[1]
        LOGGER.info(f"{m.from_user.id} used github cmd in {m.chat.id}")
    else:
        await m.reply_text(
            f"Usage: <code>{Config.PREFIX_HANDLER}github username</code>",
        )
        return

    URL = f"https://api.github.com/users/{username}"
    try:
        r = await get(URL, timeout=5)
    except asyncio.TimeoutError:
        return await m.reply_text("request timeout")
    except Exception as e:
        return await m.reply_text(f"ERROR: `{e}`")

    avtar = r.get("avatar_url", None)
    url = r.get("html_url", None)
    name = r.get("name", None)
    company = r.get("company", None)
    followers = r.get("followers", 0)
    following = r.get("following", 0)
    public_repos = r.get("public_repos", 0)
    bio = r.get("bio", None)
    created_at = r.get("created_at", "Not Found")
    location = r.get("location", None)
    email = r.get("email", None)

    REPLY = f"<b>GitHub Info for @{username}:</b>\n"
    if name:
        REPLY += f"\n<b>Name:</b> <code>{name}</code>\n"
    if bio:
        REPLY += f"<b>Bio:</b> <code>{bio}</code>\n"
    if url:
        REPLY += f"<b>URL:</b> <a href='{url}'>{name}</a>\n"
    REPLY += f"<b>Public Repos:</b> {public_repos}\n"
    REPLY += f"<b>Followers:</b> {followers}\n"
    REPLY += f"<b>Following:</b> {following}\n"
    if email:
        REPLY += f"<b>Email:</b> <code>{email}</code>\n"
    if company:
        org_url = company.strip("@")
        REPLY += (
            f"<b>Company:</b> <a href='https://github.com/{org_url}'>{company}</a>\n"
        )
    if location:
        REPLY += f"<b>Location:</b> <code>{location}</code>\n"
    REPLY += f"<b>Created at:</b> <code>{created_at}</code>\n"

    if avtar:
        return await m.reply_photo(photo=f"{avtar}", caption=REPLY)
    await m.reply_text(REPLY)
    return


# paste here
pattern = re.compile(r"^text/|json$|yaml$|xml$|toml$|x-sh$|x-shellscript$")
BASE = "https://batbin.me/"


async def paste(content: str):
    resp = await post(f"{BASE}api/v2/paste", data=content)
    if not resp["success"]:
        return
    return BASE + resp["message"]


@Gojo.on_message(command("paste"))
async def paste_func(_, message: Message):
    if not message.reply_to_message:
        return await message.reply_text("Reply To A Message With `/paste`")

    r = message.reply_to_message

    if not r.text and not r.document:
        return await message.reply_text("Only text and documents are supported")

    m = await message.reply_text("Pasting...")

    if r.text:
        content = str(r.text)
    elif r.document:
        if r.document.file_size > 40000:
            return await m.edit("You can only paste files smaller than 40KB.")

        if not pattern.search(r.document.mime_type):
            return await m.edit("Only text files can be pasted.")

        doc = await message.reply_to_message.download()

        async with aiofiles.open(doc, mode="r") as f:
            content = await f.read()

        remove(doc)

    link = await paste(content)
    kb = [[InlineKeyboardButton(text="Paste Link ", url=link)]]
    try:
        if message.from_user.is_bot:
            await message.reply_photo(
                photo=link,
                quote=False,
                caption="Pasted",
                reply_markup=InlineKeyboardMarkup(kb),
            )
        else:
            await message.reply_photo(
                photo=link,
                quote=False,
                caption="Pasted",
                reply_markup=InlineKeyboardMarkup(kb),
            )
        await m.delete()
    except Exception:
        await m.delete()
        await message.reply_text(
            "Here is the link of the document....",
            reply_markup=InlineKeyboardMarkup(kb),
        )


@Gojo.on_message(command("tr"))
async def tr(_, message):
    trl = Translator()
    if message.reply_to_message and (
        message.reply_to_message.text or message.reply_to_message.caption
    ):
        if len(message.text.split()) == 1:
            target_lang = "en"
        else:
            target_lang = message.text.split()[1]
        if message.reply_to_message.text:
            text = message.reply_to_message.text
        else:
            text = message.reply_to_message.caption
    else:
        if len(message.text.split()) <= 2:
            await message.reply_text(
                "Provide lang code.\n[Available options](https://telegra.ph/Lang-Codes-02-22).\n<b>Usage:</b> <code>/tr en</code>",
            )
            return
        target_lang = message.text.split(None, 2)[1]
        text = message.text.split(None, 2)[2]
    detectlang = await trl.detect(text)
    try:
        tekstr = await trl(text, targetlang=target_lang)
    except ValueError as err:
        await message.reply_text(f"Error: <code>{str(err)}</code>")
        return
    return await message.reply_text(
        f"<b>Translated:</b> from {detectlang} to {target_lang} \n<code>``{tekstr.text}``</code>",
    )


__PLUGIN__ = "utils"
_DISABLE_CMDS_ = ["paste", "wiki", "id", "gifid", "tr", "github", "git"]
__alt_name__ = ["util", "misc", "tools"]

__HELP__ = """
**Utils**

Some utils provided by bot to make your tasks easy!

• /id: Get the current group id. If used by replying to a message, get that user's id.
• /info: Get information about a user.
• /gifid: Reply to a gif to me to tell you its file ID.
• /wiki: `<query>`: wiki your query.
• /tr `<language>`: Translates the text and then replies to you with the language you have specifed, works as a reply to message.
• /git `<username>`: Search for the user using github api!
• /weebify `<text>` or `<reply to message>`: To weebify the text.

**Example:**
`/git iamgojoof6eyes`: this fetches the information about a user from the database."""