diff --git a/src/commands/moderation_cmds.rs b/src/commands/moderation_cmds.rs index 0c521da..b91042c 100644 --- a/src/commands/moderation_cmds.rs +++ b/src/commands/moderation_cmds.rs @@ -18,6 +18,7 @@ use crate::{ models::{ ChannelData, UserData, + GuildData, }, SQLPool, framework::SendFromDb, @@ -116,3 +117,29 @@ SELECT code FROM languages WHERE code = ? OR name = ? Ok(()) } + +#[command] +async fn prefix(ctx: &Context, msg: &Message, args: String) -> CommandResult { + let pool = ctx.data.read().await + .get::().cloned().expect("Could not get SQLPool from data"); + + let mut guild_data = GuildData::from_guild(msg.guild(&ctx).await.unwrap(), pool.clone()).await.unwrap(); + let user_data = UserData::from_id(&msg.author, &ctx, pool.clone()).await.unwrap(); + + if args.len() > 5 { + let _ = msg.channel_id.say_named(&ctx, user_data.language, "prefix/too_long").await; + + } + else if args.len() == 0 { + let _ = msg.channel_id.say_named(&ctx, user_data.language, "prefix/no_argument").await; + } + else { + guild_data.prefix = args; + + guild_data.commit_changes(pool).await; + + let _ = msg.channel_id.say_named(&ctx, user_data.language, "prefix/success").await; + } + + Ok(()) +} diff --git a/src/models.rs b/src/models.rs index 80304ca..a74e6a2 100644 --- a/src/models.rs +++ b/src/models.rs @@ -14,12 +14,12 @@ use chrono::NaiveDateTime; pub struct GuildData { id: u32, guild: u64, - name: String, - prefix: String, + pub name: String, + pub prefix: String, } impl GuildData { - pub async fn from_id(guild: Guild, pool: MySqlPool) -> Result> { + pub async fn from_guild(guild: Guild, pool: MySqlPool) -> Result> { let guild_id = guild.id.as_u64().clone(); if let Ok(g) = sqlx::query_as!(Self,