Module: OnyxCord::Bot::VoiceControl
- Included in:
- OnyxCord::Bot
- Defined in:
- lib/onyxcord/core/bot/voice.rb
Instance Attribute Summary collapse
-
#voices ⇒ Hash<Integer => Client>
readonly
The voice connections this bot currently has, by the server ID to which they are connected.
Instance Method Summary collapse
-
#voice(thing) ⇒ Voice::Client?
Gets the voice bot for a particular server or channel.
-
#voice_connect(chan, encrypted = true) ⇒ Voice::Client
Connects to a voice channel, initializes network connections and returns the Voice::Client over which audio data can then be sent.
-
#voice_destroy(server, destroy_vws = true) ⇒ Object
Disconnects the client from a specific voice connection given the server ID.
Instance Attribute Details
#voices ⇒ Hash<Integer => Client> (readonly)
Returns the voice connections this bot currently has, by the server ID to which they are connected.
7 8 9 |
# File 'lib/onyxcord/core/bot/voice.rb', line 7 def voices @voices end |
Instance Method Details
#voice(thing) ⇒ Voice::Client?
Gets the voice bot for a particular server or channel. You can connect to a new channel using the #voice_connect method.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/onyxcord/core/bot/voice.rb', line 13 def voice(thing) id = thing.resolve_id return @voices[id] if @voices[id] channel = channel(id) return nil unless channel server_id = channel.server.id return @voices[server_id] if @voices[server_id] end |
#voice_connect(chan, encrypted = true) ⇒ Voice::Client
Connects to a voice channel, initializes network connections and returns the Voice::Client over which audio data can then be sent. After connecting, the bot can also be accessed using #voice. If the bot is already connected to voice, the existing connection will be terminated - you don't have to call Voice::Client#destroy before calling this method.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/onyxcord/core/bot/voice.rb', line 32 def voice_connect(chan, encrypted = true) raise ArgumentError, 'Unencrypted voice connections are no longer supported.' unless encrypted chan = channel(chan.resolve_id) server_id = chan.server.id if @voices[chan.id] debug('Voice bot exists already! Destroying it') @voices[chan.id].destroy @voices.delete(chan.id) end debug("Got voice channel: #{chan}") @should_connect_to_voice[server_id] = chan @gateway.send_voice_state_update(server_id.to_s, chan.id.to_s, false, false) debug('Voice channel init packet sent! Now waiting.') Internal::AsyncRuntime.sleep(0.05) until @voices[server_id] debug('Voice connect succeeded!') @voices[server_id] end |
#voice_destroy(server, destroy_vws = true) ⇒ Object
Disconnects the client from a specific voice connection given the server ID. Usually it's more convenient to use Voice::Client#destroy rather than this.
61 62 63 64 65 66 |
# File 'lib/onyxcord/core/bot/voice.rb', line 61 def voice_destroy(server, destroy_vws = true) server = server.resolve_id @gateway.send_voice_state_update(server.to_s, nil, false, false) @voices[server].destroy if @voices[server] && destroy_vws @voices.delete(server) end |