♻️ Move validation to Request
This commit is contained in:
@@ -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());
|
||||
|
Reference in New Issue
Block a user