send staff message to telegram

This commit is contained in:
xiaomlove
2026-06-12 17:47:08 +07:00
parent e4cdb26c2f
commit fab32bf63d
7 changed files with 66 additions and 14 deletions
+6
View File
@@ -14,6 +14,7 @@ use App\Events\HitAndRunUpdated;
use App\Events\MessageCreated;
use App\Events\NewsCreated;
use App\Events\SnatchedUpdated;
use App\Events\StaffMessageCreated;
use App\Events\TorrentCreated;
use App\Events\TorrentDeleted;
use App\Events\TorrentUpdated;
@@ -28,6 +29,7 @@ use App\Models\HitAndRun;
use App\Models\Message;
use App\Models\News;
use App\Models\Snatch;
use App\Models\StaffMessage;
use App\Models\Torrent;
use App\Models\User;
@@ -59,6 +61,8 @@ final class ModelEventEnum {
const SNATCHED_UPDATED = 'snatched_updated';
const MESSAGE_CREATED = 'message_created';
const STAFF_MESSAGE_CREATED = 'staff_message_created';
public static array $eventMaps = [
self::TORRENT_CREATED => ['event' => TorrentCreated::class, 'model' => Torrent::class],
self::TORRENT_UPDATED => ['event' => TorrentUpdated::class, 'model' => Torrent::class],
@@ -87,5 +91,7 @@ final class ModelEventEnum {
self::AGENT_DENY_CREATED => ['event' => AgentDenyCreated::class, 'model' => AgentDeny::class],
self::AGENT_DENY_UPDATED => ['event' => AgentDenyUpdated::class, 'model' => AgentDeny::class],
self::AGENT_DENY_DELETED => ['event' => AgentDenyDeleted::class, 'model' => AgentDeny::class],
self::STAFF_MESSAGE_CREATED => ['event' => StaffMessageCreated::class, 'model' => StaffMessage::class],
];
}
+39
View File
@@ -0,0 +1,39 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class StaffMessageCreated
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public ?Model $model = null;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Model $model)
{
$this->model = $model;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
+13 -2
View File
@@ -2,8 +2,7 @@
namespace App\Models;
use App\Repositories\ToolRepository;
use Google\Service\Testing\ToolResultsExecution;
use App\Enums\ModelEventEnum;
class StaffMessage extends NexusModel
{
@@ -27,4 +26,16 @@ class StaffMessage extends NexusModel
return $this->belongsTo(User::class, 'answeredby');
}
public static function add(int $sender, string $subject, string $msg)
{
$record = self::query()->create([
'sender' => $sender,
'subject' => $subject,
'msg' => $msg,
'added' => now(),
]);
fire_event(ModelEventEnum::STAFF_MESSAGE_CREATED, $record);
return $record;
}
}