-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDLS_AlexK_bot_nst.py
More file actions
executable file
·149 lines (105 loc) · 5.28 KB
/
DLS_AlexK_bot_nst.py
File metadata and controls
executable file
·149 lines (105 loc) · 5.28 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""
This is a DLS_Alexk bot.
It can do a lot of things.
And echoes any incoming text messages.
"""
import logging
import os
from aiogram import Bot, Dispatcher, executor, types
from aiogram.dispatcher.filters.state import State, StatesGroup
#from aiogram.contrib.middlewares.logging import LoggingMiddleware
from aiogram.contrib.fsm_storage.memory import MemoryStorage
# write your telegram bot token here
API_TOKEN = ''
# Configure logging
logging.basicConfig(level=logging.INFO)
# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot, storage=MemoryStorage())
class GetPictures(StatesGroup):
waiting_for_style_picture = State()
waiting_for_content_picture = State()
@dp.message_handler(commands=['start'], state="*")
async def send_welcome(message: types.Message):
"""
This handler will be called when user sends `/start` command
"""
await message.reply("Hi!\nI'm DLS_Alexk bot!\nPowered by aiogram.\nUse /help to see what I can.")
@dp.message_handler(commands=['help'], state="*")
async def send_help(message: types.Message):
"""
This handler will be called when user sends `/help` command
"""
await message.reply("/style - загрузить картинку стиля;\n/content - загрузить картинку контента;\n/work - запустить перенос стиля на контент;\n/date - дата и время;\n/month - календарь текущего месяца;\n/uptime - uptime сервера с ботом;\n/weather - погода в Орле;\n/weatherl - погода в Орле (одной строкой).\n")
@dp.message_handler(commands=['date'], state="*")
async def send_date(message: types.Message):
cdate = os.popen('date').read()
await message.reply(cdate)
@dp.message_handler(commands=['month'], state="*")
async def send_month(message: types.Message):
cmonth = os.popen('cal').read()
await message.reply(cmonth)
@dp.message_handler(commands=['uptime'], state="*")
async def send_uptime(message: types.Message):
cmonth = os.popen('uptime').read()
await message.reply(cmonth)
@dp.message_handler(commands=['uname'], state="*")
async def send_uname(message: types.Message):
un = os.popen('uname -a').read()
await message.reply(un)
@dp.message_handler(commands=['weatherl'], state="*")
async def send_w(message: types.Message):
wl = os.popen('curl -s "http://wttr.in/Orel?lang=fr&format=%l:+%c:%C+%t+%h+%w+%m"').read()
await message.reply(wl)
@dp.message_handler(commands=['weather'], state="*")
async def send_wl(message: types.Message):
os.system('wget -q http://wttr.in/Orel_0tqp_lang=fr.png -O Orel.png')
with open('Orel.png', 'rb') as photo:
await message.reply_photo(photo, caption='🌡️')
@dp.message_handler(commands="style", state="*")
async def get_style_step_1(message: types.Message):
await message.answer("Загрузите картинку стиля:")
await GetPictures.waiting_for_style_picture.set()
@dp.message_handler(state=GetPictures.waiting_for_style_picture, content_types=types.ContentTypes.PHOTO)
async def get_style_step_2(message):
await message.answer("Результат работы команды /style: загружена картинка style.jpg")
await message.photo[0].download('style.jpg')
@dp.message_handler(commands="content", state="*")
async def get_content_step_1(message: types.Message):
await message.answer("Загрузите картинку контента:")
await GetPictures.waiting_for_content_picture.set()
@dp.message_handler(state=GetPictures.waiting_for_content_picture, content_types=types.ContentTypes.PHOTO)
async def get_content_step_2(message):
await message.answer("Результат работы команды /content: загружена картинка content.jpg")
await message.photo[0].download('content.jpg')
@dp.message_handler(commands="work", state="*")
async def execute_model(message: types.Message):
await message.reply("Запускаю перенос стиля...")
await message.reply("Ожидайте 5 минут.")
os.system('python3 gdrive/MyDrive/nst/nst.py style.jpg content.jpg')
with open('output.png', 'rb') as photo:
await message.reply_photo(photo, caption='результат переноса стиля на контент')
os.remove('style.jpg')
os.remove('content.jpg')
os.remove('output.png')
await message.reply("Результат работы команды /work: вам показан перенесённый стиль, все загруженные ранее картинки удалены.")
@dp.message_handler(regexp='(^cat[s]?$|puss)')
async def cats(message: types.Message):
with open('data/cats.jpg', 'rb') as photo:
'''
# Old fashioned way:
await bot.send_photo(
message.chat.id,
photo,
caption='Cats are here 😺',
reply_to_message_id=message.message_id,
)
'''
await message.reply_photo(photo, caption='Cats are here 😺')
@dp.message_handler()
async def echo(message: types.Message):
# old style:
# await bot.send_message(message.chat.id, message.text)
await message.answer(message.text)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)