Ejemplo n.º 1
0
    def test_slack_command_car_tagging(self, mock_car_owners, mock_rdw_client):
        bot = Bot()
        bot.car_owners = mock_car_owners
        bot.rdw_client = mock_rdw_client

        r = bot.command_car('@user1', 'tag')
        assert r == messages.command_tag_usage

        r = bot.command_car('@user1', 'tag 12-AAA-4 more-arguments')
        assert r == messages.command_invalid_owner('more-arguments')

        r = bot.command_car('@user1', 'tag 1234')
        assert r == messages.command_invalid_licence_plate('1234')

        # Invalid..
        r = bot.command_car('@user1', 'tag $$-^^^-4')
        assert r == messages.command_invalid_licence_plate('$$-^^^-4')

        # Happy Flow
        r = bot.command_car('user1', 'tag 12-AAA-4')
        assert r == 'Added 12AAA4 to <user1>'
        mock_car_owners.tag.assert_called_with('12AAA4', slackid='user1')

        r = bot.command_car('@user1', 'tag 12-AAA-4 @harry')
        assert r == 'Added 12AAA4 to <@harry>'
        mock_car_owners.tag.assert_called_with('12AAA4', slackid='@harry')

        r = bot.command_car('@user1', 'tag 12-AAA-4 "Grote beer"')
        assert r == 'Added 12AAA4 to "Grote beer"'
        mock_car_owners.tag.assert_called_with('12AAA4', name='Grote beer')

        r = bot.command_car('@user1', 'tag 12-AAA-4 “WhyTheseQoutes”')
        assert r == 'Added 12AAA4 to "WhyTheseQoutes"'
        mock_car_owners.tag.assert_called_with('12AAA4', name='WhyTheseQoutes')
Ejemplo n.º 2
0
def main():
    """設定ファイルをparseして、slackbotを起動します

    1. configparserで設定ファイルを読み込む
    2. 設定ファイルに `alembic` セクションが設定されているかチェック
    3. 設定ファイルの情報でDB周りの設定を初期化
    4. slackbotの処理を開始
    """

    parser = get_argparser()
    args = parser.parse_args()

    conf = ConfigParser()
    conf.read_file(args.config)
    # 環境変数で指定したいため ini ファイルでなくここで追記
    conf["alembic"]['sqlalchemy.url'] = SQLALCHEMY_URL
    conf["alembic"]['sqlalchemy.echo'] = SQLALCHEMY_ECHO
    if SQLALCHEMY_POOL_SIZE:
        conf["alembic"]['sqlalchemy.pool_size'] = SQLALCHEMY_POOL_SIZE
    if not conf.has_section('alembic'):
        raise NoSectionError('alembic')

    init_dbsession(conf['alembic'])
    bot = Bot()
    bot.run()
Ejemplo n.º 3
0
def main():
    logging.basicConfig(level=logging.INFO)
    logging.info("Running")

    createStorageObject()  # exception if no storage
    bot = Bot()
    bot.run()
Ejemplo n.º 4
0
    def test_slack_command_car_lookup(self, mock_car_owners, mock_rdw_client,
                                      mock_finnik):
        mock_car_owners.lookup.return_value = None
        mock_rdw_client.get_rdw_details.return_value = None
        mock_finnik.get_car_details.return_value = None

        bot = Bot()
        bot.car_owners = mock_car_owners
        bot.rdw_client = mock_rdw_client
        bot.finnik_client = mock_finnik

        r = bot.command_car('@user1', '12-AAA-4')
        mock_car_owners.lookup.assert_called_with('12AAA4')
        mock_rdw_client.get_rdw_details.assert_called_with('12AAA4')
        mock_finnik.get_car_details.assert_called_with('12AAA4')
        assert r == messages.lookup_no_details_found("12AAA4")

        r = bot.command_car('@user1', 'tag 1234')
        assert r == messages.command_invalid_licence_plate('1234')

        # Invalid..
        r = bot.command_car('@user1', 'tag $$-^^^-4')
        assert r == messages.command_invalid_licence_plate('$$-^^^-4')

        # Happy Flow
        r = bot.command_car('@user1', 'tag 12-AAA-4')
        assert r == 'Added 12AAA4 to <@user1>'
        mock_car_owners.tag.assert_called_with('12AAA4', slackid='@user1')
Ejemplo n.º 5
0
 def initialize(cls):
     print('SlackBot Started')
     json_dict = json.load(open('./ignore/slack.json', 'r'))
     cls.bot = Bot()
     cls.bot.run()
     cls.webhook = json_dict['webhook_url']
     cls.send_message_webhook('SlackBot Started')
Ejemplo n.º 6
0
def main():
    channel="競プロ"
    slack = Slacker(slackbot_settings.API_TOKEN)
    if datetime.datetime.today().weekday()==0:
        info(channel,slack)
    bot = Bot()
    bot.run()
Ejemplo n.º 7
0
def main():
    bot = Bot()

    slack = Slacker(slackbot_settings.API_TOKEN)
    slack.chat.post_message('bot', 'Run SlackBot!!', as_user=True)

    bot.run()
Ejemplo n.º 8
0
def start_slack_processing():
    sender = threading.Thread(target=ss.SlackSender)
    sender.daemon = True
    print("Starting Slack Sender")
    sender.start()

    #slack_uploader = threading.Thread(target=slackUpload.SlackUploader)
    #slack_uploader.daemon = True
    #print("Starting Slack file uploader")
    #slack_uploader.start()

    #imagebinUploader = threading.Thread(target=imagebinUpload.ImagebinUploader)
    #imagebinUploader.daemon = True
    #print("Starting Imagebin Uploader")
    #imagebinUploader.start()

    imgurUploader = threading.Thread(target=imgurUpload.ImgurUploader)
    imgurUploader.daemon = True
    print("Starting imgur Uploader")
    imgurUploader.start()

    bot = Bot()
    print("Starting Slack bot")
    user_manager = um.UserManager()
    user_manager.set_users(bot._client.users)
    bot.run()
Ejemplo n.º 9
0
 def __init__(self):
     threading.Thread.__init__(self)
     slackbot.settings.API_TOKEN = slack_token
     slackbot.settings.DEFAULT_REPLY = 'Ko?'
     slackbot.settings.BOT_EMOJI = slack_bot_icon
     #slackbot.settings.BOT_ICON = slack_bot_icon
     self.bot = Bot()
Ejemplo n.º 10
0
def main():
    logger.info('bot:pre_initialize')
    bot = Bot()
    logger.info('bot:post_initialize')
    logger.info('bot:pre_run')
    bot.run()
    logger.info('bot:post_run')
Ejemplo n.º 11
0
def main():
    ssl._create_default_https_context = ssl._create_unverified_context
    # https://qiita.com/shutokawabata0723/items/9733a7e640a175c23f39
    #export SSL_CERT_FILE = 'C:\\Users\\mnahira\\anaconda3\\lib\\site-packages\\certifi\\cacert.pem'

    # ボットの起動
    bot = Bot()
    bot.run()
Ejemplo n.º 12
0
def main():
    Motor.setup()
    bot = Bot()
    try:
        bot.run()
    except KeyboardInterrupt:
        Motor.finish()
        sys.exit()
Ejemplo n.º 13
0
def main():
    ok = create_table()
    if not ok:
        print("Resource table is not created!", file=sys.stderr)
        sys.exit(1)
    bot = Bot()
    print("start resource keeper at {}".format(datetime.now()))
    bot.run()
Ejemplo n.º 14
0
def run():
    # run setup
    setup()
    # run bot
    from slackbot.bot import Bot
    bot = Bot()
    LOG.info('Starting bot...press CTRL+C to stop')
    bot.run()
Ejemplo n.º 15
0
def main():
    executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)
    bot = Bot()
    # bitbank.bitbankstart()
    tast = [
        executor.submit(bot.run()),
        executor.submit(bitbank.bitbankstart())
    ]
    executor.shutdown()
Ejemplo n.º 16
0
def main():
    bot = Bot()
    th_me = threading.Thread(target=check_lux, name="th_check_lux")
    th_me.setDaemon(True)
    th_me.start()
    try:
        bot.run()
    except Exception as e:
        print(e)
Ejemplo n.º 17
0
def main():
    """Then main Bot application"""
    if not conf.API_TOKEN or not conf.SPEAKER_IP:
        print('Slack API token or Sonos speaker IP not set.\n'
              'Please add configure it before running Sonlack. Exiting...')
        sys.exit(0)
    bot = Bot()
    print('Sonlack is rocking now. Enjoy your favorite music...')
    bot.run()
