This commit is contained in:
2021-09-18 13:40:30 +01:00
parent a9c91bee93
commit a0974795e1
8 changed files with 276 additions and 263 deletions

View File

@ -6,6 +6,7 @@ pub mod user_data;
use std::sync::Arc;
use chrono_tz::Tz;
use serenity::{
async_trait,
model::id::{ChannelId, GuildId, UserId},
@ -33,6 +34,8 @@ pub trait CtxData {
user_id: U,
) -> Result<UserData, Box<dyn std::error::Error + Sync + Send>>;
async fn timezone<U: Into<UserId> + Send + Sync>(&self, user_id: U) -> Tz;
async fn channel_data<C: Into<ChannelId> + Send + Sync>(
&self,
channel_id: C,
@ -92,6 +95,13 @@ impl CtxData for Context {
UserData::from_user(&user, &self, &pool).await
}
async fn timezone<U: Into<UserId> + Send + Sync>(&self, user_id: U) -> Tz {
let user_id = user_id.into();
let pool = self.data.read().await.get::<SQLPool>().cloned().unwrap();
UserData::timezone_of(user_id, &pool).await
}
async fn channel_data<C: Into<ChannelId> + Send + Sync>(
&self,
channel_id: C,