sm00th / bitlbee-discord

Bitlbee plugin for Discord (http://discordapp.com)
GNU General Public License v2.0
291 stars 27 forks source link

Status aliases broken - "/away DND - some text" works, "/away Busy - some text" does not #229

Closed digitalcircuit closed 2 years ago

digitalcircuit commented 2 years ago

In brief

Details

bitlbee-discord provides Bitlbee with a set of possible states:

static GList *discord_away_states(struct im_connection *ic)
{
    static GList *m = NULL;

    m = g_list_prepend(m, "invisible");
    m = g_list_prepend(m, "dnd");
    m = g_list_prepend(m, "online");
    m = g_list_prepend(m, "idle");

    return m;
}

From which Bitlbee should auto-select the closest alias:

static char *imc_away_alias_list[8][5] =
{
    { "Away from computer", "Away", "Extended away", NULL },
    { "NA", "N/A", "Not available", NULL },
    { "Busy", "Do not disturb", "DND", "Occupied", NULL },
    { "Be right back", "BRB", NULL },
    { "On the phone", "Phone", "On phone", NULL },
    { "Out to lunch", "Lunch", "Food", NULL },
    { "Invisible", "Hidden" },
    { NULL }
};

For whatever reason, this doesn't work, despite Busy and DND being on the same alias list.

Bitlbee's Jabber away list doesn't look too different, either:

const struct jabber_away_state jabber_away_state_list[] =
{
    { "away",  "Away" },
    { "chat",  "Free for Chat" },   /* WTF actually uses this? */
    { "dnd",   "Do not Disturb" },
    { "xa",    "Extended Away" },
    { "",      NULL }
};

And using /away Busy - resting after trip/etc works with Jabber.

Is it possibly a bug in the interaction with Bitlbee's alias parsing code…?

sm00th commented 2 years ago

Hm, that is odd. I don't have a bitlbee debug environment atm, but I've extracted relevant code chunks into a separate file(build with gcc -Wall -g -o imc_away_state_find imc_away_state_find.c $(pkg-config --cflags --libs glib-2.0)) and it seems to be working as intended:

$ ./imc_away_state_find "Busy - resting after trip"
away=DND
$ ./imc_away_state_find "DND - resting after trip"
away=dnd
digitalcircuit commented 2 years ago

Thank you for your time testing this!

Huh. I wonder if Discord's API is mandating lowercase dnd/etc in order to set status as Busy/Do Not Disturb.

When I have time in these upcoming days, I'll try throwing a GLib lowercase function into the outgoing Discord WebSocket status function to see if that fixes the issue.

digitalcircuit commented 2 years ago

I'm pretty confident this is why:

Busy alias

/away Busy - resting after trip (taking longer than predicted, thanks for patience

(I accidentally left off the ending ) when testing this time, that's not a bug)

[16:04:03] >>> (digitalcircuit) discord_ws_send_payload 166
{"op":3,"d":{"since":1641330243000,"game":{"name":"Busy - resting after trip (taking longer than predicted, thanks for patience","type":0},"afk":true,"status":"DND"}}

[16:04:03] <<< (digitalcircuit) discord_parse_message 1209
{"t":"GUILD_MEMBER_LIST_UPDATE","s":102,"op":0,"d":{"ops":[{"op":"UPDATE","item":…"presence":{"user":{"id":"…"},"status":"online","game":{"type":0,"session_id":null,"name":"Busy - resting after trip (taking longer than predicted, thanks for patience","id":"e78eefaaab722356","created_at":1641330243900},"client_status":{"web":"online"},"activities":[{"type":0,"name":"Busy - resting after trip (taking longer than predicted, thanks fo
r patience","id":"e78eefaaab722356","created_at":1641330243900},{"type":0,"name":"DND - resting after trip (taking longer than predicted, thanks for patience","id":"e74904c682bdc973","created_at":1641329384811}]},…]}}

"status":"DND""client_status":{"web":"online"}

DND direct

/away DND - resting after trip (taking longer than predicted, thanks for patience

[16:04:13] >>> (digitalcircuit) discord_ws_send_payload 165
{"op":3,"d":{"since":1641330253000,"game":{"name":"DND - resting after trip (taking longer than predicted, thanks for patience","type":0},"afk":true,"status":"dnd"}}

[16:04:14] <<< (digitalcircuit) discord_parse_message 1201
{"t":"GUILD_MEMBER_LIST_UPDATE","s":117,"op":0,"d":{"ops":[{"op":"UPDATE","item":{"member":{"user":{…},"status":"dnd","game":{"type":0,"session_id":null,"name":"DND - resting after trip (taking longer than predic
ted, thanks for patience","id":"b24973adb837dcfd","created_at":1641330253980},"client_status":{"web":"dnd"},"activities":[{"type":0,"name":"DND - resting after trip (taking longer than predicted, thanks for patien
ce","id":"b24973adb837dcfd","created_at":1641330253980},{"type":0,"name":"DND - resting after trip (taking longer than predicted, thanks for patience","id":"e74904c682bdc973","created_at":1641329384811}]},…]}}

"status":"dnd""client_status":{"web":"dnd"}

Working on a fix, not yet grasped GLib's method of doing things but I'll probably figure it out.

digitalcircuit commented 2 years ago

This has been fixed in Bitlbee itself as of https://github.com/bitlbee/bitlbee/commit/b82ba4a8d245e87090059ce1cd3500b514bd011e !

I'm closing this issue here. See https://github.com/sm00th/bitlbee-discord/pull/230 if you are stuck on old Bitlbee versions.