optimize worker

This commit is contained in:
2021-03-20 16:21:06 +03:00
parent f397545412
commit b35d2ca251
2 changed files with 41 additions and 25 deletions

View File

@@ -4,7 +4,7 @@ from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils import timezone
from telegram import Bot
from telegram.ext import Dispatcher
from telegram.ext import Dispatcher, Updater
class TelegramBot(models.Model):
@@ -24,6 +24,13 @@ class TelegramBot(models.Model):
def get_bot(self):
return Bot(self.bot_token)
def build_updater(self, error_handler):
updater = Updater(self.bot_token)
updater.dispatcher.add_error_handler(error_handler)
updater.bot.get_me()
self.config.build_dispatcher(updater.dispatcher)
return updater
def build_dispatcher(self, error_handler):
bot = self.get_bot()
bot.get_me()