-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update? #15
base: master
Are you sure you want to change the base?
update? #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I currently do not plan on storing the images themselves anywhere and instead just using the images hosted on discord. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah |
||
println!("Approved image: {}", image_url); | ||
|
||
poise::send_reply( | ||
ctx, | ||
CreateReply::default() | ||
.content("Image approved.") | ||
.ephemeral(true), | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
}); | ||
|
||
Comment on lines
+61
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like and and I want to have it as you can see from #14 |
||
// If there is an error starting up the client | ||
if let Err(e) = client.start_autosharded().await { | ||
error!("Startup Error: {:?}", e); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bot is designed to run in multiple guilds so a hard coded value at this point would not work :<
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes forgot about that, I'll work on changing it