feat: handler create list main
This commit is contained in:
parent
683a9d94a4
commit
17bb4e03bf
103
src/botv2/cmd/concour/create.rs
Normal file
103
src/botv2/cmd/concour/create.rs
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
use crate::botv2::{
|
||||||
|
domain::concour::{
|
||||||
|
check_if_allowed::check_if_allowed,
|
||||||
|
create_concour::{create_concour, CreateConcourError},
|
||||||
|
},
|
||||||
|
init::{Context, Error},
|
||||||
|
};
|
||||||
|
use poise::{
|
||||||
|
serenity_prelude::{model::colour, CreateEmbed, CreateEmbedFooter, Mentionable, RoleId},
|
||||||
|
CreateReply,
|
||||||
|
};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
|
/// Create concour (only for admin)
|
||||||
|
#[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 create(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Titre du concour"] title: String,
|
||||||
|
#[description = "Description du concour"] description: 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 create_concour(guild.get(), ctx.channel_id().get(), title, description).await {
|
||||||
|
Ok(concour) => {
|
||||||
|
if concour.is_none() {
|
||||||
|
CreateEmbed::new()
|
||||||
|
.title("No concour created")
|
||||||
|
.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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => match err {
|
||||||
|
CreateConcourError::AlreadyExist => CreateEmbed::new()
|
||||||
|
.title("Concour already 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(())
|
||||||
|
}
|
98
src/botv2/cmd/concour/list.rs
Normal file
98
src/botv2/cmd/concour/list.rs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
use crate::botv2::{
|
||||||
|
domain::concour::{check_if_allowed::check_if_allowed, list_concour::list_concour},
|
||||||
|
init::{Context, Error},
|
||||||
|
};
|
||||||
|
use poise::{
|
||||||
|
serenity_prelude::{model::colour, CreateEmbed, CreateEmbedFooter, Mentionable, RoleId},
|
||||||
|
CreateReply,
|
||||||
|
};
|
||||||
|
use tracing::instrument;
|
||||||
|
|
||||||
|
/// List all concour (only for admin)
|
||||||
|
#[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 list(ctx: Context<'_>) -> 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 list_concour(guild.get()).await {
|
||||||
|
Ok(concour) => {
|
||||||
|
if concour.is_empty() {
|
||||||
|
vec![CreateEmbed::new()
|
||||||
|
.title("No concour found")
|
||||||
|
.color(colour::Color::DARK_GREEN)
|
||||||
|
.footer(footer)]
|
||||||
|
} else {
|
||||||
|
let mut list = vec![CreateEmbed::new()
|
||||||
|
.title("Concour list")
|
||||||
|
.color(colour::Color::DARK_GREEN)];
|
||||||
|
concour.into_iter().for_each(|c| {
|
||||||
|
list.push(
|
||||||
|
CreateEmbed::new()
|
||||||
|
.title(c.title)
|
||||||
|
.description(c.description)
|
||||||
|
.field("Start date", c.start_date.to_string(), false)
|
||||||
|
.field("Periode", c.periode.to_string(), false)
|
||||||
|
.field(
|
||||||
|
"Role récompense",
|
||||||
|
RoleId::new(c.role_recompense).mention().to_string(),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.footer(footer.clone()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => vec![CreateEmbed::new()
|
||||||
|
.title("Error while getting concour list")
|
||||||
|
.color(colour::Color::RED)
|
||||||
|
.footer(footer)],
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut builder = CreateReply::default().ephemeral(true);
|
||||||
|
builder.embeds = concour;
|
||||||
|
if let Err(why) = ctx.send(builder).await {
|
||||||
|
tracing::error!("Error sending message: {:?}", why);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
use crate::botv2::{
|
use crate::botv2::{
|
||||||
|
cmd::concour::list::list,
|
||||||
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,
|
||||||
},
|
},
|
||||||
@ -16,7 +17,7 @@ use tracing::instrument;
|
|||||||
slash_command,
|
slash_command,
|
||||||
prefix_command,
|
prefix_command,
|
||||||
category = "concour",
|
category = "concour",
|
||||||
subcommands("get"),
|
subcommands("get", "list"),
|
||||||
guild_only = true
|
guild_only = true
|
||||||
)]
|
)]
|
||||||
pub async fn concour(
|
pub async fn concour(
|
||||||
@ -86,10 +87,10 @@ async fn concour_get(ctx: Context<'_>, ephemeral: Option<bool>) -> Result<(), Er
|
|||||||
if let Some(concour) = concour {
|
if let Some(concour) = concour {
|
||||||
CreateEmbed::new()
|
CreateEmbed::new()
|
||||||
.title("Concour")
|
.title("Concour")
|
||||||
.field("Title", &concour.title, false)
|
.field("Title", concour.title, false)
|
||||||
.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(
|
.field(
|
||||||
"Role récompense",
|
"Role récompense",
|
||||||
RoleId::new(concour.role_recompense).mention().to_string(),
|
RoleId::new(concour.role_recompense).mention().to_string(),
|
@ -1 +1,3 @@
|
|||||||
pub mod concour;
|
pub mod create;
|
||||||
|
pub mod list;
|
||||||
|
pub mod main;
|
||||||
|
@ -50,7 +50,7 @@ pub async fn add_keyword_concour(
|
|||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
let text = res.text().await.unwrap();
|
let text = res.text().await.unwrap();
|
||||||
let split_delimiter = delimiter.unwrap_or("\n".to_string());
|
let split_delimiter = delimiter.unwrap_or("\n".to_string());
|
||||||
text.split(&split_delimiter).into_iter().for_each(|x| {
|
text.split(&split_delimiter).for_each(|x| {
|
||||||
concour.keywords.push(x.to_string());
|
concour.keywords.push(x.to_string());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ pub async fn add_keyword_concour(
|
|||||||
}
|
}
|
||||||
KeyWordSource::Text(text, delimiter) => {
|
KeyWordSource::Text(text, delimiter) => {
|
||||||
let split_delimiter = delimiter.unwrap_or("\n".to_string());
|
let split_delimiter = delimiter.unwrap_or("\n".to_string());
|
||||||
text.split(&split_delimiter).into_iter().for_each(|x| {
|
text.split(&split_delimiter).for_each(|x| {
|
||||||
concour.keywords.push(x.to_string());
|
concour.keywords.push(x.to_string());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -29,21 +29,19 @@ pub async fn end_concour(
|
|||||||
info!("Concour doesn't exist");
|
info!("Concour doesn't exist");
|
||||||
return Err(EndConcourError::DoesntExist);
|
return Err(EndConcourError::DoesntExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut concour = concour.unwrap();
|
|
||||||
|
|
||||||
// Update status to Finished
|
|
||||||
|
|
||||||
todo!("Setup logic to end the waiting period for the concour");
|
todo!("Setup logic to end the waiting period for the concour");
|
||||||
|
// let mut concour = concour.unwrap();
|
||||||
|
|
||||||
match concour.update().await {
|
// // Update status to Finished
|
||||||
Ok(_) => {}
|
|
||||||
Err(err) => {
|
// match concour.update().await {
|
||||||
tracing::error!(error = err.to_string(), "Error updating concour");
|
// Ok(_) => {}
|
||||||
return Err(EndConcourError::UnknownError(
|
// Err(err) => {
|
||||||
"Error updating concour".to_string(),
|
// tracing::error!(error = err.to_string(), "Error updating concour");
|
||||||
));
|
// return Err(EndConcourError::UnknownError(
|
||||||
}
|
// "Error updating concour".to_string(),
|
||||||
}
|
// ));
|
||||||
Ok(Some(concour))
|
// }
|
||||||
|
// }
|
||||||
|
// Ok(Some(concour))
|
||||||
}
|
}
|
||||||
|
@ -29,21 +29,19 @@ pub async fn start_concour(
|
|||||||
info!("Concour doesn't exist");
|
info!("Concour doesn't exist");
|
||||||
return Err(StartConcourError::DoesntExist);
|
return Err(StartConcourError::DoesntExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut concour = concour.unwrap();
|
|
||||||
|
|
||||||
// Update status to started
|
|
||||||
|
|
||||||
todo!("Setup logic to start the waiting period for the concour");
|
todo!("Setup logic to start the waiting period for the concour");
|
||||||
|
// let mut concour = concour.unwrap();
|
||||||
|
|
||||||
match concour.update().await {
|
// // Update status to started
|
||||||
Ok(_) => {}
|
|
||||||
Err(err) => {
|
// match concour.update().await {
|
||||||
tracing::error!(error = err.to_string(), "Error updating concour");
|
// Ok(_) => {}
|
||||||
return Err(StartConcourError::UnknownError(
|
// Err(err) => {
|
||||||
"Error updating concour".to_string(),
|
// tracing::error!(error = err.to_string(), "Error updating concour");
|
||||||
));
|
// return Err(StartConcourError::UnknownError(
|
||||||
}
|
// "Error updating concour".to_string(),
|
||||||
}
|
// ));
|
||||||
Ok(Some(concour))
|
// }
|
||||||
|
// }
|
||||||
|
// Ok(Some(concour))
|
||||||
}
|
}
|
||||||
|
@ -29,21 +29,19 @@ pub async fn stop_concour(
|
|||||||
info!("Concour doesn't exist");
|
info!("Concour doesn't exist");
|
||||||
return Err(StopConcourError::DoesntExist);
|
return Err(StopConcourError::DoesntExist);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut concour = concour.unwrap();
|
|
||||||
|
|
||||||
// Update status to Paused
|
|
||||||
|
|
||||||
todo!("Setup logic to stop the waiting period for the concour");
|
todo!("Setup logic to stop the waiting period for the concour");
|
||||||
|
// let mut concour = concour.unwrap();
|
||||||
|
|
||||||
match concour.update().await {
|
// // Update status to Paused
|
||||||
Ok(_) => {}
|
|
||||||
Err(err) => {
|
// match concour.update().await {
|
||||||
tracing::error!(error = err.to_string(), "Error updating concour");
|
// Ok(_) => {}
|
||||||
return Err(StopConcourError::UnknownError(
|
// Err(err) => {
|
||||||
"Error updating concour".to_string(),
|
// tracing::error!(error = err.to_string(), "Error updating concour");
|
||||||
));
|
// return Err(StopConcourError::UnknownError(
|
||||||
}
|
// "Error updating concour".to_string(),
|
||||||
}
|
// ));
|
||||||
Ok(Some(concour))
|
// }
|
||||||
|
// }
|
||||||
|
// Ok(Some(concour))
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ use std::sync::Arc;
|
|||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use tracing::{info, instrument};
|
use tracing::{info, instrument};
|
||||||
|
|
||||||
use super::cmd::concour::concour::concour;
|
use super::cmd::concour::main::concour;
|
||||||
|
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
pub config_img: ConfigFile,
|
pub config_img: ConfigFile,
|
||||||
|
Loading…
Reference in New Issue
Block a user