mirror of
https://github.com/revanced/revanced-discord-bot.git
synced 2025-05-09 18:24:27 +02:00
feat: send error replies as ephemeral
This commit is contained in:
parent
770f61f502
commit
128f43b232
@ -1,3 +1,4 @@
|
|||||||
|
use std::cell::Cell;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -122,6 +123,7 @@ pub async fn respond_moderation<'a>(
|
|||||||
configuration: &Configuration,
|
configuration: &Configuration,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let current_user = ctx.serenity_context().http.get_current_user().await?;
|
let current_user = ctx.serenity_context().http.get_current_user().await?;
|
||||||
|
let send_as_ephemeral = Cell::new(false);
|
||||||
|
|
||||||
let create_embed = |f: &mut serenity::CreateEmbed| {
|
let create_embed = |f: &mut serenity::CreateEmbed| {
|
||||||
let mut moderated_user: Option<&User> = None;
|
let mut moderated_user: Option<&User> = None;
|
||||||
@ -131,8 +133,9 @@ pub async fn respond_moderation<'a>(
|
|||||||
moderated_user = Some(user);
|
moderated_user = Some(user);
|
||||||
|
|
||||||
let embed = match error {
|
let embed = match error {
|
||||||
Some(err) => f
|
Some(err) => {
|
||||||
.title(format!("Failed to mute {}", user.tag()))
|
send_as_ephemeral.set(true);
|
||||||
|
f.title(format!("Failed to mute {}", user.tag()))
|
||||||
.field("Exception", err.to_string(), false)
|
.field("Exception", err.to_string(), false)
|
||||||
.field(
|
.field(
|
||||||
"Action",
|
"Action",
|
||||||
@ -142,7 +145,8 @@ pub async fn respond_moderation<'a>(
|
|||||||
author.mention()
|
author.mention()
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
None => f.title(format!("Muted {}", user.tag())).field(
|
None => f.title(format!("Muted {}", user.tag())).field(
|
||||||
"Action",
|
"Action",
|
||||||
format!("{} was muted by {}", user.mention(), author.mention()),
|
format!("{} was muted by {}", user.mention(), author.mention()),
|
||||||
@ -160,8 +164,9 @@ pub async fn respond_moderation<'a>(
|
|||||||
ModerationKind::Unmute(user, author, error) => {
|
ModerationKind::Unmute(user, author, error) => {
|
||||||
moderated_user = Some(user);
|
moderated_user = Some(user);
|
||||||
match error {
|
match error {
|
||||||
Some(err) => f
|
Some(err) => {
|
||||||
.title(format!("Failed to unmute {}", user.tag()))
|
send_as_ephemeral.set(true);
|
||||||
|
f.title(format!("Failed to unmute {}", user.tag()))
|
||||||
.field("Exception", err.to_string(), false)
|
.field("Exception", err.to_string(), false)
|
||||||
.field(
|
.field(
|
||||||
"Action",
|
"Action",
|
||||||
@ -171,7 +176,8 @@ pub async fn respond_moderation<'a>(
|
|||||||
author.mention()
|
author.mention()
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
None => f.title(format!("Unmuted {}", user.tag())).field(
|
None => f.title(format!("Unmuted {}", user.tag())).field(
|
||||||
"Action",
|
"Action",
|
||||||
format!("{} was unmuted by {}", user.mention(), author.mention()),
|
format!("{} was unmuted by {}", user.mention(), author.mention()),
|
||||||
@ -182,8 +188,9 @@ pub async fn respond_moderation<'a>(
|
|||||||
ModerationKind::Ban(user, author, reason, error) => {
|
ModerationKind::Ban(user, author, reason, error) => {
|
||||||
moderated_user = Some(user);
|
moderated_user = Some(user);
|
||||||
let f = match error {
|
let f = match error {
|
||||||
Some(err) => f
|
Some(err) => {
|
||||||
.title(format!("Failed to ban {}", user.tag()))
|
send_as_ephemeral.set(true);
|
||||||
|
f.title(format!("Failed to ban {}", user.tag()))
|
||||||
.field("Exception", err.to_string(), false)
|
.field("Exception", err.to_string(), false)
|
||||||
.field(
|
.field(
|
||||||
"Action",
|
"Action",
|
||||||
@ -193,7 +200,8 @@ pub async fn respond_moderation<'a>(
|
|||||||
author.mention()
|
author.mention()
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
None => f.title(format!("Banned {}", user.tag())).field(
|
None => f.title(format!("Banned {}", user.tag())).field(
|
||||||
"Action",
|
"Action",
|
||||||
format!("{} was banned by {}", user.mention(), author.mention()),
|
format!("{} was banned by {}", user.mention(), author.mention()),
|
||||||
@ -209,8 +217,9 @@ pub async fn respond_moderation<'a>(
|
|||||||
ModerationKind::Unban(user, author, error) => {
|
ModerationKind::Unban(user, author, error) => {
|
||||||
moderated_user = Some(user);
|
moderated_user = Some(user);
|
||||||
match error {
|
match error {
|
||||||
Some(err) => f
|
Some(err) => {
|
||||||
.title(format!("Failed to unban {}", user.tag()))
|
send_as_ephemeral.set(true);
|
||||||
|
f.title(format!("Failed to unban {}", user.tag()))
|
||||||
.field("Exception", err.to_string(), false)
|
.field("Exception", err.to_string(), false)
|
||||||
.field(
|
.field(
|
||||||
"Action",
|
"Action",
|
||||||
@ -220,7 +229,8 @@ pub async fn respond_moderation<'a>(
|
|||||||
author.mention()
|
author.mention()
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
None => f.title(format!("Unbanned {}", user.tag())).field(
|
None => f.title(format!("Unbanned {}", user.tag())).field(
|
||||||
"Action",
|
"Action",
|
||||||
format!("{} was unbanned by {}", user.mention(), author.mention()),
|
format!("{} was unbanned by {}", user.mention(), author.mention()),
|
||||||
@ -229,8 +239,9 @@ pub async fn respond_moderation<'a>(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ModerationKind::Lock(channel, author, error) => match error {
|
ModerationKind::Lock(channel, author, error) => match error {
|
||||||
Some(err) => f
|
Some(err) => {
|
||||||
.title(format!("Failed to lock {} ", channel.name()))
|
send_as_ephemeral.set(true);
|
||||||
|
f.title(format!("Failed to lock {} ", channel.name()))
|
||||||
.field("Exception", err.to_string(), false)
|
.field("Exception", err.to_string(), false)
|
||||||
.field(
|
.field(
|
||||||
"Action",
|
"Action",
|
||||||
@ -240,7 +251,8 @@ pub async fn respond_moderation<'a>(
|
|||||||
author.mention()
|
author.mention()
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
None => f
|
None => f
|
||||||
.title(format!("Locked {}", channel.name()))
|
.title(format!("Locked {}", channel.name()))
|
||||||
.description(
|
.description(
|
||||||
@ -253,8 +265,9 @@ pub async fn respond_moderation<'a>(
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
ModerationKind::Unlock(channel, author, error) => match error {
|
ModerationKind::Unlock(channel, author, error) => match error {
|
||||||
Some(err) => f
|
Some(err) => {
|
||||||
.title(format!("Failed to unlock {}", channel.name()))
|
send_as_ephemeral.set(true);
|
||||||
|
f.title(format!("Failed to unlock {}", channel.name()))
|
||||||
.field("Exception", err.to_string(), false)
|
.field("Exception", err.to_string(), false)
|
||||||
.field(
|
.field(
|
||||||
"Action",
|
"Action",
|
||||||
@ -264,7 +277,8 @@ pub async fn respond_moderation<'a>(
|
|||||||
author.mention()
|
author.mention()
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
None => f
|
None => f
|
||||||
.title(format!("Unlocked {}", channel.name()))
|
.title(format!("Unlocked {}", channel.name()))
|
||||||
.description("Restored original permission overwrites.")
|
.description("Restored original permission overwrites.")
|
||||||
@ -291,7 +305,7 @@ pub async fn respond_moderation<'a>(
|
|||||||
|
|
||||||
let reply = ctx
|
let reply = ctx
|
||||||
.send(|reply| {
|
.send(|reply| {
|
||||||
reply.embed(|embed| {
|
reply.ephemeral(send_as_ephemeral.get()).embed(|embed| {
|
||||||
create_embed(embed);
|
create_embed(embed);
|
||||||
embed
|
embed
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user