Skip to content

Commit 852e33f

Browse files
authored
Improve validate_token function, add type annotations
Also remove some extra spaces
1 parent 47dd13f commit 852e33f

14 files changed

Lines changed: 81 additions & 59 deletions

examples/asynchronous_telebot/continue_handling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ async def start2(message):
1515
This handler comes after the first one, but it will never be called.
1616
But you can call it by returning ContinueHandling() in the first handler.
1717
18-
If you return ContinueHandling() in the first handler, the next
18+
If you return ContinueHandling() in the first handler, the next
1919
registered handler with appropriate filters will be called.
2020
"""
2121
await bot.send_message(message.chat.id, 'Hello World2!')
2222

23-
import asyncio
23+
import asyncio
2424
asyncio.run(bot.polling()) # just a reminder that infinity polling
2525
# wraps polling into try/except block just as sync version,
2626
# but you can use any of them because neither of them stops if you

examples/asynchronous_telebot/mini_app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# The source of the "https://pytelegrambotminiapp.vercel.app" can be found in https://github.com/eternnoir/pyTelegramBotAPI/tree/master/examples/mini_app_web
22

33
import asyncio
4-
from telebot.async_telebot import AsyncTeleBot
4+
from telebot.async_telebot import AsyncTeleBot
55
from telebot.types import (
6-
ReplyKeyboardMarkup,
7-
KeyboardButton,
6+
ReplyKeyboardMarkup,
7+
KeyboardButton,
88
WebAppInfo,
99
InlineKeyboardMarkup,
1010
InlineKeyboardButton
1111
)
1212

13-
BOT_TOKEN = ""
13+
BOT_TOKEN = ""
1414
WEB_URL = "https://pytelegrambotminiapp.vercel.app"
1515

1616
bot = AsyncTeleBot(BOT_TOKEN)

examples/asynchronous_telebot/timer_bot_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python3
22

3-
# This is a simple bot with schedule timer
3+
# This is a simple bot with schedule timer
44
# https://github.com/ibrb/python-aioschedule
55
# https://schedule.readthedocs.io
66

examples/continue_handling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def start2(message):
1515
This handler comes after the first one, but it will never be called.
1616
But you can call it by returning ContinueHandling() in the first handler.
1717
18-
If you return ContinueHandling() in the first handler, the next
18+
If you return ContinueHandling() in the first handler, the next
1919
registered handler with appropriate filters will be called.
2020
"""
2121
bot.send_message(message.chat.id, 'Hello World2!')

examples/inline_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def query_video(inline_query):
4242
try:
4343
r = types.InlineQueryResultVideo('1',
4444
'https://github.com/eternnoir/pyTelegramBotAPI/blob/master/tests/test_data/test_video.mp4?raw=true',
45-
'video/mp4',
45+
'video/mp4',
4646
'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg',
4747
'Title'
4848
)

examples/message_reaction_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# This is a simple bot using message reactions (emoji)
44
# https://core.telegram.org/bots/api#reactiontype
55
# https://core.telegram.org/bots/api#update
6-
# allowed_updates: Specify an empty list to receive all update types except, chat_member, message_reaction, and message_reaction_count.
7-
# If you want to receive message_reaction events, you cannot simply leave the allowed_updates=None default value.
8-
# The default list of events does not include chat_member, message_reaction, and message_reaction_count events.
9-
# You must explicitly specify all the events you wish to receive and add message_reaction to this list.
10-
# It’s also important to note that after using allowed_updates=[...], in the future, using allowed_updates=None will mean
6+
# allowed_updates: Specify an empty list to receive all update types except, chat_member, message_reaction, and message_reaction_count.
7+
# If you want to receive message_reaction events, you cannot simply leave the allowed_updates=None default value.
8+
# The default list of events does not include chat_member, message_reaction, and message_reaction_count events.
9+
# You must explicitly specify all the events you wish to receive and add message_reaction to this list.
10+
# It’s also important to note that after using allowed_updates=[...], in the future, using allowed_updates=None will mean
1111
# that the list of events you will receive will consist of the events you last explicitly specified.
1212

