2024-08-05 23:33:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Shikiryu\Bot\Bot;
|
2024-08-07 17:46:01 +02:00
|
|
|
use Shikiryu\Bot\Request;
|
2024-08-05 23:33:27 +02:00
|
|
|
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
ini_set('log_errors', 1);
|
|
|
|
|
2024-08-07 17:46:01 +02:00
|
|
|
$config = include __DIR__.'/config.php';
|
2024-08-05 23:33:27 +02:00
|
|
|
|
2024-08-07 17:46:01 +02:00
|
|
|
$request = new Request();
|
|
|
|
$bot = new Bot($request, $config);
|
2024-08-05 23:33:27 +02:00
|
|
|
|
2024-08-07 17:46:01 +02:00
|
|
|
if (!$bot->isRequestValid()) {
|
|
|
|
$bot->reply('I received an invalid request');
|
|
|
|
exit;
|
|
|
|
}
|
2024-08-05 23:33:27 +02:00
|
|
|
|
|
|
|
// Give the bot something to listen for.
|
2024-08-07 17:05:07 +02:00
|
|
|
foreach ($bot->listCommands() as $command) {
|
|
|
|
$bot->hears(call_user_func([$command, 'getPattern']), $command);
|
|
|
|
}
|
2024-08-05 23:33:27 +02:00
|
|
|
|
2024-08-06 16:06:07 +02:00
|
|
|
$bot->hears('(hello|hi|bonjour|salut)', function (Bot $bot) {
|
2024-08-05 23:33:27 +02:00
|
|
|
$bot->replyPolitely('Bonjour');
|
|
|
|
});
|
|
|
|
|
2024-08-06 16:06:07 +02:00
|
|
|
// Only on message, not on event or whatever
|
2024-08-07 17:46:01 +02:00
|
|
|
if (!$request->isMessage()) {
|
2024-08-05 23:33:27 +02:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2024-08-07 17:46:01 +02:00
|
|
|
$message = $request->getMessage();
|
2024-08-05 23:33:27 +02:00
|
|
|
|
|
|
|
$bot->listen($message);
|