pub mod clip;
pub mod edit;
pub mod emote;
pub mod heat;
pub mod key;
pub mod mock;
pub mod proto;
pub mod sanitize;
pub mod slash;
pub mod vi;
use std::collections::VecDeque;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Platform {
Twitch,
Kick,
}
impl Platform {
pub fn tag(self) -> &'static str {
match self {
Platform::Twitch => "tw",
Platform::Kick => "kk",
}
}
}
#[derive(Clone, Debug)]
pub struct Message {
pub user: String,
pub text: String,
pub color: Option<String>,
pub heat: f64,
}
#[derive(Clone, Debug)]
pub struct Channel {
pub name: String,
pub platform: Platform,
pub heat: f64,
pub last_ms: u64,
pub messages: VecDeque<Message>,
cap: usize,
}
impl Channel {
pub fn new(name: &str, platform: Platform, cap: usize) -> Channel {
Channel {
name: name.to_string(),
platform,
heat: 0.0,
last_ms: 0,
messages: VecDeque::with_capacity(cap),
cap,
}
}
pub fn cool(&mut self, now_ms: u64) {
if self.last_ms == 0 {
self.last_ms = now_ms;
return;
}
let dt = now_ms.saturating_sub(self.last_ms) as f64;
self.heat = heat::decay(self.heat, dt);
self.last_ms = now_ms;
}
pub fn record(&mut self, mut msg: Message, now_ms: u64) {
self.cool(now_ms);
self.heat += heat::INCREMENT;
msg.heat = self.heat;
if self.messages.len() == self.cap {
self.messages.pop_front();
}
self.messages.push_back(msg);
}
}