From c81c9922de026904c7b6f3fb55ac36c0e59899ac Mon Sep 17 00:00:00 2001 From: moderndevslulw Date: Tue, 8 Jul 2025 17:16:54 +0500 Subject: feat: big changes and fixes in channels --- public/channels/index.php | 102 +++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 60 deletions(-) (limited to 'public') diff --git a/public/channels/index.php b/public/channels/index.php index b32b63b..cdb09b2 100644 --- a/public/channels/index.php +++ b/public/channels/index.php @@ -30,7 +30,7 @@ $channels = []; $db = new PDO(DB_URL, DB_USER, DB_PASS); if (isset($_GET['alias_id'])) { - $stmt = $db->prepare('SELECT c.*, cp.*, array_to_json(cp.features) as features + $stmt = $db->prepare('SELECT c.*, cp.* FROM channels c LEFT JOIN channel_preferences cp ON cp.id = c.id WHERE c.alias_id = ? @@ -43,35 +43,24 @@ if (isset($_GET['alias_id'])) { exit; } - $channel['features'] = json_decode($channel['features'] ?: '[]', true); - // fetching custom commands - $stmt = $db->prepare('SELECT *, array_to_json(messages) as messages + $stmt = $db->prepare('SELECT * FROM custom_commands WHERE channel_id = ? - ORDER BY created_at DESC '); $stmt->execute([$channel['id']]); $channel['commands'] = $stmt->fetchAll(PDO::FETCH_ASSOC); - foreach ($channel['commands'] as &$c) { - $c['messages'] = json_decode($c['messages'], true); - } - unset($c); // fetching timers - $stmt = $db->prepare('SELECT *, array_to_json(messages) as messages + $stmt = $db->prepare('SELECT * FROM timers WHERE channel_id = ? '); $stmt->execute([$channel['id']]); $channel['timers'] = $stmt->fetchAll(PDO::FETCH_ASSOC); - foreach ($channel['timers'] as &$c) { - $c['messages'] = json_decode($c['messages'], true); - } - unset($c); // fetching events - $stmt = $db->prepare('SELECT e.*, array_to_json(e.flags) as flags, COUNT(es.id) as subscription_count + $stmt = $db->prepare('SELECT e.*, COUNT(es.id) as subscription_count FROM events e LEFT JOIN event_subscriptions es ON es.event_id = e.id WHERE e.channel_id = ? @@ -82,20 +71,39 @@ if (isset($_GET['alias_id'])) { $channel['events'] = $stmt->fetchAll(PDO::FETCH_ASSOC); // fetching event names - $twitch_types = ['live', 'offline', 'title', 'category']; + $twitch_types = [0, 1, 2, 3, 8]; $channel_ids = []; foreach ($channel['events'] as &$e) { - $e['flags'] = json_decode($e['flags'], true); if (in_array($e['event_type'], $twitch_types)) { - array_push($channel_ids, $e['target_alias_id']); + array_push($channel_ids, $e['name']); } + + $e['event_type_translated'] = match ($e['event_type']) { + 0 => 'Live (Twitch)', + 1 => 'Offline (Twitch)', + 2 => 'Title change (Twitch)', + 3 => 'Game change (Twitch)', + 4 => 'Live (Kick)', + 5 => 'Offline (Kick)', + 6 => 'Title change (Kick)', + 7 => 'Game change (Kick)', + 8 => 'Chat message (Twitch)', + 10 => 'Emote creation (7TV)', + 11 => 'Emote deletion (7TV)', + 12 => 'Emote update (7TV)', + 13 => 'Emote creation (BTTV)', + 14 => 'Emote deletion (BTTV)', + 15 => 'Emote update (BTTV)', + 40 => 'GitHub', + default => 'Custom' + }; } unset($e); if (!empty($channel_ids)) { $event_users = get_twitch_users(implode('&id=', $channel_ids)); foreach ($event_users as $user) { foreach ($channel['events'] as &$e) { - if ($e['target_alias_id'] == $user['id']) { + if ($e['name'] == $user['id']) { $e['name'] = $user['login']; } } @@ -103,14 +111,6 @@ if (isset($_GET['alias_id'])) { } } - // translating features - foreach ($channel['features'] as &$f) { - if ($f == "notify_7tv_updates") { - $f = "7TV Updates"; - } - } - unset($f); - if ($response = get_twitch_users($channel['alias_id'])) { $user = $response[0]; $channel['pfp'] = $user['profile_image_url']; @@ -122,7 +122,7 @@ if (isset($_GET['alias_id'])) { http_response_code(403); exit; } else { - $stmt = $db->query('SELECT alias_id, alias_name FROM channels WHERE opt_outed_at IS NULL ORDER BY joined_at DESC'); + $stmt = $db->query('SELECT alias_id, alias_name FROM channels WHERE opted_out_at IS NULL ORDER BY joined_at DESC'); $stmt->execute(); $channels = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: []; @@ -175,18 +175,16 @@ if (!empty($channels)) {

Language:

Prefix:

+ +

Silent mode

+ - -
-

Features:

-
-

Joined ago

- +

Opted out!

@@ -200,12 +198,10 @@ if (!empty($channels)) { - - @@ -221,7 +217,7 @@ if (!empty($channels)) { Name Type Message - Flags + Massping Subscribers @@ -229,18 +225,15 @@ if (!empty($channels)) { - - + + - + - + - - - + @@ -256,19 +249,12 @@ if (!empty($channels)) { - - + - - +
NameMessagesLast executedMessage
- -

- -
-
@@ -283,18 +269,14 @@ if (!empty($channels)) { - + - + -- cgit v1.2.3
NameMessagesMessage Interval Last executed
- -

- -
ago