コード例 #1
0
ファイル: tg_save_bot.py プロジェクト: wshon/scripts
async def my_event_handler(event: events.NewMessage.Event):
    message: Message = event.message
    if 'hello' in message.raw_text:
        await message.reply(f'hi {message.chat_id}')
    elif file := resolve_bot_file_id(message.raw_text):
        await bot.send_file(event.chat, file, caption=message.raw_text)
        await message.delete()
コード例 #2
0
ファイル: bot.py プロジェクト: YonatanGM/songs.inc
async def inlinehandler(event):
    builder = event.builder
    chat = await event.get_sender()
    query = event.text.lower()
    df = pd.read_csv("collection.csv",
                     index_col=['title', 'artist'],
                     encoding='utf8')
    title = df.index.dropna().to_list()
    result = set()

    x = process.extractBests(query, title, score_cutoff=90, limit=8)
    for i in range(len(x)):

        msg_id = df.at[x[i][0], 'msg_id']
        from_peer = df.at[x[i][0], 'from_peer']
        print(x)
        if type(msg_id) == numpy.ndarray:
            msg_id = int(msg_id[random.randint(0, len(msg_id) - 1)])
        if type(from_peer) == numpy.ndarray:
            from_peer = int(from_peer[random.randint(0, len(from_peer) - 1)])

        from_peer_entity = await bot.get_entity(int(from_peer))
        message = await bot.get_messages(int(from_peer),
                                         limit=1,
                                         ids=int(msg_id))
        resolved_id = utils.resolve_bot_file_id(message.file.id)

        result.add(builder.document(resolved_id, type='audio'))

    await event.answer(list(result))
コード例 #3
0
ファイル: bot.py プロジェクト: parth0207/Ultroid
async def inline_alive(ult):
    pic = udB.get("ALIVE_PIC")
    uptime = time_formatter((time.time() - start_time) * 1000)
    header = udB.get("ALIVE_TEXT") or get_string("bot_1")
    y = Repo().active_branch
    xx = Repo().remotes[0].config_reader.get("url")
    rep = xx.replace(".git", f"/tree/{y}")
    kk = f" `[{y}]({rep})` "
    als = (get_string("alive_1")).format(
        header,
        OWNER_NAME,
        ultroid_version,
        UltVer,
        uptime,
        pyver(),
        __version__,
        kk,
    )
    buttons = [
        [
            Button.url(get_string("bot_3"), "https://github.com/TeamUltroid/Ultroid"),
            Button.url(get_string("bot_4"), "t.me/UltroidSupport"),
        ]
    ]
    builder = ult.builder
    if pic:
        try:
            if ".jpg" in pic:
                results = [await builder.photo(pic, text=als, buttons=buttons)]
            else:
                _pic = resolve_bot_file_id(pic)
                if _pic:
                    pic = _pic
                    buttons.insert(
                        0, [Button.inline(get_string("bot_2"), data="alive")]
                    )
                results = [
                    await builder.document(
                        pic,
                        title="Inline Alive",
                        description="@TheUltroid",
                        buttons=buttons,
                    )
                ]
            return await ult.answer(results)
        except BaseException as er:
            LOGS.info(er)
    result = [
        await builder.article("Alive", text=als, link_preview=False, buttons=buttons)
    ]
    await ult.answer(result)
コード例 #4
0
async def handler(event):
    try:
        builder = event.builder
        to = event.query.query
        arr = [
            builder.document(file=utils.resolve_bot_file_id(value),
                             title=key,
                             type="voice") for key, value in config.items()
            if to in key.lower()
        ]
        if len(arr) != 0:
            await event.answer(arr)
        else:
            await event.answer([builder.article("test", "test")])
    except Exception as er:
        print(er)
コード例 #5
0
ファイル: bot.py プロジェクト: kingoflegendsk/Ultroid
     uptime,
     kk,
 )
 if _e := udB.get_key("ALIVE_EMOJI"):
     als = als.replace("🌀", _e)
 builder = ult.builder
 if pic:
     try:
         if ".jpg" in pic:
             results = [
                 await builder.photo(
                     pic, text=als, parse_mode="html", buttons=buttons
                 )
             ]
         else:
             _pic = resolve_bot_file_id(pic)
             if _pic:
                 pic = _pic
                 buttons.insert(
                     0, [Button.inline(get_string("bot_2"), data="alive")]
                 )
             results = [
                 await builder.document(
                     pic,
                     title="Inline Alive",
                     description="@TheUltroid",
                     parse_mode="html",
                     buttons=buttons,
                 )
             ]
         return await ult.answer(results)
