use std::sync::Arc;
use nu_plugin::{Plugin, PluginCommand};
use tokio::runtime::Runtime;
use tracing_subscriber::prelude::*;
use crate::commands::{TwitchAuth, TwitchChat, TwitchNotices, TwitchSay};
#[derive(Debug)]
pub struct TwitchPlugin {
pub(crate) reactor: Arc<Runtime>,
}
impl TwitchPlugin {
pub(crate) fn setup_tracing(&self) {
let _ = tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr))
.with(tracing_subscriber::EnvFilter::from_default_env())
.try_init();
}
}
impl Default for TwitchPlugin {
fn default() -> TwitchPlugin {
TwitchPlugin {
reactor: tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.into(),
}
}
}
impl Plugin for TwitchPlugin {
fn version(&self) -> String {
env!("CARGO_PKG_VERSION").into()
}
fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> {
vec![
Box::new(TwitchAuth),
Box::new(TwitchChat),
Box::new(TwitchNotices),
Box::new(TwitchSay),
]
}
}