Skip to content

Commit

Permalink
Add channel fallback object
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostzero committed Nov 14, 2020
1 parent c5907eb commit d0311e9
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ class Channel

private array $users = [];

public function __construct(string $channel)
private bool $persisted;

public function __construct(string $channel, bool $persisted = false)
{
$this->channel = $channel;
$this->persisted = $persisted;
}

public function getName(): string
Expand Down Expand Up @@ -40,6 +43,11 @@ public function setUsers(array $users): void
$this->users = $users;
}

public function isPersisted(): bool
{
return $this->persisted;
}

public function __toString()
{
return $this->getName();
Expand Down
3 changes: 3 additions & 0 deletions src/Messages/HostTargetMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace GhostZero\Tmi\Messages;

use GhostZero\Tmi\Channel;
use GhostZero\Tmi\Client;
use GhostZero\Tmi\Events\Twitch\HostingEvent;
use GhostZero\Tmi\Events\Twitch\UnhostEvent;
Expand All @@ -23,6 +24,8 @@ public function handle(Client $client, array $channels): array
{
if (array_key_exists($this->commandSuffix, $channels)) {
$this->channel = $channels[$this->commandSuffix];
} else {
$this->channel = new Channel($this->commandSuffix);
}

$msgSplit = explode(' ', $this->payload);
Expand Down
2 changes: 2 additions & 0 deletions src/Messages/KickMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function handle(Client $client, array $channels): array
{
if (array_key_exists($this->target, $channels)) {
$this->channel = $channels[$this->target];
} else {
$this->channel = new Channel($this->target);
}

if ($client->getOptions()->getNickname() === $this->user && $client->getOptions()->shouldAutoRejoin()) {
Expand Down
7 changes: 4 additions & 3 deletions src/Messages/NoticeMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public function __construct(string $message)

public function handle(Client $client, array $channels): array
{
if (!array_key_exists($this->commandSuffix, $channels)) {
return [];
if (array_key_exists($this->commandSuffix, $channels)) {
$this->channel = $channels[$this->commandSuffix];
} else {
$this->channel = new Channel($this->commandSuffix);
}

$this->channel = $channels[$this->commandSuffix];
$msgId = $this->tags['msg-id'] ?? '';
$events = [
new NoticeEvent($this->channel, $msgId),
Expand Down
2 changes: 2 additions & 0 deletions src/Messages/PrivmsgMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function handle(Client $client, array $channels): array
{
if (array_key_exists($this->target, $channels)) {
$this->channel = $channels[$this->target];
} else {
$this->channel = new Channel($this->target);
}

$self = $client->getOptions()->getNickname() === $this->user;
Expand Down
2 changes: 2 additions & 0 deletions src/Messages/RoomStateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function handle(Client $client, array $channels): array
{
if (array_key_exists($this->commandSuffix, $channels)) {
$this->channel = $channels[$this->commandSuffix];
} else {
$this->channel = new Channel($this->commandSuffix);
}

$events = [
Expand Down
2 changes: 2 additions & 0 deletions src/Messages/UserNoticeMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function handle(Client $client, array $channels): array
{
if (array_key_exists($this->commandSuffix, $channels)) {
$this->channel = $channels[$this->commandSuffix];
} else {
$this->channel = new Channel($this->commandSuffix);
}

$msgId = $this->tags['msg-id'] ?? '';
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Irc.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function say(string $channel, string $message): void
public function join(string $channel): void
{
$channel = $this->channelName($channel);
$this->channels[$channel] = new Channel($channel);
$this->channels[$channel] = new Channel($channel, true);
$this->write("JOIN {$channel}");
}

Expand Down

0 comments on commit d0311e9

Please sign in to comment.