1313
import random

examples/mini_app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
from telebot import TeleBot
44
from telebot.types import (
5-
ReplyKeyboardMarkup,
6-
KeyboardButton,
5+
ReplyKeyboardMarkup,
6+
KeyboardButton,
77
WebAppInfo,
88
InlineKeyboardMarkup,
99
InlineKeyboardButton
1010
)
1111

12-
BOT_TOKEN = ""
13-
WEB_URL = "https://pytelegrambotminiapp.vercel.app"
12+
BOT_TOKEN = ""
13+
WEB_URL = "https://pytelegrambotminiapp.vercel.app"
1414

1515
bot = TeleBot(BOT_TOKEN)
1616

examples/stars_payment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Import required libraries
2-
import telebot
3-
from telebot import types
2+
import telebot
3+
from telebot import types
44

55
bot = telebot.TeleBot('TOKEN')
66

telebot/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def __init__(
168168
next_step_backend: Optional[HandlerBackend]=None, reply_backend: Optional[HandlerBackend]=None,
169169
exception_handler: Optional[ExceptionHandler]=None, last_update_id: Optional[int]=0,
170170
suppress_middleware_excepions: Optional[bool]=False, state_storage: Optional[StateStorageBase]=StateMemoryStorage(),
171-
use_class_middlewares: Optional[bool]=False,
171+
use_class_middlewares: Optional[bool]=False,
172172
disable_web_page_preview: Optional[bool]=None,
173173
disable_notification: Optional[bool]=None,
174174
protect_content: Optional[bool]=None,
@@ -1571,7 +1571,7 @@ def get_chat_administrators(self, chat_id: Union[int, str]) -> List[types.ChatMe
15711571
On success, returns an Array of ChatMember objects that contains
15721572
information about all chat administrators except other bots.
15731573
1574-
Telegram documentation: https://core.telegram.org/bots/api#getchatadministrators
1574+
Telegram documentation: https://core.telegram.org/bots/api#getchatadministrators
15751575
15761576
:param chat_id: Unique identifier for the target chat or username
15771577
of the target supergroup or channel (in the format @channelusername)
@@ -7051,7 +7051,7 @@ def create_new_sticker_set(
70517051
def add_sticker_to_set(
70527052
self, user_id: int, name: str, emojis: Union[List[str], str],
70537053
png_sticker: Optional[Union[Any, str]]=None,
7054-
tgs_sticker: Optional[Union[Any, str]]=None,
7054+
tgs_sticker: Optional[Union[Any, str]]=None,
70557055
webm_sticker: Optional[Union[Any, str]]=None,
70567056
mask_position: Optional[types.MaskPosition]=None,
70577057
sticker: Optional[types.InputSticker]=None) -> bool:

telebot/apihelper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def _check_result(method_name, result):
190190
raise ApiHTTPException(method_name, result)
191191
else:
192192
raise ApiInvalidJSONException(method_name, result)
193-
else:
193+
else:
194194
if not result_json['ok']:
195195
raise ApiTelegramException(method_name, result, result_json)
196196

@@ -2496,9 +2496,9 @@ def convert_input_media_array(array):
24962496
if 'thumbnail' in media_dict:
24972497
thumbnail = media_dict['thumbnail']
24982498
if isinstance(thumbnail, types.InputFile):
2499-
thumbnail_key = 'thumbnail_' + key
2500-
files[thumbnail_key] = thumbnail
2501-
media_dict['thumbnail'] = 'attach://' + thumbnail_key
2499+
thumbnail_key = 'thumbnail_' + key
2500+
files[thumbnail_key] = thumbnail
2501+
media_dict['thumbnail'] = 'attach://' + thumbnail_key
25022502
media.append(media_dict)
25032503
return json.dumps(media), files
25042504

0 commit comments

Comments
 (0)