jerodev /
php-irc-client
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Jerodev\PhpIrcClient\Messages; |
||
| 6 | |||
| 7 | use Jerodev\PhpIrcClient\Helpers\Event; |
||
| 8 | use Jerodev\PhpIrcClient\IrcChannel; |
||
| 9 | use Jerodev\PhpIrcClient\IrcClient; |
||
| 10 | |||
| 11 | class KickMessage extends IrcMessage |
||
| 12 | { |
||
| 13 | public string $message; |
||
| 14 | public string $kicker; |
||
| 15 | public string $user; |
||
| 16 | |||
| 17 | public function __construct(string $message) |
||
| 18 | { |
||
| 19 | parent::__construct($message); |
||
| 20 | [$this->kicker] = explode(' ', $message); |
||
| 21 | [$this->kicker] = explode('!', $this->kicker); |
||
| 22 | $this->kicker = substr($this->kicker, 1); |
||
| 23 | |||
| 24 | [$this->target, $this->user] = explode(' ', $this->commandsuffix ?? ''); |
||
| 25 | $this->message = $this->payload; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * When the bot is kicked form a channel, it might need to auto-rejoin. |
||
| 30 | */ |
||
| 31 | public function handle(IrcClient $client, bool $force = false): void |
||
| 32 | { |
||
| 33 | if ($this->handled && !$force) { |
||
| 34 | return; |
||
| 35 | } |
||
| 36 | |||
| 37 | if ($client->getNickname() === $this->user && $client->shouldAutoRejoin()) { |
||
| 38 | $client->join($this->target); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return array<int, Event> |
||
| 44 | */ |
||
| 45 | public function getEvents(): array |
||
| 46 | { |
||
| 47 | return [ |
||
| 48 | new Event( |
||
| 49 | 'kick', |
||
| 50 | [$this->channel, $this->user, $this->kicker, $this->message] |
||
| 51 | ), |
||
| 52 | ]; |
||
| 53 | } |
||
| 54 | } |
||
| 55 |