Verified Commit b39f4e93 authored by Mathias B.'s avatar Mathias B.
Browse files

Correction d'oublis, mise à jour de guilde. Fixes #26

parent 9d1eb764
......@@ -5,7 +5,7 @@ use crate::repositories::UserRepository;
use crate::repositories::{GuildRepository, TicketRepository};
use crate::utils::functions;
use chrono::Utc;
use datastructs::discord::{ChannelData, UserData, RoleData};
use datastructs::discord::{ChannelData, UserData, RoleData, GuildData};
use serenity::async_trait;
use serenity::model::prelude::*;
use serenity::prelude::*;
......@@ -167,7 +167,7 @@ impl EventHandler for Handler {
}
async fn guild_role_create(&self, _ctx: Context, _guild_id: GuildId, new: Role) {
process_handler_result(RoleRepository::create(&RoleData::from(&role)).await);
process_handler_result(RoleRepository::create(&RoleData::from(&new)).await);
}
async fn guild_role_delete(
......@@ -194,9 +194,9 @@ impl EventHandler for Handler {
&self,
_ctx: Context,
_old_data_if_available: Option<Guild>,
_new_but_incomplete: PartialGuild,
new_but_incomplete: PartialGuild,
) {
todo!()
process_handler_result(GuildRepository::update(GuildData::from(&new_but_incomplete)).await);
}
async fn message(&self, ctx: Context, message: Message) {
......
UPDATE discord.guilds SET name = $2, icon = $3, owner_id = $4 WHERE id = $1
\ No newline at end of file
DELETE FROM discord.roles WHERE id = $1
\ No newline at end of file
......@@ -26,6 +26,21 @@ impl GuildRepository {
Ok(())
}
pub async fn update(guild: GuildData) -> super::PostgreSQLResult<()> {
let db = DatabaseClient::get();
db.execute(
include_str!("../files/sql/guilds/update.sql"),
&[
&guild.id,
&guild.name,
&guild.icon,
&guild.owner_id
]
).await?;
Ok(())
}
pub async fn get_absent_guilds(guild_ids: &[GuildId]) -> PostgreSQLResult<Vec<GuildData>> {
let db = DatabaseClient::get();
let guild_ids = guild_ids.iter().map(|gid| i64::from(*gid)).collect_vec();
......
......@@ -66,16 +66,18 @@ impl RoleRepository {
).await.map(|_| ())
}
pub async fn delete_by_id(role: RoleId) -> super::PostgreSQLResult<u64> {
pub async fn delete_by_id(role: RoleId) -> super::PostgreSQLResult<()> {
let db = DatabaseClient::get();
db.execute(
include_str!("../files/sql/roles/delete.sql"),
&[i64::from(role)]
).await
&[&i64::from(role)]
).await?;
Ok(())
}
pub async fn update(role: &RoleData) -> super::PostgreSQLResult<u64> {
pub async fn update(role: &RoleData) -> super::PostgreSQLResult<()> {
let db = DatabaseClient::get();
db.execute(
......@@ -86,7 +88,9 @@ impl RoleRepository {
&role.position,
&role.managed
]
).await
).await?;
Ok(())
}
pub async fn copy_temporary_roles(
......
use serenity::model::guild::Guild;
use serenity::model::guild::{Guild, PartialGuild};
pub struct GuildData {
pub id: i64,
......@@ -28,3 +28,14 @@ impl From<&Guild> for GuildData {
)
}
}
impl From<&PartialGuild> for GuildData {
fn from(g: &PartialGuild) -> Self {
Self {
id: i64::from(g.id),
name: g.name.clone(),
icon: g.icon.clone(),
owner_id: i64::from(g.owner_id)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment