Voice Rework -- Events, Track Queues (#806)

This implements a proof-of-concept for an improved audio frontend. The largest change is the introduction of events and event handling: both by time elapsed and by track events, such as ending or looping. Following on from this, the library now includes a basic, event-driven track queue system (which people seem to ask for unusually often). A new sample, `examples/13_voice_events`, demonstrates both the `TrackQueue` system and some basic events via the `~queue` and `~play_fade` commands.

Locks are removed from around the control of `Audio` objects, which should allow the backend to be moved to a more granular futures-based backend solution in a cleaner way.
This commit is contained in:
Kyle Simpson
2020-10-29 20:25:20 +00:00
committed by Alex M. M
commit 7e4392ae68
76 changed files with 8756 additions and 0 deletions

121
src/id.rs Normal file
View File

@@ -0,0 +1,121 @@
//! Newtypes around Discord IDs for library cross-compatibility.
#[cfg(feature = "driver")]
use crate::model::id::{GuildId as DriverGuild, UserId as DriverUser};
#[cfg(feature = "serenity")]
use serenity::model::id::{
ChannelId as SerenityChannel,
GuildId as SerenityGuild,
UserId as SerenityUser,
};
use std::fmt::{Display, Formatter, Result as FmtResult};
#[cfg(feature = "twilight")]
use twilight_model::id::{
ChannelId as TwilightChannel,
GuildId as TwilightGuild,
UserId as TwilightUser,
};
/// ID of a Discord voice/text channel.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub struct ChannelId(pub u64);
/// ID of a Discord guild (colloquially, "server").
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub struct GuildId(pub u64);
/// ID of a Discord user.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub struct UserId(pub u64);
impl Display for ChannelId {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
Display::fmt(&self.0, f)
}
}
impl From<u64> for ChannelId {
fn from(id: u64) -> Self {
Self(id)
}
}
#[cfg(feature = "serenity")]
impl From<SerenityChannel> for ChannelId {
fn from(id: SerenityChannel) -> Self {
Self(id.0)
}
}
#[cfg(feature = "twilight")]
impl From<TwilightChannel> for ChannelId {
fn from(id: TwilightChannel) -> Self {
Self(id.0)
}
}
impl Display for GuildId {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
Display::fmt(&self.0, f)
}
}
impl From<u64> for GuildId {
fn from(id: u64) -> Self {
Self(id)
}
}
#[cfg(feature = "serenity")]
impl From<SerenityGuild> for GuildId {
fn from(id: SerenityGuild) -> Self {
Self(id.0)
}
}
#[cfg(feature = "driver")]
impl From<GuildId> for DriverGuild {
fn from(id: GuildId) -> Self {
Self(id.0)
}
}
#[cfg(feature = "twilight")]
impl From<TwilightGuild> for GuildId {
fn from(id: TwilightGuild) -> Self {
Self(id.0)
}
}
impl Display for UserId {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
Display::fmt(&self.0, f)
}
}
impl From<u64> for UserId {
fn from(id: u64) -> Self {
Self(id)
}
}
#[cfg(feature = "serenity")]
impl From<SerenityUser> for UserId {
fn from(id: SerenityUser) -> Self {
Self(id.0)
}
}
#[cfg(feature = "driver")]
impl From<UserId> for DriverUser {
fn from(id: UserId) -> Self {
Self(id.0)
}
}
#[cfg(feature = "twilight")]
impl From<TwilightUser> for UserId {
fn from(id: TwilightUser) -> Self {
Self(id.0)
}
}