adding matrix support for new uploaded videos

This commit is contained in:
w0bm
2024-02-18 15:08:10 +00:00
parent 341f8b1f07
commit bae8bcae6c
5 changed files with 30 additions and 22 deletions

View File

@@ -147,24 +147,25 @@ class VideoController extends Controller
$video->tesThumb();
// Discord
if (config('discord.enabled') && config('discord.webhookurl')) {
$nsfw = in_array('nsfw', $video->getTagArrayNormalizedAttribute());
$nsfw = $nsfw ? ' :exclamation: **NSFW** :exclamation:' : '';
$message = config('discord.message');
$message = str_replace(
['<USER>', '<ID>', '<NSFW>'],
[$user->username, $video->id, $nsfw],
$message
);
$url = config('discord.webhookurl');
$payload = json_encode([
'content' => $message,
]);
// exec with & so it is async
exec("curl -H \"Content-Type: application/json; charset=UTF-8\" -X POST -d '$payload' '$url' > /dev/null &");
}
// if (config('discord.enabled') && config('discord.webhookurl')) {
// $nsfw = in_array('nsfw', $video->getTagArrayNormalizedAttribute());
// $nsfw = $nsfw ? ' :exclamation: **NSFW** :exclamation:' : '';
// $message = config('discord.message');
// $message = str_replace(
// ['<USER>', '<ID>', '<NSFW>'],
// [$user->username, $video->id, $nsfw],
// $message
// );
// $url = config('discord.webhookurl');
// $payload = json_encode([
// 'content' => $message,
// ]);
// // exec with & so it is async
// exec("curl -H \"Content-Type: application/json; charset=UTF-8\" -X POST -d '$payload' '$url' > /dev/null &");
// }
if (config('matrix.enabled') && config('matrix.roomid')) {
if (config('matrix.enabled') && config('matrix.token') && config('matrix.homeserver') && config('matrix.room')) {
$nsfw = in_array('nsfw', $video->getTagArrayNormalizedAttribute());
$nsfw = $nsfw ? ' :exclamation: **NSFW** :exclamation:' : '';
$message = config('matrix.message');
@@ -173,14 +174,17 @@ class VideoController extends Controller
[$user->username, $video->id, $nsfw],
$message
);
$room = "DBWMqijxlNIUIjBNdM:f0ck.it";
$url = "https://f0ck.it/_matrix/client/r0/rooms/%21DBWMqijxlNIUIjBNdM:f0ck.it/send/m.room.message?access_token=syt_bml4Yw_yIqaTxnQHQBzeYnHusNi_3Th9Pn";
$token = config('matrix.token');
$homeserver = config('matrix.homeserver');
$room = config('matrix.room');
$payload = json_encode([
'content' => $message,
"msgtype" => "m.text",
"body" => $message
]);
exec("curl -X POST -d '{ 'msgtype : m.text', 'body: $payload'}' '$url' > /dev/null &");
exec("curl -v -XPOST -d '$payload' '$homeserver$room/send/m.room.message?access_token=$token' > /dev/null &");
}