2024-08-05 23:33:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Shikiryu\Bot\Bot;
|
|
|
|
use Shikiryu\Bot\Commands\Lorem;
|
|
|
|
use Shikiryu\Bot\Commands\Youtubedl;
|
|
|
|
|
|
|
|
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
ini_set('log_errors', 1);
|
|
|
|
|
|
|
|
$config = include 'config.php';
|
|
|
|
|
2024-08-06 16:06:07 +02:00
|
|
|
$bot = new Bot($config);
|
2024-08-05 23:33:27 +02:00
|
|
|
|
|
|
|
$signature = $_SERVER['HTTP_X_NEXTCLOUD_TALK_SIGNATURE'] ?? '';
|
|
|
|
$random = $_SERVER['HTTP_X_NEXTCLOUD_TALK_RANDOM'] ?? '';
|
|
|
|
$server = $_SERVER['HTTP_X_NEXTCLOUD_TALK_BACKEND'] ?? '';
|
|
|
|
|
|
|
|
$delivery = $_SERVER['HTTP_X_H1_DELIVERY'] ?? '';
|
|
|
|
$event = $_SERVER['HTTP_X_H1_EVENT'] ?? '';
|
|
|
|
$signature = $_SERVER['HTTP_X_H1_SIGNATURE'] ?? '';
|
|
|
|
|
|
|
|
// Give the bot something to listen for.
|
|
|
|
$bot->hears('(convertis|télécharges?) (https?:\/\/[^\s]+) en (audio|video|vidéo)', Youtubedl::class);
|
|
|
|
|
|
|
|
$bot->hears('lorem( ipsum)?', Lorem::class);
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
$body = file_get_contents('php://input');
|
2024-08-06 16:06:07 +02:00
|
|
|
try {
|
|
|
|
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
|
|
|
|
} catch (JsonException $e) {
|
|
|
|
$data = [];
|
|
|
|
}
|
2024-08-05 23:33:27 +02:00
|
|
|
|
2024-08-06 16:06:07 +02:00
|
|
|
// Only on message, not on event or whatever
|
2024-08-05 23:33:27 +02:00
|
|
|
if ($data['type'] !== 'Create' || $data['object']['name'] !== 'message') {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2024-08-06 16:06:07 +02:00
|
|
|
try {
|
|
|
|
$message = json_decode($data['object']['content'], true, 512, JSON_THROW_ON_ERROR)['message'];
|
|
|
|
} catch (JsonException $e) {
|
|
|
|
return;
|
|
|
|
}
|
2024-08-05 23:33:27 +02:00
|
|
|
|
|
|
|
$bot->listen($message);
|