mirror of
https://github.com/dsec-hub/dsec-discord-bot.git
synced 2026-09-22 07:44:26 +00:00
added embed command
This commit is contained in:
parent
7e6d4f014c
commit
54ba36ee1f
4 changed files with 80 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
// this file is to let main.rs know the existence of the "commands" folder
|
// this file is to let main.rs know the existence of the "commands" folder
|
||||||
pub mod info;
|
pub mod info;
|
||||||
|
pub mod mods_only;
|
||||||
pub mod verification;
|
pub mod verification;
|
||||||
pub mod weather;
|
pub mod weather;
|
||||||
|
|
|
||||||
68
src/commands/mods_only.rs
Normal file
68
src/commands/mods_only.rs
Normal file
|
|
@ -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<String>,
|
||||||
|
#[description = "URL for Title"] title_url: Option<String>,
|
||||||
|
#[description = "Description for Embed"] description: Option<String>,
|
||||||
|
#[description = "Footer text"] footer: Option<String>,
|
||||||
|
#[description = "Embed colour"] colour: Option<String>,
|
||||||
|
#[description = "Image URL for thumbnail"] thumbnail_url: Option<String>,
|
||||||
|
#[description = "Image URL"] image_url: Option<String>,
|
||||||
|
#[description = "Show timestamp"] timestamp: Option<bool>,
|
||||||
|
) -> 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(())
|
||||||
|
}
|
||||||
|
|
@ -2,10 +2,7 @@ use crate::{Data, Error};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use poise::{CreateReply, Modal};
|
use poise::{CreateReply, Modal};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serenity::all::{
|
use serenity::all::{CreateEmbed, CreateEmbedFooter, GuildId, RoleId};
|
||||||
ComponentInteractionCollector, CreateActionRow, CreateButton, CreateEmbed, CreateEmbedFooter,
|
|
||||||
GuildId, RoleId,
|
|
||||||
};
|
|
||||||
|
|
||||||
type ApplicationContext<'a> = poise::ApplicationContext<'a, Data, Error>;
|
type ApplicationContext<'a> = poise::ApplicationContext<'a, Data, Error>;
|
||||||
|
|
||||||
|
|
|
||||||
10
src/main.rs
10
src/main.rs
|
|
@ -55,11 +55,21 @@ async fn main() {
|
||||||
commands::info::botinfo(),
|
commands::info::botinfo(),
|
||||||
commands::weather::weather(),
|
commands::weather::weather(),
|
||||||
commands::verification::verify(),
|
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()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.setup(|ctx, _ready, framework| {
|
.setup(|ctx, _ready, framework| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
println!("Logged in as {}", _ready.user.name);
|
||||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||||
Ok(Data { state: app_state })
|
Ok(Data { state: app_state })
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue