some better transaction usage
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -202,7 +202,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bot"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"dotenv",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "bot"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -59,9 +59,9 @@ pub async fn color(ctx: Context<'_>, #[autocomplete = "autocomplete_colors"] col
|
||||
Color::from_rgb(rgb.r, rgb.g, rgb.b)
|
||||
};
|
||||
|
||||
if let Some(guild) = ctx.guild_id() {
|
||||
let mut tx = ctx.data().database.begin().await?;
|
||||
|
||||
if let Some(guild) = ctx.guild_id() {
|
||||
match super::get_user_role(ctx.author().id, guild, &mut *tx).await? {
|
||||
Some(role) => {
|
||||
guild.edit_role(ctx, role, EditRole::new().colour(color)).await?;
|
||||
@@ -83,12 +83,13 @@ pub async fn color(ctx: Context<'_>, #[autocomplete = "autocomplete_colors"] col
|
||||
.bind(guild.get() as i64)
|
||||
.execute(&mut *tx).await?;
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
let member = guild.member(ctx, ctx.author().id).await?;
|
||||
member.add_role(ctx, role.clone()).await?;
|
||||
|
||||
ctx.reply(format!("You have been given the {} role!", role)).await?;
|
||||
|
||||
tx.commit().await?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ use poise::serenity_prelude::EditRole;
|
||||
/// Change the name of your personal role
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
pub async fn name(ctx: Context<'_>, name: String) -> Result<(), Error> {
|
||||
if let Some(guild) = ctx.guild_id() {
|
||||
let mut tx = ctx.data().database.begin().await?;
|
||||
|
||||
if let Some(guild) = ctx.guild_id() {
|
||||
let role = match super::get_user_role(ctx.author().id, guild, &mut *tx).await? {
|
||||
Some(role) => role,
|
||||
None => {
|
||||
@@ -20,11 +20,11 @@ pub async fn name(ctx: Context<'_>, name: String) -> Result<(), Error> {
|
||||
.bind(guild.get() as i64)
|
||||
.execute(&mut *tx).await?;
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
let member = guild.member(ctx, ctx.author().id).await?;
|
||||
member.add_role(ctx, role.clone()).await?;
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
ctx.reply(format!("You've been given the {} role!", role)).await?;
|
||||
|
||||
return Ok(());
|
||||
|
||||
@@ -6,9 +6,9 @@ use poise::serenity_prelude as serenity;
|
||||
/// Register an existing role as a user's custom role
|
||||
#[poise::command(slash_command, prefix_command, required_permissions = "MANAGE_ROLES")]
|
||||
pub async fn register(ctx: Context<'_>, user: serenity::User, role: serenity::Role) -> Result<(), Error> {
|
||||
if let Some(guild) = ctx.guild_id() {
|
||||
let mut tx = ctx.data().database.begin().await?;
|
||||
|
||||
if let Some(guild) = ctx.guild_id() {
|
||||
match super::get_user_role(user.id, guild, &mut *tx).await? {
|
||||
Some(role) => {
|
||||
let role = guild.role(ctx, role).await?;
|
||||
@@ -21,6 +21,8 @@ pub async fn register(ctx: Context<'_>, user: serenity::User, role: serenity::Ro
|
||||
.bind(role.id.get() as i64)
|
||||
.execute(&mut *tx).await?;
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
let member = guild.member(ctx, user.id).await?;
|
||||
member.add_role(ctx, role.id).await?;
|
||||
|
||||
@@ -31,6 +33,5 @@ pub async fn register(ctx: Context<'_>, user: serenity::User, role: serenity::Ro
|
||||
ctx.reply("This command can only be run in a guild!").await?;
|
||||
}
|
||||
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user