Exemplo n.º 1
0
def getsticker(message):
    args = extract_args(message)
    reply = message.reply_to_message
    if not reply or not reply.sticker:
        edit(message, f'`{get_translation("replySticker")}`')
        return

    video = False
    photo = False

    if reply.sticker and reply.sticker.is_animated or reply.sticker.is_video:
        video = download_media_wc(reply)
    else:
        photo = download_media_wc(reply, f'{get_download_dir()}/sticker.png')
        image = Image.open(photo)
        photo = f'{get_download_dir()}/sticker.png'
        image.save(photo)

    reply_doc(
        reply,
        video or photo,
        caption=f'**Sticker ID:** `{reply.sticker.file_id}'
        f'`\n**Emoji**: `{reply.sticker.emoji or get_translation("notSet")}`'
        if args == '-v' else '',
        delete_after_send=True,
    )
    message.delete()
def wiki(message):
    args = extract_args(message)
    if len(args) < 1:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return
    set_lang(SEDEN_LANG)
    try:
        summary(args)
    except DisambiguationError as error:
        edit(message, get_translation('wikiError', [error]))
        return
    except PageError as pageerror:
        edit(message, get_translation('wikiError2', [pageerror]))
        return
    result = summary(args)
    if len(result) >= 4096:
        file = open('wiki.txt', 'w+')
        file.write(result)
        file.close()
        reply_doc(
            message,
            'wiki.txt',
            caption=f'`{get_translation("outputTooLarge")}`',
            delete_after_send=True,
        )
    edit(message, get_translation('sedenQuery', ['**', '`', args, result]))

    send_log(get_translation('wikiLog', ['`', args]))
Exemplo n.º 3
0
def ss(message):
    input_str = extract_args(message)
    link_match = match(r'\bhttp(.*)?://.*\.\S+', input_str)
    if link_match:
        link = link_match.group()
    else:
        edit(message, f'`{get_translation("ssUsage")}`')
        return
    edit(message, f'`{get_translation("processing")}`')
    driver = get_webdriver()
    driver.get(link)
    height = driver.execute_script(
        "return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);"
    )
    width = driver.execute_script(
        "return Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth);"
    )
    driver.set_window_size(width + 125, height + 125)
    wait_for = int(height / 1000)
    edit(message,
         f'`{get_translation("ssResult", [height, width, wait_for])}`')
    sleep(wait_for)
    im_png = driver.get_screenshot_as_base64()
    driver.close()
    message_id = message.message_id
    if message.reply_to_message:
        message_id = message.reply_to_message
    name = 'screenshot.png'
    with open(name, 'wb') as out:
        out.write(b64decode(im_png))
    edit(message, f'`{get_translation("ssUpload")}`')
    reply_doc(message, name, caption=input_str, delete_after_send=True)
Exemplo n.º 4
0
def rbg(message):
    if not RBG_APIKEY:
        return edit(
            message,
            get_translation('rbgApiMissing', ['**', 'Remove.BG', '`']),
            preview=False,
        )
    reply = message.reply_to_message

    if reply and (reply.photo or
                  (reply.document and 'image' in reply.document.mime_type)):
        edit(message, f'`{get_translation("processing")}`')
    else:
        edit(message, f'`{get_translation("rbgUsage")}`')
        return

    IMG_PATH = f'{DOWNLOAD_DIRECTORY}/image.png'

    if path.exists(IMG_PATH):
        remove(IMG_PATH)
    download_media_wc(reply, IMG_PATH)
    edit(message, f'`{get_translation("rbgProcessing")}`')
    try:
        remove_bg = RemoveBg(RBG_APIKEY, get_translation('rbgLog'))
        remove_bg.remove_background_from_img_file(IMG_PATH)
        rbg_img = f'{IMG_PATH}_no_bg.png'
        reply_doc(reply,
                  rbg_img,
                  caption=get_translation('rbgResult'),
                  delete_after_send=True)
        message.delete()
    except Exception as e:
        return edit(message, get_translation('banError', ['`', '**', e]))
