Skip to content

Commit

Permalink
Add /vote command
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinegb committed Jul 31, 2024
1 parent cb3d21f commit 16b8715
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ chrono = "0.4.38"
paste = "1.0.15"
octocrab = "0.38.0"
serde_json = "1.0.120"
topgg = { version = "1.4.1", features = ["autoposter", "serenity-cached"] }
topgg = { version = "1.4.1", features = ["autoposter", "serenity-cached"], git = "https://github.com/valentinegb/topgg-rs.git", branch = "client-debug-impl" }

[workspace]
members = ["shuttle-persist-msgpack"]
4 changes: 4 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod rock_paper_scissors;
mod silly;
mod sponsors;
mod strike;
#[cfg(not(debug_assertions))]
mod vote;

pub(super) use anon::*;
pub(super) use config::*;
Expand All @@ -29,3 +31,5 @@ pub(super) use rock_paper_scissors::*;
pub(super) use silly::*;
pub(super) use sponsors::*;
pub(super) use strike::*;
#[cfg(not(debug_assertions))]
pub(super) use vote::*;
26 changes: 26 additions & 0 deletions src/commands/vote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use poise::command;

use crate::{emoji::*, Context, Error};

/// Vote for Goober Bot on Top.gg!
#[command(
slash_command,
install_context = "Guild|User",
interaction_context = "Guild|BotDm|PrivateChannel",
ephemeral
)]
pub(crate) async fn vote(ctx: Context<'_>) -> Result<(), Error> {
let has_voted = ctx.data().topgg_client.has_voted(ctx.author().id).await?;
let message = if has_voted {
format!("You've already voted today, thank you so much! ily {FLOOF_HEART}")
} else {
format!(
"You're able to vote for <@{bot_id}> on Top.gg today still! You can [do so here](https://top.gg/bot/{bot_id}/vote). Thank you for your consideration! {FLOOF_HAPPY}",
bot_id = ctx.framework().bot_id,
)
};

ctx.say(message).await?;

Ok(())
}
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ use crate::activity::start_activity_loop;
#[derive(Debug)]
struct Data {
persist: PersistInstance,
#[cfg(not(debug_assertions))]
topgg_client: topgg::Client,
}

type Context<'a> = poise::Context<'a, Data, Error>;
Expand Down Expand Up @@ -91,6 +93,8 @@ async fn main(
commands::rock_paper_scissors(),
commands::sponsors(),
commands::strike(),
#[cfg(not(debug_assertions))]
commands::vote(),
],
on_error: |error| {
Box::pin(async move {
Expand Down Expand Up @@ -120,7 +124,11 @@ async fn main(
octocrab::initialise(Octocrab::builder().personal_token(github_pat).build()?);
info!("GitHub authenticated");

Ok(Data { persist })
Ok(Data {
persist,
#[cfg(not(debug_assertions))]
topgg_client,
})
})
})
.build();
Expand Down

0 comments on commit 16b8715

Please sign in to comment.