first commit
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
$cacheFile = DATA_DIR . '/lanyard.json';
|
||||
$ttl = 4;
|
||||
|
||||
if (!is_file($cacheFile) || time() - filemtime($cacheFile) > $ttl) {
|
||||
$ch = curl_init('https://api.lanyard.rest/v1/users/' . DISCORD_ID);
|
||||
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 4]);
|
||||
$res = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
if ($res) {
|
||||
@mkdir(DATA_DIR, 0755, true);
|
||||
file_put_contents($cacheFile, $res);
|
||||
}
|
||||
}
|
||||
|
||||
$data = json_decode(@file_get_contents($cacheFile), true)['data'] ?? null;
|
||||
$status = $data['discord_status'] ?? 'offline';
|
||||
$spotify = ($data['listening_to_spotify'] ?? false) ? $data['spotify'] : null;
|
||||
|
||||
$user = $data['discord_user'] ?? [];
|
||||
$did = $user['id'] ?? DISCORD_ID;
|
||||
$name = $user['global_name'] ?? $user['username'] ?? '';
|
||||
|
||||
$avatarHash = $user['avatar'] ?? null;
|
||||
$avatar = $avatarHash
|
||||
? "https://cdn.discordapp.com/avatars/$did/$avatarHash." . (str_starts_with($avatarHash, 'a_') ? 'gif' : 'png') . '?size=128'
|
||||
: 'https://cdn.discordapp.com/embed/avatars/0.png';
|
||||
|
||||
$bannerHash = $user['banner'] ?? null;
|
||||
$banner = $bannerHash
|
||||
? "https://cdn.discordapp.com/banners/$did/$bannerHash." . (str_starts_with($bannerHash, 'a_') ? 'gif' : 'png') . '?size=480'
|
||||
: null;
|
||||
?>
|
||||
<div class="status-card"<?= $banner ? ' style="background-image:url(\'' . htmlspecialchars($banner) . '\')"' : '' ?>>
|
||||
<img class="avatar" src="<?= htmlspecialchars($avatar) ?>" alt="" width="56" height="56" loading="lazy">
|
||||
<div class="who">
|
||||
<span class="name"><?= htmlspecialchars($name) ?></span>
|
||||
<span class="state"><span class="dot dot-<?= htmlspecialchars($status) ?>"></span> <?= htmlspecialchars($status) ?></span>
|
||||
<?php if ($spotify): ?>
|
||||
<span class="now-playing">♪ <?= htmlspecialchars($spotify['song']) ?> — <?= htmlspecialchars($spotify['artist']) ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user