Example #1
0
 def _activate_bot(self, serviceName):
     '''Gets bot state. Starts it if not yet running.'''
     # check if bot running
     try:
         bot = self.activeBots[serviceName]
     except KeyError:
         # ask container for bot acls
         acls = self.access.on_service_acls(self.session, serviceName)
         # build a bot state object
         bot = BotState(serviceName, uuid.uuid4().hex, acls)
         # decide if tracking sync or not now
         self.needsSync |= (acls & ACL_SERVICE_SYNC)
         # ask container if any additional params for service
         appData = self.access.on_service_config(self.session, serviceName)
         # launch the bot because not started
         self.launcher.start_service(bot.serviceName, bot.token,
                                     self.manager, appData)
         # store bot state for future lookup
         self.activeBots[serviceName] = bot
     return bot
Example #2
0
import time

import telebot

from availablecommands import commands
from botstate import BotState
from database import DataBase
from yandexdisk import YandexDisk
from mthreading import mult_threading
import schedule
from commands.publish import send_photos

database = DataBase()
ydisk = YandexDisk(token=os.environ["YADISKTOKEN"])
bot = telebot.TeleBot(os.environ['TOKEN'])
bot_state = BotState(saved_commands=commands.get_na_commands())


@mult_threading
def time_publish():
    # schedule.every().day.at("20:00").do(send_photos, bot, database, ydisk, 10)
    schedule.every(2).hours.do(send_photos, bot, database, ydisk, 1)
    while True:
        schedule.run_pending()
        time.sleep(1)


@bot.message_handler(content_types=["text"])
def answer_commands(message):
    try:
        global bot_state