1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Badiboy
5d74e18d1a
Merge pull request #1550 from Badiboy/master
Poll type parameter parse fix
2022-05-15 01:06:04 +03:00
Badiboy
91b665ea94 Poll type parameter parse fix
Plus some typo
2022-05-15 00:59:35 +03:00
Badiboy
6e4c63b09c
Merge pull request #1549 from coder2020official/master
Set escape=True by default.
2022-05-14 19:27:44 +03:00
coder2020official
42efb8488c Set escape=True by default. 2022-05-14 20:32:28 +05:00
7 changed files with 57 additions and 52 deletions

View File

@ -10,6 +10,5 @@ OS:
## Checklist: ## Checklist:
- [ ] I added/edited example on new feature/change (if exists) - [ ] I added/edited example on new feature/change (if exists)
- [ ] My changes won't break backend compatibility - [ ] My changes won't break backward compatibility
- [ ] I made changes for async and sync - [ ] I made changes both for sync and async

View File

@ -10,11 +10,11 @@ async def start_message(message):
message.chat.id, message.chat.id,
# function which connects all strings # function which connects all strings
formatting.format_text( formatting.format_text(
formatting.mbold(message.from_user.first_name, escape=True), # pass escape=True to escape special characters formatting.mbold(message.from_user.first_name),
formatting.mitalic(message.from_user.first_name, escape=True), formatting.mitalic(message.from_user.first_name),
formatting.munderline(message.from_user.first_name, escape=True), formatting.munderline(message.from_user.first_name),
formatting.mstrikethrough(message.from_user.first_name, escape=True), formatting.mstrikethrough(message.from_user.first_name),
formatting.mcode(message.from_user.first_name, escape=True), formatting.mcode(message.from_user.first_name),
separator=" " # separator separates all strings separator=" " # separator separates all strings
), ),
parse_mode='MarkdownV2' parse_mode='MarkdownV2'
@ -23,7 +23,7 @@ async def start_message(message):
# just a bold text using markdownv2 # just a bold text using markdownv2
await bot.send_message( await bot.send_message(
message.chat.id, message.chat.id,
formatting.mbold(message.from_user.first_name, escape=True), formatting.mbold(message.from_user.first_name),
parse_mode='MarkdownV2' parse_mode='MarkdownV2'
) )
@ -31,11 +31,11 @@ async def start_message(message):
await bot.send_message( await bot.send_message(
message.chat.id, message.chat.id,
formatting.format_text( formatting.format_text(
formatting.hbold(message.from_user.first_name, escape=True), formatting.hbold(message.from_user.first_name),
formatting.hitalic(message.from_user.first_name, escape=True), formatting.hitalic(message.from_user.first_name),
formatting.hunderline(message.from_user.first_name, escape=True), formatting.hunderline(message.from_user.first_name),
formatting.hstrikethrough(message.from_user.first_name, escape=True), formatting.hstrikethrough(message.from_user.first_name),
formatting.hcode(message.from_user.first_name, escape=True), formatting.hcode(message.from_user.first_name),
separator=" " separator=" "
), ),
parse_mode='HTML' parse_mode='HTML'
@ -44,7 +44,7 @@ async def start_message(message):
# just a bold text in html # just a bold text in html
await bot.send_message( await bot.send_message(
message.chat.id, message.chat.id,
formatting.hbold(message.from_user.first_name, escape=True), formatting.hbold(message.from_user.first_name),
parse_mode='HTML' parse_mode='HTML'
) )

View File

@ -10,11 +10,11 @@ def start_message(message):
message.chat.id, message.chat.id,
# function which connects all strings # function which connects all strings
formatting.format_text( formatting.format_text(
formatting.mbold(message.from_user.first_name, escape=True), # pass escape=True to escape special characters formatting.mbold(message.from_user.first_name),
formatting.mitalic(message.from_user.first_name, escape=True), formatting.mitalic(message.from_user.first_name),
formatting.munderline(message.from_user.first_name, escape=True), formatting.munderline(message.from_user.first_name),
formatting.mstrikethrough(message.from_user.first_name, escape=True), formatting.mstrikethrough(message.from_user.first_name),
formatting.mcode(message.from_user.first_name, escape=True), formatting.mcode(message.from_user.first_name),
separator=" " # separator separates all strings separator=" " # separator separates all strings
), ),
parse_mode='MarkdownV2' parse_mode='MarkdownV2'
@ -23,7 +23,7 @@ def start_message(message):
# just a bold text using markdownv2 # just a bold text using markdownv2
bot.send_message( bot.send_message(
message.chat.id, message.chat.id,
formatting.mbold(message.from_user.first_name, escape=True), formatting.mbold(message.from_user.first_name),
parse_mode='MarkdownV2' parse_mode='MarkdownV2'
) )
@ -31,11 +31,11 @@ def start_message(message):
bot.send_message( bot.send_message(
message.chat.id, message.chat.id,
formatting.format_text( formatting.format_text(
formatting.hbold(message.from_user.first_name, escape=True), formatting.hbold(message.from_user.first_name),
formatting.hitalic(message.from_user.first_name, escape=True), formatting.hitalic(message.from_user.first_name),
formatting.hunderline(message.from_user.first_name, escape=True), formatting.hunderline(message.from_user.first_name),
formatting.hstrikethrough(message.from_user.first_name, escape=True), formatting.hstrikethrough(message.from_user.first_name),
formatting.hcode(message.from_user.first_name, escape=True), formatting.hcode(message.from_user.first_name),
separator=" " separator=" "
), ),
parse_mode='HTML' parse_mode='HTML'
@ -44,7 +44,7 @@ def start_message(message):
# just a bold text in html # just a bold text in html
bot.send_message( bot.send_message(
message.chat.id, message.chat.id,
formatting.hbold(message.from_user.first_name, escape=True), formatting.hbold(message.from_user.first_name),
parse_mode='HTML' parse_mode='HTML'
) )

View File

@ -35,7 +35,7 @@ class StateRedisStorage(StateStorageBase):
""" """
Function to get record from database. Function to get record from database.
It has nothing to do with states. It has nothing to do with states.
Made for backend compatibility Made for backward compatibility
""" """
result = await self.redis.get(self.prefix+str(key)) result = await self.redis.get(self.prefix+str(key))
if result: return json.loads(result) if result: return json.loads(result)
@ -45,7 +45,7 @@ class StateRedisStorage(StateStorageBase):
""" """
Function to set record to database. Function to set record to database.
It has nothing to do with states. It has nothing to do with states.
Made for backend compatibility Made for backward compatibility
""" """
await self.redis.set(self.prefix+str(key), json.dumps(value)) await self.redis.set(self.prefix+str(key), json.dumps(value))
@ -55,7 +55,7 @@ class StateRedisStorage(StateStorageBase):
""" """
Function to delete record from database. Function to delete record from database.
It has nothing to do with states. It has nothing to do with states.
Made for backend compatibility Made for backward compatibility
""" """
await self.redis.delete(self.prefix+str(key)) await self.redis.delete(self.prefix+str(key))
return True return True

View File

@ -49,7 +49,7 @@ def escape_markdown(content: str) -> str:
return reparse return reparse
def mbold(content: str, escape: bool=False) -> str: def mbold(content: str, escape: bool=True) -> str:
""" """
Returns a Markdown-formatted bold string. Returns a Markdown-formatted bold string.
@ -59,7 +59,7 @@ def mbold(content: str, escape: bool=False) -> str:
return '*{}*'.format(escape_markdown(content) if escape else content) return '*{}*'.format(escape_markdown(content) if escape else content)
def hbold(content: str, escape: bool=False) -> str: def hbold(content: str, escape: bool=True) -> str:
""" """
Returns an HTML-formatted bold string. Returns an HTML-formatted bold string.
@ -69,7 +69,7 @@ def hbold(content: str, escape: bool=False) -> str:
return '<b>{}</b>'.format(escape_html(content) if escape else content) return '<b>{}</b>'.format(escape_html(content) if escape else content)
def mitalic(content: str, escape: bool=False) -> str: def mitalic(content: str, escape: bool=True) -> str:
""" """
Returns a Markdown-formatted italic string. Returns a Markdown-formatted italic string.
@ -79,7 +79,7 @@ def mitalic(content: str, escape: bool=False) -> str:
return '_{}_\r'.format(escape_markdown(content) if escape else content) return '_{}_\r'.format(escape_markdown(content) if escape else content)
def hitalic(content: str, escape: bool=False) -> str: def hitalic(content: str, escape: bool=True) -> str:
""" """
Returns an HTML-formatted italic string. Returns an HTML-formatted italic string.
@ -89,7 +89,7 @@ def hitalic(content: str, escape: bool=False) -> str:
return '<i>{}</i>'.format(escape_html(content) if escape else content) return '<i>{}</i>'.format(escape_html(content) if escape else content)
def munderline(content: str, escape: bool=False) -> str: def munderline(content: str, escape: bool=True) -> str:
""" """
Returns a Markdown-formatted underline string. Returns a Markdown-formatted underline string.
@ -99,7 +99,7 @@ def munderline(content: str, escape: bool=False) -> str:
return '__{}__'.format(escape_markdown(content) if escape else content) return '__{}__'.format(escape_markdown(content) if escape else content)
def hunderline(content: str, escape: bool=False) -> str: def hunderline(content: str, escape: bool=True) -> str:
""" """
Returns an HTML-formatted underline string. Returns an HTML-formatted underline string.
@ -109,7 +109,7 @@ def hunderline(content: str, escape: bool=False) -> str:
return '<u>{}</u>'.format(escape_html(content) if escape else content) return '<u>{}</u>'.format(escape_html(content) if escape else content)
def mstrikethrough(content: str, escape: bool=False) -> str: def mstrikethrough(content: str, escape: bool=True) -> str:
""" """
Returns a Markdown-formatted strikethrough string. Returns a Markdown-formatted strikethrough string.
@ -119,7 +119,7 @@ def mstrikethrough(content: str, escape: bool=False) -> str:
return '~{}~'.format(escape_markdown(content) if escape else content) return '~{}~'.format(escape_markdown(content) if escape else content)
def hstrikethrough(content: str, escape: bool=False) -> str: def hstrikethrough(content: str, escape: bool=True) -> str:
""" """
Returns an HTML-formatted strikethrough string. Returns an HTML-formatted strikethrough string.
@ -129,7 +129,7 @@ def hstrikethrough(content: str, escape: bool=False) -> str:
return '<s>{}</s>'.format(escape_html(content) if escape else content) return '<s>{}</s>'.format(escape_html(content) if escape else content)
def mspoiler(content: str, escape: bool=False) -> str: def mspoiler(content: str, escape: bool=True) -> str:
""" """
Returns a Markdown-formatted spoiler string. Returns a Markdown-formatted spoiler string.
@ -139,7 +139,7 @@ def mspoiler(content: str, escape: bool=False) -> str:
return '||{}||'.format(escape_markdown(content) if escape else content) return '||{}||'.format(escape_markdown(content) if escape else content)
def hspoiler(content: str, escape: bool=False) -> str: def hspoiler(content: str, escape: bool=True) -> str:
""" """
Returns an HTML-formatted spoiler string. Returns an HTML-formatted spoiler string.
@ -149,7 +149,7 @@ def hspoiler(content: str, escape: bool=False) -> str:
return '<tg-spoiler>{}</tg-spoiler>'.format(escape_html(content) if escape else content) return '<tg-spoiler>{}</tg-spoiler>'.format(escape_html(content) if escape else content)
def mlink(content: str, url: str, escape: bool=False) -> str: def mlink(content: str, url: str, escape: bool=True) -> str:
""" """
Returns a Markdown-formatted link string. Returns a Markdown-formatted link string.
@ -160,7 +160,7 @@ def mlink(content: str, url: str, escape: bool=False) -> str:
return '[{}]({})'.format(escape_markdown(content), escape_markdown(url) if escape else content) return '[{}]({})'.format(escape_markdown(content), escape_markdown(url) if escape else content)
def hlink(content: str, url: str, escape: bool=False) -> str: def hlink(content: str, url: str, escape: bool=True) -> str:
""" """
Returns an HTML-formatted link string. Returns an HTML-formatted link string.
@ -171,7 +171,7 @@ def hlink(content: str, url: str, escape: bool=False) -> str:
return '<a href="{}">{}</a>'.format(escape_html(url), escape_html(content) if escape else content) return '<a href="{}">{}</a>'.format(escape_html(url), escape_html(content) if escape else content)
def mcode(content: str, language: str="", escape: bool=False) -> str: def mcode(content: str, language: str="", escape: bool=True) -> str:
""" """
Returns a Markdown-formatted code string. Returns a Markdown-formatted code string.
@ -181,7 +181,7 @@ def mcode(content: str, language: str="", escape: bool=False) -> str:
return '```{}\n{}```'.format(language, escape_markdown(content) if escape else content) return '```{}\n{}```'.format(language, escape_markdown(content) if escape else content)
def hcode(content: str, escape: bool=False) -> str: def hcode(content: str, escape: bool=True) -> str:
""" """
Returns an HTML-formatted code string. Returns an HTML-formatted code string.
@ -191,7 +191,7 @@ def hcode(content: str, escape: bool=False) -> str:
return '<code>{}</code>'.format(escape_html(content) if escape else content) return '<code>{}</code>'.format(escape_html(content) if escape else content)
def hpre(content: str, escape: bool=False, language: str="") -> str: def hpre(content: str, escape: bool=True, language: str="") -> str:
""" """
Returns an HTML-formatted preformatted string. Returns an HTML-formatted preformatted string.

View File

@ -28,7 +28,7 @@ class StateRedisStorage(StateStorageBase):
""" """
Function to get record from database. Function to get record from database.
It has nothing to do with states. It has nothing to do with states.
Made for backend compatibility Made for backward compatibility
""" """
connection = Redis(connection_pool=self.redis) connection = Redis(connection_pool=self.redis)
result = connection.get(self.prefix+str(key)) result = connection.get(self.prefix+str(key))
@ -40,7 +40,7 @@ class StateRedisStorage(StateStorageBase):
""" """
Function to set record to database. Function to set record to database.
It has nothing to do with states. It has nothing to do with states.
Made for backend compatibility Made for backward compatibility
""" """
connection = Redis(connection_pool=self.redis) connection = Redis(connection_pool=self.redis)
connection.set(self.prefix+str(key), json.dumps(value)) connection.set(self.prefix+str(key), json.dumps(value))
@ -51,7 +51,7 @@ class StateRedisStorage(StateStorageBase):
""" """
Function to delete record from database. Function to delete record from database.
It has nothing to do with states. It has nothing to do with states.
Made for backend compatibility Made for backward compatibility
""" """
connection = Redis(connection_pool=self.redis) connection = Redis(connection_pool=self.redis)
connection.delete(self.prefix+str(key)) connection.delete(self.prefix+str(key))

View File

@ -2774,23 +2774,29 @@ class Poll(JsonDeserializable):
obj['explanation_entities'] = Message.parse_entities(obj['explanation_entities']) obj['explanation_entities'] = Message.parse_entities(obj['explanation_entities'])
return cls(**obj) return cls(**obj)
# noinspection PyShadowingBuiltins
def __init__( def __init__(
self, self,
question, options, question, options,
poll_id=None, total_voter_count=None, is_closed=None, is_anonymous=None, poll_type=None, poll_id=None, total_voter_count=None, is_closed=None, is_anonymous=None, type=None,
allows_multiple_answers=None, correct_option_id=None, explanation=None, explanation_entities=None, allows_multiple_answers=None, correct_option_id=None, explanation=None, explanation_entities=None,
open_period=None, close_date=None, **kwargs): open_period=None, close_date=None, poll_type=None, **kwargs):
self.id: str = poll_id self.id: str = poll_id
self.question: str = question self.question: str = question
self.options: List[PollOption] = options self.options: List[PollOption] = options
self.total_voter_count: int = total_voter_count self.total_voter_count: int = total_voter_count
self.is_closed: bool = is_closed self.is_closed: bool = is_closed
self.is_anonymous: bool = is_anonymous self.is_anonymous: bool = is_anonymous
self.type: str = poll_type self.type: str = type
if poll_type is not None:
# Wrong param name backward compatibility
logger.warning("Poll: poll_type parameter is deprecated. Use type instead.")
if type is None:
self.type: str = poll_type
self.allows_multiple_answers: bool = allows_multiple_answers self.allows_multiple_answers: bool = allows_multiple_answers
self.correct_option_id: int = correct_option_id self.correct_option_id: int = correct_option_id
self.explanation: str = explanation self.explanation: str = explanation
self.explanation_entities: List[MessageEntity] = explanation_entities # Default state of entities is None. if (explanation_entities is not None) else [] self.explanation_entities: List[MessageEntity] = explanation_entities
self.open_period: int = open_period self.open_period: int = open_period
self.close_date: int = close_date self.close_date: int = close_date