throw new \Exception('channel has no twitch chat set');
}
$validatedData = $request->validate([
+ 'bot_nick' => 'string',
'text' => 'string|required',
]);
$this->authorize('editRestream', $channel);
- TwitchBotCommand::chat($channel->twitch_chat, $validatedData['text'], $request->user());
+ $nick = empty($validatedData['bot_nick']) ? 'localhorsttv' : $validatedData['bot_nick'];
+ TwitchBotCommand::chat($channel->twitch_chat, $validatedData['text'], $request->user(), $nick);
return $channel->toJson();
}
if (!$channel->twitch_chat) {
throw new \Exception('channel has no twitch chat set');
}
+ $validatedData = $request->validate([
+ 'bot_nick' => 'string',
+ ]);
$this->authorize('editRestream', $channel);
- $channel->join = true;
+ $nick = empty($validatedData['bot_nick']) ? 'localhorsttv' : $validatedData['bot_nick'];
+ if ($nick == 'localhorsttv') {
+ $channel->join = true;
+ } else if ($nick == 'horstiebot') {
+ $channel->chat = true;
+ }
$channel->save();
- TwitchBotCommand::join($channel->twitch_chat, $request->user());
+ TwitchBotCommand::join($channel->twitch_chat, $request->user(), $nick);
return $channel->toJson();
}
if (!$channel->twitch_chat) {
throw new \Exception('channel has no twitch chat set');
}
+ $validatedData = $request->validate([
+ 'bot_nick' => 'string',
+ ]);
$this->authorize('editRestream', $channel);
- $channel->join = false;
+ $nick = empty($validatedData['bot_nick']) ? 'localhorsttv' : $validatedData['bot_nick'];
+ if ($nick == 'localhorsttv') {
+ $channel->join = false;
+ } else if ($nick == 'horstiebot') {
+ $channel->chat = false;
+ }
$channel->save();
- TwitchBotCommand::part($channel->twitch_chat, $request->user());
+ TwitchBotCommand::part($channel->twitch_chat, $request->user(), $nick);
return $channel->toJson();
}
{
use HasFactory;
- public static function chat($channel, $text, User $user = null) {
+ public static function chat($channel, $text, User $user = null, $nick = 'localhorsttv') {
$cmd = new TwitchBotCommand();
$cmd->command = 'chat';
$cmd->parameters = [
];
$cmd->status = 'pending';
$cmd->user()->associate($user);
+ $cmd->bot_nick = $nick;
$cmd->save();
}
- public static function join($channel, User $user = null) {
+ public static function join($channel, User $user = null, $nick = 'localhorsttv') {
$cmd = new TwitchBotCommand();
$cmd->command = 'join';
$cmd->parameters = [
];
$cmd->status = 'pending';
$cmd->user()->associate($user);
+ $cmd->bot_nick = $nick;
$cmd->save();
}
- public static function part($channel, User $user = null) {
+ public static function part($channel, User $user = null, $nick = 'localhorsttv') {
$cmd = new TwitchBotCommand();
$cmd->command = 'part';
$cmd->parameters = [
];
$cmd->status = 'pending';
$cmd->user()->associate($user);
+ $cmd->bot_nick = $nick;
$cmd->save();
}
namespace App\TwitchBot;
use App\Models\Channel;
-use App\Models\TwitchBotCommand;
class TwitchAppBot extends TwitchBot {
}
}
-
- private function listenCommands() {
- $this->getLoop()->addPeriodicTimer(1, function () {
- if (!$this->isReady()) return;
- $command = TwitchBotCommand::where('status', '=', 'pending')->oldest()->first();
- if ($command) {
- try {
- $command->execute($this);
- } catch (\Exception $e) {
- }
- }
- });
- }
-
}
namespace App\TwitchBot;
use App\Models\Channel;
+use App\Models\TwitchBotCommand;
use App\Models\TwitchToken;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
}
+ protected function listenCommands() {
+ $this->getLoop()->addPeriodicTimer(1, function () {
+ if (!$this->isReady()) return;
+ $command = TwitchBotCommand::where('bot_nick', '=', $this->nick)->where('status', '=', 'pending')->oldest()->first();
+ if ($command) {
+ try {
+ $command->execute($this);
+ } catch (\Exception $e) {
+ }
+ }
+ });
+ }
+
+
private $logger;
private $nick;
];
}
$this->startTimer();
+ $this->listenCommands();
}
public function joinChannels() {
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('twitch_bot_commands', function(Blueprint $table) {
+ $table->string('bot_nick')->default('localhorsttv');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('twitch_bot_commands', function(Blueprint $table) {
+ $table->dropColumn('bot_nick');
+ });
+ }
+};
const { t } = useTranslation();
- const chat = React.useCallback(async text => {
+ const chat = React.useCallback(async (text, bot_nick) => {
try {
await axios.post(`/api/channels/${channel.id}/chat`, {
text,
+ bot_nick,
});
toastr.success(t('twitchBot.chatSuccess'));
} catch (e) {
}
}, [channel, chatText, t]);
- const join = React.useCallback(async () => {
+ const join = React.useCallback(async (bot_nick) => {
try {
- const rsp = await axios.post(`/api/channels/${channel.id}/join`);
+ const rsp = await axios.post(`/api/channels/${channel.id}/join`, { bot_nick });
setChannel(rsp.data);
toastr.success(t('twitchBot.joinSuccess'));
} catch (e) {
}
}, [channel, t]);
- const part = React.useCallback(async () => {
+ const part = React.useCallback(async (bot_nick) => {
try {
- const rsp = await axios.post(`/api/channels/${channel.id}/part`);
+ const rsp = await axios.post(`/api/channels/${channel.id}/part`, { bot_nick });
setChannel(rsp.data);
toastr.success(t('twitchBot.partSuccess'));
} catch (e) {
value={channel ? channel.id : ''}
/>
</Form.Group>
- {channel ?
- <Form.Group as={Col} md={6}>
- <Form.Label>{t('twitchBot.join')}</Form.Label>
+ {channel ? <>
+ <Form.Group as={Col} md={3}>
+ <Form.Label>{t('twitchBot.joinApp')}</Form.Label>
<div>
<Form.Control
as={ToggleSwitch}
onChange={({ target: { value } }) => {
if (value) {
- join();
+ join('localhorsttv');
} else {
- part();
+ part('localhorsttv');
}
}}
value={channel.join}
/>
</div>
</Form.Group>
- : null}
+ <Form.Group as={Col} md={3}>
+ <Form.Label>{t('twitchBot.joinChat')}</Form.Label>
+ <div>
+ <Form.Control
+ as={ToggleSwitch}
+ onChange={({ target: { value } }) => {
+ if (value) {
+ join('horstiebot');
+ } else {
+ part('horstiebot');
+ }
+ }}
+ value={channel.chat}
+ />
+ </div>
+ </Form.Group>
+ </> : null}
</Row>
{channel ?
<Row>
}}
value={chatText}
/>
- <Button
- className="mt-2"
- disabled={!chatText}
- onClick={() => {
- if (chatText) chat(chatText);
- }}
- variant="twitch"
- >
- {t('button.send')}
- </Button>
+ <div className="button-bar">
+ <Button
+ className="mt-2"
+ disabled={!chatText || !channel.join}
+ onClick={() => {
+ if (chatText) chat(chatText, 'localhorsttv');
+ }}
+ variant="twitch"
+ >
+ {t('twitchBot.sendApp')}
+ </Button>
+ <Button
+ className="mt-2"
+ disabled={!chatText || !channel.chat}
+ onClick={() => {
+ if (chatText) chat(chatText, 'horstiebot');
+ }}
+ variant="twitch"
+ >
+ {t('twitchBot.sendChat')}
+ </Button>
+ </div>
</Form.Group>
</Row>
:
},
twitchBot: {
channel: 'Channel',
- chat: 'Chat',
+ chatApp: 'Chat als App Bot',
+ chatChat: 'Chat als Chat Bot',
chatError: 'Fehler beim Senden',
chatSuccess: 'Nachricht in Warteschlange',
controls: 'Controls',
heading: 'Twitch Bot',
- join: 'Join',
+ joinApp: 'Join als App Bot',
+ joinChat: 'Join als Chat Bot',
joinError: 'Fehler beim Betreten',
joinSuccess: 'Betreten',
noManagePermission: 'Du verfügst nicht über die notwendigen Berechtigungen, um den Twitch Bot zu administrieren.',
partError: 'Fehler beim Verlassen',
partSuccess: 'Verlassen',
selectChannel: 'Bitte wählen einen Channel, den du verändern möchtest.',
+ sendApp: 'Als App Bot senden',
+ sendChat: 'Als Chat Bot senden',
},
users: {
discordTag: 'Discord Tag',
chatSuccess: 'Message queued',
controls: 'Controls',
heading: 'Twitch Bot',
- join: 'Join',
+ joinApp: 'Join as App Bot',
+ joinChat: 'Join as Chat Bot',
joinError: 'Error joining channel',
joinSuccess: 'Joined',
noManagePermission: 'You lack the required privileges to manage the twitch bot.',
partError: 'Error parting channel',
partSuccess: 'Parted',
selectChannel: 'Please select a channel to manage.',
+ sendApp: 'Send as App Bot',
+ sendChat: 'Send as Chat Bot',
},
users: {
discordTag: 'Discord tag',