Exemplo n.º 5
0
def barcode(message):
    input_str = extract_args(message)
    usage = get_translation('barcodeUsage', ['**', '`'])
    reply = message.reply_to_message
    if len(input_str) < 1 and not reply:
        edit(message, usage)
        return
    edit(message, f'`{get_translation("processing")}`')
    if reply:
        if reply.media:
            downloaded_file_name = download_media_wc(reply)
            media_list = None
            with open(downloaded_file_name, 'rb') as file:
                media_list = file.readlines()
            qrmsg = ''
            for media in media_list:
                qrmsg += media.decode('UTF-8') + '\r\n'
            remove(downloaded_file_name)
        else:
            qrmsg = reply
    else:
        qrmsg = input_str

    bar_code_type = 'code128'
    try:
        bar_code_mode_f = get(bar_code_type, qrmsg, writer=ImageWriter())
        filename = bar_code_mode_f.save(bar_code_type)
        reply_doc(message, filename, delete_after_send=True)
    except Exception as e:
        edit(message, str(e))
        return
    message.delete()
Exemplo n.º 6
0
def upload(message):
    args = extract_args(message)

    if len(args) < 1:
        edit(message, f'`{get_translation("uploadReply")}`')
        return

    def progress(current, total):
        edit(
            message,
            get_translation(
                'updownUpload',
                ['`', '(½{:.2f})'.format(current * 100 / total), args]))

    if isfile(args):
        try:
            edit(message, get_translation('updownUpload', ['`', '', args]))
            reply_doc(message, args, progress=progress)
            edit(message, f'`{get_translation("uploadFinish")}`')
        except Exception as e:
            edit(message, f'`{get_translation("uploadError")}`')
            raise e

        return

    edit(message, f'`{get_translation("uploadFileError")}`')
Exemplo n.º 7
0
def carbon(message):
    match = extract_args(message)
    if len(match) < 1:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return
    edit(message, f'`{get_translation("processing")}`')
    textx = message.reply_to_message
    pcode = message.text
    if pcode[8:]:
        pcode = str(pcode[8:])
    elif textx:
        pcode = str(textx.message)
    code = quote_plus(pcode)
    global CARBONLANG
    CARBON = f'https://carbon.now.sh/?l={CARBONLANG}&code={code}'
    edit(message, f'`{get_translation("processing")}\n%25`')
    if path.isfile('./carbon.png'):
        remove('./carbon.png')
    driver = get_webdriver()
    driver.get(CARBON)
    edit(message, f'`{get_translation("processing")}\n%50`')
    driver.command_executor._commands['send_command'] = (
        'POST', '/session/$sessionId/chromium/send_command')
    driver.find_element_by_xpath("//button[contains(text(),'Export')]").click()
    edit(message, f'`{get_translation("processing")}\n%`75')
    while not path.isfile('./carbon.png'):
        sleep(0.5)
    edit(message, f'`{get_translation("processing")}\n%100`')
    file = './carbon.png'
    edit(message, f'`{get_translation("carbonUpload")}`')
    reply_doc(message, file, caption=get_translation('carbonResult'),
              delete_orig=True, delete_after_send=True)
    driver.quit()
def rbg(client, message):
    if not RBG_APIKEY:
        edit(message,
             get_translation("rbgApiMissing", ['**', 'Remove.BG', '`']),
             preview=False)
        return

    reply = message.reply_to_message

    if reply and (reply.photo or
                  (reply.document
                   and 'image' in reply.document.mime_typereply.document)):
        edit(message, f'`{get_translation("processing")}`')
    else:
        edit(message, f'`{get_translation("rbgUsage")}`')
        return

    IMG_PATH = f'{DOWNLOAD_DIRECTORY}/image.png'

    if path.exists(IMG_PATH):
        remove(IMG_PATH)
    client.download_media(message=reply, file_name=IMG_PATH)
    edit(message, f'`{get_translation("rbgProcessing")}`')
    try:
        remove_bg = RemoveBg(RBG_APIKEY, f'{get_translation("rbgLog")}')
        remove_bg.remove_background_from_img_file(IMG_PATH)
        rbg_img = IMG_PATH + '_no_bg.png'
        reply_doc(reply, rbg_img, caption=f'{get_translation("rbgResult")}')
        message.delete()
    except Exception as e:
        raise e
