コード例 #1
0
def main():
    """Handle command line arguments and run a command"""
    envs = get_envs()

    if len(sys.argv) < 3:
        raise Exception(
            "Expected arguments: channel_name command arg1 arg2...")

    _, channel_name, *words = sys.argv

    channels_info = get_channels_info(envs['SLACK_ACCESS_TOKEN'])
    try:
        channel_id = channels_info[channel_name]
    except KeyError:
        raise Exception(
            "Unable to find channel by name {}".format(channel_name))

    repos_info = load_repos_info(channels_info)

    bot = Bot(websocket=None,
              slack_access_token=envs['SLACK_ACCESS_TOKEN'],
              github_access_token=envs['GITHUB_ACCESS_TOKEN'],
              timezone=envs['TIMEZONE'],
              repos_info=repos_info)

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        loop.create_task(
            bot.handle_message(
                manager='mitodl_user',
                channel_id=channel_id,
                words=words,
                loop=loop,
            )))
コード例 #2
0
ファイル: bot_local.py プロジェクト: lresende/release-script
async def async_main():
    """Handle command line arguments and run a command"""
    envs = get_envs()

    if len(sys.argv) < 3:
        raise Exception(
            "Expected arguments: channel_name command arg1 arg2...")

    _, channel_name, *words = sys.argv

    channels_info = await get_channels_info(envs['SLACK_ACCESS_TOKEN'])
    try:
        channel_id = channels_info[channel_name]
    except KeyError:
        raise Exception(
            "Unable to find channel by name {}".format(channel_name))

    repos_info = load_repos_info(channels_info)

    bot = ConsoleBot(
        doof_id="console",
        slack_access_token=envs['SLACK_ACCESS_TOKEN'],
        github_access_token=envs['GITHUB_ACCESS_TOKEN'],
        timezone=envs['TIMEZONE'],
        repos_info=repos_info,
        loop=asyncio.get_event_loop(),
    )

    await bot.startup()

    await bot.handle_message(
        manager='mitodl_user',
        channel_id=channel_id,
        words=words,
    )