diff options
| author | Fuwn <[email protected]> | 2020-10-29 23:50:10 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2020-10-29 23:50:10 -0700 |
| commit | c20c9a59a1d487286116809856497fa089781659 (patch) | |
| tree | 9be2c51c61ec355df471d1d6fc3b809d354e64c4 /src/modules | |
| parent | feat, annotate, chore (desc) (diff) | |
| download | dep-core-next-c20c9a59a1d487286116809856497fa089781659.tar.xz dep-core-next-c20c9a59a1d487286116809856497fa089781659.zip | |
feat, chore, doc
feat:
- implement rocket webserver (switch to rust nightly)
- implement basic voice handling (outdated as i will probably be adding lavalink soon)
chore:
- specify rust toolchain in `rust-toolchain` file.
- tidy up code a tiny bit
doc:
- add cc enviroment variables to file for future reference.
- thicken readme.md (useless tbh)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/commands/general/mod.rs | 4 | ||||
| -rw-r--r-- | src/modules/commands/general/voice.rs | 108 |
2 files changed, 112 insertions, 0 deletions
diff --git a/src/modules/commands/general/mod.rs b/src/modules/commands/general/mod.rs index acff760..ce87755 100644 --- a/src/modules/commands/general/mod.rs +++ b/src/modules/commands/general/mod.rs @@ -5,6 +5,7 @@ pub mod nsfw; pub mod fun; pub mod utilities; pub mod animals; +// pub mod voice; use self::misc::*; use self::nsfw::*; @@ -13,6 +14,7 @@ use self::nsfw::*; use self::fun::*; use self::utilities::*; use self::animals::*; +// use self::voice::*; use serenity::framework::standard::CreateGroup; pub fn init_animals() -> CreateGroup { @@ -119,4 +121,6 @@ pub fn init_utilities() -> CreateGroup { .cmd("user", UserInfo) // .cmd("weather", Weather) .cmd("wisp", Wisp) + // .cmd("join", Join) + // .cmd("leave", Leave) } diff --git a/src/modules/commands/general/voice.rs b/src/modules/commands/general/voice.rs new file mode 100644 index 0000000..1849f78 --- /dev/null +++ b/src/modules/commands/general/voice.rs @@ -0,0 +1,108 @@ +// use crate::core::model::ApiClient; +// use crate::core::consts::*; +use crate::core::model::*; +use serenity::framework::standard::{ + Args, + Command, + CommandError, + CommandOptions +}; +use serenity::model::channel::Message; +use serenity::prelude::Context; +use std::sync::Arc; + +pub struct Join; +impl Command for Join { + fn options(&self) -> Arc<CommandOptions> { + let default = CommandOptions::default(); + let options = CommandOptions { + // desc: Some("I see your a individual of culture...".to_string()), + // usage: Some("[tags]".to_string()), + // example: Some("minecraft".to_string()), + guild_only: true, + owner_privileges: false, + ..default + }; + Arc::new(options) + } + + fn execute(&self, ctx: &mut Context, message: &Message, _args: Args) -> Result<(), CommandError> { + // if not deafened, ask to please deeafen + let channel_id = message.guild().unwrap().read() + .voice_states.get(&message.author.id) + .and_then(|voice_state| voice_state.channel_id); + + let connect_to = match channel_id { + Some(channel) => channel, + None => { + message.channel_id.say("You aren't in a voice channel...")?; + + return Ok(()) + } + }; + + let manager_lock = ctx.data.lock().get::<VoiceManager>().cloned() + .expect("Expected VoiceManager in ShareMap."); // mut + let mut manager = manager_lock.lock(); + let has_handler = manager.get(message.guild().unwrap().read().id).is_some(); + + if has_handler { + message.channel_id.say(format!("Sorry, but I'm already in <#{}>.", connect_to))?; + } else { + if manager.join(message.guild().unwrap().read().id, connect_to).is_some() { + message.channel_id.say(format!("I'm now in <#{}>.", connect_to))?; + } else { + message.channel_id.say("I've encountered an error while trying to join your voice channel.")?; + } + } + + Ok(()) + } +} + +pub struct Leave; +impl Command for Leave { + fn options(&self) -> Arc<CommandOptions> { + let default = CommandOptions::default(); + let options = CommandOptions { + // desc: Some("I see your a individual of culture...".to_string()), + // usage: Some("[tags]".to_string()), + // example: Some("minecraft".to_string()), + guild_only: true, + owner_privileges: false, + ..default + }; + Arc::new(options) + } + + fn execute(&self, ctx: &mut Context, message: &Message, _args: Args) -> Result<(), CommandError> { + let channel_id = message.guild().unwrap().read() + .voice_states.get(&message.author.id) + .and_then(|voice_state| voice_state.channel_id); + + let connect_to = match channel_id { + Some(channel) => channel, + None => { + message.channel_id.say("You aren't in a voice channel... Only the people within a given voice channel can make me leave.")?; + + return Ok(()) + } + }; + + let manager_lock = ctx.data.lock().get::<VoiceManager>().cloned() + .expect("Expected VoiceManager in ShareMap."); // mut + let mut manager = manager_lock.lock(); + let has_handler = manager.get(message.guild().unwrap().read().id).is_some(); + + if has_handler { + manager.remove(message.guild().unwrap().read().id); + + message.channel_id.say(format!("I've left <#{:?}>.", + manager.get(message.guild().unwrap().read().id)))?; + } else { + message.channel_id.say("Sorry, but I'm not in a voice channel right now.")?; + } + + Ok(()) + } +} |