async def test_start_find_bot_id(self, aiohttp_server, find_bot_id_query):
     bot = SirBot()
     bot.load_plugin(
         SlackPlugin(token="foo", verify="bar", bot_user_id="baz"))
     bot["plugins"]["slack"].api.query = find_bot_id_query
     await aiohttp_server(bot)
     assert bot["plugins"]["slack"].bot_id == "B00000000"
def bot():
    b = SirBot()
    slack = SlackPlugin(token='token',
                        verify='supersecuretoken',
                        bot_user_id='bot_user_id',
                        bot_id='bot_id')
    b.load_plugin(slack)
    return b
    async def test_register_admin_message_no_admin(self, caplog):
        async def handler():
            pass

        bot = SirBot()
        bot.load_plugin(SlackPlugin(token='foo', verify='bar', bot_user_id='baz', bot_id='boo'))
        bot['plugins']['slack'].on_message('hello', handler, admin=True)
        assert 'Slack admins ids are not set. Admin limited endpoint will not work.' in caplog.text
Example #4
0
async def bot(request, loop):
    b = SirBot()
    pg = PgPlugin(
        dsn="postgres://[email protected]:5432/sirbot",
        sql_migration_directory="tests/data/sql",
        version="0.0.2",
    )
    b.load_plugin(pg)
    yield b
async def slack_bot(bot: SirBot):
    slack = SlackPlugin(
        token='token',
        verify='supersecuretoken',
        bot_user_id='bot_user_id',
        bot_id='bot_id',
    )
    endpoints.slack.create_endpoints(slack)
    bot.load_plugin(slack)
    return bot
Example #6
0
def slack_bot(bot: SirBot):
    slack = SlackPlugin(
        token="token",
        verify="supersecuretoken",
        bot_user_id="bot_user_id",
        bot_id="bot_id",
    )
    endpoints.slack.create_endpoints(slack)
    bot.load_plugin(slack)
    return bot
Example #7
0
    async def test_load_plugin_no_name(self):
        class MyPlugin:
            def __init__(self):
                pass

            def load(self, test_bot):
                pass

        bot = SirBot()
        with pytest.raises(AttributeError):
            bot.load_plugin(MyPlugin())
async def bot_signing():
    b = SirBot()
    b.load_plugin(
        SlackPlugin(
            token="foo",
            signing_secret="sharedsigningkey",
            bot_user_id="baz",
            bot_id="boo",
            admins=["aaa", "bbb"],
        ))
    return b
async def bot():
    b = SirBot()
    b.load_plugin(
        SlackPlugin(
            token="foo",
            verify="supersecuretoken",
            bot_user_id="baz",
            bot_id="boo",
            admins=["aaa", "bbb"],
        ))
    return b
    async def test_register_admin_message_no_admin(self, caplog):
        async def handler():
            pass

        bot = SirBot()
        bot.load_plugin(
            SlackPlugin(token="foo",
                        verify="bar",
                        bot_user_id="baz",
                        bot_id="boo"))
        bot["plugins"]["slack"].on_message("hello", handler, admin=True)
        assert (
            "Slack admins ids are not set. Admin limited endpoint will not work."
            in caplog.text)
Example #11
0
    async def test_load_plugin(self, test_server):
        class MyPlugin:
            __name__ = 'myplugin'

            def __init__(self):
                pass

            def load(self, test_bot):
                pass

        bot = SirBot()
        bot.load_plugin(MyPlugin())
        assert 'myplugin' in bot.plugins
        assert isinstance(bot['plugins']['myplugin'], MyPlugin)
        await test_server(bot)
Example #12
0
    async def test_load_plugin(self, aiohttp_server):
        class MyPlugin:
            __name__ = "myplugin"

            def __init__(self):
                pass

            def load(self, test_bot):
                pass

        bot = SirBot()
        bot.load_plugin(MyPlugin())
        assert "myplugin" in bot.plugins
        assert isinstance(bot["plugins"]["myplugin"], MyPlugin)
        await aiohttp_server(bot)
Example #13
0
    async def test_list_plugin(self, test_client):
        class MyPlugin:
            __name__ = 'myplugin'

            def __init__(self):
                pass

            def load(self, test_bot):
                pass

        bot = SirBot()
        bot.load_plugin(MyPlugin())
        client = await test_client(bot)
        rep = await client.get('/sirbot/plugins')
        data = await rep.json()
        assert data == {'plugins': ['myplugin']}
Example #14
0
    async def test_list_plugin(self, aiohttp_client):
        class MyPlugin:
            __name__ = "myplugin"

            def __init__(self):
                pass

            def load(self, test_bot):
                pass

        bot = SirBot()
        bot.load_plugin(MyPlugin())
        client = await aiohttp_client(bot)
        rep = await client.get("/sirbot/plugins")
        data = await rep.json()
        assert data == {"plugins": ["myplugin"]}
Example #15
0
async def bot(loop) -> SirBot:
    b = SirBot()
    slack = SlackPlugin(
        token="token",
        verify="supersecuretoken",
        bot_user_id="bot_user_id",
        bot_id="bot_id",
    )
    airtable = AirtablePlugin()
    endpoints.slack.create_endpoints(slack)

    api = APIPlugin()
    endpoints.api.create_endpoints(api)

    b.load_plugin(slack)
    b.load_plugin(airtable)
    b.load_plugin(api)

    return b
async def bot(loop) -> SirBot:
    b = SirBot()
    slack = SlackPlugin(
        token='token',
        verify='supersecuretoken',
        bot_user_id='bot_user_id',
        bot_id='bot_id',
    )
    airtable = AirtablePlugin()
    endpoints.slack.create_endpoints(slack)
    b.load_plugin(slack)
    b.load_plugin(airtable)

    return b
