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

Compare commits

..

No commits in common. "7fe60e19ef83ec318915b9d0b27bdcf778403ff7" and "7588c9fb9fd96fddd8b762ecc4847b76f78229d6" have entirely different histories.

20 changed files with 26 additions and 55 deletions

View File

@ -58,7 +58,6 @@
* [How can I distinguish a User and a GroupChat in message.chat?](#how-can-i-distinguish-a-user-and-a-groupchat-in-messagechat)
* [How can I handle reocurring ConnectionResetErrors?](#how-can-i-handle-reocurring-connectionreseterrors)
* [The Telegram Chat Group](#the-telegram-chat-group)
* [Telegram Channel](#telegram-channel)
* [More examples](#more-examples)
* [Bots using this API](#bots-using-this-api)
@ -717,7 +716,6 @@ Echo Bot example on AsyncTeleBot:
# It echoes any incoming text messages.
from telebot.async_telebot import AsyncTeleBot
import asyncio
bot = AsyncTeleBot('TOKEN')
@ -737,7 +735,7 @@ async def echo_message(message):
await bot.reply_to(message, message.text)
asyncio.run(bot.polling())
bot.polling()
```
As you can see here, keywords are await and async.
@ -782,11 +780,7 @@ Bot instances that were idle for a long time might be rejected by the server whe
Get help. Discuss. Chat.
* Join the [pyTelegramBotAPI Telegram Chat Group](https://telegram.me/joinchat/Bn4ixj84FIZVkwhk2jag6A)
## Telegram Channel
Join the [News channel](https://t.me/pyTelegramBotAPI). Here we will post releases and updates.
## More examples
* [Echo Bot](https://github.com/eternnoir/pyTelegramBotAPI/blob/master/examples/echo_bot.py)

View File

@ -84,5 +84,4 @@ async def back_callback(call: types.CallbackQuery):
bot.add_custom_filter(ProductsCallbackFilter())
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -8,5 +8,4 @@ async def make_some(message: telebot.types.ChatJoinRequest):
await bot.send_message(message.chat.id, 'I accepted a new user!')
await bot.approve_chat_join_request(message.chat.id, message.from_user.id)
import asyncio
asyncio.run(bot.polling())
bot.polling(skip_pending=True)

View File

@ -30,5 +30,4 @@ async def my_chat_m(message: types.ChatMemberUpdated):
@bot.message_handler(content_types=util.content_type_service)
async def delall(message: types.Message):
await bot.delete_message(message.chat.id,message.message_id)
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -9,6 +9,4 @@ async def answer_for_admin(message):
# Register filter
bot.add_custom_filter(asyncio_filters.IsAdminFilter(bot))
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -40,5 +40,4 @@ async def bye_user(message):
bot.add_custom_filter(MainFilter())
bot.add_custom_filter(IsAdmin())
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -14,5 +14,4 @@ async def not_admin(message):
# Do not forget to register
bot.add_custom_filter(telebot.asyncio_filters.ChatFilter())
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -19,5 +19,4 @@ async def text_filter(message):
bot.add_custom_filter(telebot.asyncio_filters.IsReplyFilter())
bot.add_custom_filter(telebot.asyncio_filters.ForwardFilter())
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -17,5 +17,4 @@ async def text_filter(message):
bot.add_custom_filter(telebot.asyncio_filters.TextMatchFilter())
bot.add_custom_filter(telebot.asyncio_filters.TextStartsFilter())
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -71,5 +71,4 @@ bot.add_custom_filter(asyncio_filters.IsDigitFilter())
# set saving states into file.
bot.enable_saving_states() # you can delete this if you do not need to save states
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -17,5 +17,4 @@ async def new_message(message: telebot.types.Message):
await bot.edit_message_text(chat_id=message.chat.id, message_id=result_message.id, text='<i>Done!</i>', parse_mode='HTML')
import asyncio
asyncio.run(bot.polling())
bot.polling(skip_pending=True)

View File

@ -23,5 +23,4 @@ async def echo_message(message):
await bot.reply_to(message, message.text)
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -24,5 +24,4 @@ async def photo_send(message: telebot.types.Message):
import asyncio
asyncio.run(bot.polling())
bot.polling(skip_pending=True)

View File

@ -36,5 +36,4 @@ bot.setup_middleware(SimpleMiddleware(2))
async def start(message):
await bot.send_message(message.chat.id, 'Hello!')
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -45,5 +45,4 @@ async def start(message, data: dict):
await bot.send_message(message.chat.id, data['response'])
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -15,6 +15,4 @@ bot.register_message_handler(start_executor, commands=['start']) # Start command
# bot.register_edited_message_handler(*args, **kwargs)
# And other functions..
import asyncio
asyncio.run(bot.polling())
bot.polling(skip_pending=True)

View File

@ -24,6 +24,4 @@ async def photos_send(message: telebot.types.Message):
import asyncio
asyncio.run(bot.polling())
bot.polling(skip_pending=True)

View File

@ -10,6 +10,4 @@ async def send_welcome(message):
async def echo_all(message):
await bot.reply_to(message, message.text)
import asyncio
asyncio.run(bot.polling(skip_pending=True)) # to skip updates
bot.polling(skip_pending=True)# Skip pending skips old updates

View File

@ -11,6 +11,4 @@ async def update_listener(messages):
bot.set_update_listener(update_listener)
import asyncio
asyncio.run(bot.polling())
bot.polling()

View File

@ -211,7 +211,7 @@ class AsyncTeleBot:
json_updates = await asyncio_helper.get_updates(self.token, offset, limit, timeout, allowed_updates, request_timeout)
return [types.Update.de_json(ju) for ju in json_updates]
async def polling(self, non_stop: bool=False, skip_pending=False, interval: int=0, timeout: int=20,
def polling(self, non_stop: bool=False, skip_pending=False, interval: int=0, timeout: int=20,
request_timeout: int=20, allowed_updates: Optional[List[str]]=None,
none_stop: Optional[bool]=None):
"""
@ -240,10 +240,10 @@ class AsyncTeleBot:
non_stop = none_stop
if skip_pending:
await self.skip_updates()
await self._process_polling(non_stop, interval, timeout, request_timeout, allowed_updates)
asyncio.run(self.skip_updates())
asyncio.run(self._process_polling(non_stop, interval, timeout, request_timeout, allowed_updates))
async def infinity_polling(self, timeout: int=20, skip_pending: bool=False, request_timeout: int=20, logger_level=logging.ERROR,
def infinity_polling(self, timeout: int=20, skip_pending: bool=False, request_timeout: int=20, logger_level=logging.ERROR,
allowed_updates: Optional[List[str]]=None, *args, **kwargs):
"""
Wrap polling with infinite loop and exception handling to avoid bot stops polling.
@ -263,12 +263,12 @@ class AsyncTeleBot:
so unwanted updates may be received for a short period of time.
"""
if skip_pending:
await self.skip_updates()
asyncio.run(self.skip_updates())
self._polling = True
while self._polling:
try:
await self._process_polling(non_stop=True, timeout=timeout, request_timeout=request_timeout,
allowed_updates=allowed_updates, *args, **kwargs)
asyncio.run( self._process_polling(non_stop=True, timeout=timeout, request_timeout=request_timeout,
allowed_updates=allowed_updates, *args, **kwargs) )
except Exception as e:
if logger_level and logger_level >= logging.ERROR:
logger.error("Infinity polling exception: %s", str(e))