Skip to content

Commit

Permalink
(Discord) Send Twitch relay messages to designated channel using #cha…
Browse files Browse the repository at this point in the history
…nnel prefix in Discord

If the bot is in ValZarGaming's or DAAthren's channel, sending the message `#valzargaming hello` or `#daathren hello` in the proper Discord channel will send the message `[DISCORD] Username: hello` to the named channel. If the channel does not exist the message will be sent to the last known channel or the first channel in the channels array if none has been used yet. Additionally, sending a message via Discord without specifying a channel will always go to the channel that last had a message sent to it, or the first channel in the channels list if no message has been sent yet.
  • Loading branch information
valzargaming committed Mar 8, 2021
1 parent 91b80bb commit bd263a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Twitch/Twitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ public function close(bool $closeLoop = true): void
}
}

public function sendMessage(string $data, string $channel = null): void
public function sendMessage(string $data, ?string $channel = null): void
{
$this->connection->write("PRIVMSG #" . ($channel ?? $this->reallastchannel) . " :" . $data . "\n");
$this->connection->write("PRIVMSG #" . ($channel ?? $this->reallastchannel ?? current($this->channels)) . " :" . $data . "\n");
$this->emit('[REPLY] #' . ($channel ?? $this->reallastchannel) . ' - ' . $data);
if ($channel) $this->reallastchannel = $channel;
}

public function joinChannel(string $string): void
Expand Down Expand Up @@ -292,6 +293,11 @@ public function emit(string $string): void
echo "[EMIT] $string" . PHP_EOL;
}

public function getChannels(): array
{
return $this->channels;
}

public function getCommandSymbol(): array
{
return $this->commandsymbol;
Expand Down Expand Up @@ -351,4 +357,4 @@ public function discordRelay($payload): void
$channel->sendMessage($payload);
}
}
}
}
2 changes: 2 additions & 0 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
],
'private_functions' => [ // Enabled functions usable only by the bot owner sharing the same username as the bot
'php', //Outputs the current version of PHP as a message
'join', //Joins another user's channel
'leave', //Leave the current user's channel
],
);
//include 'commands.php';
Expand Down

0 comments on commit bd263a6

Please sign in to comment.