Ejemplo n.º 18
0
def main():
    logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

    bot = Bot()
    # make @respond_to receive multi-line messages
    bot._dispatcher.AT_MESSAGE_MATCHER = re.compile(
        bot._dispatcher.AT_MESSAGE_MATCHER.pattern, re.S | re.M
    )
    bot.run()
Ejemplo n.º 19
0
def main():
    # BOTの生成
    bot = Bot()

    try:
        # BOT実行
        bot.run()
    except KeyboardInterrupt:
        logging.info('catch KeyboardInterrupt')
Ejemplo n.º 20
0
def main():
    Database.initialise()
    try:
        file = File()
        file.create_table()
    except:
        pass

    bot = Bot()
    bot.run()
Ejemplo n.º 21
0
    def test_slack_command_car(self, mock_car_owners, mock_rdw_client):
        bot = Bot()
        bot.car_owners = mock_car_owners
        bot.rdw_client = mock_rdw_client

        r = bot.command_car('@user1', 'help')
        assert r == messages.command_car_usage

        r = bot.command_car('@user1', '')
        assert r == messages.command_car_usage
Ejemplo n.º 22
0
def main():
    print("running")
    try:
        bot = Bot()
        bot.run()
        print("run")
    except Exception as e:
        print(str(e))
        traceback.print_exc()
        exit(1)
Ejemplo n.º 23
0
def main():
    bot = Bot()

    image_thread = threading.Thread(target=check_img_file)
    image_thread.setDaemon(True)
    image_thread.start()

    try:
        bot.run()
    except Exception as e:
        print(e)
Ejemplo n.º 24
0
    def test_slack_command_car_untag(self, mock_car_owners, mock_rdw_client):
        bot = Bot()
        bot.car_owners = mock_car_owners
        bot.rdw_client = mock_rdw_client

        r = bot.command_car('user1', 'untag')
        assert r == messages.command_tag_usage

        r = bot.command_car('user1', 'untag 12-AAA-4')
        assert r == 'Removed the licence plate 12AAA4'
        mock_car_owners.untag.assert_called_with('user1', '12AAA4')
Ejemplo n.º 25
0
def main():
    kw = {
        'format': '[%(asctime)s] %(message)s',
        'datefmt': '%m/%d/%Y %H:%M:%S',
        'level': logging.DEBUG if settings.DEBUG else logging.INFO,
        'stream': sys.stdout,
    }
    logging.basicConfig(**kw)
    logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.WARNING)
    bot = Bot()
    bot.run()
Ejemplo n.º 26
0
def main():
    import dotenv
    import logging

    logging.basicConfig(level=logging.DEBUG)

    # update API_TOKEN
    dotenv.load_dotenv()
    settings.API_TOKEN = os.environ["SLACKBOT_API_TOKEN"]

    bot = Bot()
    bot.run()
Ejemplo n.º 27
0
def main():
    bot = Bot()
    # ボタン監視用のスレッドを起動する
    th_me = threading.Thread(target=check_button, name="th_check_button")
    th_me.setDaemon(True)
    th_me.start()
    try:
        slacker.chat.post_message(c_name, '起動しました。', as_user=True)
        # botを起動する
        bot.run()
    except Exception as e:
        print(e)
Ejemplo n.º 28
0
def run():
    # 基本的に止めるつもりはない
    # ログを出して、続行するただし、前回の停止から1分いないなら、終了する
    bef_time = 0
    while time.time() - bef_time > BORDER_END_TIME:
        bef_time = time.time()
        try:
            logger.debug("run!")
            bot = Bot()
            bot.run()
        except:
            import traceback
            logger.warning(traceback.format_exc())
Ejemplo n.º 29
0
def main():
    print('-- main --')
    # Botを動かす前にそのチャンネルにBotアプリケーションを追加することを忘れずに
    channel = "test"
    # slack api token 設定
    slack = Slacker(slackbot_settings.API_TOKEN)
    print('-- info --')
    # 月曜であることの確認 (テスト用に削除)
    if datetime.datetime.today().weekday() == 0:
        info(channel, slack)

    bot = Bot()
    bot.run()
Ejemplo n.º 30
0
def main():
    import dotenv
    import logging
    from importlib import reload
    import slackbot.settings
    import slackbot.bot

    logging.basicConfig(level=logging.DEBUG)
    # overwrite with dotenv
    dotenv.load_dotenv(verbose=True)
    slackbot.bot.settings = reload(slackbot.settings)

    bot = Bot()
    bot.run()