mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #1375 from coder2020official/master
Forgot to make polling sync
This commit is contained in:
commit
1f918dece5
@ -1,5 +1,5 @@
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
import asyncio
|
||||
|
||||
import telebot
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
|
||||
@ -8,4 +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)
|
||||
|
||||
asyncio.run(bot.polling(skip_pending=True))
|
||||
bot.polling(skip_pending=True)
|
@ -1,6 +1,6 @@
|
||||
from telebot import types,util
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
import asyncio
|
||||
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
|
||||
#chat_member_handler. When status changes, telegram gives update. check status from old_chat_member and new_chat_member.
|
||||
@ -30,4 +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)
|
||||
asyncio.run(bot.polling())
|
||||
bot.polling()
|
||||
|
@ -1,4 +1,3 @@
|
||||
import asyncio
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
from telebot import asyncio_filters
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
@ -10,4 +9,4 @@ async def answer_for_admin(message):
|
||||
|
||||
# Register filter
|
||||
bot.add_custom_filter(asyncio_filters.IsAdminFilter(bot))
|
||||
asyncio.run(bot.polling())
|
||||
bot.polling()
|
||||
|
@ -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()
|
||||
|
@ -1,6 +1,5 @@
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
import telebot
|
||||
import asyncio
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
|
||||
|
||||
@ -15,5 +14,4 @@ async def not_admin(message):
|
||||
|
||||
# Do not forget to register
|
||||
bot.add_custom_filter(telebot.asyncio_filters.ChatFilter())
|
||||
|
||||
asyncio.run(bot.polling())
|
||||
bot.polling()
|
||||
|
@ -1,6 +1,6 @@
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
import telebot
|
||||
import asyncio
|
||||
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
|
||||
|
||||
@ -19,4 +19,4 @@ async def text_filter(message):
|
||||
bot.add_custom_filter(telebot.asyncio_filters.IsReplyFilter())
|
||||
bot.add_custom_filter(telebot.asyncio_filters.ForwardFilter())
|
||||
|
||||
asyncio.run(bot.polling())
|
||||
bot.polling()
|
||||
|
@ -1,6 +1,5 @@
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
import telebot
|
||||
import asyncio
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
|
||||
|
||||
@ -18,4 +17,4 @@ async def text_filter(message):
|
||||
bot.add_custom_filter(telebot.asyncio_filters.TextMatchFilter())
|
||||
bot.add_custom_filter(telebot.asyncio_filters.TextStartsFilter())
|
||||
|
||||
asyncio.run(bot.polling())
|
||||
bot.polling()
|
||||
|
@ -1,7 +1,6 @@
|
||||
import telebot
|
||||
from telebot import asyncio_filters
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
import asyncio
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
|
||||
|
||||
@ -72,4 +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
|
||||
|
||||
asyncio.run(bot.polling())
|
||||
bot.polling()
|
@ -4,7 +4,6 @@
|
||||
# It echoes any incoming text messages.
|
||||
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
import asyncio
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
|
||||
|
||||
@ -24,4 +23,4 @@ async def echo_message(message):
|
||||
await bot.reply_to(message, message.text)
|
||||
|
||||
|
||||
asyncio.run(bot.polling())
|
||||
bot.polling()
|
||||
|
@ -1,5 +1,4 @@
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
import asyncio
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
|
||||
async def start_executor(message):
|
||||
@ -16,4 +15,4 @@ bot.register_message_handler(start_executor, commands=['start']) # Start command
|
||||
# bot.register_edited_message_handler(*args, **kwargs)
|
||||
# And other functions..
|
||||
|
||||
asyncio.run(bot.polling(skip_pending=True))
|
||||
bot.polling(skip_pending=True)
|
||||
|
@ -1,5 +1,5 @@
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
import asyncio
|
||||
|
||||
bot = AsyncTeleBot('TOKEN')
|
||||
|
||||
@bot.message_handler(commands=['start', 'help'])
|
||||
@ -10,4 +10,4 @@ async def send_welcome(message):
|
||||
async def echo_all(message):
|
||||
await bot.reply_to(message, message.text)
|
||||
|
||||
asyncio.run(bot.polling(skip_pending=True))# Skip pending skips old updates
|
||||
bot.polling(skip_pending=True)# Skip pending skips old updates
|
||||
|
@ -138,7 +138,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):
|
||||
"""
|
||||
@ -167,10 +167,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.
|
||||
@ -190,12 +190,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))
|
||||
|
Loading…
Reference in New Issue
Block a user