async def bot():
    b = SirBot()
    b.load_plugin(RTDPlugin())
    return b
Example #18
0
async def bot():
    b = SirBot()
    b.load_plugin(APSchedulerPlugin())
    return b
Example #19
0
                             "../logging.yml")) as log_configfile:
            logging.config.dictConfig(
                yaml.load(log_configfile.read(), Loader=yaml.SafeLoader))
    except Exception as e:
        logging.basicConfig(level=logging.DEBUG)
        logger.exception(e)

    if "SENTRY_DSN" in os.environ:
        sentry_sdk.init(
            dsn=os.environ["SENTRY_DSN"],
            release=os.environ.get("VERSION", "1.0.0"),
            environment=os.environ.get("ENVIRONMENT", "production"),
            integrations=[AioHttpIntegration()],
        )

    bot = SirBot()

    slack = SlackPlugin(**slack_configs)
    endpoints.slack.create_endpoints(slack)
    bot.load_plugin(slack)

    admin_configs = dict(**slack_configs)
    admin_token = os.environ.get("APP_ADMIN_OAUTH_TOKEN", "FAKE_ADMIN_TOKEN")
    if admin_token:
        admin_configs["token"] = admin_token
    admin_slack = SlackPlugin(**admin_configs)
    bot.load_plugin(admin_slack, name="admin_slack")

    airtable = AirtablePlugin()
    endpoints.airtable.create_endpoints(airtable)
    bot.load_plugin(airtable)
Example #20
0

if __name__ == "__main__":
    try:
        with open(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             "../logging.yml")) as log_configfile:
            logging.config.dictConfig(yaml.load(log_configfile.read()))
    except Exception as e:
        logging.basicConfig(level=logging.DEBUG)
        logger.exception(e)

    if "SENTRY_DSN" in os.environ:
        make_sentry_logger()

    bot = SirBot()

    slack = SlackPlugin()
    endpoints.slack.create_endpoints(slack)
    bot.load_plugin(slack)

    airtable = AirtablePlugin()
    endpoints.airtable.create_endpoints(airtable)
    bot.load_plugin(airtable)

    # Add route to respond to AWS health check
    bot.router.add_get("/health", lambda request: Response(status=200))
    logging.getLogger('aiohttp.access').setLevel(logging.WARNING)

    bot.start(host=HOST, port=PORT, print=False)
Example #21
0
        raise RuntimeError(
            "No postgresql configuration available. Use POSTGRES_DSN environment variable"
        )


if __name__ == "__main__":

    setup_logging()

    if len(sys.argv) > 1 and sys.argv[1] == "migrate":
        postgres = configure_postgresql_plugin()
        loop = asyncio.get_event_loop()
        loop.run_until_complete(postgres.startup(None))
        sys.exit(0)

    bot = SirBot()

    slack = SlackPlugin()
    endpoints.slack.create_endpoints(slack)
    bot.load_plugin(slack)

    pypi = PypiPlugin()
    bot.load_plugin(pypi)

    stocks = StocksPlugin()
    bot.load_plugin(stocks)

    scheduler = APSchedulerPlugin(timezone="UTC")
    endpoints.apscheduler.create_jobs(scheduler, bot)
    bot.load_plugin(scheduler)
Example #22
0
 async def test_bot(self, aiohttp_server):
     bot = SirBot()
     await aiohttp_server(bot)
Example #23
0
async def bot():
    b = SirBot()
    b.load_plugin(GithubPlugin(verify="supersecrettoken"))
    return b
Example #24
0
 async def test_list_plugin_empty(self, aiohttp_client):
     bot = SirBot()
     client = await aiohttp_client(bot)
     rep = await client.get("/sirbot/plugins")
     data = await rep.json()
     assert data == {"plugins": []}
async def bot():
    b = SirBot()
    b.load_plugin(SlackPlugin(token='foo', verify='supersecuretoken', bot_user_id='baz', bot_id='boo',
                              admins=['aaa', 'bbb']))
    return b
 async def test_start_find_bot_id(self, test_server, find_bot_id_query):
     bot = SirBot()
     bot.load_plugin(SlackPlugin(token='foo', verify='bar', bot_user_id='baz'))
     bot['plugins']['slack'].api.query = find_bot_id_query
     await test_server(bot)
     assert bot['plugins']['slack'].bot_id == 'B00000000'
Example #27
0
 async def test_list_plugin_empty(self, test_client):
     bot = SirBot()
     client = await test_client(bot)
     rep = await client.get('/sirbot/plugins')
     data = await rep.json()
     assert data == {'plugins': []}
if __name__ == "__main__":
    try:
        with open(
            os.path.join(os.path.dirname(os.path.realpath(__file__)), "../logging.yml")
        ) as log_configfile:
            logging.config.dictConfig(
                yaml.load(log_configfile.read(), Loader=yaml.SafeLoader)
            )
    except Exception as e:
        logging.basicConfig(level=logging.DEBUG)
        logger.exception(e)

    if "SENTRY_DSN" in os.environ:
        make_sentry_logger()

    bot = SirBot()

    slack = SlackPlugin(**slack_configs)
    endpoints.slack.create_endpoints(slack)
    bot.load_plugin(slack)

    airtable = AirtablePlugin()
    endpoints.airtable.create_endpoints(airtable)
    bot.load_plugin(airtable)

    # Add route to respond to AWS health check
    bot.router.add_get("/health", handle_health_check)
    logging.getLogger("aiohttp.access").setLevel(logging.WARNING)

    bot.start(host=HOST, port=PORT, print=logger.info)
Example #29
0
 async def test_bot(self, test_server):
     bot = SirBot()
     await test_server(bot)