From 675625f31e4efb48f3bc8da06a950e520895b84f Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 6 Sep 2024 12:16:08 +0200 Subject: [PATCH] show which channels the chatbot is in --- app/Console/Commands/TwitchChannelInfo.php | 2 + app/Http/Controllers/ChannelController.php | 4 ++ app/Http/Controllers/SitemapXmlController.php | 2 +- app/Models/Channel.php | 3 +- .../2024_09_06_090755_more_twitch_props.php | 30 +++++++++ resources/js/components/channel/Item.js | 45 ++++++++++++++ resources/js/components/channel/Link.js | 2 +- resources/js/components/channel/List.js | 19 ++++++ resources/js/helpers/Channel.js | 41 +++++++++++++ resources/js/i18n/de.js | 1 + resources/js/i18n/en.js | 1 + resources/js/pages/HorstieLog.js | 61 ++++++++++++++++++- resources/sass/channels.scss | 29 +++++++++ 13 files changed, 235 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2024_09_06_090755_more_twitch_props.php create mode 100644 resources/js/components/channel/Item.js create mode 100644 resources/js/components/channel/List.js diff --git a/app/Console/Commands/TwitchChannelInfo.php b/app/Console/Commands/TwitchChannelInfo.php index c297c7c..dabc018 100644 --- a/app/Console/Commands/TwitchChannelInfo.php +++ b/app/Console/Commands/TwitchChannelInfo.php @@ -113,6 +113,8 @@ class TwitchChannelInfo extends Command { } else { $channel->twitch_live = true; $channel->twitch_category = $data['game_id']; + $channel->twitch_category_name = $data['game_name']; + $channel->twitch_title = $data['title']; $channel->twitch_viewers = $data['viewer_count']; } $channel->save(); diff --git a/app/Http/Controllers/ChannelController.php b/app/Http/Controllers/ChannelController.php index 121ae4e..cb16abb 100644 --- a/app/Http/Controllers/ChannelController.php +++ b/app/Http/Controllers/ChannelController.php @@ -13,6 +13,7 @@ class ChannelController extends Controller { public function search(Request $request) { $validatedData = $request->validate([ + 'chatting' => 'boolean|nullable', 'id' => 'array', 'id.*' => 'integer|numeric', 'joinable' => 'boolean|nullable', @@ -24,6 +25,9 @@ class ChannelController extends Controller { if (!empty($validatedData['id'])) { $channels = $channels->whereIn('id', $validatedData['id']); } + if (isset($validatedData['chatting'])) { + $channels = $channels->where('chat', '=', !!$validatedData['chatting']); + } if (isset($validatedData['joinable']) && $validatedData['joinable']) { $channels = $channels->where('twitch_chat', '!=', ''); } diff --git a/app/Http/Controllers/SitemapXmlController.php b/app/Http/Controllers/SitemapXmlController.php index f85e40e..1ee7bfd 100644 --- a/app/Http/Controllers/SitemapXmlController.php +++ b/app/Http/Controllers/SitemapXmlController.php @@ -79,7 +79,7 @@ class SitemapXmlController extends Controller $url = new SitemapUrl(); $url->path = '/horstielog'; $url->lastmod = ChatBotLog::latest()->first()->created_at; - $url->changefreq = 'daily'; + $url->changefreq = 'hourly'; $url->priority = 0.5; $urls[] = $url; diff --git a/app/Models/Channel.php b/app/Models/Channel.php index f50c267..72c3e5e 100644 --- a/app/Models/Channel.php +++ b/app/Models/Channel.php @@ -16,6 +16,7 @@ class Channel extends Model { public function broadcastOn($event) { $channels = [ + new PublicChannel('Channel'), new PrivateChannel('Channel.'.$this->id), ]; if (!empty($this->access_key)) { @@ -289,11 +290,11 @@ class Channel extends Model { 'guessing_start' => 'datetime', 'languages' => 'array', 'join' => 'boolean', + 'twitch_live' => 'boolean', ]; protected $hidden = [ 'access_key', - 'chat', 'chat_commands', 'chat_settings', 'created_at', diff --git a/database/migrations/2024_09_06_090755_more_twitch_props.php b/database/migrations/2024_09_06_090755_more_twitch_props.php new file mode 100644 index 0000000..25017c4 --- /dev/null +++ b/database/migrations/2024_09_06_090755_more_twitch_props.php @@ -0,0 +1,30 @@ +string('twitch_category_name')->default(''); + $table->string('twitch_title')->default(''); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('channels', function (Blueprint $table) { + $table->dropColumn('twitch_category_name'); + $table->dropColumn('twitch_title'); + }); + } +}; diff --git a/resources/js/components/channel/Item.js b/resources/js/components/channel/Item.js new file mode 100644 index 0000000..a2b712f --- /dev/null +++ b/resources/js/components/channel/Item.js @@ -0,0 +1,45 @@ +import PropTypes from 'prop-types'; +import React from 'react'; + +import Icon from '../common/Icon'; + +const Item = ({ channel }) => { + const classNames = [ + 'channel-item', + channel.twitch_live ? 'is-live' : 'not-live', + ]; + return +
+
{channel.title}
+ {channel.twitch_live ? +
+ + {' '} + {channel.twitch_viewers} +
+ : null} +
+
{channel.twitch_title}
+
+ {channel.twitch_category_name} +
+
; +}; + +Item.propTypes = { + channel: PropTypes.shape({ + stream_link: PropTypes.string, + title: PropTypes.string, + twitch_category_name: PropTypes.string, + twitch_live: PropTypes.bool, + twitch_title: PropTypes.string, + twitch_viewers: PropTypes.number, + }), +}; + +export default Item; diff --git a/resources/js/components/channel/Link.js b/resources/js/components/channel/Link.js index cb6cb79..3eeb7b9 100644 --- a/resources/js/components/channel/Link.js +++ b/resources/js/components/channel/Link.js @@ -7,7 +7,7 @@ import Icon from '../common/Icon'; const Link = ({ channel }) => { return