Compare commits

..

No commits in common. "master" and "v0.4" have entirely different histories.
master ... v0.4

7 changed files with 36 additions and 59 deletions

View File

@ -1,41 +0,0 @@
<?php
namespace App\Helpers;
use App\Models\Quote;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
class Slack
{
private string $url;
public function __construct()
{
$this->url = config('bot.webhook');
}
private function send(string $text): Response
{
return Http::post($this->url, ['text' => $text]);
}
public function sendText(string $text): Response
{
activity()
->event('send')
->log("Manually sent quote: $text");
return $this->send($text);
}
public function sendQuote(Quote $quote): Response
{
activity()
->performedOn($quote)
->event('send')
->log("Requested quote: $quote");
return $this->send($quote->quote);
}
}

View File

@ -2,7 +2,6 @@
namespace App\Http\Controllers\Api;
use App\Helpers\Slack;
use App\Http\Controllers\Controller;
use App\Models\Quote;
use Illuminate\Http\Request;
@ -10,11 +9,11 @@ use Illuminate\Support\Facades\Http;
class WebHookController extends Controller
{
private Slack $slack;
public function __construct() {
$this->slack = new Slack();
public function webHookSend(string $payload)
{
// TODO: move this to a helper class so we can reuse code between API and FE
$data = ['text' => $payload];
$response = Http::post(config('bot.webhook'), $data);
}
public function sendQuote(Request $request)
@ -25,13 +24,28 @@ class WebHookController extends Controller
return;
}
$this->slack->sendText($quote);
activity()
->event('send')
->log("Manually sent quote: $quote");
$this->webHookSend($quote);
}
public function sendRandomQuote()
{
$quote = Quote::inRandomOrder()->first();
$this->slack->sendQuote($quote);
activity()
->performedOn($quote)
->event('send')
->log("Requested quote: $quote->quote");
$this->webHookSend($quote->quote);
}
public function test()
{
var_dump('secrets');
}
}

View File

@ -2,7 +2,6 @@
namespace App\Models;
use App\Helpers\Slack;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\LogOptions;
@ -23,9 +22,13 @@ class Quote extends Model
public function request(): void
{
$slack = new Slack();
// Send the quote
// If success, add it to the transactions
$slack->sendQuote($this);
activity()
->performedOn($this)
->event('send')
->log("Requested quote: $this->quote");
}
public function tapActivity(Activity $activity, string $eventName)

View File

@ -37,7 +37,7 @@ run("cd {{release_path}} && {{bin/npm}} run {$command}");
});
task('perm:fix', function () {
run("chown -R nginx:nginx /opt/PriceyBotPanel/{current,release,shared}");
run("chown -R nginx:nginx /opt/PriceyBotPanel");
});

View File

@ -1,6 +1,5 @@
<?php
use App\Helpers\Slack;
use App\Models\Log;
use Illuminate\Support\Facades\Http;
use Livewire\Attributes\Layout;
@ -16,9 +15,12 @@ new #[Layout('layouts.app')] class extends Component
{
$validated = $this->validate();
$slack = new Slack();
// TODO: move this to a helper class so we can reuse code between API and FE
$response = Http::post(config('bot.webhook'), ['text' => $validated['quote']]);
$slack->sendText($validated['quote']);
activity()
->event('send')
->log("Manually sent quote: {$validated['quote']}");
$this->quote = '';
}

View File

@ -20,6 +20,7 @@ new #[Layout('layouts.guest')] class extends Component
$this->authorize('request', $quote);
$quote->request();
// TODO: add code to send a notification
}
public function delete(Quote $quote): void
@ -63,12 +64,9 @@ new #[Layout('layouts.guest')] class extends Component
@if(auth()->user())
<td class="relative w-8 pl-4 pr-3 text-sm sm:pl-6 border-t">
<div class="flex flex-row space-x-2">
@if(auth()->user()->is_admin)
{{-- For now this is admin only, when we add credits we can make it avaliable to users --}}
<form wire:submit="request({{ $quote }})">
<x-button wire:loading.attr="disabled" wire:loading.class="opacity-50" class="bg-nexi-purple w-24">{{ __('Request') }}</x-button>
</form>
@endif
@if(auth()->user()->is_admin)
<x-button
x-data=""

View File

@ -16,6 +16,7 @@ use Illuminate\Support\Facades\Route;
*/
Route::middleware(['header.auth', 'throttle:api'])->group(function () {
Route::get('/test', [WebHookController::class, 'test']);
Route::post('/sendQuote', [WebHookController::class, 'sendQuote']);
Route::post('/randomQuote', [WebHookController::class, 'sendRandomQuote']);