feat: add keywords function //TODO : changing the keywoard function to a fully featureed submodule with Add/Delete
This commit is contained in:
parent
bf34d95197
commit
8f65b52112
109
src/botv2/cmd/concour/keyword.rs
Normal file
109
src/botv2/cmd/concour/keyword.rs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
use crate::botv2::{
|
||||||
|
domain::concour::{
|
||||||
|
add_keyword::{add_keyword_concour, AddKeywordConcourError, KeyWordSource},
|
||||||
|
check_if_allowed::check_if_allowed,
|
||||||
|
},
|
||||||
|
init::{Context, Error},
|
||||||
|
};
|
||||||
|
use poise::{
|
||||||
|
serenity_prelude::{model::colour, CreateEmbed, CreateEmbedFooter, Mentionable, RoleId},
|
||||||
|
CreateReply,
|
||||||
|
};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
|
/// Add keyword for concour (only for admin)
|
||||||
|
/// this function will turn into submodule in the futur
|
||||||
|
#[instrument(skip(ctx), level = "info", fields(channel = ctx.channel_id().get(), guild = ?ctx.guild_id().unwrap().get()))]
|
||||||
|
#[poise::command(
|
||||||
|
slash_command,
|
||||||
|
prefix_command,
|
||||||
|
category = "server_config",
|
||||||
|
guild_only = true
|
||||||
|
)]
|
||||||
|
pub async fn keyword(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Delimiter de list (\\n par defaut)"] delimiter: Option<String>,
|
||||||
|
#[description = "Url de la liste"] url: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let guild = match ctx.guild_id() {
|
||||||
|
Some(guild) => guild,
|
||||||
|
None => return Ok(()),
|
||||||
|
};
|
||||||
|
let entity_name = ctx.data().entity_name.clone();
|
||||||
|
let footer = CreateEmbedFooter::new(entity_name.clone());
|
||||||
|
match check_if_allowed(guild.get(), ctx.author().id.get(), ctx.http()).await {
|
||||||
|
Ok(ok) => {
|
||||||
|
if !ok {
|
||||||
|
let embed = CreateEmbed::new()
|
||||||
|
.title("You are not an admin")
|
||||||
|
.color(colour::Color::RED)
|
||||||
|
.footer(footer);
|
||||||
|
if let Err(why) = ctx
|
||||||
|
.send(CreateReply::default().embed(embed).ephemeral(true))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
tracing::error!("Error sending message: {:?}", why);
|
||||||
|
}
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
let embed = CreateEmbed::new()
|
||||||
|
.title("You are not an admin")
|
||||||
|
.color(colour::Color::RED)
|
||||||
|
.footer(footer);
|
||||||
|
if let Err(why) = ctx
|
||||||
|
.send(CreateReply::default().embed(embed).ephemeral(true))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
tracing::error!("Error sending message: {:?}", why);
|
||||||
|
}
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let concour = match add_keyword_concour(
|
||||||
|
guild.get(),
|
||||||
|
ctx.channel_id().get(),
|
||||||
|
KeyWordSource::Url(url, delimiter),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(concour) => {
|
||||||
|
if concour.is_none() {
|
||||||
|
CreateEmbed::new()
|
||||||
|
.title("No concour updated")
|
||||||
|
.color(colour::Color::RED)
|
||||||
|
} else {
|
||||||
|
let concour = concour.unwrap();
|
||||||
|
CreateEmbed::new()
|
||||||
|
.title(concour.title)
|
||||||
|
.description(concour.description)
|
||||||
|
.field("Start date", concour.start_date.to_string(), false)
|
||||||
|
.field("Periode", concour.periode.to_string(), false)
|
||||||
|
.field(
|
||||||
|
"Role récompense",
|
||||||
|
RoleId::new(concour.role_recompense).mention().to_string(),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.field("keyword", concour.keywords.len().to_string(), true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => match err {
|
||||||
|
AddKeywordConcourError::DoesntExist => CreateEmbed::new()
|
||||||
|
.title("Concour dont exist")
|
||||||
|
.color(colour::Color::RED),
|
||||||
|
_ => CreateEmbed::new()
|
||||||
|
.title("Error while creating concour")
|
||||||
|
.field("Please contact your administrator", "", false)
|
||||||
|
.field("Your concour is possibly not initied correctly", "", false)
|
||||||
|
.color(colour::Color::RED),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut builder = CreateReply::default().ephemeral(true);
|
||||||
|
builder = builder.embed(concour.footer(footer));
|
||||||
|
if let Err(why) = ctx.send(builder).await {
|
||||||
|
tracing::error!("Error sending message: {:?}", why);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -71,6 +71,7 @@ pub async fn list(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
.description(c.description)
|
.description(c.description)
|
||||||
.field("Start date", c.start_date.to_string(), false)
|
.field("Start date", c.start_date.to_string(), false)
|
||||||
.field("Periode", c.periode.to_string(), false)
|
.field("Periode", c.periode.to_string(), false)
|
||||||
|
.field("keyword", c.keywords.len().to_string(), true)
|
||||||
.footer(footer.clone());
|
.footer(footer.clone());
|
||||||
if c.role_recompense != 0 {
|
if c.role_recompense != 0 {
|
||||||
output = output.field(
|
output = output.field(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::botv2::{
|
use crate::botv2::{
|
||||||
cmd::concour::{create::create, list::list, update::update},
|
cmd::concour::{create::create, keyword::keyword, list::list, update::update},
|
||||||
domain::concour::{
|
domain::concour::{
|
||||||
check_if_allowed::check_if_concour_allowed, get_channel_concour::get_channel_concour,
|
check_if_allowed::check_if_concour_allowed, get_channel_concour::get_channel_concour,
|
||||||
},
|
},
|
||||||
@ -17,7 +17,7 @@ use tracing::instrument;
|
|||||||
slash_command,
|
slash_command,
|
||||||
prefix_command,
|
prefix_command,
|
||||||
category = "concour",
|
category = "concour",
|
||||||
subcommands("get", "list", "update", "create"),
|
subcommands("get", "list", "update", "create", "keyword"),
|
||||||
guild_only = true
|
guild_only = true
|
||||||
)]
|
)]
|
||||||
pub async fn concour(
|
pub async fn concour(
|
||||||
@ -91,6 +91,7 @@ async fn concour_get(ctx: Context<'_>, ephemeral: Option<bool>) -> Result<(), Er
|
|||||||
.field("Description", concour.description, false)
|
.field("Description", concour.description, false)
|
||||||
.field("Start date", concour.start_date.to_string(), false)
|
.field("Start date", concour.start_date.to_string(), false)
|
||||||
.field("Periode", concour.periode.to_string(), false)
|
.field("Periode", concour.periode.to_string(), false)
|
||||||
|
.field("keyword", concour.keywords.len().to_string(), true)
|
||||||
.color(colour::Color::DARK_GREEN);
|
.color(colour::Color::DARK_GREEN);
|
||||||
|
|
||||||
if concour.role_recompense != 0 {
|
if concour.role_recompense != 0 {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
pub mod create;
|
pub mod create;
|
||||||
|
pub mod keyword;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
pub mod main;
|
pub mod main;
|
||||||
pub mod update;
|
pub mod update;
|
||||||
|
@ -3,15 +3,14 @@ use poise::samples::HelpConfiguration;
|
|||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
/// Show help message
|
/// Show help message
|
||||||
#[poise::command(prefix_command, track_edits, category = "Utility")]
|
#[instrument(skip(ctx), level = "info",fields(channel = ctx.channel_id().get(), guild = ?ctx.guild_id().unwrap().get()))]
|
||||||
#[instrument(skip(ctx), level = "info")]
|
#[poise::command(prefix_command, slash_command, track_edits, category = "Utility")]
|
||||||
pub async fn help(
|
pub async fn help(
|
||||||
ctx: Context<'_>,
|
ctx: Context<'_>,
|
||||||
#[description = "Command to get help for"]
|
#[description = "Command to get help for"]
|
||||||
#[rest]
|
#[rest]
|
||||||
mut command: Option<String>,
|
mut command: Option<String>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
tracing::info!(channel = ctx.channel_id().get(), guild = ?ctx.guild_id().unwrap().get(),"Help command called");
|
|
||||||
// This makes it possible to just make `help` a subcommand of any command
|
// This makes it possible to just make `help` a subcommand of any command
|
||||||
// `/fruit help` turns into `/help fruit`
|
// `/fruit help` turns into `/help fruit`
|
||||||
// `/fruit help apple` turns into `/help fruit apple`
|
// `/fruit help apple` turns into `/help fruit apple`
|
||||||
|
Loading…
Reference in New Issue
Block a user