use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum PlatformKind {
Telegram,
Discord,
}
impl fmt::Display for PlatformKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Telegram => "telegram",
Self::Discord => "discord",
})
}
}
#[derive(Debug, Clone)]
pub struct Platform {
pub(crate) kind: PlatformKind,
pub(crate) config: PlatformConfig,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
#[allow(dead_code)] pub(crate) enum PlatformConfig {
Telegram { token: String },
Discord { token: String },
}
impl Platform {
pub fn telegram(token: impl Into<String>) -> Self {
Self {
kind: PlatformKind::Telegram,
config: PlatformConfig::Telegram {
token: token.into(),
},
}
}
pub fn discord(token: impl Into<String>) -> Self {
Self {
kind: PlatformKind::Discord,
config: PlatformConfig::Discord {
token: token.into(),
},
}
}
pub fn kind(&self) -> PlatformKind {
self.kind
}
}
#[derive(Debug, Clone)]
pub struct Presence {
pub(crate) kind: PresenceKind,
pub(crate) name: String,
pub(crate) url: Option<String>,
pub(crate) state: Option<String>,
pub(crate) status: PresenceStatus,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum PresenceKind {
Playing,
Streaming,
Listening,
Watching,
Competing,
Custom,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum PresenceStatus {
#[default]
Online,
Idle,
DoNotDisturb,
Invisible,
}
impl Presence {
fn new(kind: PresenceKind, name: impl Into<String>) -> Self {
Self {
kind,
name: name.into(),
url: None,
state: None,
status: PresenceStatus::Online,
}
}
pub fn playing(name: impl Into<String>) -> Self {
Self::new(PresenceKind::Playing, name)
}
pub fn streaming(name: impl Into<String>, url: impl Into<String>) -> Self {
let mut p = Self::new(PresenceKind::Streaming, name);
p.url = Some(url.into());
p
}
pub fn listening(name: impl Into<String>) -> Self {
Self::new(PresenceKind::Listening, name)
}
pub fn watching(name: impl Into<String>) -> Self {
Self::new(PresenceKind::Watching, name)
}
pub fn competing(name: impl Into<String>) -> Self {
Self::new(PresenceKind::Competing, name)
}
pub fn custom(text: impl Into<String>) -> Self {
Self::new(PresenceKind::Custom, text)
}
pub fn status(mut self, status: PresenceStatus) -> Self {
self.status = status;
self
}
pub fn state(mut self, state: impl Into<String>) -> Self {
self.state = Some(state.into());
self
}
}