Exemplo n.º 9
0
def urbandictionary(message):
    match = extract_args(message)
    if len(match) < 1:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return
    edit(message, f'`{get_translation("processing")}`')
    query = extract_args(message)
    try:
        define(query)
    except HTTPError:
        edit(message, get_translation('udResult', ['**', query]))
        return
    mean = define(query)
    deflen = sum(len(i) for i in mean[0]['def'])
    exalen = sum(len(i) for i in mean[0]['example'])
    meanlen = deflen + exalen
    if int(meanlen) >= 0:
        if int(meanlen) >= 4096:
            edit(message, f'`{get_translation("outputTooLarge")}`')
            file = open('urbandictionary.txt', 'w+')
            file.write('Query: ' + query + '\n\nMeaning: ' + mean[0]['def'] +
                       '\n\n' + 'Örnek: \n' + mean[0]['example'])
            file.close()
            reply_doc(message, 'urbandictionary.txt',
                      caption=f'`{get_translation("outputTooLarge")}`')
            if path.exists('urbandictionary.txt'):
                remove('urbandictionary.txt')
            message.delete()
            return
        edit(message, get_translation('sedenQueryUd', [
             '**', '`', query, mean[0]['def'], mean[0]['example']]))
    else:
        edit(message, get_translation('udNoResult', ['**', query]))
Exemplo n.º 10
0
def wiki(message):
    match = extract_args(message)
    if len(match) < 1:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return
    set_lang(SEDEN_LANG)
    match = extract_args(message)
    try:
        summary(match)
    except DisambiguationError as error:
        edit(message, get_translation('wikiError', [error]))
        return
    except PageError as pageerror:
        edit(message, get_translation('wikiError2', [pageerror]))
        return
    result = summary(match)
    if len(result) >= 4096:
        file = open('wiki.txt', 'w+')
        file.write(result)
        file.close()
        reply_doc(message, 'wiki.txt',
                  caption=f'`{get_translation("outputTooLarge")}`')
        if path.exists('wiki.txt'):
            remove('wiki.txt')
        return
    edit(message, get_translation('sedenQuery', ['**', '`', match, result]))

    send_log(get_translation('wikiLog', ['`', match]))
Exemplo n.º 11
0
def dyno_logs(message):
    if not HEROKU_KEY:
        edit(message, f"`{get_translation('notHeroku')}`")
        return

    edit(message, f"`{get_translation('processing')}`")

    heroku = from_key(HEROKU_KEY)
    heroku_app = None
    heroku_applications = heroku.apps()
    if not HEROKU_APPNAME:
        edit(
            message,
            f'`{get_translation("updateHerokuVariables", ["HEROKU_APPNAME "])}`',
        )

    for app in heroku_applications:
        if app.name == HEROKU_APPNAME:
            heroku_app = app
            break

    if heroku_app is None:
        edit(
            message,
            f'`{get_translation("updateHerokuVariables", ["HEROKU_APPNAME "])}`',
        )
        return

    filename = 'seden_heroku_log.txt'

    with open(filename, 'w+') as log:
        log.write(heroku_app.get_log())

    reply_doc(message, filename, delete_after_send=True, delete_orig=True)
def pip3(message):
    pipmodule = extract_args(message)
    if len(pipmodule) > 0:
        edit(message, f'`{get_translation("pipSearch")}`')
        pipsorgu = f"pip3 search {pipmodule}"
        from subprocess import PIPE, Popen
        islem = Popen(pipsorgu.split(),
                      stdout=PIPE,
                      stderr=PIPE,
                      universal_newlines=True)
        sonuc, _ = islem.communicate()

        if sonuc:
            if len(sonuc) > 4096:
                edit(message, f'`{get_translation("outputTooLarge")}`')
                file = open('pip3.txt', 'w+')
                file.write(sonuc)
                file.close()
                reply_doc(message, 'pip3.txt')
                remove('pip3.txt')
                return
            edit(message,
                 get_translation('sedenQuery', ['**', '`', pipsorgu, sonuc]))
        else:
            edit(
                message,
                get_translation(
                    'sedenQuery',
                    ['**', '`', pipsorgu,
                     get_translation('sedenZeroResults')]))
    else:
        edit(message, f'`{get_translation("pipHelp")}`')
