34 lines
935 B
Rust
34 lines
935 B
Rust
use std::sync::Arc;
|
|
|
|
use twilight_http::Client;
|
|
use twilight_model::oauth::Application;
|
|
|
|
use crate::framework::{
|
|
bot::IntoPrefixes, commands::Command, interactions::registry::ComponentRegistry,
|
|
};
|
|
|
|
pub struct Runtime<T> {
|
|
pub http: Client,
|
|
pub app: Application,
|
|
pub registry: ComponentRegistry<T>,
|
|
pub prefixes: Arc<dyn IntoPrefixes<T> + Send + Sync + 'static>,
|
|
pub commands: Vec<Arc<dyn Command<T>>>,
|
|
pub state: Arc<T>,
|
|
}
|
|
|
|
impl<T> Runtime<T> {
|
|
pub async fn get_prefixes(&self, server_id: Option<u64>, user_id: Option<u64>) -> Vec<String> {
|
|
self.prefixes.clone().get(self, server_id, user_id).await
|
|
}
|
|
|
|
pub fn get_command(&self, name: &str) -> Option<Arc<dyn Command<T>>> {
|
|
self.commands
|
|
.iter()
|
|
.find(|cmd| {
|
|
cmd.identifiers()
|
|
.contains(&name.to_ascii_lowercase().as_str())
|
|
})
|
|
.cloned()
|
|
}
|
|
}
|