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(); $video->tesThumb();
// Discord // Discord
if (config('discord.enabled') && config('discord.webhookurl')) { // if (config('discord.enabled') && config('discord.webhookurl')) {
$nsfw = in_array('nsfw', $video->getTagArrayNormalizedAttribute()); // $nsfw = in_array('nsfw', $video->getTagArrayNormalizedAttribute());
$nsfw = $nsfw ? ' :exclamation: **NSFW** :exclamation:' : ''; // $nsfw = $nsfw ? ' :exclamation: **NSFW** :exclamation:' : '';
$message = config('discord.message'); // $message = config('discord.message');
$message = str_replace( // $message = str_replace(
['<USER>', '<ID>', '<NSFW>'], // ['<USER>', '<ID>', '<NSFW>'],
[$user->username, $video->id, $nsfw], // [$user->username, $video->id, $nsfw],
$message // $message
); // );
$url = config('discord.webhookurl'); // $url = config('discord.webhookurl');
$payload = json_encode([ // $payload = json_encode([
'content' => $message, // 'content' => $message,
]); // ]);
// exec with & so it is async // // exec with & so it is async
exec("curl -H \"Content-Type: application/json; charset=UTF-8\" -X POST -d '$payload' '$url' > /dev/null &"); // 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 = in_array('nsfw', $video->getTagArrayNormalizedAttribute());
$nsfw = $nsfw ? ' :exclamation: **NSFW** :exclamation:' : ''; $nsfw = $nsfw ? ' :exclamation: **NSFW** :exclamation:' : '';
$message = config('matrix.message'); $message = config('matrix.message');
@@ -173,14 +174,17 @@ class VideoController extends Controller
[$user->username, $video->id, $nsfw], [$user->username, $video->id, $nsfw],
$message $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([ $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 &");
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 234 KiB

After

Width:  |  Height:  |  Size: 60 KiB

1
blah.log Normal file
View File

@@ -0,0 +1 @@
{"errcode":"M_UNKNOWN","error":"'body' not a string type"}

1
blah2.log Normal file
View File

@@ -0,0 +1 @@
{"event_id":"$RcOS8ZN5HNujEnr9cEjFb-2UJ3A7pj0rSm4RiSZ9WIk"}

View File

@@ -1,6 +1,8 @@
<?php <?php
return [ return [
'enabled' => true, 'enabled' => true,
'webhookurl' => env('matrix_WEBHOOK', false), 'homeserver' => env('MATRIX_HOMESERVER'),
'room' => env('MATRIX_ROOMID'),
'token' => env('MATRIX_TOKEN'),
'message' => '<USER> uploaded a new webm: https://w0bm.com/<ID><NSFW>', 'message' => '<USER> uploaded a new webm: https://w0bm.com/<ID><NSFW>',
]; ];