Add guild_only to all commands
This commit is contained in:
@@ -31,6 +31,8 @@ pub enum AppError<E> {
|
|||||||
RepositoryError(#[from] RepositoryError<E>),
|
RepositoryError(#[from] RepositoryError<E>),
|
||||||
#[error("staff-only command used by non-staff user")]
|
#[error("staff-only command used by non-staff user")]
|
||||||
StaffOnly { command_name: String },
|
StaffOnly { command_name: String },
|
||||||
|
#[error("unknown cache or http error")]
|
||||||
|
UnknownCacheOrHttpError,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type AppContext<'a, R, E> = poise::ApplicationContext<'a, AppData<R>, AppError<E>>;
|
pub type AppContext<'a, R, E> = poise::ApplicationContext<'a, AppData<R>, AppError<E>>;
|
||||||
|
|||||||
@@ -299,6 +299,12 @@ where
|
|||||||
format!("`/{}` can only be used by staff.", command_name),
|
format!("`/{}` can only be used by staff.", command_name),
|
||||||
format!("staff-only command `{}` cannot be run by non-staff users", command_name),
|
format!("staff-only command `{}` cannot be run by non-staff users", command_name),
|
||||||
log::Level::Info,
|
log::Level::Info,
|
||||||
|
),
|
||||||
|
A::UnknownCacheOrHttpError => ErrorMessage::new(
|
||||||
|
"Unknown Cache or Http Error",
|
||||||
|
"Failed to get resource.",
|
||||||
|
"cache lookup or http request failed",
|
||||||
|
log::Level::Warn,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::app::AppError;
|
|||||||
use crate::utils;
|
use crate::utils;
|
||||||
|
|
||||||
/// Show information about the bot.
|
/// Show information about the bot.
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command, guild_only)]
|
||||||
pub async fn about<R: RepositoryProvider + Send + Sync>(
|
pub async fn about<R: RepositoryProvider + Send + Sync>(
|
||||||
ctx: AppContext<'_, R, R::BackendError>,
|
ctx: AppContext<'_, R, R::BackendError>,
|
||||||
#[description = "Hide reply from other users. Defaults to True."] ephemeral: Option<bool>,
|
#[description = "Hide reply from other users. Defaults to True."] ephemeral: Option<bool>,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Show help message.
|
/// Show help message.
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command, guild_only)]
|
||||||
pub async fn help<R: RepositoryProvider + Send + Sync>(
|
pub async fn help<R: RepositoryProvider + Send + Sync>(
|
||||||
ctx: AppContext<'_, R, R::BackendError>,
|
ctx: AppContext<'_, R, R::BackendError>,
|
||||||
#[rename = "command"]
|
#[rename = "command"]
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use crate::app::AppError;
|
|||||||
/// Manage friend codes.
|
/// Manage friend codes.
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
slash_command,
|
slash_command,
|
||||||
|
guild_only,
|
||||||
subcommands(
|
subcommands(
|
||||||
"edit",
|
"edit",
|
||||||
"overwrite",
|
"overwrite",
|
||||||
@@ -220,7 +221,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Edit your friend codes.
|
/// Edit your friend codes.
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command, guild_only)]
|
||||||
async fn edit<R: RepositoryProvider + Send + Sync>(ctx: AppContext<'_, R, R::BackendError>) -> Result<(), AppError<R::BackendError>> {
|
async fn edit<R: RepositoryProvider + Send + Sync>(ctx: AppContext<'_, R, R::BackendError>) -> Result<(), AppError<R::BackendError>> {
|
||||||
let author_id = ctx.author().id.get();
|
let author_id = ctx.author().id.get();
|
||||||
|
|
||||||
@@ -249,6 +250,7 @@ async fn edit<R: RepositoryProvider + Send + Sync>(ctx: AppContext<'_, R, R::Bac
|
|||||||
/// Edit any user's friend codes.
|
/// Edit any user's friend codes.
|
||||||
#[poise::command(
|
#[poise::command(
|
||||||
slash_command,
|
slash_command,
|
||||||
|
guild_only,
|
||||||
hide_in_help,
|
hide_in_help,
|
||||||
check = "crate::checks::is_staff",
|
check = "crate::checks::is_staff",
|
||||||
)]
|
)]
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use cipher_core::repository::user_repository::UserRepository;
|
use cipher_core::repository::user_repository::UserRepository;
|
||||||
use cipher_core::repository::RepositoryProvider;
|
use cipher_core::repository::RepositoryProvider;
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
use serenity::all::Color;
|
|
||||||
use serenity::all::CreateEmbed;
|
use serenity::all::CreateEmbed;
|
||||||
|
|
||||||
use crate::app::AppContext;
|
use crate::app::AppContext;
|
||||||
@@ -24,7 +23,7 @@ pub async fn profile<R: RepositoryProvider + Send + Sync>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Show your profile or someone else's.
|
/// Show your profile or someone else's.
|
||||||
#[poise::command(slash_command)]
|
#[poise::command(slash_command, guild_only)]
|
||||||
async fn show<R: RepositoryProvider + Send + Sync>(
|
async fn show<R: RepositoryProvider + Send + Sync>(
|
||||||
ctx: AppContext<'_, R, R::BackendError>,
|
ctx: AppContext<'_, R, R::BackendError>,
|
||||||
#[rename = "member"]
|
#[rename = "member"]
|
||||||
@@ -37,23 +36,7 @@ async fn show<R: RepositoryProvider + Send + Sync>(
|
|||||||
|
|
||||||
let member = match option_member {
|
let member = match option_member {
|
||||||
Some(member) => member,
|
Some(member) => member,
|
||||||
None => match ctx.author_member().await {
|
None => ctx.author_member().await.ok_or(AppError::UnknownCacheOrHttpError)?.into_owned(),
|
||||||
Some(member) => member.into_owned(),
|
|
||||||
None => {
|
|
||||||
let embed = CreateEmbed::new()
|
|
||||||
.title("Error")
|
|
||||||
.description("This command can only be used in server.")
|
|
||||||
.color(Color::RED);
|
|
||||||
|
|
||||||
let reply = CreateReply::default()
|
|
||||||
.embed(embed)
|
|
||||||
.ephemeral(true);
|
|
||||||
|
|
||||||
ctx.send(reply).await?;
|
|
||||||
|
|
||||||
return Ok(())
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let avatar_url = crate::utils::member_avatar_url(&member);
|
let avatar_url = crate::utils::member_avatar_url(&member);
|
||||||
|
|||||||
Reference in New Issue
Block a user