slack/src/Listeners/ChannelLeftListener.php
2021-08-12 14:09:40 +10:00

35 lines
764 B
PHP

<?php
namespace Slack\Listeners;
use Illuminate\Support\Facades\Log;
use Illuminate\Contracts\Queue\ShouldQueue;
use Slack\Event\{Base,ChannelLeft,GroupLeft};
class ChannelLeftListener implements ShouldQueue
{
private const LOGKEY = 'LCL';
public $queue = 'high';
/**
* Handle the event.
*
* @param Base $event
* @return void
*/
public function handle(Base $event)
{
if (! $event instanceof ChannelLeft AND ! $event instanceof GroupLeft)
abort(500,'Wrong class calling this listener? '.get_class($event));
// Do some magic with event data
Log::info(sprintf('%s:Bot Left Channel [%s]',self::LOGKEY,$event->channel_id),['m'=>__METHOD__,'c'=>$event->channel_id]);
$o = $event->channel(TRUE);
$o->active = FALSE;
$o->save();
}
}