sm00th / bitlbee-discord

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

websocket: Lowercase "status" state to fix aliases #230

Closed digitalcircuit closed 2 years ago

digitalcircuit commented 2 years ago

In brief

Details

Lowercase the status state provided by Bitlbee to fix handling aliases.

Doing /away DND - test would give dnd, but /away Busy - test would give DND from the alias list.

See sm00th's comment with a self-contained example:

$ ./imc_away_state_find "Busy - resting after trip"
away=DND
$ ./imc_away_state_find "DND - resting after trip"
away=dnd

Bitlbee plugin API

@dequis In the future, Bitlbee may want to change imc_away_state_find to match case with the plugin's provided away states?

If so, bitlbee-discord may want to keep this patch for some time until new Bitlbee versions have rolled out across distros.

Test case

Steps

  1. Run Bitlbee with debugging information
    • sudo --user=bitlbee BITLBEE_DEBUG=1 bitlbee -nvD
  2. Connect
  3. Clear any /away status (in Quassel IRC, use /back)
  4. Run /away DND - test, observe results
  5. Clear /away status
  6. Run /away Busy - test, observe results

Before

/away Busy - test

[16:04:03] >>> (digitalcircuit) discord_ws_send_payload 166
{"op":3,"d":{"since":1641330243000,"game":{"name":"Busy - test","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 - test","id":"e78eefaaab722356","created_at":1641330243900},"client_status":{"web":"online"},"activities":[{"type":0,"name":"Busy - test","id":"e78eefaaab722356","created_at":1641330243900},…]}}

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

After

/away Busy - test

[16:42:53] >>> (digitalcircuit) discord_ws_send_payload 115
{"op":3,"d":{"since":1641332573000,"game":{"name":"Busy - test","type":0},"afk":true,"status":"dnd"}}

[16:42:53] <<< (digitalcircuit) discord_parse_message 954
{"t":"GUILD_MEMBER_LIST_UPDATE","s":148,"op":0,"d":{"ops":[{"op":"UPDATE","item":{"presence":{"user":{"status":"dnd","game":{"type":0,"session_id":null,"name":"Busy - test","id":"e1d494c83a244256","created_at":1641332573548},"client_status":{"web":"dnd"},"activities":[{"type":0,"name":"Busy - test","id":"e1d494c83a244256","created_at":1641332573548}]}]}}

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

sm00th commented 2 years ago

Hi, first of all thanks for getting the issue to this stage. It is nice to have people contributing code.

As you mention the solution is a bit hacky. I was wondering whether we can fix this (and any similar potential problems in other protocols) in bitlbee itself by something like this:

diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index de954e34..7e029944 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -836,7 +836,7 @@ static char *imc_away_state_find(GList *gcm, char *away, char **message)
                                                *message = NULL;
                                        }

-                                       return imc_away_alias_list[i][j];
+                                       return m->data;
                                }
                        }
                }

This makes sure imc_away_state_find() returns what protocols expects, casing intact. @dequis what do you think?

digitalcircuit commented 2 years ago

That approach makes more sense to me, too.

It is technically changing Bitlbee's plugin API, but it's to something that (in my opinion) is more consistent and intuitive, so it may be fine. As both of us mentioned dx, I'm guessing we should wait a bit for feedback. And maybe file a pull request on Bitlbee if no negative signal is heard for a while.

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 pull request here, though others may find it useful if they are stuck on old Bitlbee versions.