true, CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_TIMEOUT => 3, ]); $res = curl_exec($ch); curl_close($ch); if ($res) { @mkdir(DATA_DIR, 0755, true); file_put_contents($cacheFile, $res, LOCK_EX); } } } $isPoll = realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__; $stale = !is_file($cacheFile) || (time() - filemtime($cacheFile) > $ttl); if ($stale && ($isPoll || !is_file($cacheFile))) { lanyard_refresh($cacheFile); } $data = json_decode(@file_get_contents($cacheFile), true)['data'] ?? null; $status = $data['discord_status'] ?? 'offline'; $spotify = ($data['listening_to_spotify'] ?? false) ? $data['spotify'] : null; // Discord can lag clearing the Spotify activity after playback stops, leaving a // stale "ghost" track. If the song's end time has already passed, treat it as stopped. if ($spotify && !empty($spotify['timestamps']['end']) && $spotify['timestamps']['end'] < time() * 1000) { $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; ?>
>
discord
♪ listening on spotify
spotify nothing playing not listening right now