summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoderndevslulw <moderndevslulw@alright.party>2025-07-08 17:16:54 +0500
committermoderndevslulw <moderndevslulw@alright.party>2025-07-08 17:16:54 +0500
commitc81c9922de026904c7b6f3fb55ac36c0e59899ac (patch)
treebab32ae38dfae9e95bfe70cae46fb012c43df88e
parent28863f40a7f9ffc8e59e0c3587cbc5938a683342 (diff)
feat: big changes and fixes in channels
-rw-r--r--public/channels/index.php102
1 files changed, 42 insertions, 60 deletions
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)) {
<p>Language: <img src="/static/img/icons/flags/<?= $channel['language'] ?>.png" alt="">
<?= ucfirst($channel['language']) ?></p>
<p>Prefix: <b><?= $channel['prefix'] ?></b></p>
+ <?php if ($channel['silent_mode']): ?>
+ <p>Silent mode</p>
+ <?php endif; ?>
</div>
- <?php if (!empty($channel['features'])): ?>
- <div class="row gap-16 font-small">
- <p>Features: <b><?= implode(', ', $channel['features']) ?></b></p>
- </div>
- <?php endif; ?>
</div>
<div class="column gap-8">
<p><img src="/static/img/icons/door_in.png" alt=""> Joined
<?= format_timestamp(time() - strtotime($channel['joined_at'])) ?> ago
</p>
- <?php if (isset($channel['opt_outed_at'])): ?>
+ <?php if (isset($channel['opted_out_at'])): ?>
<p class="red box text-center"><img src="/static/img/icons/door_out.png" alt=""> Opted out!</p>
<?php endif; ?>
</div>
@@ -200,12 +198,10 @@ if (!empty($channels)) {
<button class="tab" id="events-button">Events</button>
<?php endif; ?>
<?php if (!empty($channel['commands'])): ?>
-
<button class="tab" id="commands-button">Custom commands</button>
<?php endif; ?>
<?php if (!empty($channel['timers'])): ?>
-
<button class="tab" id="timers-button">Timers</button>
<?php endif; ?>
@@ -221,7 +217,7 @@ if (!empty($channels)) {
<th>Name</th>
<th>Type</th>
<th>Message</th>
- <th>Flags</th>
+ <th>Massping</th>
<th>Subscribers</th>
</tr>
<?php foreach ($channel['events'] as $e): ?>
@@ -229,18 +225,15 @@ if (!empty($channels)) {
<td>
<?php if (in_array($e['event_type'], $twitch_types)): ?>
<a href="https://twitch.tv/<?= $e['name'] ?>"><?= $e['name'] ?></a>
- <?php elseif ($e['event_type'] == 'github'): ?>
- <a
- href="https://github.com/<?= $e['custom_alias_id'] ?>"><?= $e['custom_alias_id'] ?></a>
+ <?php elseif ($e['event_type'] == 40): ?>
+ <a href="https://github.com/<?= $e['name'] ?>"><?= $e['name'] ?></a>
<?php else: ?>
- <?= $e['custom_alias_id'] ?>
+ <?= $e['name'] ?>
<?php endif; ?>
</td>
- <td><?= $e['event_type'] ?></td>
+ <td><?= $e['event_type_translated'] ?></td>
<td><?= $e['message'] ?></td>
- <td>
- <?= empty($e['flags']) ? '-' : implode(', ', $e['flags']) ?>
- </td>
+ <td><?= $e['is_massping'] ? '✅' : '❌' ?></td>
<td><?= $e['subscription_count'] ?></td>
</tr>
<?php endforeach; ?>
@@ -256,19 +249,12 @@ if (!empty($channels)) {
<table>
<tr>
<th>Name</th>
- <th>Messages</th>
- <th>Last executed</th>
+ <th>Message</th>
</tr>
<?php foreach ($channel['commands'] as $c): ?>
<tr>
<td><?= $c['name'] ?></td>
- <td class="column">
- <?php foreach ($c['messages'] as $m): ?>
- <p><?= $m ?></p>
- <?php endforeach; ?>
- </td>
- <td><?= isset($c['last_executed_at']) ? format_timestamp(time() - strtotime($c['last_executed_at'])) . ' ago' : '-' ?>
- </td>
+ <td><?= $c['message'] ?></td>
</tr>
<?php endforeach; ?>
</table>
@@ -283,18 +269,14 @@ if (!empty($channels)) {
<table>
<tr>
<th>Name</th>
- <th>Messages</th>
+ <th>Message</th>
<th>Interval</th>
<th>Last executed</th>
</tr>
<?php foreach ($channel['timers'] as $t): ?>
<tr>
<td><?= $t['name'] ?></td>
- <td class="column">
- <?php foreach ($t['messages'] as $m): ?>
- <p><?= $m ?></p>
- <?php endforeach; ?>
- </td>
+ <td><?= $t['message'] ?> </td>
<td><?= format_timestamp($t['interval_sec']) ?></td>
<td><?= format_timestamp(time() - strtotime($t['last_executed_at'])) ?> ago</td>
</tr>