-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (40 loc) · 2.08 KB
/
main.py
File metadata and controls
56 lines (40 loc) · 2.08 KB
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
import logging
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
import os, func
# Configure logging
logging.basicConfig(level=logging.INFO)
bot = Bot(token="5413986641:AAF0af8LQw_d4YTTvm1HJoZNKY6L1FOouKM")
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
cid = message.from_user.id
if os.path.isdir(f"./users/{cid}") == False:
os.mkdir(f"./users/{cid}")
await message.answer_photo("https://www.boredpanda.com/blog/wp-content/uploads/2018/04/I-make-everything-alive-again-5ad5baced289b__880.jpg",
"Hello, I colorize old black and white photos with a set of colors\n\nTry it by sending a photo")
@dp.message_handler(content_types=['photo'])
async def echo_message(message: types.Message):
markup = types.InlineKeyboardMarkup()
color = types.InlineKeyboardButton("💡 Colorized", callback_data="color")
grey = types.InlineKeyboardButton("🔲 Greyscale", callback_data="grey")
markup.add(color, grey)
await message.answer_photo(message.photo[-1].file_id, caption="🔸 @iCoderNet", reply_markup=markup)
@dp.callback_query_handler()
async def echo_message(query: types.CallbackQuery):
cid = query.message.from_user.id
await query.message.photo[-1].download(f"./users/{cid}/input.jpg")
await query.message.delete()
if query.data == "color":
if func.colorized(f"./users/{cid}/input.jpg", f"./users/{cid}/output.jpg")['status'] == 'ok':
await query.message.answer_photo(open(f"./users/{cid}/output.jpg", 'rb'), caption="🔸 @iCoderNet")
else:
await query.message.answer("Error: Try again")
elif query.data == "grey":
if func.picGray(f"./users/{cid}/input.jpg", f"./users/{cid}/output.jpg")['status'] == 'ok':
await query.message.answer_photo(open(f"./users/{cid}/output.jpg", 'rb'), caption="🔸 @iCoderNet")
else:
await query.message.answer("Error: Try again")
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)