yourWaifu / sleepy-discord

C++ library for the Discord chat client. Please use Rust for new bots
https://yourWaifu.github.io/sleepy-discord/
MIT License
707 stars 92 forks source link

updateStatus not working #69

Open Panakotta00 opened 6 years ago

Panakotta00 commented 6 years ago

Hey, when I use updateStatus, the server disconnects, because he doesn't know that opcode.

The problem is, the discord team has updated the version 6 of the gateway.

Here is my solution code:

enum GameType {
    game = 0,
    streaming = 1,
    listening = 2
};

enum Status {
    online = 0,
    dnd = 1,
    idle = 2,
    invisible = 3,
    offline = 4
};

std::map<int, std::string> statusMap = { { 0, "online" }, { 1, "dnd" }, { 2, "idle" }, { 3, "invisble" }, { 4, "offline"} };

void BaseDiscordClient::updateStatus(std::string gameName, GameType gameType, Status status, bool afk, uint64_t idleSince) {
    sendL(SleepyDiscord::json::createJSON({
        { "op", SleepyDiscord::json::integer(STATUS_UPDATE) },
        { "d", SleepyDiscord::json::createJSON({
            { "since", idleSince != 0 ? SleepyDiscord::json::UInteger(idleSince) : "null" },
            { "game", gameName != "" ? SleepyDiscord::json::createJSON({
                { "name", SleepyDiscord::json::string(gameName) },
                { "type", SleepyDiscord::json::integer(gameType)}
            }) : "null" },
            { "status", SleepyDiscord::json::string(statusMap[status]) },
            { "afk", SleepyDiscord::json::boolean(afk) }
        }) }
    }));
}

BUT please add the streaming url to the game tab

yourWaifu commented 6 years ago

ok thanks for telling, sorry I wasn't aware. However, is there a reason you are using a map with global scope instead of an array?

TylerTheFox commented 6 years ago

Only reason I can think of is he didn't want to check if status < 5. If Discord API adds another status that would be an illegal read. Other than that std::array will probably work which has bounds checking in debug mode.

Panakotta00 commented 6 years ago

it's only as an example an a fast workaround