♻️ Move validation to Request

This commit is contained in:
2024-08-07 17:51:07 +02:00
parent e25502f4f8
commit 06a8be0583
3 changed files with 16 additions and 21 deletions

View File

@@ -10,10 +10,10 @@ ini_set('log_errors', 1);
$config = include __DIR__.'/config.php';
$request = new Request();
$request = new Request($config);
$bot = new Bot($request, $config);
if (!$bot->isRequestValid()) {
if (!$request->isValid()) {
$bot->reply('I received an invalid request');
exit;
}
@@ -23,15 +23,8 @@ 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');
});
$bot->hears('(hello|hi|bonjour|salut)', function (Bot $bot) { $bot->replyPolitely('Bonjour'); });
// Only on message, not on event or whatever
if (!$request->isMessage()) {
return ;
}
if (!$request->isMessage()) { exit(); }
$message = $request->getMessage();
$bot->listen($message);
$bot->listen($request->getMessage());