Ejemplo n.º 1
0
    def handle_add(self, tmessage):
        '''Handle /add command'''
        user_id = str(tmessage.from_user.id)
        stream_name = tmessage.text[4:].strip()

        if len(stream_name) == 0:
            self._bot.send_message(user_id,
                                   "Enter stream name in command: `/add NAME`",
                                   parse_mode="Markdown")

        secret = Streams().add(user_id, stream_name)

        if not secret:
            self._bot.send_message(
                user_id,
                "*Failed to add new stream!*\nPlease, try again later…",
                parse_mode="Markdown")
            return

        link = self.__getStreamLink(secret)
        message = "*New stream has been created:* %s\n*Key:* %s\n*Link:* %s" % (
            stream_name, secret, link)
        self._bot.send_message(user_id,
                               message,
                               parse_mode="Markdown",
                               disable_web_page_preview=True)
Ejemplo n.º 2
0
    def __init__(self, base_url, is_local=None):
        self.__base_url = base_url
        self.__webhook_path = Config().webhook_path
        self.__webhook_url = "%s%s" % (base_url, self.__webhook_path)
        self.__is_local = is_local
        self.__bot_token = Config().bot_token

        log_main.info("Starting BackendServer…")
        # Some debug info (for local dev mode )
        if is_local:
            print("Base URL: %s" % self.__base_url)
            print("Webhook URL: %s" % self.__webhook_url)
            print("Bot token: %s" % self.__bot_token)

        # Initializing Flask
        self.init_flask()

        # Checking and initializing the database connection
        status, description = Database.checkConnection(Config().db_host,
                                                       Config().db_user,
                                                       Config().db_password,
                                                       Config().db_database)
        if not status:
            msg = "Database connect failed\n%s" % description
            self._flask_app.logger.error(msg)  # pylint: disable=no-member
            log_main.error(msg)
            sys.exit()
        Database(Config().db_host,
                 Config().db_user,
                 Config().db_password,
                 Config().db_database)

        # Init streams
        log_main.info("Loading streams…")
        Streams()
        log_main.info("Streams loaded")

        # Init telebot
        self.init_telebot()