<?php

use Shikiryu\Bot\Bot;
use Shikiryu\Bot\Request;

require 'vendor/autoload.php';

error_reporting(E_ALL);
ini_set('log_errors', 1);

$config = include __DIR__.'/config.php';

$request = new Request();
$bot = new Bot($request, $config);

if (!$bot->isRequestValid()) {
    $bot->reply('I received an invalid request');
    exit;
}

// Give the bot something to listen for.
foreach ($bot->listCommands() as $command) {
    $bot->hears(call_user_func([$command, 'getPattern']), $command);
}

$bot->hears('(hello|hi|bonjour|salut)', function (Bot $bot) {
    $bot->replyPolitely('Bonjour');
});

// Only on message, not on event or whatever
if (!$request->isMessage()) {
    return ;
}

$message = $request->getMessage();

$bot->listen($message);
