Skip to content

Commit

Permalink
Update top.gg stats every 3 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
jdh8 committed May 5, 2024
1 parent 2c9cc69 commit b32d972
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 76 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "natsuki"
version = "3.0.3"
version = "3.0.4"
authors = [
"Chen-Pang He (https://jdh8.org)",
"u/YourWrstNightmare (https://www.reddit.com/user/YourWrstNightmare)",
Expand All @@ -18,6 +18,7 @@ anyhow = "1.0.75"
base64 = "0.22.1"
bitflags = "2.4.0"
chrono = "0.4.30"
command_attr = "0.5.1"
csscolorparser = "0.6.2"
futures = "0.3.28"
image = "0.25.0"
Expand All @@ -31,5 +32,6 @@ shuttle-runtime = "0.44.0"
shuttle-serenity = "0.44.0"
strum = { version = "0.26", features = ["derive"] }
tokio = { version = "1.32.0", features = ["full"] }
topgg = { version = "1.4.1", features = ["autoposter", "serenity-cached"] }
tree_magic_mini = "3.0.3"
webp = "0.3.0"
22 changes: 14 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod fun;
mod information;
mod tools;
mod weeb;
mod topgg;
use anyhow::Context as _;
use poise::serenity_prelude as serenity;

Expand Down Expand Up @@ -57,9 +56,13 @@ fn get_commands() -> Vec<poise::Command<Data, anyhow::Error>> {
async fn main(
#[shuttle_runtime::Secrets] secrets: shuttle_runtime::SecretStore,
) -> shuttle_serenity::ShuttleSerenity {
let poster = topgg::Poster::new(secrets.get("TOP_GG_TOKEN"));
let token = secrets.get("TOKEN").context("Discord token not found")?;

let poster = secrets.get("TOP_GG_TOKEN").map(|token| {
let client = topgg::Client::new(token);
topgg::Autoposter::serenity(&client, std::time::Duration::from_secs(10800)).handler()
});

let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: secrets.get("CLEAR").map_or_else(get_commands, |_| Vec::new()),
Expand All @@ -80,12 +83,15 @@ async fn main(
})
.build();

Ok(serenity::ClientBuilder::new(token, serenity::GatewayIntents::non_privileged())
.framework(framework)
.event_handler(poster)
.await
.map_err(shuttle_runtime::CustomError::new)?
.into())
let client = serenity::ClientBuilder
::new(token, serenity::GatewayIntents::non_privileged())
.framework(framework);

let client = match poster {
Some(p) => client.event_handler_arc(p),
None => client,
};
Ok(client.await.map_err(shuttle_runtime::CustomError::new)?.into())
}

#[macro_export]
Expand Down
67 changes: 0 additions & 67 deletions src/topgg.rs

This file was deleted.

0 comments on commit b32d972

Please sign in to comment.