コード例 #6
0
ファイル: pmpermit.py プロジェクト: nightwalkerx24/Ultroid
async def in_pm_ans(event):
    from_user = int(event.pattern_match.group(1).strip())
    try:
        warns = U_WARNS[from_user]
    except Exception as e:
        LOGS.info(e)
        warns = "?"
    try:
        msg_ = WARN_MSGS[from_user]
    except KeyError:
        msg_ = "**PMSecurity of {OWNER_NAME}**"
    wrns = f"{warns}/{WARNS}"
    buttons = [
        [
            Button.inline("Warns", data=f"admin_only{from_user}"),
            Button.inline(wrns, data=f"don_{wrns}"),
        ]
    ]
    include_media = True
    mime_type, res = None, None
    cont = None
    try:
        ext = PMPIC.split(".")[-1].lower()
    except (AttributeError, IndexError):
        ext = None
    if ext in ["img", "jpg", "png"]:
        _type = "photo"
        mime_type = "image/jpg"
    elif ext in ["mp4", "mkv", "gif"]:
        mime_type = "video/mp4"
        _type = "gif"
    else:
        try:
            res = resolve_bot_file_id(PMPIC)
        except ValueError:
            pass
        if res:
            res = [
                await event.builder.document(
                    res,
                    title="Inline PmPermit",
                    description="~ @TheUltroid",
                    text=msg_,
                    buttons=buttons,
                    link_preview=False,
                )
            ]
        else:
            _type = "article"
            include_media = False
    if not res:
        if include_media:
            cont = types.InputWebDocument(PMPIC, 0, mime_type, [])
        res = [
            event.builder.article(
                title="Inline PMPermit.",
                type=_type,
                text=msg_,
                description="@TeamUltroid",
                include_media=include_media,
                buttons=buttons,
                thumb=cont,
                content=cont,
            )
        ]
    await event.answer(res, switch_pm="• Ultroid •", switch_pm_param="start")
コード例 #7
0
async def ibuild(e):
    n = e.pattern_match.group(1).strip()
    builder = e.builder
    if not (n and n.isdigit()):
        return
    ok = STUFF.get(int(n))
    txt = ok.get("msg")
    pic = ok.get("media")
    btn = ok.get("button")
    if not (pic or txt):
        txt = "Hey!"
    if pic:
        try:
            include_media = True
            mime_type, _pic = None, None
            cont, results = None, None
            try:
                ext = str(pic).split(".")[-1].lower()
            except BaseException:
                ext = None
            if ext in ["img", "jpg", "png"]:
                _type = "photo"
                mime_type = "image/jpg"
            elif ext in ["mp4", "mkv", "gif"]:
                mime_type = "video/mp4"
                _type = "gif"
            else:
                try:
                    if "telethon.tl.types" in str(type(pic)):
                        _pic = pic
                    else:
                        _pic = resolve_bot_file_id(pic)
                except BaseException:
                    pass
                if _pic:
                    results = [
                        await builder.document(
                            _pic,
                            title="Ultroid Op",
                            text=txt,
                            description="@TheUltroid",
                            buttons=btn,
                            link_preview=False,
                        )
                    ]
                else:
                    _type = "article"
                    include_media = False
            if not results:
                if include_media:
                    cont = InputWebDocument(pic, 0, mime_type, [])
                results = [
                    await builder.article(
                        title="Ultroid Op",
                        type=_type,
                        text=txt,
                        description="@TeamUltroid",
                        include_media=include_media,
                        buttons=btn,
                        thumb=cont,
                        content=cont,
                        link_preview=False,
                    )
                ]
            return await e.answer(results)
        except Exception as er:
            LOGS.exception(er)
    result = [
        await builder.article("Ultroid Op",
                              text=txt,
                              link_preview=False,
                              buttons=btn)
    ]
    await e.answer(result)