Exemplo n.º 13
0
def youtubedl(message):
    args = extract_args(message).split(' ', 2)

    if len(args) != 2:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return

    util = args[0].lower()
    url = args[1]

    try:
        video_info = YoutubeDL().extract_info(url, False)
    except DownloadError as e:
        return edit(message, get_translation('banError', ['`', '**', e]))

    title = video_info.get('title')
    uploader = video_info.get('uploader')
    duration = video_info.get('duration')

    if util == 'mp4':
        edit(message, get_translation('downloadYTVideo', ['**', title, '`']))
        ydl_opts = {
            'outtmpl': f'{title}.%(ext)s',
            'format':
            'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'
        }
        with YoutubeDL(ydl_opts) as ydl:
            ydl.download([url])
        edit(message, f'{get_translation("uploadMedia")}')
        reply_doc(
            message,
            f'{title}.mp4',
            caption=
            f"{get_translation('title', ['**' , ':'])} {title}`\n`{get_translation('uploader',['**',':'])} {uploader}",
            delete_after_send=True,
            delete_orig=True)

    elif util == 'mp3':
        edit(message, get_translation('downloadYTAudio', ['**', title, '`']))
        ydl_opts = {
            'outtmpl':
            f'{title}.%(ext)s',
            'format':
            'bestaudio/best',
            'postprocessors': [{
                'key': 'FFmpegExtractAudio',
                'preferredcodec': 'mp3',
                'preferredquality': '320',
            }]
        }
        with YoutubeDL(ydl_opts) as ydl:
            ydl.download([url])
        edit(message, f'`{get_translation("uploadMedia")}`')
        reply_audio(
            message,
            f'{title}.mp3',
            caption=f"{get_translation('uploader',['**',':'])} {uploader}",
            delete_orig=True)
        remove(f'{title}.mp3')
Exemplo n.º 14
0
def get_users(client, message):
    args = message.text.split(' ', 1)
    users = args[0][1:5] == 'user'
    showdel = users and args[0][-3:] == 'del'
    bots = not users and args[0][1:5] == 'bots'
    admins = not bots and args[0][1:7] == 'admins'

    out = ''
    if users:
        out = get_translation(
            'userlist',
            [
                '**',
                f'{get_translation("deleted") if showdel else ""}',
                '`',
                message.chat.title,
            ],
        )
        filtr = 'all'
    elif admins:
        out = get_translation('adminlist', ['**', '`', message.chat.title])
        filtr = 'administrators'
    elif bots:
        out = get_translation('botlist', ['**', '`', message.chat.title])
        filtr = 'bots'

    try:
        chat_id = message.chat.id
        find = client.iter_chat_members(chat_id, filter=filtr)
        for i in find:
            if not i.user.is_deleted and showdel:
                continue
            name = f'[{get_translation("deletedAcc") if i.user.is_deleted else i.user.first_name}](tg://user?id={i.user.id}) | `{i.user.id}`'
            out += f'\n`•`  **{name}**'
    except Exception as e:
        out += f'\n{get_translation("banError", ["`", "**", e])}'

    try:
        edit(message, out)
    except MessageTooLong:
        edit(message, f'`{get_translation("outputTooLarge")}`')
        file = open('userslist.txt', 'w+')
        file.write(out)
        file.close()
        reply_doc(
            message,
            'userslist.txt',
            caption=get_translation(
                'userlist',
                [
                    '**',
                    f'{get_translation("deleted") if showdel else ""}',
                    '`',
                    message.chat.title,
                ],
            ),
            delete_after_send=True,
            delete_orig=True,
        )
