diff options
| author | Jokler <jokler@protonmail.com> | 2020-02-22 18:57:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-22 18:57:12 +0100 |
| commit | 2792ba9c8a7120a91b3bd2c6075e737690e73405 (patch) | |
| tree | 5bc007e03ef7782bbfeeb81ca936c97c992be1a2 /src | |
| parent | 00b60b8f210b93a5d6cbdde2bc98feff2f2ec1ca (diff) | |
| parent | dbaaeb68bdf4143b9dca55b2baa86a2656a3249e (diff) | |
| download | pokebot-2792ba9c8a7120a91b3bd2c6075e737690e73405.tar.gz pokebot-2792ba9c8a7120a91b3bd2c6075e737690e73405.zip | |
Merge pull request #37 from Mavulp/branches/fkaa/BBCode
Add functions for BBCode formatting
Diffstat (limited to 'src')
| -rw-r--r-- | src/bot/music.rs | 9 | ||||
| -rw-r--r-- | src/teamspeak/bbcode.rs | 42 | ||||
| -rw-r--r-- | src/teamspeak/mod.rs (renamed from src/teamspeak.rs) | 4 |
3 files changed, 51 insertions, 4 deletions
diff --git a/src/bot/music.rs b/src/bot/music.rs index 75e61de..2539695 100644 --- a/src/bot/music.rs +++ b/src/bot/music.rs @@ -12,8 +12,9 @@ use tsclientlib::{data, ChannelId, ClientId, ConnectOptions, Identity, Invoker, use crate::audio_player::{AudioPlayer, AudioPlayerError, PollResult, Seek}; use crate::command::Command; use crate::playlist::Playlist; -use crate::teamspeak::TeamSpeakConnection; +use crate::teamspeak as ts; use crate::youtube_dl::AudioMetadata; +use ts::TeamSpeakConnection; #[derive(Debug)] pub struct Message { @@ -173,7 +174,7 @@ impl MusicBot { fn start_playing_audio(&self, metadata: AudioMetadata) { if let Some(title) = metadata.title { - self.send_message(&format!("Playing '{}'", title)); + self.send_message(&format!("Playing {}", ts::underline(&title))); self.set_description(&format!("Currently playing '{}'", title)); } else { self.send_message("Playing unknown title"); @@ -198,7 +199,7 @@ impl MusicBot { } } else { if let Some(title) = metadata.title { - self.send_message(&format!("Added '{}' to playlist", title)); + self.send_message(&format!("Added {} to playlist", ts::underline(&title))); } else { self.send_message("Added to playlist"); } @@ -293,7 +294,7 @@ impl MusicBot { Command::Seek { amount } => { if let Ok(seek) = parse_seek(&amount) { if let Ok(time) = self.player.seek(seek) { - self.send_message(&format!("New position: {}", time)); + self.send_message(&format!("New position: {}", ts::bold(&time))); } else { self.send_message("Failed to seek"); } diff --git a/src/teamspeak/bbcode.rs b/src/teamspeak/bbcode.rs new file mode 100644 index 0000000..28be08a --- /dev/null +++ b/src/teamspeak/bbcode.rs @@ -0,0 +1,42 @@ +use std::fmt::{Formatter, Display, Error}; + +#[allow(dead_code)] +pub enum BbCode<'a> { + Bold(&'a dyn Display), + Italic(&'a dyn Display), + Underline(&'a dyn Display), + Link(&'a dyn Display, &'a str), +} + +impl<'a> Display for BbCode<'a> { + fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { + match self { + BbCode::Bold(text) => fmt.write_fmt(format_args!("[B]{}[/B]", text))?, + BbCode::Italic(text) => fmt.write_fmt(format_args!("[I]{}[/I]", text))?, + BbCode::Underline(text) => fmt.write_fmt(format_args!("[U]{}[/U]", text))?, + BbCode::Link(text, url) => fmt.write_fmt(format_args!("[URL={}]{}[/URL]", url, text))?, + }; + + Ok(()) + } +} + +#[allow(dead_code)] +pub fn bold(text: &dyn Display) -> BbCode { + BbCode::Bold(text) +} + +#[allow(dead_code)] +pub fn italic(text: &dyn Display) -> BbCode { + BbCode::Italic(text) +} + +#[allow(dead_code)] +pub fn underline(text: &dyn Display) -> BbCode { + BbCode::Underline(text) +} + +#[allow(dead_code)] +pub fn link<'a>(text: &'a dyn Display, url: &'a str) -> BbCode<'a> { + BbCode::Link(text, url) +} diff --git a/src/teamspeak.rs b/src/teamspeak/mod.rs index b429869..5ac0d44 100644 --- a/src/teamspeak.rs +++ b/src/teamspeak/mod.rs @@ -15,6 +15,10 @@ use log::error; use crate::bot::{Message, MusicBotMessage}; +mod bbcode; + +pub use bbcode::*; + pub struct TeamSpeakConnection { conn: Connection, } |
