Beispiel #1
0
 def get(self, request, *args, **kwargs):
     from bot import updater
     updater.start_webhook(listen='127.0.0.1',
                           port=getenv('WEBHOOK_PORT'),
                           url_path=getenv('TELEGRAM_BOT_TOKEN'))
     updater.bot.set_webhook(url='https://{host}/{path}'.format(
         host=getenv('WEBHOOK_HOST'), path=getenv('TELEGRAM_BOT_TOKEN')))
     return HttpResponse('Bot started!')
def main():
    test_handler = CommandHandler("test", test)
    start_handler = CommandHandler("start", start, pass_args=True)

    IMDB_HANDLER = CommandHandler('imdb', imdb, pass_args=True)
    IMDB_SEARCHDATAHANDLER = CallbackQueryHandler(imdb_searchdata)

    start_callback_handler = CallbackQueryHandler(send_start,
                                                  pattern=r"bot_start")
    dispatcher.add_handler(start_callback_handler)

    help_handler = CommandHandler("help", get_help)
    help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_")

    settings_handler = CommandHandler("settings", get_settings)
    settings_callback_handler = CallbackQueryHandler(settings_button,
                                                     pattern=r"stngs_")

    source_handler = CommandHandler("source", source)

    migrate_handler = MessageHandler(Filters.status_update.migrate,
                                     migrate_chats)

    M_CONNECT_BTN_HANDLER = CallbackQueryHandler(m_connect_button,
                                                 pattern=r"main_connect")

    # dispatcher.add_handler(test_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(settings_handler)
    dispatcher.add_handler(help_callback_handler)
    dispatcher.add_handler(settings_callback_handler)
    dispatcher.add_handler(migrate_handler)
    dispatcher.add_handler(source_handler)
    dispatcher.add_handler(M_CONNECT_BTN_HANDLER)
    dispatcher.add_handler(IMDB_HANDLER)
    dispatcher.add_handler(IMDB_SEARCHDATAHANDLER)

    # dispatcher.add_error_handler(error_callback)

    if WEBHOOK:
        LOGGER.info("Using webhooks.")
        updater.start_webhook(listen="127.0.0.1", port=PORT, url_path=TOKEN)

        if CERT_PATH:
            updater.bot.set_webhook(url=URL + TOKEN,
                                    certificate=open(CERT_PATH, 'rb'))
        else:
            updater.bot.set_webhook(url=URL + TOKEN)

    else:
        LOGGER.info("bot running...")
        updater.start_polling(timeout=15, read_latency=4)

    updater.idle()
Beispiel #3
0
def main():
    fs_utils.start_cleanup()
    # Check if the bot is restarting
    if path.exists('restart.pickle'):
        with open('restart.pickle', 'rb') as status:
            restart_message = pickle.load(status)
        restart_message.edit_text("Restarted Successfully!")
        remove('restart.pickle')

    start_handler = CommandHandler(BotCommands.StartCommand,
                                   start,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    ping_handler = CommandHandler(BotCommands.PingCommand,
                                  ping,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    restart_handler = CommandHandler(BotCommands.RestartCommand,
                                     restart,
                                     filters=CustomFilters.owner_filter)
    help_handler = CommandHandler(BotCommands.HelpCommand,
                                  bot_help,
                                  filters=CustomFilters.authorized_chat
                                  | CustomFilters.authorized_user)
    stats_handler = CommandHandler(BotCommands.StatsCommand,
                                   stats,
                                   filters=CustomFilters.authorized_chat
                                   | CustomFilters.authorized_user)
    log_handler = CommandHandler(BotCommands.LogCommand,
                                 log,
                                 filters=CustomFilters.owner_filter)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(ping_handler)
    dispatcher.add_handler(restart_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(stats_handler)
    dispatcher.add_handler(log_handler)
    if USE_WEBHOOKS:
        from bot import (BOT_TOKEN, WEBHOOK_PORT, WEBHOOK_HOST, WEBHOOK_URL)
        updater.start_webhook(
            listen=WEBHOOK_HOST,
            # (c) https://t.me/c/1186975633/22915
            port=WEBHOOK_PORT,
            url_path=BOT_TOKEN)
        updater.bot.set_webhook(url=WEBHOOK_URL + "/" + BOT_TOKEN)
    else:
        updater.start_polling()
    LOGGER.info("Bot Started!")
    signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Beispiel #4
0
def main():
    test_handler = CommandHandler("test", test)
    start_handler = CommandHandler("start", start, pass_args=True)

    help_handler = CommandHandler("help", get_help)
    help_callback_handler = CallbackQueryHandler(help_button, pattern=r"help_")

    settings_handler = CommandHandler("settings", get_settings)
    settings_callback_handler = CallbackQueryHandler(settings_button,
                                                     pattern=r"stngs_")

    donate_handler = CommandHandler("donate", donate)
    migrate_handler = MessageHandler(Filters.status_update.migrate,
                                     migrate_chats)

    # dispatcher.add_handler(test_handler)
    dispatcher.add_handler(start_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(settings_handler)
    dispatcher.add_handler(help_callback_handler)
    dispatcher.add_handler(settings_callback_handler)
    dispatcher.add_handler(migrate_handler)
    dispatcher.add_handler(donate_handler)

    dispatcher.add_error_handler(error_callback)

    if WEBHOOK:
        LOGGER.info("Using webhooks.")
        updater.start_webhook(listen="127.0.0.1", port=PORT, url_path=TOKEN)

        if CERT_PATH:
            updater.bot.set_webhook(url=URL + TOKEN,
                                    certificate=open(CERT_PATH, 'rb'))
        else:
            updater.bot.set_webhook(url=URL + TOKEN)

    else:
        LOGGER.info("Using long polling.")
        updater.start_polling(timeout=15, read_latency=4, clean=True)

    updater.idle()
Beispiel #5
0
def main(hook=False):

    from bot import updater
    init()

    if not hook:
        updater.start_polling()
    else:
        WEBHOOK_HOST = sys.argv[3]
        WEBHOOK_PORT = 443  # 443, 80, 88 или 8443
        WEBHOOK_LISTEN = '0.0.0.0'

        WEBHOOK_SSL_CERT = './webhook_cert.pem'
        WEBHOOK_SSL_PRIV = './webhook_pkey.pem'

        WEBHOOK_URL = "https://%s:%d/%s" % (WEBHOOK_HOST, WEBHOOK_PORT,
                                            sys.argv[1])

        updater.start_webhook(listen=WEBHOOK_LISTEN,
                              port=WEBHOOK_PORT,
                              url_path=sys.argv[1],
                              cert=WEBHOOK_SSL_CERT,
                              key=WEBHOOK_SSL_PRIV,
                              webhook_url='%s' % WEBHOOK_URL)
Beispiel #6
0
        except TelegramError:
            pass
    session.commit()
    session.close()


logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)

cleanup_db()

load_posts_from_db(updater.job_queue)
prepare_daily_job(updater.job_queue)

for handler in handlers.all_handlers:
    dispatcher.add_handler(handler)

# updater.start_polling()
updater.start_webhook(
    listen="0.0.0.0",
    port=int(os.environ.get("PORT", "8443")),
    url_path=TOKEN
)
bot.set_webhook(url="https://li465-188.members.linode.com/" + TOKEN)

while True:
    logging.info("Updates in queue: {}".format(updater.update_queue.qsize()))
    logging.info("Forwarding next time: {}".format(bot.forwarding_next_time))
    time.sleep(2.0)

# updater.idle()