def speed_test(message):
    input_str = extract_args(message)
    as_text = False
    as_document = True
    if input_str == 'image':
        as_document = False
    elif input_str == 'file':
        as_document = True
    elif input_str == 'text':
        as_text = True
    edit(message, f'`{get_translation("speedtest")}`')
    start = DateTime.now()
    spdtst = Speedtest()
    spdtst.get_best_server()
    spdtst.download()
    spdtst.upload()
    end = DateTime.now()
    ms = (end - start).microseconds / 1000
    response = spdtst.results.dict()
    download_speed = response.get('download')
    upload_speed = response.get('upload')
    ping_time = response.get('ping')
    client_infos = response.get('client')
    i_s_p = client_infos.get('isp')
    i_s_p_rating = client_infos.get('isprating')
    reply_msg_id = message.chat.id
    if message.reply_to_message:
        reply_msg_id = message.reply_to_message
    try:
        response = spdtst.results.share()
        speedtest_image = response
        if as_text:
            edit(
                message,
                get_translation('speedtestResultText', [
                    '**', ms,
                    convert_from_bytes(download_speed),
                    convert_from_bytes(upload_speed), ping_time, i_s_p,
                    i_s_p_rating, ''
                ]))
        else:
            reply_doc(message,
                      speedtest_image,
                      caption=get_translation('speedtestResultDoc',
                                              ['**', ms]))
            message.delete()
    except Exception as exc:
        edit(
            message,
            get_translation('speedtestResultText', [
                '**', ms,
                convert_from_bytes(download_speed),
                convert_from_bytes(upload_speed), ping_time, i_s_p,
                i_s_p_rating, f'ERROR: {str(exc)}'
            ]))
Exemplo n.º 16
0
def earrape(message):
    args = extract_args(message).split(' ', 1)
    reply = message.reply_to_message
    earrape = 'earrape'
    if path.isfile(earrape):
        remove(earrape)

    util = args[0].lower()
    if util == 'mp4':
        if not (reply.video or reply.video_note or
                (reply.document and 'video' in reply.document.mime_type)):
            edit(message, f'`{get_translation("wrongMedia")}`')
        else:
            edit(message, f'`{get_translation("applyEarrape")}`')
            media = download_media_wc(reply, earrape)
            process = Popen([
                'ffmpeg',
                '-i',
                f'{media}',
                '-af',
                'acrusher=.1:1:64:0:log',
                f'{media}.mp4',
            ])
            process.communicate()
            edit(message, f'`{get_translation("uploadMedia")}`')
            reply_doc(message,
                      f'{media}.mp4',
                      delete_after_send=True,
                      delete_orig=True)
            remove(media)
    elif util == 'mp3':
        if not (reply.video or reply.video_note or
                (reply.audio or reply.voice or
                 (reply.document and 'video' in reply.document.mime_type))):
            edit(message, f'`{get_translation("wrongMedia")}`')
        else:
            edit(message, f'`{get_translation("applyEarrape")}`')
            media = download_media_wc(reply, earrape)
            process = Popen([
                'ffmpeg',
                '-i',
                f'{media}',
                '-af',
                'acrusher=.1:1:64:0:log',
                f'{media}.mp3',
            ])
            process.communicate()
            edit(message, f'`{get_translation("uploadMedia")}`')
            reply_voice(message, f'{media}.mp3', delete_orig=True)
            remove(media)
            remove(f'{media}.mp3')
    else:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return
Exemplo n.º 17
0
def getsticker(message):
    reply = message.reply_to_message
    if not reply or not reply.sticker:
        edit(message, f'`{get_translation("replySticker")}`')
        return

    photo = download_media_wc(reply)

    reply_doc(message,
              photo,
              caption=f'**Sticker ID:** `{reply.sticker.file_id}'
              f'`\n**Emoji**: `{reply.sticker.emoji}`',
              delete_after_send=True,
              delete_orig=True)
def urbandictionary(message):
    query = extract_args(message)
    if len(query) < 1:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return
    edit(message, f'`{get_translation("processing")}`')
    mean = []
    example = []
    try:
        for i in search(query, 1):
            mean.append(i.definition + "\n")
            example.append(i.example + "\n")
    except TypeError:
        return edit(message, f'`{get_translation("udNotFound")}`')
    except HTTPError:
        edit(message, get_translation('udResult', ['**', query]))
        return
    deflen = sum(len(i) for i in mean)
    exalen = sum(len(i) for i in example)
    meanlen = deflen + exalen
    if int(meanlen) >= 0:
        if int(meanlen) >= 4096:
            edit(message, f'`{get_translation("outputTooLarge")}`')
            file = open('urbandictionary.txt', 'w+')
            file.write('Query: ' + query + '\n\nMeaning: ' + "".join(mean) +
                       '\n\n' + 'Örnek: \n' + "".join(example))
            file.close()
            reply_doc(
                message,
                'urbandictionary.txt',
                caption=f'`{get_translation("outputTooLarge")}`',
            )
            if path.exists('urbandictionary.txt'):
                remove('urbandictionary.txt')
            message.delete()
            return
        edit(
            message,
            get_translation(
                'sedenQueryUd',
                [
                    '**', '`', query, "".join(choice(mean)), "".join(
                        choice(example))
                ],
            ),
        )
    else:
        edit(message, get_translation('udNoResult', ['**', query]))
