Phineas / lanyard

🏷️   Expose your Discord presence and activities to a RESTful API and WebSocket in less than 10 seconds
https://discord.gg/lanyard
MIT License
1k stars 142 forks source link

Discord Status #200

Closed hellomikko closed 1 year ago

hellomikko commented 1 year ago

So im having an issue with the "discord_status":"..." not showing up correctly and I have as my snippet:

                {#if userPresence.discord_status === 'offline'}
                    <br />
                    Offline
                {:else}
                    <div
                        class="inline-block text-sm drop-shadow-3xl shadow-orange-300/50 bg-gradient-to-r from-blue-500/[.15] ring-2 ring-orange-800/95 rounded-md p-3 -ml-6"
                    >
                        {#if userPresence.discord_status === 'idle'}
                            🟑 Idle&nbsp;&nbsp;
                        {:else if userPresence.discord_status === 'dnd'}
                            🟠 Do Not Disturb&nbsp;&nbsp;
                        {:else}
                            🟒 Online&nbsp;
                        {/if} 

and my <script></script> is:

    // check if the user is currently in VSCode
    $: inVSCode =
        userPresence?.data?.discord_status == 'dnd' &&
        userPresence?.data?.activities?.find((activity) => activity?.name == 'Visual Studio Code');

    // get the icon to display based on whether the user is listening to Spotify or coding in VSCode
    $: statusIcon = inVSCode ? VSCODE_ICON : currentActivity ? SPOTIFY_ICON : null;

    // check if the user is online or idle
    $: isOnline =
        userPresence?.discord_status === 'online' || userPresence?.discord_status === 'idle';

    // get the details of the user's current VSCode session
    $: vsCodeSession = userPresence?.data?.activities?.find(
        (activity) => activity?.name === 'Visual Studio Code'
    );

    // get the name and ID of the current file being edited
    $: fileName = vsCodeSession?.details?.match(/(?<=πŸ“\s).+(?=\s\|)/)?.[0];
    $: fileId = vsCodeSession?.id;

    // get the line number being edited
    $: lineNum = vsCodeSession?.details?.match(/(?<=πŸ“ Editing line ).+(?=\/)/)?.[0] ?? '';

    // construct the status message to display
    $: statusMessage =
        isOnline && inVSCode && fileName && lineNum
            ? `Editing ${fileName} on line ${lineNum} in VSCode`
            : isOnline && currentActivity
            ? `Listening to ${currentSong}`
            : 'Offline';

So when I manually change the status to test it, it works via lanyard api and shows the correct status but, it change on my webpage.

Is anyone else having this issue or is it just me?

hellomikko commented 1 year ago

Also not to mention it shows im Editing line 75/625 for like an hour and im using the LeonardSSH.vscord extension on vscode.

hueodev commented 1 year ago

This works for me but replace it with your values

{#if $data && $data.discord_status === "online"}
  <p>Online</p>
{:else if $data && $data.discord_status === "offline"}
  <p>Offline</p>
{:else}
   <p>Do not disturb</p>
{/if}
hellomikko commented 1 year ago

Thanks, Ill give it a try here in a min or two, just in for work. Thanks for you comment! πŸ‘πŸΎ

hellomikko commented 1 year ago

Ive tried that and it still dont update the discord_status at all. I even change my status left and right on purpose to see each time and it dosnt work no matter what from https://api.lanyard.rest/v1/users/625796542456004639. But when I go to @eggsy's doc it works on the fly on https://lanyard.eggsy.xyz/. This crap is giving me gray hairs without tailwind too:

SEE THE BOTTOM REPLY TO THE SCRIPT THERE

{#if userPresence.discord_status === 'online'}
    🟒 Online&nbsp;&nbsp;
{:else if userPresence.discord_status === 'idle'}
    🟑 Idle&nbsp;&nbsp;
{:else if userPresence.discord_status === 'dnd'}
    🟠 Do Not Disturb&nbsp;&nbsp;
{:else}
    <span class="text-gray-500">&#9899;</span> Offline&nbsp;
{/if}

That is what I have and the only thing thats working is the spotify. But for some damn reason the discord_status is not working and theres not 1 person in the svelte community or here even to help.

hellomikko commented 1 year ago

What does the discord_status label under anyways?

Also here is the full code I was using https://sourceb.in/R1nGgMPZzG

hueodev commented 1 year ago

Use this one instead https://github.com/iGalaxyYT/svelte-lanyard

hueodev commented 1 year ago

Did you do this?

{#if $userPresence && $userPresence.discord_status === "online"}
  <p>Online</p>
{:else if $userPresence && $userPresence.discord_status === "offline"}
  <p>Offline</p>
{:else}
   <p>Do not disturb</p>
{/if}
hellomikko commented 1 year ago

Sorry I've been away guys and I do thank you for your cooperation and help. @Ogooooo , I used the code you gave me which didnt work but I reworked and and got something else that will work. You can see it here which is similar to what you and I both have: https://codesandbox.io/s/svelte-lanyard-demo-forked-qtflmc?file=/App.svelte.

I see that lanyard uses data but my blog posts uses data as well. its like a IP Conflict if you know what I mean. So I had to rename something, or both in order for it to work and not cause any conflicts. Thank you guys and I will use that. :) You can see the my page for the live version https://mikko.codes. Again, I do appreciate everyone's help even if you responded and I did not mentioned your name.

hueodev commented 1 year ago

πŸ‘