serenity-rs / songbird

An async Rust library for the Discord voice API
ISC License
394 stars 116 forks source link

Allow connection resumption on bot (re)start #113

Open FelixMcFelix opened 2 years ago

FelixMcFelix commented 2 years ago

A discord user raised that automatically rejoining all calls on connection might be useful, i.e., in event of a bot crash or other failure needing a restart. This feature would be configurable, and disabled by default.

There was some discussion on Discord on how this could be done from 2022-01-24:

FelixMcFelix — 24/01/2022
in config.rs: add a new field, gated by #[cfg(feature = "gateway-core")]. Default to false? You should also add a setter method to Config.

in manager.rs: modify impl VoiceGatewayManager (server_update, state_update) to check this new field in the config. If new field is true, do a get_or_insert (rather than get)? You need to make the same change to Songbird::process for twilight.

What I'm unclear on is what discord actually send you when the bot comes back up: if they send you both voice_state_update and voice_server_update then you need to set call.connection to Some(...) before the calls to Call::update_server and Call::update_state. If not, then you can probably just call Call::join with the received channel id. 
you might need to do some of your own testing on that last part
Since Config is non-exhaustive, this should be good for the current branch