Exemplo n.º 19
0
def lyrics(message):
    args = extract_args(message)
    if r"-" in args:
        pass
    else:
        edit(message, f'`{get_translation("lyricsError")}`')
        return

    if not GENIUS_TOKEN:
        edit(message, f'`{get_translation("geniusToken")}`')
    else:
        genius = Genius(GENIUS_TOKEN)
        try:
            args = args.split('-')
            artist = args[0].strip()
            song = args[1].strip()
        except BaseException:
            edit(message, f'`{get_translation("lyricsError2")}`')
            return

    if len(args) < 1:
        edit(message, f'`{get_translation("lyricsError2")}`')
        return

    edit(message, get_translation('lyricsSearch', ['`', artist, song]))

    try:
        songs = genius.search_song(song, artist)
    except TypeError:
        songs = None

    if not songs:
        edit(message, get_translation('lyricsNotFound', ['**', artist, song]))
        return
    if len(songs.lyrics) > 4096:
        edit(message, f'`{get_translation("lyricsOutput")}`')
        with open('lyrics.txt', 'w+') as f:
            f.write(
                get_translation('lyricsQuery',
                                ['', '', artist, song, songs.lyrics]))
        reply_doc(message, 'lyrics.txt', delete_after_send=True)
    else:
        edit(
            message,
            get_translation('lyricsQuery',
                            ['**', '`', artist, song, songs.lyrics]),
        )
    return
Exemplo n.º 20
0
def getsticker(message):
    reply = message.reply_to_message
    if not reply or not reply.sticker:
        edit(message, f'`{get_translation("replySticker")}`')
        return

    photo = download_media_wc(reply)

    reply_doc(
        reply,
        photo,
        caption=
        f'**Sticker ID:** `{reply.sticker.file_id}`\n**Emoji**: `{reply.sticker.emoji}`'
    )
    message.delete()
    remove(photo)
Exemplo n.º 21
0
def img_to_ascii(message):
    reply = message.reply_to_message
    edit(message, f'`{get_translation("processing")}`')
    if not reply:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return

    if not (reply.photo or (reply.sticker and not reply.sticker.is_animated) or
            (reply.document and 'image' in reply.document.mime_type)):
        edit(message, f'`{get_translation("wrongMedia")}`')
    else:
        media = download_media_wc(reply, file_name='ascii.png')
        ImageToAscii(imagePath=media, outputFile="output.txt")
        reply_doc(reply, 'output.txt', delete_after_send=True)
        message.delete()
        remove(media)
Exemplo n.º 22
0
def barcode(message):
    input_str = extract_args(message)
    reply = message.reply_to_message
    if len(input_str) < 1:
        edit(message, get_translation('barcodeUsage', ['**', '`']))
        return
    edit(message, f'`{get_translation("processing")}`')
    try:
        bar_code_mode_f = get('code128', input_str, writer=ImageWriter())
        filename = bar_code_mode_f.save('code128')
        reply_doc(reply if reply else message,
                  filename,
                  delete_after_send=True)
        message.delete()
    except Exception as e:
        edit(message, str(e))
        return
