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:
@@ -3,8 +3,7 @@
|
||||
namespace App\Http\Livewire\News;
|
||||
|
||||
use App\Models\LibraryItem;
|
||||
use App\Traits\TwitterTrait;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use App\Traits\NostrTrait;
|
||||
use Livewire\Component;
|
||||
use RalphJSmit\Laravel\SEO\Support\SEOData;
|
||||
use WireUi\Traits\Actions;
|
||||
@@ -12,62 +11,7 @@ use WireUi\Traits\Actions;
|
||||
class ArticleOverview extends Component
|
||||
{
|
||||
use Actions;
|
||||
use TwitterTrait;
|
||||
|
||||
public function tweet($id)
|
||||
{
|
||||
$libraryItem = LibraryItem::query()
|
||||
->with([
|
||||
'lecturer',
|
||||
])
|
||||
->find($id);
|
||||
if ($libraryItem->tweet) {
|
||||
$this->notification()
|
||||
->error(__('Article already tweeted'));
|
||||
|
||||
return;
|
||||
}
|
||||
$libraryItem->setStatus('published');
|
||||
$libraryItemName = $libraryItem->name;
|
||||
if ($libraryItem->lecturer->twitter_username && $libraryItem->type !== 'markdown_article') {
|
||||
$libraryItemName .= ' von @'.$libraryItem->lecturer->twitter_username;
|
||||
}
|
||||
if (!$libraryItem->lecturer->twitter_username) {
|
||||
$libraryItemName .= ' von '.$libraryItem->lecturer->name;
|
||||
}
|
||||
|
||||
try {
|
||||
if (config('feeds.services.twitterAccountId')) {
|
||||
$this->setNewAccessToken(1);
|
||||
|
||||
if (!$libraryItem->approved) {
|
||||
$this->notification()
|
||||
->error(__('Article not approved yet'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$text = sprintf("Ein neuer News-Artikel wurde verfasst:\n\n%s\n\n%s\n\n#Bitcoin #News #Einundzwanzig #gesundesgeld",
|
||||
$libraryItemName,
|
||||
url()->route('article.view',
|
||||
['libraryItem' => $libraryItem->slug]),
|
||||
);
|
||||
|
||||
$this->postTweet($text);
|
||||
|
||||
$libraryItem->tweet = true;
|
||||
$libraryItem->save();
|
||||
|
||||
$this->notification()
|
||||
->success(__('Article tweeted'));
|
||||
|
||||
$this->emit('$refresh');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->notification()
|
||||
->error(__('Error tweeting article', $e->getMessage()));
|
||||
}
|
||||
}
|
||||
use NostrTrait;
|
||||
|
||||
public function nostr($id)
|
||||
{
|
||||
@@ -88,20 +32,14 @@ class ArticleOverview extends Component
|
||||
url()->route('article.view',
|
||||
['libraryItem' => $libraryItem->slug]),
|
||||
);
|
||||
|
||||
//noscl publish "Good morning!"
|
||||
$result = Process::timeout(60 * 5)->run('noscl publish "'.$text.'"');
|
||||
|
||||
if ($result->successful()) {
|
||||
$libraryItem->nostr = $result->output();
|
||||
$libraryItem->save();
|
||||
$result = $this->publishOnNostr($libraryItem, $text);
|
||||
if ($result['success']) {
|
||||
$this->notification()
|
||||
->success(title: __('Published on Nostr'), description: $result->output());
|
||||
}
|
||||
if ($result->failed()) {
|
||||
} else {
|
||||
$this->notification()
|
||||
->error(title: __('Failed'),
|
||||
description: 'Exit Code: '.$result->exitCode().' Reason: '.$result->errorOutput());
|
||||
description: 'Exit Code: '.$result['exitCode'].' Reason: '.$result['errorOutput']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\BitcoinEvent;
|
||||
use App\Traits\TwitterTrait;
|
||||
use App\Traits\NostrTrait;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BitcoinEventObserver
|
||||
{
|
||||
use TwitterTrait;
|
||||
use NostrTrait;
|
||||
|
||||
/**
|
||||
* Handle the BitcoinEvent "created" event.
|
||||
*/
|
||||
public function created(BitcoinEvent $bitcoinEvent): void
|
||||
{
|
||||
if (config('feeds.services.twitterAccountId')) {
|
||||
$this->setNewAccessToken(1);
|
||||
|
||||
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",
|
||||
$bitcoinEvent->title,
|
||||
$bitcoinEvent->from->asDateTime(),
|
||||
@@ -24,8 +24,9 @@ class BitcoinEventObserver
|
||||
$bitcoinEvent->venue->name,
|
||||
$bitcoinEvent->link,
|
||||
);
|
||||
|
||||
$this->postTweet($text);
|
||||
$this->publishOnNostr($bitcoinEvent, $text);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\CourseEvent;
|
||||
use App\Traits\TwitterTrait;
|
||||
use App\Traits\NostrTrait;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CourseEventObserver
|
||||
{
|
||||
use TwitterTrait;
|
||||
use NostrTrait;
|
||||
|
||||
/**
|
||||
* Handle the CourseEvent "created" event.
|
||||
*/
|
||||
public function created(CourseEvent $courseEvent): void
|
||||
{
|
||||
if (config('feeds.services.twitterAccountId')) {
|
||||
$this->setNewAccessToken(1);
|
||||
|
||||
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",
|
||||
$courseEvent->course->lecturer->name,
|
||||
$courseEvent->course->name,
|
||||
@@ -25,7 +25,9 @@ class CourseEventObserver
|
||||
['country' => 'de', 'lecturer' => $courseEvent->course->lecturer]),
|
||||
);
|
||||
|
||||
$this->postTweet($text);
|
||||
$this->publishOnNostr($courseEvent, $text);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Course;
|
||||
use App\Traits\TwitterTrait;
|
||||
use App\Traits\NostrTrait;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CourseObserver
|
||||
{
|
||||
use TwitterTrait;
|
||||
use NostrTrait;
|
||||
|
||||
/**
|
||||
* Handle the Course "created" event.
|
||||
*/
|
||||
public function created(Course $course): void
|
||||
{
|
||||
if (config('feeds.services.twitterAccountId')) {
|
||||
$this->setNewAccessToken(1);
|
||||
|
||||
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",
|
||||
$course->lecturer->name,
|
||||
$course->name,
|
||||
@@ -25,7 +25,9 @@ class CourseObserver
|
||||
['country' => 'de', 'lecturer' => $course->lecturer]),
|
||||
);
|
||||
|
||||
$this->postTweet($text);
|
||||
$this->publishOnNostr($course, $text);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\CourseEvent;
|
||||
|
||||
class EventObserver
|
||||
{
|
||||
/**
|
||||
* Handle the Event "created" event.
|
||||
*/
|
||||
public function created(CourseEvent $event): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Event "updated" event.
|
||||
*/
|
||||
public function updated(CourseEvent $event): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Event "deleted" event.
|
||||
*/
|
||||
public function deleted(CourseEvent $event): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Event "restored" event.
|
||||
*/
|
||||
public function restored(CourseEvent $event): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Event "force deleted" event.
|
||||
*/
|
||||
public function forceDeleted(CourseEvent $event): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,28 @@
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Enums\LibraryItemType;
|
||||
use App\Models\LibraryItem;
|
||||
use App\Traits\TwitterTrait;
|
||||
use App\Traits\NostrTrait;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LibraryItemObserver
|
||||
{
|
||||
use TwitterTrait;
|
||||
use NostrTrait;
|
||||
|
||||
/**
|
||||
* Handle the LibraryItem "created" event.
|
||||
*/
|
||||
public function created(LibraryItem $libraryItem): void
|
||||
{
|
||||
// todo: we can change this later
|
||||
try {
|
||||
$libraryItem->setStatus('published');
|
||||
|
||||
$libraryItemName = $libraryItem->name;
|
||||
if ($libraryItem->lecturer->twitter_username && $libraryItem->type !== 'markdown_article') {
|
||||
$libraryItemName .= ' von @'.$libraryItem->lecturer->twitter_username;
|
||||
}
|
||||
if (! $libraryItem->lecturer->twitter_username) {
|
||||
$libraryItemName .= ' von '.$libraryItem->lecturer->name;
|
||||
}
|
||||
|
||||
if (config('feeds.services.twitterAccountId')) {
|
||||
$this->setNewAccessToken(1);
|
||||
|
||||
// http://localhost/de/library/library-item?l=de&table[filters][id]=2
|
||||
|
||||
if ($libraryItem->type !== 'markdown_article') {
|
||||
if ($libraryItem->type !== LibraryItemType::MarkdownArticle()) {
|
||||
if ($libraryItem->whereDoesntHave('libraries',
|
||||
fn($query) => $query->where('libraries.is_public', false))
|
||||
->exists()) {
|
||||
@@ -40,12 +32,11 @@ class LibraryItemObserver
|
||||
url()->route('article.view',
|
||||
['libraryItem' => $libraryItem->slug]),
|
||||
);
|
||||
$this->postTweet($text);
|
||||
$this->publishOnNostr($libraryItem, $text);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// todo: log this
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\MeetupEvent;
|
||||
use App\Traits\TwitterTrait;
|
||||
use App\Traits\NostrTrait;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MeetupEventObserver
|
||||
{
|
||||
use TwitterTrait;
|
||||
use NostrTrait;
|
||||
|
||||
/**
|
||||
* Handle the MeetupEvent "created" event.
|
||||
@@ -16,14 +17,10 @@ class MeetupEventObserver
|
||||
public function created(MeetupEvent $meetupEvent): void
|
||||
{
|
||||
try {
|
||||
if (config('feeds.services.twitterAccountId')) {
|
||||
$this->setNewAccessToken(1);
|
||||
|
||||
$meetupName = $meetupEvent->meetup->name;
|
||||
if ($meetupEvent->meetup->twitter_username) {
|
||||
$meetupName .= ' @'.$meetupEvent->meetup->twitter_username;
|
||||
if ($meetupEvent->meetup->nostr) {
|
||||
$meetupName .= ' @'.$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",
|
||||
$meetupName,
|
||||
$meetupEvent->start->asDateTime(),
|
||||
@@ -31,10 +28,8 @@ class MeetupEventObserver
|
||||
url()->route('meetup.event.landing',
|
||||
['country' => 'de', 'meetupEvent' => $meetupEvent->id]),
|
||||
);
|
||||
|
||||
$this->postTweet($text);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->publishOnNostr($meetupEvent, $text);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Meetup;
|
||||
use App\Traits\TwitterTrait;
|
||||
use App\Traits\NostrTrait;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MeetupObserver
|
||||
{
|
||||
use TwitterTrait;
|
||||
use NostrTrait;
|
||||
|
||||
/**
|
||||
* Handle the Meetup "created" event.
|
||||
@@ -16,22 +17,16 @@ class MeetupObserver
|
||||
public function created(Meetup $meetup): void
|
||||
{
|
||||
try {
|
||||
if (config('feeds.services.twitterAccountId')) {
|
||||
$this->setNewAccessToken(1);
|
||||
|
||||
$meetupName = $meetup->name;
|
||||
if ($meetup->twitter_username) {
|
||||
$meetupName .= ' @'.$meetup->twitter_username;
|
||||
if ($meetup->nostr) {
|
||||
$meetupName .= ' @'.$meetup->nostr;
|
||||
}
|
||||
|
||||
$text = sprintf("Eine neue Meetup Gruppe wurde hinzugefügt:\n\n%s\n\n%s\n\n#Bitcoin #Meetup #Einundzwanzig #gesundesgeld",
|
||||
$meetupName,
|
||||
url()->route('meetup.landing', ['country' => $meetup->city->country->code, 'meetup' => $meetup])
|
||||
);
|
||||
|
||||
$this->postTweet($text);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->publishOnNostr($meetup, $text);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,28 +3,29 @@
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\OrangePill;
|
||||
use App\Traits\TwitterTrait;
|
||||
use App\Traits\NostrTrait;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OrangePillObserver
|
||||
{
|
||||
use TwitterTrait;
|
||||
use NostrTrait;
|
||||
|
||||
/**
|
||||
* Handle the OrangePill "created" event.
|
||||
*/
|
||||
public function created(OrangePill $orangePill): void
|
||||
{
|
||||
// if (config('feeds.services.twitterAccountId')) {
|
||||
// $this->setNewAccessToken(1);
|
||||
//
|
||||
// $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",
|
||||
// $orangePill->bookCase->title,
|
||||
// $orangePill->bookCase->address,
|
||||
// url()->route('bookCases.comment.bookcase', ['country' => 'de', 'bookCase' => $orangePill->bookCase]),
|
||||
// );
|
||||
//
|
||||
// $this->postTweet($text);
|
||||
// }
|
||||
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",
|
||||
$orangePill->bookCase->title,
|
||||
$orangePill->bookCase->address,
|
||||
url()->route('bookCases.comment.bookcase', ['country' => 'de', 'bookCase' => $orangePill->bookCase]),
|
||||
);
|
||||
$this->publishOnNostr($orangePill, $text);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
27
app/Traits/NostrTrait.php
Normal file
27
app/Traits/NostrTrait.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Process;
|
||||
|
||||
trait NostrTrait
|
||||
{
|
||||
public function publishOnNostr($model, $text): array
|
||||
{
|
||||
//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()
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('library_items', function (Blueprint $table) {
|
||||
$table->renameColumn('nostr', 'nostr_status');
|
||||
});
|
||||
Schema::table('bitcoin_events', function (Blueprint $table) {
|
||||
$table->text('nostr_status')
|
||||
->nullable();
|
||||
});
|
||||
Schema::table('course_events', function (Blueprint $table) {
|
||||
$table->text('nostr_status')
|
||||
->nullable();
|
||||
});
|
||||
Schema::table('courses', function (Blueprint $table) {
|
||||
$table->text('nostr_status')
|
||||
->nullable();
|
||||
});
|
||||
Schema::table('meetup_events', function (Blueprint $table) {
|
||||
$table->text('nostr_status')
|
||||
->nullable();
|
||||
});
|
||||
Schema::table('meetups', function (Blueprint $table) {
|
||||
$table->text('nostr_status')
|
||||
->nullable();
|
||||
});
|
||||
Schema::table('orange_pills', function (Blueprint $table) {
|
||||
$table->text('nostr_status')
|
||||
->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tables', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user