diff --git a/src/commands.rs b/src/commands.rs index 7cc32a4..afb9c1c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,4 +1,5 @@ // this file is to let main.rs know the existence of the "commands" folder pub mod info; +pub mod mods_only; pub mod verification; pub mod weather; diff --git a/src/commands/mods_only.rs b/src/commands/mods_only.rs new file mode 100644 index 0000000..9c816b1 --- /dev/null +++ b/src/commands/mods_only.rs @@ -0,0 +1,68 @@ +use crate::{Context, Error}; +use poise::CreateReply; +use serenity::all::CreateEmbed; + +/// Create a message embed +#[poise::command( + track_edits, + slash_command, + required_permissions = "MANAGE_MESSAGES | MANAGE_THREADS" +)] +pub async fn embed( + ctx: Context<'_>, + #[description = "Title of embed"] title: Option, + #[description = "URL for Title"] title_url: Option, + #[description = "Description for Embed"] description: Option, + #[description = "Footer text"] footer: Option, + #[description = "Embed colour"] colour: Option, + #[description = "Image URL for thumbnail"] thumbnail_url: Option, + #[description = "Image URL"] image_url: Option, + #[description = "Show timestamp"] timestamp: Option, +) -> Result<(), Error> { + let mut embed = CreateEmbed::new(); + + // Set title and title URL + if let Some(title) = title { + embed = embed.title(title); + if let Some(url) = title_url { + embed = embed.url(url); + } + } + + // Set description + if let Some(desc) = description { + embed = embed.description(desc); + } + + // Set footer + if let Some(footer_text) = footer { + embed = embed.footer(serenity::all::CreateEmbedFooter::new(footer_text)); + } + + // Set color (parse hex color) + if let Some(color_str) = colour { + if let Ok(color_value) = u32::from_str_radix(color_str.trim_start_matches('#'), 16) { + embed = embed.color(color_value); + } + } + + // Set thumbnail + if let Some(thumb_url) = thumbnail_url { + embed = embed.thumbnail(thumb_url); + } + + // Set image + if let Some(img_url) = image_url { + embed = embed.image(img_url); + } + + // Set timestamp + if timestamp.unwrap_or(false) { + embed = embed.timestamp(serenity::model::Timestamp::now()); + } + + // Send the embed + ctx.send(CreateReply::default().embed(embed)).await?; + + Ok(()) +} diff --git a/src/commands/verification.rs b/src/commands/verification.rs index 01c48be..94286fe 100644 --- a/src/commands/verification.rs +++ b/src/commands/verification.rs @@ -2,10 +2,7 @@ use crate::{Data, Error}; use dotenv::dotenv; use poise::{CreateReply, Modal}; use serde::{Deserialize, Serialize}; -use serenity::all::{ - ComponentInteractionCollector, CreateActionRow, CreateButton, CreateEmbed, CreateEmbedFooter, - GuildId, RoleId, -}; +use serenity::all::{CreateEmbed, CreateEmbedFooter, GuildId, RoleId}; type ApplicationContext<'a> = poise::ApplicationContext<'a, Data, Error>; diff --git a/src/main.rs b/src/main.rs index 79bf7b1..de1200c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,11 +55,21 @@ async fn main() { commands::info::botinfo(), commands::weather::weather(), commands::verification::verify(), + commands::mods_only::embed(), ], + event_handler: |_ctx, _event, _framework, _data| { + Box::pin(async move { + // println!("Got an event in event handler: {:?}", event); + + Ok(()) + }) + }, + ..Default::default() }) .setup(|ctx, _ready, framework| { Box::pin(async move { + println!("Logged in as {}", _ready.user.name); poise::builtins::register_globally(ctx, &framework.options().commands).await?; Ok(Data { state: app_state }) })