コード例 #1
0
def instagram(bot, update):
    global filename
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return False
    instagram_key_list = []
    for i in filters:
        inst_filter = i
        instagram_key = InlineKeyboardButton(str(i)[5:],
                                             callback_data=",".join(
                                                 [inst_filter, extension]))
        instagram_key_list.append(instagram_key)
    row_split = lambda list, size, acc=[]: (row_split(list[
        size:], size, acc + [list[:size]]) if list else acc)
    rows = row_split(instagram_key_list, 3)
    instagram_keyboard = rows
    instagram_reply_markup = InlineKeyboardMarkup(instagram_keyboard)
    update.message.reply_text("Available filters are:",
                              reply_markup=instagram_reply_markup)
コード例 #2
0
def lego(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    size = get_param(update, 50, 1, 100)
    if size is None:
        return
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("Can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return False
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    if extension == ".webp" or ".png":
        stick = "convert " + path + filename + extension + " -background white -flatten " + path + filename + extension
        subprocess.run(stick, shell=True)
    legofy.main(image_path=path + filename + extension,
                output_path=path + filename + "-lego" + extension,
                size=size,
                palette_mode=None,
                dither=False)
    send_image(update, path, filename + "-lego", extension)
    os.remove(path + filename + extension)
    os.remove(path + filename + "-lego" + extension)
コード例 #3
0
ファイル: jpeg.py プロジェクト: artb1sh/rikka-telegram-bot
def jpeg(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    compress = get_param(update, 6, 1, 10)
    if compress is None:
        return
    else:
        compress = 11 - compress
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return

    original = Image.open(path + filename + extension, 'r')
    if extension == ".jpg":
        original.save(path + filename + ".jpg",
                      quality=compress,
                      optimize=True)
    else:
        rgb_im = original.convert('RGB')
        rgb_im.save(path + "compressed.jpg", quality=compress, optimize=True)
        foreground = Image.open(path + "compressed.jpg")
        try:
            original.paste(foreground, (0, 0), original)
        except:
            pass
        original.save(path + filename + extension)
        os.remove(path + "compressed.jpg")
    send_image(update, path, filename, extension)
    os.remove(path + filename + extension)
コード例 #4
0
ファイル: liquid.py プロジェクト: artb1sh/rikka-telegram-bot
def liquid(bot, update):
    current_time = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M:%S")
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    power = get_param(update, 60, 1, 100)
    if power is None:
        return
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    identify = subprocess.Popen("identify " + path + filename + extension, stdout=subprocess.PIPE).communicate()[0]
    res = str(identify.split()[2])[2:-1]
    size = str(100 - (power / 1.3))
    name = filename + "-liquid"
    x = "convert " + path + filename + extension + " -liquid-rescale " + \
         size + "%x" + size + "% -resize " + res + "! " + path + name + extension
    subprocess.run(x, shell=True)
    if extension == ".mp4":
        mp4fix = "ffmpeg -loglevel panic -i " + path + name + extension + \
                  " -an -vf scale=trunc(iw/2)*2:trunc(ih/2)*2 \
                  -pix_fmt yuv420p -c:v libx264 -profile:v high -level:v 2.0 " \
                  + path + name + "_mp4" + extension + " -y"
        subprocess.run(mp4fix, shell=True)
        os.remove(path+name+extension)
        name = name + "_mp4"
    send_image(update, path, name, extension)
    os.remove(path+filename+extension)
    os.remove(path+name+extension)
    print(current_time, ">", "/liquid", ">", update.message.from_user.username)
    log_command(bot, update, current_time, "liquid")
コード例 #5
0
def kek(update, context):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    if update.message.reply_to_message is not None:
        kek_param = "".join(update.message.text[5:7])
    elif update.message.caption is not None:
        kek_param = "".join(update.message.caption[5:7])
    else:
        update.message.reply_text("You need an image for that")
        return
    try:
        extension = get_image(update, context, path, filename)
    except:
        update.message.reply_text("Can't get the image")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file")
        return False
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)

    if extension in [".mp4", ".gif"]:
        if kek_param == "-m":
            update.message.reply_text("Multikek unsupported for animations")
            return
        result = kekify_gifs(kek_param, filename, extension)
    else:
        _, _, result = kekify(kek_param, filename, extension, None)
    result.save(filename=path + filename + extension)
    result.close()
    if extension == ".mp4":
        filename = mp4_fix(path, filename)
    send_image(update, path, filename, extension)
    os.remove(path + filename + extension)
コード例 #6
0
def liquid(update, context):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    power = get_param(update, 60, -100, 100)
    if power is None:
        return
    try:
        extension = get_image(update, context, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    power = (100 - (power / 1.3)) / 100
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    with Image(filename=path + filename + extension) as original:
        w, h = original.size
        new = Image()
        for i in range(len(original.sequence)):
            with original.sequence[i] as frame:
                img = Image(image=frame)
            img.liquid_rescale(int(w * power), int(h * power), delta_x=1)
            img.resize(w, h)
            new.sequence.append(img)
            img.close()
        new.save(filename=path + filename + extension)
        if extension == ".mp4":
            filename = mp4_fix(path, filename)
        send_image(update, path, filename, extension)
        new.close()
        os.remove(path + filename + extension)
コード例 #7
0
def merch(update, context):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    try:
        extension = get_image(update, context, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file")
        return False
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    templates_list = list(templates_dict.keys())

    if len(context.args) > 0:
        if context.args[0] in templates_list:
            amount = 1
            template = True
        else:
            amount = get_param(update, 1, 1, 10)
            template = False
    else:
        amount = get_param(update, 1, 1, 10)
        template = False

    image = path + filename + extension
    photos = []
    upload_files = []
    for i in range(amount):
        if template is True:
            product = context.args[0]
        else:
            product = random.choice(templates_list)
        templates_list.remove(product)
        result_image = make_merch(image, templates_path,
                                  templates_dict[product],
                                  templates_dict[product]["offset"])
        result_image.save(path + "merch" + str(i) + ".jpg")

        image_to_attach = "merch" + str(i) + ".jpg"
        attach_name = "".join(
            random.choice("abcdef1234567890") for x in range(16))
        photos.append({"type": "photo", "media": "attach://" + attach_name})
        upload_files.append(
            (attach_name, (image_to_attach, open(path + image_to_attach,
                                                 "rb"))))

    requests.post("https://api.telegram.org/bot" + token + "/sendMediaGroup",
                  params={
                      "chat_id": update.message.chat.id,
                      "media": json.dumps(photos)
                  },
                  files=upload_files,
                  timeout=120)
    os.remove(path + filename + extension)
    return amount
コード例 #8
0
def glitch(update, context):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    try:
        extension = get_image(update, context, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return False
    jpg = "convert " + path + filename + extension + " -resize 100% " + path + filename + ".jpg"
    subprocess.run(jpg, shell=True)
    process_img(update, filename)
    os.remove(path + filename + extension)
    os.remove(path + filename + "-glitched.jpg")
コード例 #9
0
def glitch(bot, update):
    current_time = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M:%S")
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return False
    jpg = "convert " + path + filename + extension + " -resize 100% " + path + filename + ".jpg"
    subprocess.run(jpg, shell=True)
    process_img(update, filename)
    os.remove(path + filename + extension)
    os.remove(path + filename + "-glitched.jpg")
    print(current_time, ">", "/glitch", ">", update.message.from_user.username)
    log_command(bot, update, current_time, "glitch")
コード例 #10
0
ファイル: palette.py プロジェクト: artb1sh/rikka-telegram-bot
def palette(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    name = filename + "-palette"
    colors = get_param(update, 4, 1, 10)
    if colors is None:
        return
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    start_computing(path, filename, extension, colors, "flat")
    send_image(update, path, name, extension)
    os.remove(path + filename + extension)
    os.remove(path + name + extension)
コード例 #11
0
def meme(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")

    if len(update.message.photo) > 0:
        args = update.message.caption.split(" ")
    else:
        args = update.message.text.split(" ")

    args = args[1:]

    if len(args) < 1:
        update.message.reply_text("Type in some text!")
        return

    font = fonts_dict["impact"]
    for i in fonts_dict:
        if "-" + i in args[0] or "-" + i[0] in args[0]:
            font = fonts_dict[i]
            args = args[1:]
            break

    if len(args) < 1:
        update.message.reply_text("Type in some text!")
        return

    initial_text = " ".join(args)
    split_text = initial_text.split("@", maxsplit=1)

    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    try:
        extension = get_image(bot, update, path, filename)
    except IndexError as e:
        update.message.reply_text("Can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return
    top_text, bottom_text = text_format(update, split_text)
    make_meme(top_text, bottom_text, filename, extension, path, font)
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    send_image(update, path, filename + "-meme", extension)
    os.remove(path + filename + extension)
    os.remove(path + filename + "-meme" + extension)
コード例 #12
0
ファイル: kek.py プロジェクト: artb1sh/rikka-telegram-bot
def kek(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    if update.message.reply_to_message is not None:
        kek_param = "".join(update.message.text[5:7])
    elif update.message.caption is not None:
        kek_param = "".join(update.message.caption[5:7])
    else:
        update.message.reply_text("You need an image for that!")
        return
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("Can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return False
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    result = kekify(update, kek_param, filename, extension)
    send_image(update, path, result, extension)
    os.remove(path + result + extension)
    os.remove(path + filename + extension)
コード例 #13
0
def fap(update, context):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    try:
        extension = get_image(update, context, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)

    with Image(filename=path + filename + extension) as decal:
        decal.resize(320, 172)
        w, h = decal.size
        decal.virtual_pixel = 'transparent'
        source_points = ((0, 0), (w, 0), (w, h), (0, h))
        with Image(filename=launchpad_gif) as template_gif:
            new = Image()
            for i in range(len(template_gif.sequence)):
                with template_gif.sequence[i] as frame:
                    img = Image(image=frame)
                    img.delay = 6
                destination_points = (coords_by_frame[i])
                order = chain.from_iterable(
                    zip(source_points, destination_points))
                arguments = list(chain.from_iterable(order))
                decal_current = Image(image=decal)
                decal_current.matte_color = "rgba(255, 255, 255, 0)"
                decal_current.distort('perspective', arguments)
                img.composite(decal_current, left=0, top=0)
                new.sequence.append(img)
                decal_current.close()
                img.close()
            new.save(filename=path + "result.mp4")
            result_filename = mp4_fix(path, "result")
            send_image(update, path, result_filename, ".mp4")
            new.close()
            os.remove(path + result_filename + ".mp4")
            os.remove(path + filename + extension)