Queer European MD passionate about IT
Browse Source

Backward compatibility: allow regular functions instead of coroutines

Wrap regular functions passed to `set_chosen_inline_result_handler` 
since it accepts only coroutines.
Davte 5 years ago
parent
commit
0557b67734
2 changed files with 7 additions and 2 deletions
  1. 1 1
      davtelepot/__init__.py
  2. 6 1
      davtelepot/custombot.py

+ 1 - 1
davtelepot/__init__.py

@@ -7,7 +7,7 @@ __author__ = "Davide Testa"
 __email__ = "davide@davte.it"
 __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
 __license__ = "GNU General Public License v3.0"
-__version__ = "2.1.8"
+__version__ = "2.1.9"
 __maintainer__ = "Davide Testa"
 __contact__ = "t.me/davte"
 

+ 6 - 1
davtelepot/custombot.py

@@ -246,10 +246,15 @@ class Bot(davtelepot.bot.Bot):
         This method is deprecated: use `set_chosen_inline_result_handler`
             instead.
         """
+        if not asyncio.iscoroutinefunction(func):
+            async def _func(update):
+                return func(update)
+        else:
+            _func = func
         return self.set_chosen_inline_result_handler(
             user_id=user_id,
             result_id=result_id,
-            handler=func
+            handler=_func
         )
 
     async def handle_pinned_message(self, update, user_record=None):