deathandmayhem / jolly-roger

Dead men tell no tales!
MIT License
18 stars 5 forks source link

Discord fails to refresh after initial configuration until server restart #2116

Open jpd236 opened 2 months ago

jpd236 commented 2 months ago

I've tested the following sequence of events twice now:

I'd expect the lists of Discord channels to be populated there for the various selectors, but they're empty, even after a few minutes. Upon restarting the server the lists are populated immediately.

I see there is an observer for changes to the "disable.discord" flag here which I'd expect to trigger the refresh loop upon completing configuration.

ebroder commented 1 month ago

For reference, the relevant watcher is actually the one just above the disable.discord one: https://github.com/deathandmayhem/jolly-roger/blob/914135fd39c5e8cdab742ecfeba4502333e556bd/imports/server/discordClientRefresher.ts#L32-L37

That causes JR to establish a gateway connection to Discord, and it then listens for various change events that get delivered over the connection. It also does an initial cache of the data at startup time (because you don't get an individual channelCreate event for every channel when you first connect, which is why this works after restarting the server.

However, it looks like getting added to a guild doesn't trigger (e.g.) channelCreate messages for the channels in the guild. Instead (looking at docs), it seems like channels and roles are included in the guildCreate event, so we need to break those out somehow.

I think the cacheResource logic further down is maybe a little too clever to easily adapt to this, but that would basically be the place to start improving the behavior here.