Skip to content

Commit 83f3d23

Browse files
author
Nikita Aksenov
authored
Merge pull request #1 from nawinds/v1.0.1
v1.0.1: Markdown escape added
2 parents e0cfbb2 + b9c1a02 commit 83f3d23

File tree

8 files changed

+19
-31
lines changed

8 files changed

+19
-31
lines changed

handlers/callbacks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from string import Template
21

32
from aiogram import Router
43
from aiogram import types, F
@@ -11,6 +10,7 @@
1110
from data.sticker_sets import StickerSet
1211
from data.user_sets import UserSet
1312
from instances import bot
13+
from instances import escape_md
1414

1515
callbacks = Router()
1616
callbacks.message.filter(F.chat.type == "private")
@@ -43,10 +43,10 @@ async def add_set(callback: types.CallbackQuery, i18n: I18nContext):
4343
if notifications:
4444
await bot.send_message(
4545
sticker_set.owner_id,
46-
Template(i18n.gettext("callbacks.add_set.notification", title=sticker_set.title))
47-
.substitute(title=sticker_set.title),
46+
i18n.gettext("callbacks.add_set.notification", title=escape_md(sticker_set.title)),
4847
parse_mode="markdown")
49-
await bot.send_message(callback.from_user.id, i18n.gettext("callbacks.add_set.added"))
48+
await bot.send_message(callback.from_user.id, i18n.gettext("callbacks.add_set.added"),
49+
parse_mode="markdown")
5050

5151

5252
@callbacks.callback_query(lambda c: c.data.startswith("share_set-"), StateFilter("*"))
@@ -80,8 +80,8 @@ async def share_set(callback: types.CallbackQuery, i18n: I18nContext):
8080
f"{link.code}")
8181
await bot.send_message(callback.from_user.id,
8282
i18n.gettext("callbacks.share_set.link_text",
83-
title=sticker_set.title,
84-
username=bot_info.username,
83+
title=escape_md(sticker_set.title),
84+
username=escape_md(bot_info.username),
8585
code=link.code), reply_markup=builder.as_markup(),
8686
parse_mode="markdown")
8787

handlers/commands.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from data.user_sets import UserSet
1414
from instances import NewSetState
1515
from instances import bot
16+
from instances import escape_md
1617

1718
commands = Router()
1819
commands.message.filter(F.chat.type == "private")
@@ -34,14 +35,14 @@ async def cmd_start_add_set(message: types.Message, i18n: I18nContext):
3435
builder.button(text=i18n.gettext("commands.start_deep.no"), callback_data="add_set-0")
3536
builder.adjust(1)
3637

37-
await message.answer(i18n.gettext("commands.start_deep.reply_text", link_set_title=link.set.title),
38+
await message.answer(i18n.gettext("commands.start_deep.reply_text", link_set_title=escape_md(link.set.title)),
3839
reply_markup=builder.as_markup(), parse_mode="markdown")
3940

4041

4142
@commands.message(CommandStart(), StateFilter(None))
4243
async def cmd_start(message: types.Message, i18n: I18nContext):
4344
bot_info = await bot.get_me()
44-
await message.answer(i18n.gettext("commands.start.hello_text", username=bot_info.username),
45+
await message.answer(i18n.gettext("commands.start.hello_text", username=escape_md(bot_info.username)),
4546
parse_mode="markdown", disable_web_page_preview=True)
4647

4748

instances.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from aiogram.fsm.context import FSMContext
77
from aiogram.fsm.storage.memory import MemoryStorage
88
from aiogram.types import TelegramObject
9+
from aiogram.utils.markdown import markdown_decoration, _join
910
from aiogram_i18n.managers.fsm import FSMManager
1011

1112
storage = MemoryStorage()
@@ -31,3 +32,7 @@ async def get_locale(self, event: TelegramObject, data: Dict[str, Any]) -> str:
3132
if state:
3233
await state.update_data(data={self.key: locale})
3334
return locale
35+
36+
37+
def escape_md(*content, sep=" ") -> str:
38+
return markdown_decoration.quote(_join(*content, sep=sep)).replace("\\.", ".")

locales/en/LC_MESSAGES/en.mo

2 Bytes
Binary file not shown.

locales/en/LC_MESSAGES/en.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ msgid ""
22
msgstr ""
33
"Project-Id-Version: Inline stickers bot\n"
44
"POT-Creation-Date: 2023-07-20 18:07+0300\n"
5-
"PO-Revision-Date: 2023-07-20 18:08+0300\n"
5+
"PO-Revision-Date: 2023-07-23 23:23+0300\n"
66
"Last-Translator: Nikita Aksenov <[email protected]>\n"
77
"Language-Team: Nikita Aksenov\n"
88
"Language: en\n"
@@ -57,7 +57,7 @@ msgstr " notifications"
5757
#: handlers/callbacks.py:82
5858
msgid "callbacks.share_set.link_text"
5959
msgstr ""
60-
"Here is a link for adding the {title} set. You can now share it with your "
60+
"Here is a link for adding the *{title}* set. You can now share it with your "
6161
"friends.\n"
6262
"\n"
6363
"https://t.me/{username}?start=add\\_set-{code}\n"

locales/ru/LC_MESSAGES/ru.mo

2 Bytes
Binary file not shown.

locales/ru/LC_MESSAGES/ru.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ msgid ""
22
msgstr ""
33
"Project-Id-Version: Inline stickers bot\n"
44
"POT-Creation-Date: 2023-07-20 18:07+0300\n"
5-
"PO-Revision-Date: 2023-07-20 18:08+0300\n"
5+
"PO-Revision-Date: 2023-07-23 23:24+0300\n"
66
"Last-Translator: Nikita Aksenov <[email protected]>\n"
77
"Language-Team: Nikita Aksenov\n"
88
"Language: ru\n"
@@ -57,7 +57,7 @@ msgstr " уведомления"
5757
#: handlers/callbacks.py:82
5858
msgid "callbacks.share_set.link_text"
5959
msgstr ""
60-
"Ниже ссылка для добавления сета {title}. Вы можете поделиться ей с "
60+
"Ниже ссылка для добавления сета *{title}*. Вы можете поделиться ей с "
6161
"друзьями.\n"
6262
"\n"
6363
"https://t.me/{username}?start=add\\_set-{code}\n"

requirements.txt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
aiofiles==23.1.0
21
aiogram==3.0.0b7
3-
aiogram_i18n==1.0
4-
aiohttp==3.8.4
5-
aiosignal==1.3.1
6-
async-timeout==4.0.2
7-
attrs==23.1.0
8-
certifi==2023.5.7
9-
charset-normalizer==3.2.0
10-
click==8.1.4
11-
colorama==0.4.6
12-
frozenlist==1.4.0
13-
greenlet==2.0.2
14-
idna==3.4
15-
magic-filter==1.0.10
16-
multidict==6.0.4
172
numpy==1.25.1
18-
pydantic==1.10.11
193
pyxDamerauLevenshtein==1.7.1
20-
SQLAlchemy==2.0.19
21-
typing_extensions==4.7.1
22-
yarl==1.9.2
4+
SQLAlchemy==2.0.19

0 commit comments

Comments
 (0)