コード例 #1
0
    def test_doubleblueprintability_and_execute(self):
        states_tbp = TBlueprint(__name__)
        states_tbp2 = TBlueprint(__name__ + "2")
        states_tbp.register_tblueprint(states_tbp2)
        states_drvr = SilentDriver()
        states = TeleStateMachine(__name__,
                                  database_driver=states_drvr,
                                  teleflask_or_tblueprint=states_tbp2)
        states.teleflask._bot = BotMock('FAKE_API_KEY',
                                        return_python_objects=True)

        called = [False]

        @states.DEFAULT.command('cancel')
        def func_1(update, text):
            called[0] = True

        # end def

        bot = Teleflask('FAKE_API_KEY',
                        app=None,
                        hostname="localhost",
                        debug_routes=False,
                        disable_setting_webhook_telegram=True,
                        disable_setting_webhook_route=True)
        bot._bot = BotMock('FAKE_API_KEY', return_python_objects=True)
        bot.init_bot()
        bot.register_tblueprint(states_tbp)
        bot.process_update(update1)
        self.assertTrue(called[0], 'func_1 should have been called')
コード例 #2
0
    def test_blueprintability_and_register(self):
        states_tbp = TBlueprint(__name__)
        states_drvr = SilentDriver()
        states: TeleStateMachine = TeleStateMachine(
            __name__,
            database_driver=states_drvr,
            teleflask_or_tblueprint=states_tbp)
        states.teleflask._bot = BotMock('FAKE_API_KEY',
                                        return_python_objects=True)
        states.teleflask.init_bot()

        @states.DEFAULT.command('cancel')
        def func_1(update):
            pass

        # end def

        bot = Teleflask('FAKE_API_KEY',
                        app=None,
                        hostname="localhost",
                        debug_routes=False,
                        disable_setting_webhook_telegram=True,
                        disable_setting_webhook_route=True)
        bot._bot = BotMock('FAKE_API_KEY', return_python_objects=True)
        bot.init_bot()
        bot.register_tblueprint(states_tbp)
        self.assertGreater(len(states.CURRENT.update_handler.commands), 0,
                           'should have added an command.')
コード例 #3
0
logger = logging.getLogger(__name__)
logging.add_colored_handler(level=logging.DEBUG)

POSSIBLE_CHAT_TYPES = ("supergroup", "group", "channel")
SEND_BACKOFF = 5

app = Flask(__name__)
app.register_blueprint(version_bp)
# sentry = add_error_reporting(app)

bot = Teleflask(API_KEY,
                hostname=URL_HOSTNAME,
                hostpath=URL_PATH,
                hookpath="/income/{API_KEY}")
bot.init_app(app)
bot.register_tblueprint(version_tbp)

assert_type_or_raise(bot.bot, Bot)
AT_ADMIN_REGEX = re.compile(".*([^\\w]|^)@(admins?)(\\W|$).*")


@app.errorhandler(404)
def url_404(error):
    return "Nope.", 404


# end def


@app.route("/", methods=["GET", "POST"])
def url_root():
コード例 #4
0
from .secrets import API_KEY, EVENT_CHANNEL
from .commands import bot as commands_tbp
from .features import bot as features_tbp
from .gitinfo import bot as versions_tbp

__author__ = 'luckydonald'
logger = logging.getLogger(__name__)

logging.add_colored_handler(level=logging.DEBUG)


app = Flask(__name__)

bot = Teleflask(API_KEY, app)

bot.register_tblueprint(commands_tbp)
bot.register_tblueprint(features_tbp)
bot.register_tblueprint(versions_tbp)


@app.route("/info/<api_key>/<command>")
@to_json_remove_api_key
def info(api_key, command):

    """
    Issue commands. E.g. /info/getMe

    :param command:
    :return:
    """
    if api_key != API_KEY: