prepare('SELECT c.*, cp.*, array_to_json(cp.features) as features FROM channels c LEFT JOIN channel_preferences cp ON cp.id = c.id WHERE c.alias_id = ? '); $stmt->execute([$_GET['alias_id']]); $channel = $stmt->fetch(PDO::FETCH_ASSOC) ?: null; if (!isset($channel)) { http_response_code(404); exit; } $channel['features'] = json_decode($channel['features'] ?: '[]', true); // fetching custom commands $stmt = $db->prepare('SELECT *, array_to_json(messages) as messages 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 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 FROM events e LEFT JOIN event_subscriptions es ON es.event_id = e.id WHERE e.channel_id = ? GROUP BY e.id ORDER BY subscription_count DESC '); $stmt->execute([$channel['id']]); $channel['events'] = $stmt->fetchAll(PDO::FETCH_ASSOC); // fetching event names $twitch_types = ['live', 'offline', 'title', 'category']; $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']); } } 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']) { $e['name'] = $user['login']; } } unset($e); } } // 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']; $channel['description'] = $user['description'] ?: null; } $has_content = !empty($channel['events']) || !empty($channel['commands']) || !empty($channel['timers']); } else if (!SHOW_CHANNEL_LIST) { 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->execute(); $channels = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: []; } // fetching user pfps if (!empty($channels)) { $channel_ids = []; foreach ($channels as $c) { array_push($channel_ids, $c['alias_id']); } $response = get_twitch_users(implode('&id=', $channel_ids)); if (!empty($response)) { foreach ($response as $c) { $index = array_search($c['id'], array_column($channels, 'alias_id')); $channels[$index]['pfp'] = $c['profile_image_url']; } } } ?> Channels - The Tinybot Project

About

Language:

Prefix:

Features:

Joined ago

Opted out!

Events


Name Type Message Flags Subscribers

Custom commands


Name Messages Last executed

Timers


Name Messages Interval Last executed

ago

Nothing found...

No one has joined yet... ;(

Be the first one!

channels have already joined us

Check out the !join command to participate!