-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
64 lines (53 loc) · 2.27 KB
/
bot.py
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
import time
import logging
from aiogram import Bot, Dispatcher, executor, types
TOKEN = "" # add your Token here
bot = Bot(token=TOKEN)
dp = Dispatcher(bot=bot)
logging.basicConfig(filename="name_rus_to_lat_bot_log",
level=logging.INFO)
bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
dict = {ord('А') : ord('A'), ord('Б') : ord('B'),
ord('В') : ord('V'), ord('Г') : ord('G'),
ord('Д') : ord('D'), ord('Е') : ord('E'),
ord('Ё') : ord('E'),
ord('Ж') : 'ZH',
ord('З') : ord('Z'), ord('И') : ord('I'),
ord('Й') : ord('I'), ord('К') : ord('K'),
ord('Л') : ord('L'), ord('М') : ord('M'),
ord('Н') : ord('N'), ord('О') : ord('O'),
ord('П') : ord('P'), ord('Р') : ord('R'),
ord('С') : ord('S'), ord('Т') : ord('T'),
ord('У') : ord('U'), ord('Ф') : ord('F'),
ord('Х') : 'KH',
ord('Ц') : 'TS',
ord('Ч') : 'CH',
ord('Ш') : 'SH',
ord('Щ') : 'SHCH',
ord('Ъ') : 'IE',
ord('Ы') : ord('Y'), ord('Ь') : None,
ord('Э') : ord('E'),
ord('Ю') : 'IU',
ord('Я') : 'IA'}
@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
user_full_name = message.from_user.full_name
user_id = message.from_user.id
logging.info(f'START: {user_id=} {user_full_name=} {time.asctime()}')
await message.reply("Привет, введи имя для перевода!")
@dp.message_handler(commands=['help'])
async def process_help_command(message: types.Message):
user_full_name = message.from_user.full_name
user_id = message.from_user.id
logging.info(f'HELP: {user_id=} {user_full_name=} {time.asctime()}')
await message.reply("Напиши мне имя на кирилице, и я его переведу в латиницу!")
@dp.message_handler()
async def echo_message(message: types.Message):
user_full_name = message.from_user.full_name
user_id = message.from_user.id
logging.info(f'TRANSLATE: {user_id=} {user_full_name=} {time.asctime()}')
tranlatted_message = message.text.upper().translate(dict)
await bot.send_message(user_id, tranlatted_message)
if __name__ == '__main__':
executor.start_polling(dp)