mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 09:22:03 +00:00
Add example. Check user language.
Demonstrate language and markdown utils.
This commit is contained in:
parent
2fdd804114
commit
e06920681d
1 changed files with 40 additions and 0 deletions
40
examples/check_user_language.py
Normal file
40
examples/check_user_language.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import asyncio
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from aiogram.bot import AIOGramBot
|
||||||
|
from aiogram.dispatcher import Dispatcher
|
||||||
|
from aiogram.types.message import ParseMode
|
||||||
|
from aiogram.utils.markdown import *
|
||||||
|
|
||||||
|
API_TOKEN = 'BOT TOKEN HERE'
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
bot = AIOGramBot(token=API_TOKEN, loop=loop)
|
||||||
|
dp = Dispatcher(bot)
|
||||||
|
|
||||||
|
|
||||||
|
@dp.message_handler()
|
||||||
|
async def check_language(message):
|
||||||
|
language = message.from_user.language
|
||||||
|
|
||||||
|
await message.reply(text(
|
||||||
|
bold('Info about your language:'),
|
||||||
|
text(' 🔸', bold('Code:'), italic(language.code)),
|
||||||
|
text(' 🔸', bold('Type:'), italic(language.type)),
|
||||||
|
text(' 🔸', bold('Title:'), italic(language.title)),
|
||||||
|
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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue