Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: use Mutex instead of Cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie committed May 12, 2023
1 parent 30e7634 commit 9785ab6
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/utils/moderation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::cell::Cell;
use std::cmp;
use std::ops::DerefMut;
use std::sync::Arc;

use mongodb::options::FindOptions;
use std::sync::Mutex;
use poise::serenity_prelude::{ChannelId, GuildChannel, GuildId, Mentionable, User, UserId};
use tokio::task::JoinHandle;
use tracing::{debug, error, warn};
Expand Down Expand Up @@ -123,7 +124,7 @@ pub async fn respond_moderation<'a>(
configuration: &Configuration,
) -> Result<(), Error> {
let current_user = ctx.serenity_context().http.get_current_user().await?;
let send_as_ephemeral = Cell::new(false);
let send_as_ephemeral = Mutex::new(false);

let create_embed = |f: &mut serenity::CreateEmbed| {
let mut moderated_user: Option<&User> = None;
Expand All @@ -134,7 +135,8 @@ pub async fn respond_moderation<'a>(

let embed = match error {
Some(err) => {
send_as_ephemeral.set(true);
let mut send_as_ephemeral = send_as_ephemeral.lock().unwrap().deref_mut();
*send_as_ephemeral = true;
f.title(format!("Failed to mute {}", user.tag()))
.field("Exception", err.to_string(), false)
.field(
Expand Down Expand Up @@ -165,7 +167,8 @@ pub async fn respond_moderation<'a>(
moderated_user = Some(user);
match error {
Some(err) => {
send_as_ephemeral.set(true);
let mut send_as_ephemeral = send_as_ephemeral.lock().unwrap().deref_mut();
*send_as_ephemeral = true;
f.title(format!("Failed to unmute {}", user.tag()))
.field("Exception", err.to_string(), false)
.field(
Expand All @@ -189,7 +192,8 @@ pub async fn respond_moderation<'a>(
moderated_user = Some(user);
let f = match error {
Some(err) => {
send_as_ephemeral.set(true);
let mut send_as_ephemeral = send_as_ephemeral.lock().unwrap().deref_mut();
*send_as_ephemeral = true;
f.title(format!("Failed to ban {}", user.tag()))
.field("Exception", err.to_string(), false)
.field(
Expand Down Expand Up @@ -218,7 +222,8 @@ pub async fn respond_moderation<'a>(
moderated_user = Some(user);
match error {
Some(err) => {
send_as_ephemeral.set(true);
let mut send_as_ephemeral = send_as_ephemeral.lock().unwrap().deref_mut();
*send_as_ephemeral = true;
f.title(format!("Failed to unban {}", user.tag()))
.field("Exception", err.to_string(), false)
.field(
Expand All @@ -240,7 +245,8 @@ pub async fn respond_moderation<'a>(
},
ModerationKind::Lock(channel, author, error) => match error {
Some(err) => {
send_as_ephemeral.set(true);
let mut send_as_ephemeral = send_as_ephemeral.lock().unwrap().deref_mut();
*send_as_ephemeral = true;
f.title(format!("Failed to lock {} ", channel.name()))
.field("Exception", err.to_string(), false)
.field(
Expand All @@ -266,7 +272,8 @@ pub async fn respond_moderation<'a>(
},
ModerationKind::Unlock(channel, author, error) => match error {
Some(err) => {
send_as_ephemeral.set(true);
let mut send_as_ephemeral = send_as_ephemeral.lock().unwrap().deref_mut();
*send_as_ephemeral = true;
f.title(format!("Failed to unlock {}", channel.name()))
.field("Exception", err.to_string(), false)
.field(
Expand Down

0 comments on commit 9785ab6

Please sign in to comment.