mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2025-12-20 01:30:15 +00:00
✨ Add Nostr publishing and login keys cleanup commands
This commit is contained in:
104
app/Traits/NostrTrait.php
Normal file
104
app/Traits/NostrTrait.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\Course;
|
||||
use App\Models\CourseEvent;
|
||||
use App\Models\Meetup;
|
||||
use App\Models\MeetupEvent;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
|
||||
trait NostrTrait
|
||||
{
|
||||
public function publishOnNostr($model, $text): array
|
||||
{
|
||||
if (app()->environment('local')) {
|
||||
return [
|
||||
'success' => true,
|
||||
'output' => 'local',
|
||||
'exitCode' => 0,
|
||||
'errorOutput' => '',
|
||||
];
|
||||
}
|
||||
|
||||
//noscl publish "Good morning!"
|
||||
$result = Process::timeout(60 * 5)
|
||||
->run('noscl publish "'.$text.'"');
|
||||
|
||||
if ($result->successful()) {
|
||||
$model->nostr_status = $result->output();
|
||||
$model->save();
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => $result->successful(),
|
||||
'output' => $result->output(),
|
||||
'exitCode' => $result->exitCode(),
|
||||
'errorOutput' => $result->errorOutput(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getText($model)
|
||||
{
|
||||
$from = '';
|
||||
if ($model instanceof CourseEvent) {
|
||||
if ($model->course->lecturer->nostr) {
|
||||
$from .= '@'.$model->course->lecturer->nostr;
|
||||
} else {
|
||||
$from .= $model->course->lecturer->name;
|
||||
}
|
||||
|
||||
return sprintf("Unser Dozent %s hat einen neuen Kurs-Termin eingestellt:\n%s\n%s\n%s\n\n#Bitcoin #Kurs #Education #Einundzwanzig #gesundesgeld #einundzwanzig_portal_lecturer_%s",
|
||||
$from,
|
||||
$model->course->name,
|
||||
str($model->course->description)->toString(),
|
||||
url()->route('courses.landingpage',
|
||||
['country' => 'de', 'course' => $model->course]),
|
||||
str($model->course->lecturer->slug)->replace('-', '_'),
|
||||
);
|
||||
}
|
||||
if ($model instanceof MeetupEvent) {
|
||||
$from = $model->meetup->name;
|
||||
if ($model->meetup->nostr) {
|
||||
$from .= ' @'.$model->meetup->nostr;
|
||||
}
|
||||
|
||||
return sprintf("%s hat einen neuen Termin eingestellt:\n%s\n%s\n%s\n\n#Bitcoin #Meetup #Einundzwanzig #gesundesgeld #einundzwanzig_portal_%s",
|
||||
$from,
|
||||
$model->start->asDateTime(),
|
||||
$model->location,
|
||||
url()->route('meetups.landingpage-event',
|
||||
['country' => 'de', 'meetup' => $model, 'event' => $model]),
|
||||
str($model->meetup->slug)->replace('-', '_'),
|
||||
);
|
||||
}
|
||||
if ($model instanceof Meetup) {
|
||||
$from = $model->name;
|
||||
if ($model->nostr) {
|
||||
$from .= ' @'.$model->nostr;
|
||||
}
|
||||
|
||||
return sprintf("Eine neue Meetup Gruppe wurde hinzugefügt:\n%s\n%s\n\n#Bitcoin #Meetup #Einundzwanzig #gesundesgeld #einundzwanzig_portal_%s",
|
||||
$from,
|
||||
url()->route('meetups.landingpage', ['country' => $model->city->country->code, 'meetup' => $model]),
|
||||
str($model->slug)->replace('-', '_'),
|
||||
);
|
||||
}
|
||||
if ($model instanceof Course) {
|
||||
if ($model->lecturer->nostr) {
|
||||
$from .= '@'.$model->lecturer->nostr;
|
||||
} else {
|
||||
$from .= $model->lecturer->name;
|
||||
}
|
||||
|
||||
return sprintf("Unser Dozent %s hat einen neuen Kurs eingestellt:\n%s\n%s\n%s\n\n#Bitcoin #Kurs #Education #Einundzwanzig #gesundesgeld #einundzwanzig_portal_lecturer_%s",
|
||||
$from,
|
||||
$model->name,
|
||||
str($model->description)->toString(),
|
||||
url()->route('courses.landingpage',
|
||||
['country' => 'de', 'course' => $model]),
|
||||
str($model->lecturer->slug)->replace('-', '_'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user