From 7adefecfbb3e9c2da60850f0480f1ebc28d18937 Mon Sep 17 00:00:00 2001 From: HolgerHatGarKeineNode Date: Fri, 21 Nov 2025 16:34:38 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20Nostr=20publishing=20and=20lo?= =?UTF-8?q?gin=20keys=20cleanup=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/Database/CleanupLoginKeys.php | 35 ++++++ .../Nostr/PublishUnpublishedItems.php | 47 ++++++++ app/Traits/NostrTrait.php | 104 ++++++++++++++++++ routes/console.php | 16 ++- 4 files changed, 197 insertions(+), 5 deletions(-) create mode 100644 app/Console/Commands/Database/CleanupLoginKeys.php create mode 100644 app/Console/Commands/Nostr/PublishUnpublishedItems.php create mode 100644 app/Traits/NostrTrait.php diff --git a/app/Console/Commands/Database/CleanupLoginKeys.php b/app/Console/Commands/Database/CleanupLoginKeys.php new file mode 100644 index 0000000..26547e2 --- /dev/null +++ b/app/Console/Commands/Database/CleanupLoginKeys.php @@ -0,0 +1,35 @@ +where('created_at', '<', now()->subDays(1)) + ->delete(); + + return Command::SUCCESS; + } +} diff --git a/app/Console/Commands/Nostr/PublishUnpublishedItems.php b/app/Console/Commands/Nostr/PublishUnpublishedItems.php new file mode 100644 index 0000000..05e5e61 --- /dev/null +++ b/app/Console/Commands/Nostr/PublishUnpublishedItems.php @@ -0,0 +1,47 @@ + 'Europe/Berlin']); + $modelName = $this->option('model'); + $className = '\\App\Models\\' . $modelName; + $model = $className::query() + ->whereNull('nostr_status') + ->when($modelName === 'BitcoinEvent', fn($q) => $q->where('from', '>', now())) + ->when($modelName === 'CourseEvent', fn($q) => $q->where('from', '>', now())) + ->when($modelName === 'MeetupEvent', fn($q) => $q->where('start', '>', now())) + ->when($modelName === 'LibraryItem', fn($q) => $q + ->where('type', '<>', 'markdown_article') + ->where('type', '<>', 'bindle') + ) + ->orderByDesc('created_at') + ->first(); + if ($model) { + $this->publishOnNostr($model, $this->getText($model)); + } + } +} diff --git a/app/Traits/NostrTrait.php b/app/Traits/NostrTrait.php new file mode 100644 index 0000000..33ca003 --- /dev/null +++ b/app/Traits/NostrTrait.php @@ -0,0 +1,104 @@ +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('-', '_'), + ); + } + } +} diff --git a/routes/console.php b/routes/console.php index 3c9adf1..faa9c7a 100644 --- a/routes/console.php +++ b/routes/console.php @@ -1,8 +1,14 @@ comment(Inspiring::quote()); -})->purpose('Display an inspiring quote'); +Schedule::command(CleanupLoginKeys::class)->everyFifteenMinutes(); + +Schedule::command(PublishUnpublishedItems::class, [ + '--model' => 'MeetupEvent', +])->dailyAt('17:00'); + +Schedule::command(PublishUnpublishedItems::class, [ + '--model' => 'Meetup', +])->dailyAt('18:00');