mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
nostr events added
This commit is contained in:
39
app/Console/Commands/Nostr/PublishUnpublishedItems.php
Normal file
39
app/Console/Commands/Nostr/PublishUnpublishedItems.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Nostr;
|
||||||
|
|
||||||
|
use App\Traits\NostrTrait;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class PublishUnpublishedItems extends Command
|
||||||
|
{
|
||||||
|
use NostrTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'nostr:publish {--model=}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Command description';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$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()))
|
||||||
|
->first();
|
||||||
|
$this->publishOnNostr($model, $this->getText($model));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,14 +17,7 @@ class BitcoinEventObserver
|
|||||||
public function created(BitcoinEvent $bitcoinEvent): void
|
public function created(BitcoinEvent $bitcoinEvent): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$text = sprintf("Ein neues Event wurde eingestellt:\n\n%s\n\n%s bis %s\n\n%s\n\n%s\n\n#Bitcoin #Event #Einundzwanzig #gesundesgeld",
|
$this->publishOnNostr($bitcoinEvent, $this->getText('BitcoinEvent'));
|
||||||
$bitcoinEvent->title,
|
|
||||||
$bitcoinEvent->from->asDateTime(),
|
|
||||||
$bitcoinEvent->to->asDateTime(),
|
|
||||||
$bitcoinEvent->venue->name,
|
|
||||||
$bitcoinEvent->link,
|
|
||||||
);
|
|
||||||
$this->publishOnNostr($bitcoinEvent, $text);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,7 @@ class CourseEventObserver
|
|||||||
public function created(CourseEvent $courseEvent): void
|
public function created(CourseEvent $courseEvent): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$text = sprintf("Unser Dozent %s hat einen neuen Kurs-Termin eingestellt:\n\n%s\n\n%s\n\n%s\n\n#Bitcoin #Kurs #Education #Einundzwanzig #gesundesgeld",
|
$this->publishOnNostr($courseEvent, $this->getText('CourseEvent'));
|
||||||
$courseEvent->course->lecturer->name,
|
|
||||||
$courseEvent->course->name,
|
|
||||||
str($courseEvent->course->description)->limit(80),
|
|
||||||
url()->route('school.landingPage.lecturer',
|
|
||||||
['country' => 'de', 'lecturer' => $courseEvent->course->lecturer]),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->publishOnNostr($courseEvent, $text);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,7 @@ class CourseObserver
|
|||||||
public function created(Course $course): void
|
public function created(Course $course): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$text = sprintf("Unser Dozent %s hat einen neuen Kurs eingestellt:\n\n%s\n\n%s\n\n%s\n\n#Bitcoin #Kurs #Education #Einundzwanzig #gesundesgeld",
|
$this->publishOnNostr($course, $this->getText('Course'));
|
||||||
$course->lecturer->name,
|
|
||||||
$course->name,
|
|
||||||
str($course->description)->limit(80),
|
|
||||||
url()->route('school.landingPage.lecturer',
|
|
||||||
['country' => 'de', 'lecturer' => $course->lecturer]),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->publishOnNostr($course, $text);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Observers;
|
|
||||||
|
|
||||||
use App\Models\Episode;
|
|
||||||
|
|
||||||
class EpisodeObserver
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Handle the Episode "created" event.
|
|
||||||
*/
|
|
||||||
public function created(Episode $episode): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the Episode "updated" event.
|
|
||||||
*/
|
|
||||||
public function updated(Episode $episode): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the Episode "deleted" event.
|
|
||||||
*/
|
|
||||||
public function deleted(Episode $episode): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the Episode "restored" event.
|
|
||||||
*/
|
|
||||||
public function restored(Episode $episode): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle the Episode "force deleted" event.
|
|
||||||
*/
|
|
||||||
public function forceDeleted(Episode $episode): void
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,19 +20,14 @@ class LibraryItemObserver
|
|||||||
try {
|
try {
|
||||||
$libraryItem->setStatus('published');
|
$libraryItem->setStatus('published');
|
||||||
|
|
||||||
$libraryItemName = $libraryItem->name;
|
$from = $libraryItem->name;
|
||||||
$libraryItemName .= ' von '.$libraryItem->lecturer->name;
|
$from .= ' von '.$libraryItem->lecturer->name;
|
||||||
|
|
||||||
if ($libraryItem->type !== LibraryItemType::MarkdownArticle()) {
|
if ($libraryItem->type !== LibraryItemType::MarkdownArticle()) {
|
||||||
if ($libraryItem->whereDoesntHave('libraries',
|
if ($libraryItem->whereDoesntHave('libraries',
|
||||||
fn($query) => $query->where('libraries.is_public', false))
|
fn($query) => $query->where('libraries.is_public', false))
|
||||||
->exists()) {
|
->exists()) {
|
||||||
$text = sprintf("Es gibt was Neues zum Lesen oder Anhören:\n\n%s\n\n%s\n\n#Bitcoin #Wissen #Einundzwanzig #gesundesgeld",
|
$this->publishOnNostr($libraryItem, $this->getText('LibraryItem', $from));
|
||||||
$libraryItemName,
|
|
||||||
url()->route('article.view',
|
|
||||||
['libraryItem' => $libraryItem->slug]),
|
|
||||||
);
|
|
||||||
$this->publishOnNostr($libraryItem, $text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
@@ -17,18 +17,11 @@ class MeetupEventObserver
|
|||||||
public function created(MeetupEvent $meetupEvent): void
|
public function created(MeetupEvent $meetupEvent): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$meetupName = $meetupEvent->meetup->name;
|
$from = $meetupEvent->meetup->name;
|
||||||
if ($meetupEvent->meetup->nostr) {
|
if ($meetupEvent->meetup->nostr) {
|
||||||
$meetupName .= ' @'.$meetupEvent->meetup->nostr;
|
$from .= ' @'.$meetupEvent->meetup->nostr;
|
||||||
}
|
}
|
||||||
$text = sprintf("%s hat einen neuen Termin eingestellt:\n\n%s\n\n%s\n\n%s\n\n#Bitcoin #Meetup #Einundzwanzig #gesundesgeld",
|
$this->publishOnNostr($meetupEvent, $this->getText('MeetupEvent', $from));
|
||||||
$meetupName,
|
|
||||||
$meetupEvent->start->asDateTime(),
|
|
||||||
$meetupEvent->location,
|
|
||||||
url()->route('meetup.event.landing',
|
|
||||||
['country' => 'de', 'meetupEvent' => $meetupEvent->id]),
|
|
||||||
);
|
|
||||||
$this->publishOnNostr($meetupEvent, $text);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,11 @@ class MeetupObserver
|
|||||||
public function created(Meetup $meetup): void
|
public function created(Meetup $meetup): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$meetupName = $meetup->name;
|
$from = $meetup->name;
|
||||||
if ($meetup->nostr) {
|
if ($meetup->nostr) {
|
||||||
$meetupName .= ' @'.$meetup->nostr;
|
$from .= ' @'.$meetup->nostr;
|
||||||
}
|
}
|
||||||
$text = sprintf("Eine neue Meetup Gruppe wurde hinzugefügt:\n\n%s\n\n%s\n\n#Bitcoin #Meetup #Einundzwanzig #gesundesgeld",
|
$this->publishOnNostr($meetup, $this->getText('Meetup', $from));
|
||||||
$meetupName,
|
|
||||||
url()->route('meetup.landing', ['country' => $meetup->city->country->code, 'meetup' => $meetup])
|
|
||||||
);
|
|
||||||
$this->publishOnNostr($meetup, $text);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,7 @@ class OrangePillObserver
|
|||||||
public function created(OrangePill $orangePill): void
|
public function created(OrangePill $orangePill): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$text = sprintf("Ein neues Bitcoin-Buch liegt nun in diesem öffentlichen Bücherschrank:\n\n%s\n\n%s\n\n%s\n\n#Bitcoin #Education #Einundzwanzig #gesundesgeld",
|
$this->publishOnNostr($orangePill, $this->getText('OrangePill'));
|
||||||
$orangePill->bookCase->title,
|
|
||||||
$orangePill->bookCase->address,
|
|
||||||
url()->route('bookCases.comment.bookcase', ['country' => 'de', 'bookCase' => $orangePill->bookCase]),
|
|
||||||
);
|
|
||||||
$this->publishOnNostr($orangePill, $text);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
|
use App\Models\BitcoinEvent;
|
||||||
|
use App\Models\Course;
|
||||||
|
use App\Models\LibraryItem;
|
||||||
|
use App\Models\Meetup;
|
||||||
|
use App\Models\MeetupEvent;
|
||||||
|
use App\Models\OrangePill;
|
||||||
|
use App\Nova\CourseEvent;
|
||||||
use Illuminate\Support\Facades\Process;
|
use Illuminate\Support\Facades\Process;
|
||||||
|
|
||||||
trait NostrTrait
|
trait NostrTrait
|
||||||
@@ -24,4 +31,64 @@ trait NostrTrait
|
|||||||
'errorOutput' => $result->errorOutput()
|
'errorOutput' => $result->errorOutput()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getText($model, $from = null)
|
||||||
|
{
|
||||||
|
if ($model instanceof BitcoinEvent) {
|
||||||
|
return sprintf("Ein neues Event wurde eingestellt:\n\n%s\n\n%s bis %s\n\n%s\n\n%s\n\n#Bitcoin #Event #Einundzwanzig #gesundesgeld",
|
||||||
|
$model->title,
|
||||||
|
$model->from->asDateTime(),
|
||||||
|
$model->to->asDateTime(),
|
||||||
|
$model->venue->name,
|
||||||
|
$model->link,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($model instanceof CourseEvent) {
|
||||||
|
return sprintf("Unser Dozent %s hat einen neuen Kurs-Termin eingestellt:\n\n%s\n\n%s\n\n%s\n\n#Bitcoin #Kurs #Education #Einundzwanzig #gesundesgeld",
|
||||||
|
$model->course->lecturer->name,
|
||||||
|
$model->course->name,
|
||||||
|
str($model->course->description)->limit(80),
|
||||||
|
url()->route('school.landingPage.lecturer',
|
||||||
|
['country' => 'de', 'lecturer' => $model->course->lecturer]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($model instanceof MeetupEvent) {
|
||||||
|
return sprintf("%s hat einen neuen Termin eingestellt:\n\n%s\n\n%s\n\n%s\n\n#Bitcoin #Meetup #Einundzwanzig #gesundesgeld",
|
||||||
|
$from,
|
||||||
|
$model->start->asDateTime(),
|
||||||
|
$model->location,
|
||||||
|
url()->route('meetup.event.landing',
|
||||||
|
['country' => 'de', 'meetupEvent' => $model->id]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($model instanceof Meetup) {
|
||||||
|
return sprintf("Eine neue Meetup Gruppe wurde hinzugefügt:\n\n%s\n\n%s\n\n#Bitcoin #Meetup #Einundzwanzig #gesundesgeld",
|
||||||
|
$from,
|
||||||
|
url()->route('meetup.landing', ['country' => $model->city->country->code, 'meetup' => $model])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($model instanceof Course) {
|
||||||
|
return sprintf("Unser Dozent %s hat einen neuen Kurs eingestellt:\n\n%s\n\n%s\n\n%s\n\n#Bitcoin #Kurs #Education #Einundzwanzig #gesundesgeld",
|
||||||
|
$model->lecturer->name,
|
||||||
|
$model->name,
|
||||||
|
str($model->description)->limit(80),
|
||||||
|
url()->route('school.landingPage.lecturer',
|
||||||
|
['country' => 'de', 'lecturer' => $model->lecturer]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($model instanceof LibraryItem) {
|
||||||
|
return sprintf("Es gibt was Neues zum Lesen oder Anhören:\n\n%s\n\n%s\n\n#Bitcoin #Wissen #Einundzwanzig #gesundesgeld",
|
||||||
|
$from,
|
||||||
|
url()->route('article.view',
|
||||||
|
['libraryItem' => $model->slug]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($model instanceof OrangePill) {
|
||||||
|
return sprintf("Ein neues Bitcoin-Buch liegt nun in diesem öffentlichen Bücherschrank:\n\n%s\n\n%s\n\n%s\n\n#Bitcoin #Education #Einundzwanzig #gesundesgeld",
|
||||||
|
$model->bookCase->title,
|
||||||
|
$model->bookCase->address,
|
||||||
|
url()->route('bookCases.comment.bookcase', ['country' => 'de', 'bookCase' => $model->bookCase]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user