mirror of
https://github.com/arthur-pbty/shadowbot.git
synced 2026-06-16 08:12:46 +02:00
netoyage et optimisation des commande pour que elle soit trier correctement
This commit is contained in:
@@ -12,49 +12,13 @@ pub async fn handle_autopublish(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
return;
|
||||
};
|
||||
|
||||
if args.is_empty() {
|
||||
let Some(pool) = ({
|
||||
let data = ctx.data.read().await;
|
||||
data.get::<db::DbPoolKey>().cloned()
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let bot_id = ctx.cache.current_user().id.get() as i64;
|
||||
let channels = db::get_autopublish_channels(&pool, bot_id, guild_id.get() as i64)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
let description = if channels.is_empty() {
|
||||
"Aucun salon d'annonces configuré.".to_string()
|
||||
} else {
|
||||
channels
|
||||
.into_iter()
|
||||
.map(|channel| format!("<#{}>", channel.channel_id))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
};
|
||||
|
||||
if !args.is_empty() {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Autopublish")
|
||||
.description(description)
|
||||
.colour(Colour::from_rgb(100, 150, 255)),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
let enabled = args[0].eq_ignore_ascii_case("on") || args[0].eq_ignore_ascii_case("enable");
|
||||
let disabled = args[0].eq_ignore_ascii_case("off") || args[0].eq_ignore_ascii_case("disable");
|
||||
if !enabled && !disabled {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Autopublish")
|
||||
.description("Utilisation: +autopublish on|off [#canal]")
|
||||
.description("Utilisation: +autopublish")
|
||||
.color(0xED4245),
|
||||
)
|
||||
.await;
|
||||
@@ -68,18 +32,53 @@ pub async fn handle_autopublish(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
return;
|
||||
};
|
||||
|
||||
let bot_id = ctx.cache.current_user().id.get() as i64;
|
||||
let guild_id_i64 = guild_id.get() as i64;
|
||||
|
||||
let channels = db::get_autopublish_channels(&pool, bot_id, guild_id_i64)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
let description = if channels.is_empty() {
|
||||
"Aucun salon d'annonces configuré.".to_string()
|
||||
} else {
|
||||
channels
|
||||
.into_iter()
|
||||
.map(|channel| format!("<#{}>", channel.channel_id))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
};
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Autopublish")
|
||||
.description(description)
|
||||
.colour(Colour::from_rgb(100, 150, 255)),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn handle_autopublishon(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
let Some(guild_id) = msg.guild_id else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(pool) = ({
|
||||
let data = ctx.data.read().await;
|
||||
data.get::<db::DbPoolKey>().cloned()
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let bot_id = ctx.cache.current_user().id.get() as i64;
|
||||
let guild_id_i64 = guild_id.get() as i64;
|
||||
let channel_id = args
|
||||
.get(1)
|
||||
.first()
|
||||
.and_then(|value| parse_channel_id(value))
|
||||
.unwrap_or(msg.channel_id);
|
||||
|
||||
let result = if enabled {
|
||||
db::add_autopublish_channel(&pool, bot_id, guild_id_i64, channel_id.get() as i64).await
|
||||
} else {
|
||||
db::remove_autopublish_channel(&pool, bot_id, guild_id_i64, channel_id.get() as i64).await
|
||||
};
|
||||
let result = db::add_autopublish_channel(&pool, bot_id, guild_id_i64, channel_id.get() as i64).await;
|
||||
|
||||
if result.is_err() {
|
||||
send_embed(
|
||||
@@ -94,21 +93,63 @@ pub async fn handle_autopublish(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
return;
|
||||
}
|
||||
|
||||
let embed = if enabled {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Autopublish activé")
|
||||
.description(format!("Salon: <#{}>", channel_id.get()))
|
||||
.colour(Colour::from_rgb(0, 200, 120))
|
||||
.timestamp(Utc::now())
|
||||
} else {
|
||||
.timestamp(Utc::now()),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn handle_autopublishoff(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
let Some(guild_id) = msg.guild_id else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(pool) = ({
|
||||
let data = ctx.data.read().await;
|
||||
data.get::<db::DbPoolKey>().cloned()
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let bot_id = ctx.cache.current_user().id.get() as i64;
|
||||
let guild_id_i64 = guild_id.get() as i64;
|
||||
let channel_id = args
|
||||
.first()
|
||||
.and_then(|value| parse_channel_id(value))
|
||||
.unwrap_or(msg.channel_id);
|
||||
|
||||
let result =
|
||||
db::remove_autopublish_channel(&pool, bot_id, guild_id_i64, channel_id.get() as i64).await;
|
||||
|
||||
if result.is_err() {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Autopublish")
|
||||
.description("Impossible de mettre à jour le salon d'annonces.")
|
||||
.color(0xED4245),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Autopublish désactivé")
|
||||
.description(format!("Salon: <#{}>", channel_id.get()))
|
||||
.colour(Colour::from_rgb(255, 120, 0))
|
||||
.timestamp(Utc::now())
|
||||
};
|
||||
|
||||
send_embed(ctx, msg, embed).await;
|
||||
.timestamp(Utc::now()),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub struct AutopublishCommand;
|
||||
@@ -119,13 +160,9 @@ impl crate::commands::command_contract::CommandSpec for AutopublishCommand {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "autopublish",
|
||||
category: "automation",
|
||||
params: "on|off [#canal]",
|
||||
description: "Affiche, active ou desactive la publication automatique des annonces.",
|
||||
examples: &[
|
||||
"+autopublish",
|
||||
"+autopublish on #annonces",
|
||||
"+help autopublish",
|
||||
],
|
||||
params: "aucun",
|
||||
description: "Affiche les salons ou la publication automatique des annonces est active.",
|
||||
examples: &["+autopublish", "+help autopublish"],
|
||||
default_aliases: &["apb"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 5,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub async fn handle_autopublishoff_command(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
crate::commands::autopublish::handle_autopublishoff(ctx, msg, args).await;
|
||||
}
|
||||
|
||||
pub struct AutopublishoffCommand;
|
||||
pub static COMMAND_DESCRIPTOR: AutopublishoffCommand = AutopublishoffCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for AutopublishoffCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "autopublishoff",
|
||||
category: "automation",
|
||||
params: "[#canal]",
|
||||
description: "Desactive la publication automatique des annonces sur un salon.",
|
||||
examples: &["+autopublishoff", "+autopublishoff #annonces", "+help autopublishoff"],
|
||||
default_aliases: &["apboff"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub async fn handle_autopublishon_command(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
crate::commands::autopublish::handle_autopublishon(ctx, msg, args).await;
|
||||
}
|
||||
|
||||
pub struct AutopublishonCommand;
|
||||
pub static COMMAND_DESCRIPTOR: AutopublishonCommand = AutopublishonCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for AutopublishonCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "autopublishon",
|
||||
category: "automation",
|
||||
params: "[#canal]",
|
||||
description: "Active la publication automatique des annonces sur un salon.",
|
||||
examples: &["+autopublishon", "+autopublishon #annonces", "+help autopublishon"],
|
||||
default_aliases: &["apbon"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,61 +106,65 @@ pub async fn handle_piconly(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
let bot_id = ctx.cache.current_user().id.get() as i64;
|
||||
let guild_id_i64 = guild_id.get() as i64;
|
||||
|
||||
if args.is_empty() {
|
||||
let channels = db::get_piconly_channels(&pool, bot_id, guild_id_i64)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
let description = if channels.is_empty() {
|
||||
"Aucun salon selfie configure.".to_string()
|
||||
} else {
|
||||
channels
|
||||
.into_iter()
|
||||
.map(|channel| format!("<#{}>", channel.channel_id))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
};
|
||||
|
||||
if !args.is_empty() {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("PicOnly")
|
||||
.description(description)
|
||||
.timestamp(Utc::now()),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
let adding = args[0].eq_ignore_ascii_case("add");
|
||||
let deleting = args[0].eq_ignore_ascii_case("del")
|
||||
|| args[0].eq_ignore_ascii_case("remove")
|
||||
|| args[0].eq_ignore_ascii_case("delete");
|
||||
|
||||
if !adding && !deleting {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("PicOnly")
|
||||
.description("Utilisation: +piconly <add/del> [#salon]")
|
||||
.description("Utilisation: +piconly")
|
||||
.color(0xED4245),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
let channels = db::get_piconly_channels(&pool, bot_id, guild_id_i64)
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
let description = if channels.is_empty() {
|
||||
"Aucun salon selfie configure.".to_string()
|
||||
} else {
|
||||
channels
|
||||
.into_iter()
|
||||
.map(|channel| format!("<#{}>", channel.channel_id))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
};
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("PicOnly")
|
||||
.description(description)
|
||||
.timestamp(Utc::now()),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn handle_piconlyadd(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
let Some(guild_id) = msg.guild_id else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(pool) = ({
|
||||
let data = ctx.data.read().await;
|
||||
data.get::<db::DbPoolKey>().cloned()
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let bot_id = ctx.cache.current_user().id.get() as i64;
|
||||
let guild_id_i64 = guild_id.get() as i64;
|
||||
|
||||
let channel_id = args
|
||||
.get(1)
|
||||
.first()
|
||||
.and_then(|raw| parse_channel_id(raw))
|
||||
.unwrap_or(msg.channel_id);
|
||||
|
||||
let result = if adding {
|
||||
db::add_piconly_channel(&pool, bot_id, guild_id_i64, channel_id.get() as i64).await
|
||||
} else {
|
||||
db::remove_piconly_channel(&pool, bot_id, guild_id_i64, channel_id.get() as i64).await
|
||||
};
|
||||
let result = db::add_piconly_channel(&pool, bot_id, guild_id_i64, channel_id.get() as i64).await;
|
||||
|
||||
if result.is_err() {
|
||||
send_embed(
|
||||
@@ -175,19 +179,61 @@ pub async fn handle_piconly(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
return;
|
||||
}
|
||||
|
||||
let embed = if adding {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Salon selfie ajoute")
|
||||
.description(format!("Salon: <#{}>", channel_id.get()))
|
||||
.timestamp(Utc::now())
|
||||
} else {
|
||||
.timestamp(Utc::now()),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn handle_piconlydel(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
let Some(guild_id) = msg.guild_id else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(pool) = ({
|
||||
let data = ctx.data.read().await;
|
||||
data.get::<db::DbPoolKey>().cloned()
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let bot_id = ctx.cache.current_user().id.get() as i64;
|
||||
let guild_id_i64 = guild_id.get() as i64;
|
||||
|
||||
let channel_id = args
|
||||
.first()
|
||||
.and_then(|raw| parse_channel_id(raw))
|
||||
.unwrap_or(msg.channel_id);
|
||||
|
||||
let result = db::remove_piconly_channel(&pool, bot_id, guild_id_i64, channel_id.get() as i64).await;
|
||||
|
||||
if result.is_err() {
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("PicOnly")
|
||||
.description("Impossible de mettre a jour le salon selfie.")
|
||||
.color(0xED4245),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
send_embed(
|
||||
ctx,
|
||||
msg,
|
||||
CreateEmbed::new()
|
||||
.title("Salon selfie retire")
|
||||
.description(format!("Salon: <#{}>", channel_id.get()))
|
||||
.timestamp(Utc::now())
|
||||
};
|
||||
|
||||
send_embed(ctx, msg, embed).await;
|
||||
.timestamp(Utc::now()),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub struct PiconlyCommand;
|
||||
@@ -198,9 +244,9 @@ impl crate::commands::command_contract::CommandSpec for PiconlyCommand {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "piconly",
|
||||
category: "automation",
|
||||
params: "<add/del> [salon]",
|
||||
description: "Definit ou supprime un salon selfie, ou les membres ne peuvent envoyer que des photos.",
|
||||
examples: &["+piconly", "+piconly add #selfie", "+piconly del #selfie"],
|
||||
params: "aucun",
|
||||
description: "Affiche la liste des salons selfie, ou les membres ne peuvent envoyer que des photos.",
|
||||
examples: &["+piconly", "+help piconly"],
|
||||
default_aliases: &["selfieonly"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 6,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub async fn handle_piconlyadd_command(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
crate::commands::piconly::handle_piconlyadd(ctx, msg, args).await;
|
||||
}
|
||||
|
||||
pub struct PiconlyaddCommand;
|
||||
pub static COMMAND_DESCRIPTOR: PiconlyaddCommand = PiconlyaddCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for PiconlyaddCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "piconlyadd",
|
||||
category: "automation",
|
||||
params: "[#salon]",
|
||||
description: "Ajoute un salon selfie (photos uniquement).",
|
||||
examples: &["+piconlyadd", "+piconlyadd #selfie", "+help piconlyadd"],
|
||||
default_aliases: &["selfieadd"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 6,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
use serenity::model::prelude::*;
|
||||
use serenity::prelude::*;
|
||||
|
||||
pub async fn handle_piconlydel_command(ctx: &Context, msg: &Message, args: &[&str]) {
|
||||
crate::commands::piconly::handle_piconlydel(ctx, msg, args).await;
|
||||
}
|
||||
|
||||
pub struct PiconlydelCommand;
|
||||
pub static COMMAND_DESCRIPTOR: PiconlydelCommand = PiconlydelCommand;
|
||||
|
||||
impl crate::commands::command_contract::CommandSpec for PiconlydelCommand {
|
||||
fn metadata(&self) -> crate::commands::command_contract::CommandMetadata {
|
||||
crate::commands::command_contract::CommandMetadata {
|
||||
name: "piconlydel",
|
||||
category: "automation",
|
||||
params: "[#salon]",
|
||||
description: "Retire un salon selfie (photos uniquement).",
|
||||
examples: &["+piconlydel", "+piconlydel #selfie", "+help piconlydel"],
|
||||
default_aliases: &["selfiedel"],
|
||||
allow_in_dm: false,
|
||||
default_permission: 6,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user