prefix command
This commit is contained in:
parent
58298de0be
commit
1f410899b2
@ -18,6 +18,7 @@ use crate::{
|
|||||||
models::{
|
models::{
|
||||||
ChannelData,
|
ChannelData,
|
||||||
UserData,
|
UserData,
|
||||||
|
GuildData,
|
||||||
},
|
},
|
||||||
SQLPool,
|
SQLPool,
|
||||||
framework::SendFromDb,
|
framework::SendFromDb,
|
||||||
@ -116,3 +117,29 @@ SELECT code FROM languages WHERE code = ? OR name = ?
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
async fn prefix(ctx: &Context, msg: &Message, args: String) -> CommandResult {
|
||||||
|
let pool = ctx.data.read().await
|
||||||
|
.get::<SQLPool>().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(())
|
||||||
|
}
|
||||||
|
@ -14,12 +14,12 @@ use chrono::NaiveDateTime;
|
|||||||
pub struct GuildData {
|
pub struct GuildData {
|
||||||
id: u32,
|
id: u32,
|
||||||
guild: u64,
|
guild: u64,
|
||||||
name: String,
|
pub name: String,
|
||||||
prefix: String,
|
pub prefix: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GuildData {
|
impl GuildData {
|
||||||
pub async fn from_id(guild: Guild, pool: MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
|
pub async fn from_guild(guild: Guild, pool: MySqlPool) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
|
||||||
let guild_id = guild.id.as_u64().clone();
|
let guild_id = guild.id.as_u64().clone();
|
||||||
|
|
||||||
if let Ok(g) = sqlx::query_as!(Self,
|
if let Ok(g) = sqlx::query_as!(Self,
|
||||||
|
Loading…
Reference in New Issue
Block a user