sleepy-discord icon indicating copy to clipboard operation
sleepy-discord copied to clipboard

updateStatus not working

Open Panakotta00 opened this issue 6 years ago • 3 comments

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

Panakotta00 avatar Apr 17 '18 13:04 Panakotta00

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?

yourWaifu avatar Apr 19 '18 00:04 yourWaifu

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.

TylerTheFox avatar Apr 19 '18 09:04 TylerTheFox

it's only as an example an a fast workaround

Panakotta00 avatar May 16 '18 13:05 Panakotta00