def carbon(message):
    match = extract_args(message)
    if len(match) < 1:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return
    edit(message, f'`{get_translation("processing")}`')
    CARBON = 'https://carbon.now.sh/?l={lang}&code={code}'
    global CARBONLANG
    textx = message.reply_to_message
    pcode = message.text
    if pcode[8:]:
        pcode = str(pcode[8:])
    elif textx:
        pcode = str(textx.message)
    code = quote_plus(pcode)
    edit(message, f'`{get_translation("processing")}\n%25`')
    if path.isfile("./carbon.png"):
        remove("./carbon.png")
    url = CARBON.format(code=code, lang=CARBONLANG)
    driver = get_webdriver()
    driver.get(url)
    edit(message, f'`{get_translation("processing")}\n%50`')
    download_path = './'
    driver.command_executor._commands["send_command"] = (
        "POST", '/session/$sessionId/chromium/send_command')
    params = {
        'cmd': 'Page.setDownloadBehavior',
        'params': {
            'behavior': 'allow',
            'downloadPath': download_path
        }
    }
    command_result = driver.execute("send_command", params)
    driver.find_element_by_xpath("//button[contains(text(),'Export')]").click()
    edit(message, f'`{get_translation("processing")}\n%`75')
    while not path.isfile("./carbon.png"):
        sleep(0.5)
    edit(message, f'`{get_translation("processing")}\n%100`')
    file = './carbon.png'
    edit(message, f'`{get_translation("carbonUpload")}`')
    reply_doc(message,
              file,
              caption=f'{get_translation("carbonResult")}',
              delete_orig=True,
              delete_after_send=True)
    driver.quit()
def terminal(message):
    command = extract_args(message)

    if len(command) < 1:
        edit(message, f'`{get_translation("termUsage")}`')
        return

    curruser = getuser()
    try:
        from os import geteuid

        uid = geteuid()
    except ImportError:
        uid = 0

    if not command:
        edit(message, f'`{get_translation("termHelp")}`')
        return

    result = get_translation("termNoResult")
    try:
        from sedenecem.core.misc import __status_out__

        _, result = __status_out__(command)
    except BaseException as e:
        pass

    if len(result) > 4096:
        output = open('output.txt', 'w+')
        output.write(result)
        output.close()
        reply_doc(
            message,
            'output.txt',
            caption=f'`{get_translation("outputTooLarge")}`',
            delete_after_send=True,
        )
        return

    edit(message,
         f'`{curruser}:~{"#" if uid == 0 else "$"} {command}\n{result}`')

    send_log(get_translation('termLog', [command]))
Exemplo n.º 25
0
def terminal(message):
    command = extract_args(message)

    if len(command) < 1:
        edit(message, f'`{get_translation("termUsage")}`')
        return

    curruser = getuser()
    try:
        from os import geteuid

        uid = geteuid()
    except ImportError:
        uid = 0

    if not command:
        edit(message, f'`{get_translation("termHelp")}`')
        return

    sonuc = f'`{get_translation("termNoResult")}`'
    try:
        from subprocess import getoutput

        sonuc = getoutput(command)
    except BaseException:
        pass

    if len(sonuc) > 4096:
        output = open('output.txt', 'w+')
        output.write(sonuc)
        output.close()
        reply_doc(
            message,
            'output.txt',
            caption=f'`{get_translation("outputTooLarge")}`',
            delete_after_send=True,
        )
        return

    edit(message, f'`{curruser}:~{"#" if uid == 0 else "$"} {command}\n{sonuc}`')

    send_log(get_translation('termLog', [command]))
def showblacklist(message):
    if not sql:
        edit(message, f'`{get_translation("nonSqlMode")}`')
        return
    all_blacklisted = sql.get_chat_blacklist(message.chat.id)
    OUT_STR = f'**{get_translation("blacklistChats")}**\n'
    if len(all_blacklisted) > 0:
        for trigger in all_blacklisted:
            OUT_STR += f'`{trigger}`\n'
    else:
        OUT_STR = f'**{get_translation("blankBlacklist")}**'
    if len(OUT_STR) > 4096:
        with BytesIO(str.encode(OUT_STR)) as out_file:
            out_file.name = 'blacklist.text'
            reply_doc(message,
                      out_file,
                      caption=f'**{get_translation("blacklistChats")}**')
            message.delete()
    else:
        edit(message, OUT_STR)
