diff --git a/commands/banner.rs b/commands/banner.rs new file mode 100644 index 0000000..07d4241 --- /dev/null +++ b/commands/banner.rs @@ -0,0 +1,69 @@ +use poise::serenity_prelude::{AttachmentType, ChannelId, CreateEmbed, EmbedMessageBuilding}; + +/// Command to submit an image for the banner rotation +#[poise::command( + prefix_command, + slash_command, + guild_only, + required_bot_permissions = "SEND_MESSAGES", +)] +pub async fn submit_image( + ctx: Context<'_>, + #[description = "Image to submit"] image: AttachmentType, +) -> Result<(), Error> { + let guild_id = ctx.guild_id().ok_or(CommandErr::GuildOnly)?; + + // Define the private channel ID where submissions will be sent + let private_channel_id = ChannelId(123456789012345678); // Replace with your private channel ID + + // Create an embed with the submitted image + let embed = CreateEmbed::new() + .title("New Image Submission") + .description(format!("Submitted by <@{}>", ctx.author().id)) + .image(image.url()) + .colour((0, 255, 0)); + + // Send the embed to the private channel + private_channel_id + .send_message(ctx.http(), |m| m.set_embed(embed)) + .await?; + + // Acknowledge the submission + poise::send_reply( + ctx, + CreateReply::default() + .content("Image submitted for review.") + .ephemeral(true), + ) + .await?; + + Ok(()) +} + +/// Command to approve an image +#[poise::command( + prefix_command, + slash_command, + guild_only, + required_permissions = "MANAGE_GUILD", +)] +pub async fn approve_image( + ctx: Context<'_>, + #[description = "Image URL to approve"] image_url: String, +) -> Result<(), Error> { + let guild_id = ctx.guild_id().ok_or(CommandErr::GuildOnly)?; + + // Add the approved image to the rotation (implement your own storage for approved images) + // For simplicity, we'll just log it here + println!("Approved image: {}", image_url); + + poise::send_reply( + ctx, + CreateReply::default() + .content("Image approved.") + .ephemeral(true), + ) + .await?; + + Ok(()) +} diff --git a/src/bin/bot.rs b/src/bin/bot.rs index e59cf03..4e3b859 100644 --- a/src/bin/bot.rs +++ b/src/bin/bot.rs @@ -1,7 +1,7 @@ use clap::Parser; use discord_banner_bot::{ cli::BotCli, - commands::commands, + commands::{commands, banner::{submit_image, approve_image}}, error::{self, Error}, startup::{event_handler, State}, utils::start_logging, @@ -11,6 +11,7 @@ use poise::{ serenity_prelude::{self, GatewayIntents}, FrameworkOptions, PrefixFrameworkOptions, }; +use tokio::signal; use tracing::{error, info}; #[tokio::main] @@ -27,7 +28,11 @@ async fn main() -> Result<(), Error> { // set up & start client let framework = poise::Framework::builder() .options(FrameworkOptions { - commands: commands(), + commands: vec![ + submit_image(), + approve_image(), + // other commands... + ], on_error: |err| { Box::pin(async move { if let Err(e) = error::handle_framework_error(err).await { @@ -53,6 +58,14 @@ async fn main() -> Result<(), Error> { .framework(framework) .await?; + // Spawn a task to handle SIGINT + let shard_manager = client.shard_manager.clone(); + tokio::spawn(async move { + signal::ctrl_c().await.expect("Failed to listen for ctrl_c"); + shard_manager.lock().await.shutdown_all().await; + info!("Received SIGINT, shutting down."); + }); + // If there is an error starting up the client if let Err(e) = client.start_autosharded().await { error!("Startup Error: {:?}", e);