|
1
|
|
|
#!/usr/bin/python |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
from modules.utils import caption_filter, get_image, send_image |
|
4
|
|
|
from telegram.ext import CommandHandler, MessageHandler |
|
5
|
|
|
from telegram import ChatAction |
|
6
|
|
|
import subprocess |
|
7
|
|
|
import datetime |
|
8
|
|
|
import yaml |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
def handler(dp): |
|
12
|
|
|
dp.add_handler(MessageHandler(caption_filter("/kek"), kek)) |
|
13
|
|
|
dp.add_handler(CommandHandler("kek", kek)) |
|
14
|
|
|
|
|
15
|
|
|
# import path |
|
16
|
|
|
with open("config.yml", "r") as f: |
|
17
|
|
|
path = yaml.load(f)["path"]["kek"] |
|
18
|
|
|
|
|
19
|
|
|
extensions = (".jpg", ".jpeg", ".png", ".bmp", ".webp") |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
# get image, pass parameter |
|
23
|
|
|
def kek(bot, update): |
|
24
|
|
|
if update.message.reply_to_message is not None: |
|
25
|
|
|
kek_param = "".join(update.message.text[5:7]) |
|
26
|
|
|
else: |
|
27
|
|
|
kek_param = "".join(update.message.caption[5:7]) |
|
28
|
|
|
try: |
|
29
|
|
|
extension = get_image(bot, update, path) |
|
30
|
|
|
except: |
|
31
|
|
|
update.message.reply_text("Can't get the image! :(") |
|
32
|
|
|
return |
|
33
|
|
|
if extension not in extensions: |
|
34
|
|
|
update.message.reply_text("Unsupported file, onii-chan!") |
|
35
|
|
|
return False |
|
36
|
|
|
update.message.chat.send_action(ChatAction.UPLOAD_PHOTO) |
|
37
|
|
|
result = kekify(update, kek_param, extension) |
|
38
|
|
|
send_image(update, path, result, extension) |
|
39
|
|
|
print(datetime.datetime.now(), ">>>", "Done kek", ">>>", update.message.from_user.username) |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
# kek process + send |
|
43
|
|
|
def kekify(update, kek_param, extension): |
|
44
|
|
|
try: |
|
45
|
|
|
if kek_param == "-l" or kek_param == "": |
|
46
|
|
|
crop = "50%x100% " |
|
47
|
|
|
piece_one = "result-0" + extension |
|
48
|
|
|
piece_two = "result-1" + extension |
|
49
|
|
|
flip = "-flop " |
|
50
|
|
|
order = path + piece_one + " " + path + piece_two |
|
51
|
|
|
append = "+append " |
|
52
|
|
|
result = "kek-left" |
|
53
|
|
|
elif kek_param == "-r": |
|
54
|
|
|
crop = "50%x100% " |
|
55
|
|
|
piece_one = "result-1" + extension |
|
56
|
|
|
piece_two = "result-0" + extension |
|
57
|
|
|
flip = "-flop " |
|
58
|
|
|
order = path + piece_two + " " + path + piece_one |
|
59
|
|
|
append = "+append " |
|
60
|
|
|
result = "kek-right" |
|
61
|
|
|
elif kek_param == "-t": |
|
62
|
|
|
crop = "100%x50% " |
|
63
|
|
|
piece_one = "result-0" + extension |
|
64
|
|
|
piece_two = "result-1" + extension |
|
65
|
|
|
flip = "-flip " |
|
66
|
|
|
order = path + piece_one + " " + path + piece_two |
|
67
|
|
|
append = "-append " |
|
68
|
|
|
result = "kek-top" |
|
69
|
|
|
elif kek_param == "-b": |
|
70
|
|
|
crop = "100%x50% " |
|
71
|
|
|
piece_one = "result-1" + extension |
|
72
|
|
|
piece_two = "result-0" + extension |
|
73
|
|
|
flip = "-flip " |
|
74
|
|
|
order = path + piece_two + " " + path + piece_one |
|
75
|
|
|
append = "-append " |
|
76
|
|
|
result = "kek-bot" |
|
77
|
|
|
elif kek_param == "-m": |
|
78
|
|
|
result = multikek(update, extension) |
|
79
|
|
|
return result |
|
80
|
|
|
cut = "convert " + path + "original" + extension + " -crop " + crop + path + "result" + extension |
|
81
|
|
|
subprocess.run(cut, shell=True) |
|
82
|
|
|
mirror = "convert " + path + piece_one + " " + flip + " " + path + piece_two |
|
83
|
|
|
subprocess.run(mirror, shell=True) |
|
84
|
|
|
append = "convert " + order + " " + append + path + result + extension |
|
85
|
|
|
subprocess.run(append, shell=True) |
|
86
|
|
|
return result |
|
87
|
|
|
except: |
|
88
|
|
|
update.message.reply_text("Unknown kek parameter.\nUse -l, -r, -t, -b or -m") |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
def multikek(update, extension): |
|
92
|
|
|
kekify(update, "-l", extension) |
|
93
|
|
|
kekify(update, "-r", extension) |
|
94
|
|
|
kekify(update, "-t", extension) |
|
95
|
|
|
kekify(update, "-b", extension) |
|
96
|
|
|
append_lr = "convert " + path + "kek-left" + extension + " " + path + "kek-right" + extension + " +append " + path + "kek-lr-temp" + extension |
|
97
|
|
|
subprocess.run(append_lr, shell=True) |
|
98
|
|
|
append_tb = "convert " + path + "kek-top" + extension + " " + path + "kek-bot" + extension + " +append " + path + "kek-tb-temp" + extension |
|
99
|
|
|
subprocess.run(append_tb, shell=True) |
|
100
|
|
|
append_all = "convert " + path + "kek-lr-temp" + extension + " " + path + "kek-tb-temp" + extension + " -append " + path + "multikek" + extension |
|
101
|
|
|
subprocess.run(append_all, shell=True) |
|
102
|
|
|
result = "multikek" |
|
103
|
|
|
return result |