def eval(message):
    args = extract_args(message)
    if len(args) < 1:
        edit(message, f'`{get_translation("evalUsage")}`')
        return

    try:
        evaluation = safe_eval(args)
        if evaluation:
            if isinstance(evaluation, str):
                if len(evaluation) >= 4096:
                    file = open('output.txt', 'w+')
                    file.write(evaluation)
                    file.close()
                    reply_doc(
                        message,
                        'output.txt',
                        caption=f'`{get_translation("outputTooLarge")}`',
                        delete_after_send=True,
                    )
                    return
                edit(
                    message,
                    get_translation('sedenQuery',
                                    ['**', '`', args, evaluation]),
                )
        else:
            edit(
                message,
                get_translation(
                    'sedenQuery',
                    ['**', '`', args,
                     get_translation('sedenErrorResult')]),
            )
    except Exception as err:
        edit(message,
             get_translation('sedenQuery',
                             ['**', '`', args, str(err)]))

    send_log(get_translation('evalLog', [args]))
Exemplo n.º 28
0
    def download_track(self, message, song_list: list, is_zip):
        lock = Lock()
        with lock:
            with ThreadPoolExecutor(min(32, cpu_count() or 0) + 4) as executor:
                executor.map(self.search_track, song_list)

        if is_zip:
            zipfile = ZipFile('Spotify/playlist.zip', 'w')
            for song in glob('Spotify/*.mp3'):
                zipfile.write(song)
                remove(song)
            zipfile.close()

            edit(message, f'`{get_translation("uploadingZip")}`')
            reply_doc(
                message,
                'Spotify/playlist.zip',
                delete_orig=True,
                delete_after_send=True,
            )
        else:
            for song in glob('Spotify/*.mp3'):
                reply_audio(message, song, delete_orig=True, delete_file=True)
Exemplo n.º 29
0
def hash(message):
    hashtxt_ = extract_args(message)
    if len(hashtxt_) < 1:
        edit(message, f'`{get_translation("wrongCommand")}`')
        return
    hashtxt = open('hash.txt', 'w+')
    hashtxt.write(hashtxt_)
    hashtxt.close()
    md5 = runapp(['md5sum', 'hash.txt'], stdout=PIPE)
    md5 = md5.stdout.decode()
    sha1 = runapp(['sha1sum', 'hash.txt'], stdout=PIPE)
    sha1 = sha1.stdout.decode()
    sha256 = runapp(['sha256sum', 'hash.txt'], stdout=PIPE)
    sha256 = sha256.stdout.decode()
    sha512 = runapp(['sha512sum', 'hash.txt'], stdout=PIPE)
    runapp(['rm', 'hash.txt'], stdout=PIPE)
    sha512 = sha512.stdout.decode()

    def rem_filename(st):
        return st[:st.find(' ')]

    ans = (f'Text: `{hashtxt_}`'
           f'\nMD5: `{rem_filename(md5)}`'
           f'\nSHA1: `{rem_filename(sha1)}`'
           f'\nSHA256: `{rem_filename(sha256)}`'
           f'\nSHA512: `{rem_filename(sha512)}`')
    if len(ans) > 4096:
        hashfile = open('hash.txt', 'w+')
        hashfile.write(ans)
        hashfile.close()
        reply_doc(message,
                  'hash.txt',
                  caption=f'`{get_translation("outputTooLarge")}`')
        runapp(['rm', 'hash.txt'], stdout=PIPE)
        message.delete()
    else:
        edit(message, ans)
Exemplo n.º 30
0
def makeqr(message):
    input_str = extract_args(message)
    usage = get_translation('makeqrUsage', ['**', '`'])
    reply = message.reply_to_message
    if len(input_str) < 1 and not reply:
        edit(message, usage)
        return
    edit(message, f'`{get_translation("processing")}`')
    if reply:
        if reply.media:
            downloaded_file_name = download_media_wc(reply)
            media_list = None
            with open(downloaded_file_name, 'rb') as file:
                media_list = file.readlines()
            qrmsg = ''
            for media in media_list:
                qrmsg += media.decode('UTF-8') + '\r\n'
            remove(downloaded_file_name)
        else:
            qrmsg = reply
    else:
        qrmsg = input_str

    try:
        qr = QRCode(version=1,
                    error_correction=constants.ERROR_CORRECT_L,
                    box_size=10,
                    border=4)
        qr.add_data(qrmsg)
        qr.make(fit=True)
        img = qr.make_image(fill_color='black', back_color='white')
        img.save('img_file.webp', 'PNG')
        reply_doc(message, 'img_file.webp', delete_after_send=True)
    except Exception as e:
        edit(message, str(e))
        return
    message.delete()