Created
September 27, 2020 16:09
-
-
Save KaratekHD/7b4fa76d6d79ecd4ffbb60e891fd6d73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import telegram.ext as tg | |
from telegram import Update, TelegramError | |
from telegram.ext import run_async, CallbackContext, CommandHandler, DispatcherHandlerStop, Dispatcher | |
def process_update(self, update): | |
for group in self.groups: | |
try: | |
for handler in (x for x in self.handlers[group] if x.check_update(update)): | |
# I think this line is the problem: | |
handler.handle_update(update, self, handler.check_update(update)) | |
break | |
# Stop processing with any other handler. | |
except DispatcherHandlerStop: | |
self.logger.debug("Stopping further handlers due to DispatcherHandlerStop") | |
break | |
# Dispatch any error. | |
except TelegramError as te: | |
self.logger.warning("A TelegramError was raised while processing the Update") | |
try: | |
self.dispatch_error(update, te) | |
except DispatcherHandlerStop: | |
self.logger.debug("Error handler stopped further handlers") | |
break | |
except Exception: | |
self.logger.exception("An uncaught error was raised while handling the error") | |
# Errors should not stop the thread. | |
except Exception: | |
self.logger.exception("An uncaught error was raised while processing the update") | |
@run_async | |
def start(update: Update, context: CallbackContext): | |
if update.effective_chat.type == "private": | |
args = context.args | |
first_name = update.effective_user.first_name | |
update.effective_message.reply_text("Hello " + first_name) | |
else: | |
update.effective_message.reply_text("You started this bot in a group.") # START_IN_GROUP | |
if __name__ == '__main__': | |
TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
WORKERS=8 | |
updater = tg.Updater(TOKEN, workers=WORKERS, use_context=True) | |
dispatcher = updater.dispatcher | |
start_handler = CommandHandler("start", start) | |
dispatcher.add_handler(start_handler) | |
Dispatcher.process_update = process_update | |
updater.start_polling(timeout=15, read_latency=4) | |
updater.idle() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment