Skip to content

Commit bd263a6

Browse files
committed
(Discord) Send Twitch relay messages to designated channel using #channel 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.
1 parent 91b80bb commit bd263a6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Twitch/Twitch.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ public function close(bool $closeLoop = true): void
112112
}
113113
}
114114

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

121122
public function joinChannel(string $string): void
@@ -292,6 +293,11 @@ public function emit(string $string): void
292293
echo "[EMIT] $string" . PHP_EOL;
293294
}
294295

296+
public function getChannels(): array
297+
{
298+
return $this->channels;
299+
}
300+
295301
public function getCommandSymbol(): array
296302
{
297303
return $this->commandsymbol;
@@ -351,4 +357,4 @@ public function discordRelay($payload): void
351357
$channel->sendMessage($payload);
352358
}
353359
}
354-
}
360+
}

run.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
],
5555
'private_functions' => [ // Enabled functions usable only by the bot owner sharing the same username as the bot
5656
'php', //Outputs the current version of PHP as a message
57+
'join', //Joins another user's channel
58+
'leave', //Leave the current user's channel
5759
],
5860
);
5961
//include 'commands.php';

0 commit comments

Comments
 (0)