add custom prefixes for servers to set
This commit is contained in:
@@ -6,6 +6,7 @@ mod yeehaw;
|
||||
mod gambling;
|
||||
mod eval;
|
||||
mod self_roles;
|
||||
mod settings;
|
||||
|
||||
use crate::common::{Data, Error};
|
||||
|
||||
@@ -22,5 +23,6 @@ pub fn commands() -> Vec<Command<Data, Error>> {
|
||||
gambling::shop::buy(),
|
||||
eval::eval(),
|
||||
self_roles::role(),
|
||||
settings::setting(),
|
||||
]
|
||||
}
|
||||
|
||||
30
src/commands/settings.rs
Normal file
30
src/commands/settings.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use crate::common::{Context, Error};
|
||||
|
||||
#[poise::command(prefix_command, slash_command, required_permissions = "MANAGE_GUILD")]
|
||||
async fn prefix(ctx: Context<'_>, prefix: String) -> Result<(), Error> {
|
||||
let guild = match ctx.guild_id() {
|
||||
Some(g) => g,
|
||||
None => {
|
||||
ctx.reply("This command must be ran within a guild.").await?;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let mut tx = ctx.data().database.begin().await?;
|
||||
|
||||
sqlx::query("INSERT INTO settings (guildid, prefix) VALUES ($1, $2) ON CONFLICT (guildid) DO UPDATE SET prefix = EXCLUDED.prefix")
|
||||
.bind(guild.get() as i64)
|
||||
.bind(&prefix)
|
||||
.execute(&mut *tx).await?;
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
ctx.reply(format!("This server's custom prefix has been updated to `{prefix}`.")).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[poise::command(prefix_command, slash_command, subcommands("prefix"), subcommand_required)]
|
||||
pub async fn setting(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user