feat: add listing logger channels in a guild
This commit also allows in the database to hold more than one channel per guild and introduces clippy linting. Closes #2 BREAKING CHANGES: The database schema changed from its root. All databases should be dropped and recreated before running this new version.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#![allow(clippy::cast_possible_wrap, clippy::cast_sign_loss)]
|
||||
|
||||
use std::env;
|
||||
|
||||
use poise::serenity_prelude::{ChannelId, GuildId};
|
||||
use sqlx::SqlitePool;
|
||||
use tracing::error;
|
||||
|
||||
pub type Result<T> = ::std::result::Result<T, sqlx::Error>;
|
||||
|
||||
@@ -22,9 +25,9 @@ impl Database {
|
||||
|
||||
pub async fn get_logging_channel(
|
||||
&self,
|
||||
guild_id: u64,
|
||||
guild_id: GuildId,
|
||||
) -> Result<Vec<u64>> {
|
||||
let guild_id = guild_id as i64;
|
||||
let guild_id = guild_id.0 as i64;
|
||||
let channels = sqlx::query!(
|
||||
r#"
|
||||
SELECT channel_id
|
||||
@@ -34,7 +37,11 @@ WHERE guild_id = ?1
|
||||
guild_id
|
||||
)
|
||||
.fetch_all(&self.pool)
|
||||
.await?;
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("Error getting logging channels for guild {guild_id}: {e:?}");
|
||||
e
|
||||
})?;
|
||||
Ok(channels.iter().map(|id| id.channel_id as u64).collect())
|
||||
}
|
||||
|
||||
@@ -57,6 +64,10 @@ VALUES ( ?1, ?2 )
|
||||
)
|
||||
.execute(&mut *conn)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("Error setting channel {channel_id} as logger for guild {guild_id}: {e:?}");
|
||||
e
|
||||
})
|
||||
.map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user