2nd attempt at doing poise stuff
This commit is contained in:
@ -6,15 +6,12 @@ pub mod look_flags;
|
||||
|
||||
use chrono::{NaiveDateTime, TimeZone};
|
||||
use chrono_tz::Tz;
|
||||
use serenity::{
|
||||
client::Context,
|
||||
model::id::{ChannelId, GuildId, UserId},
|
||||
};
|
||||
use sqlx::MySqlPool;
|
||||
use poise::serenity::model::id::{ChannelId, GuildId, UserId};
|
||||
use sqlx::Executor;
|
||||
|
||||
use crate::{
|
||||
models::reminder::look_flags::{LookFlags, TimeDisplayType},
|
||||
SQLPool,
|
||||
Context, Data, Database,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -33,7 +30,10 @@ pub struct Reminder {
|
||||
}
|
||||
|
||||
impl Reminder {
|
||||
pub async fn from_uid(pool: &MySqlPool, uid: String) -> Option<Self> {
|
||||
pub async fn from_uid(
|
||||
pool: impl Executor<'_, Database = Database>,
|
||||
uid: String,
|
||||
) -> Option<Self> {
|
||||
sqlx::query_as_unchecked!(
|
||||
Self,
|
||||
"
|
||||
@ -70,12 +70,10 @@ WHERE
|
||||
}
|
||||
|
||||
pub async fn from_channel<C: Into<ChannelId>>(
|
||||
ctx: &Context,
|
||||
ctx: &Context<'_>,
|
||||
channel_id: C,
|
||||
flags: &LookFlags,
|
||||
) -> Vec<Self> {
|
||||
let pool = ctx.data.read().await.get::<SQLPool>().cloned().unwrap();
|
||||
|
||||
let enabled = if flags.show_disabled { "0,1" } else { "1" };
|
||||
let channel_id = channel_id.into();
|
||||
|
||||
@ -113,16 +111,18 @@ ORDER BY
|
||||
channel_id.as_u64(),
|
||||
enabled,
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.fetch_all(&ctx.data().database)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn from_guild(ctx: &Context, guild_id: Option<GuildId>, user: UserId) -> Vec<Self> {
|
||||
let pool = ctx.data.read().await.get::<SQLPool>().cloned().unwrap();
|
||||
|
||||
pub async fn from_guild(
|
||||
ctx: &Context<'_>,
|
||||
guild_id: Option<GuildId>,
|
||||
user: UserId,
|
||||
) -> Vec<Self> {
|
||||
if let Some(guild_id) = guild_id {
|
||||
let guild_opt = guild_id.to_guild_cached(&ctx);
|
||||
let guild_opt = guild_id.to_guild_cached(&ctx.discord());
|
||||
|
||||
if let Some(guild) = guild_opt {
|
||||
let channels = guild
|
||||
@ -163,7 +163,7 @@ WHERE
|
||||
",
|
||||
channels
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.fetch_all(&ctx.data().database)
|
||||
.await
|
||||
} else {
|
||||
sqlx::query_as_unchecked!(
|
||||
@ -196,7 +196,7 @@ WHERE
|
||||
",
|
||||
guild_id.as_u64()
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.fetch_all(&ctx.data().database)
|
||||
.await
|
||||
}
|
||||
} else {
|
||||
@ -230,7 +230,7 @@ WHERE
|
||||
",
|
||||
user.as_u64()
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.fetch_all(&ctx.data().database)
|
||||
.await
|
||||
}
|
||||
.unwrap()
|
||||
|
Reference in New Issue
Block a user