aiogram/examples/check_user_language.py
2017-06-03 10:53:13 +03:00

45 lines
1.1 KiB
Python

"""
Babel is required.
"""
import asyncio
import logging
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.types import ParseMode
from aiogram.utils.markdown import *
API_TOKEN = 'BOT TOKEN HERE'
logging.basicConfig(level=logging.INFO)
loop = asyncio.get_event_loop()
bot = Bot(token=API_TOKEN, loop=loop)
dp = Dispatcher(bot)
@dp.message_handler()
async def check_language(message: types.Message):
locale = message.from_user.locale
await message.reply(text(
bold('Info about your language:'),
text(' 🔸', bold('Code:'), italic(locale.locale)),
text(' 🔸', bold('Territory:'), italic(locale.territory or 'Unknown')),
text(' 🔸', bold('Language name:'), italic(locale.language_name)),
text(' 🔸', bold('English language name:'), italic(locale.english_name)),
sep='\n'), parse_mode=ParseMode.MARKDOWN)
async def main():
count = await dp.skip_updates()
print(f"Skipped {count} updates.")
await dp.start_pooling()
if __name__ == '__main__':
try:
loop.run_until_complete(main())
except KeyboardInterrupt:
loop.stop()