Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "topgg"
version = "2.0.0"
version = "1.5.0"
edition = "2021"
authors = ["null (https://github.com/null8626)", "Top.gg <support@top.gg> (https://top.gg)"]
description = "A simple API wrapper for Top.gg written in Rust."
Expand All @@ -22,21 +22,21 @@ urlencoding = "2"

serenity = { version = "0.12", features = ["builder", "client", "gateway", "model", "utils"], optional = true }

twilight-http = { version = "0.15", optional = true }
twilight-model = { version = "0.15", optional = true }
twilight-cache-inmemory = { version = "0.15", optional = true }

chrono = { version = "0.4", default-features = false, optional = true, features = ["serde", "now"] }
chrono = { version = "0.4", default-features = false, optional = true, features = ["serde"] }
serde_json = { version = "1", optional = true }

rocket = { version = "0.5", default-features = false, features = ["json"], optional = true }
axum = { version = "0.8", default-features = false, optional = true, features = ["http1", "tokio"] }
async-trait = { version = "0.1", optional = true }
warp = { version = "0.3", default-features = false, optional = true }
actix-web = { version = "4", default-features = false, optional = true }
warp = { version = "0.4", default-features = false, features = ["server"], optional = true }
actix-web = { version = "4", default-features = false, features = ["macros"], optional = true }

[dev-dependencies]
tokio = { version = "1", features = ["rt", "macros"] }
reqwest = "0.12"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
twilight-gateway = "0.15"

[lints.clippy]
Expand All @@ -63,18 +63,19 @@ rustc-args = ["--cfg", "docsrs"]

[features]
default = ["api"]
api = ["async-trait", "base64", "chrono", "reqwest", "serde_json"]
bot-autoposter = ["api", "tokio"]
autoposter = ["bot-autoposter"]
api = ["base64", "chrono", "reqwest", "serde_json"]
autoposter = ["api", "tokio"]

serenity = ["dep:serenity", "paste"]
serenity = ["dep:serenity", "async-trait", "paste"]
serenity-cached = ["serenity", "serenity/cache"]

twilight = ["twilight-model", "twilight-http"]
twilight = ["twilight-model"]
twilight-cached = ["twilight", "twilight-cache-inmemory"]

webhooks = []
rocket = ["webhooks", "dep:rocket"]
axum = ["webhooks", "async-trait", "serde_json", "dep:axum"]
warp = ["webhooks", "async-trait", "dep:warp"]
actix-web = ["webhooks", "dep:actix-web"]
webhook = []
rocket = ["webhook", "async-trait", "dep:rocket"]
axum = ["webhook", "async-trait", "serde_json", "dep:axum"]
warp = ["webhook", "async-trait", "dep:warp"]
actix-web = ["webhook", "dep:actix-web"]

_internal-doctest = []
133 changes: 100 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
# [topgg](https://crates.io/crates/topgg) [![crates.io][crates-io-image]][crates-io-url] [![crates.io downloads][crates-io-downloads-image]][crates-io-url]
# [topgg](https://crates.io/crates/topgg) [![crates.io][crates-io-image]][crates-io-url] [![crates.io downloads][crates-io-downloads-image]][crates-io-url] [![license][github-license-image]][github-license-url] [![BLAZINGLY FAST!!!][blazingly-fast-image]][blazingly-fast-url]

[crates-io-image]: https://img.shields.io/crates/v/topgg?style=flat-square
[crates-io-downloads-image]: https://img.shields.io/crates/d/topgg?style=flat-square
[crates-io-url]: https://crates.io/crates/topgg

[github-license-image]: https://img.shields.io/github/license/top-gg/rust-sdk?style=flat-square
[github-license-url]: https://github.com/top-gg/rust-sdk/blob/main/LICENSE
[blazingly-fast-image]: https://img.shields.io/badge/speed-BLAZINGLY%20FAST!!!%20%F0%9F%94%A5%F0%9F%9A%80%F0%9F%92%AA%F0%9F%98%8E-brightgreen.svg?style=flat-square
[blazingly-fast-url]: https://twitter.com/acdlite/status/974390255393505280
The official Rust SDK for the [Top.gg API](https://docs.top.gg).

## Getting Started

Make sure to have a [Top.gg API](https://docs.top.gg) token handy. If not, then [view this tutorial on how to retrieve yours](https://github.com/top-gg/rust-sdk/assets/60427892/d2df5bd3-bc48-464c-b878-a04121727bff). After that, add the following line to the `dependencies` section of your `Cargo.toml`:

```toml
topgg = "1.4"
topgg = "1.5"
```

For more information, please read [the documentation](https://docs.rs/topgg)!

## Features

This library provides several feature flags that can be enabled/disabled in `Cargo.toml`. Such as:

- **`api`**: Interacting with the [Top.gg API](https://docs.top.gg) and accessing the `top.gg/api/*` endpoints. (enabled by default)
- **`autoposter`**: Automating the process of periodically posting bot statistics to the [Top.gg API](https://docs.top.gg).
- **`webhook`**: Accessing the [serde deserializable](https://docs.rs/serde/latest/serde/de/trait.DeserializeOwned.html) `topgg::Vote` struct.
- **`actix-web`**: Wrapper for working with the [actix-web](https://actix.rs/) web framework.
- **`axum`**: Wrapper for working with the [axum](https://crates.io/crates/axum) web framework.
- **`rocket`**: Wrapper for working with the [rocket](https://rocket.rs/) web framework.
- **`warp`**: Wrapper for working with the [warp](https://crates.io/crates/warp) web framework.
- **`serenity`**: Extra helpers for working with [serenity](https://crates.io/crates/serenity) library (with bot caching disabled).
- **`serenity-cached`**: Extra helpers for working with [serenity](https://crates.io/crates/serenity) library (with bot caching enabled).
- **`twilight`**: Extra helpers for working with [twilight](https://twilight.rs) library (with bot caching disabled).
- **`twilight-cached`**: Extra helpers for working with [twilight](https://twilight.rs) library (with bot caching enabled).
- **`webhook`**: Accessing the [`serde` deserializable](https://docs.rs/serde/latest/serde/de/trait.DeserializeOwned.html) `topgg::Vote` struct.
- **`actix-web`**: Wrapper for working with the [`actix-web`](https://actix.rs/) web framework.
- **`axum`**: Wrapper for working with the [`axum`](https://crates.io/crates/axum) web framework.
- **`rocket`**: Wrapper for working with the [`rocket`](https://rocket.rs/) web framework.
- **`warp`**: Wrapper for working with the [`warp`](https://crates.io/crates/warp) web framework.
- **`serenity`**: Extra helpers for working with [`serenity`](https://crates.io/crates/serenity) library (with bot caching disabled).
- **`serenity-cached`**: Extra helpers for working with [`serenity`](https://crates.io/crates/serenity) library (with bot caching enabled).
- **`twilight`**: Extra helpers for working with [`twilight`](https://twilight.rs) library (with bot caching disabled).
- **`twilight-cached`**: Extra helpers for working with [`twilight`](https://twilight.rs) library (with bot caching enabled).

## Examples

### Fetching a user from its Discord ID
More things can be read in the [documentation](https://docs.rs/topgg).

<details>
<summary><b><code>api</code></b>: Fetching a single Discord user from it's Discord ID</summary>

```rust,no_run
use topgg::Client;
Expand All @@ -51,7 +55,54 @@ async fn main() {
}
```

### Posting your bot's statistics
</details>
<details>
<summary><b><code>api</code></b>: Fetching a single Discord bot from it's Discord ID</summary>

```rust,no_run
use topgg::Client;

#[tokio::main]
async fn main() {
let client = Client::new(env!("TOPGG_TOKEN").to_string());
let bot = client.get_bot(264811613708746752).await.unwrap();

assert_eq!(bot.username, "Luca");
assert_eq!(bot.discriminator, "1375");
assert_eq!(bot.id, 264811613708746752);

println!("{:?}", bot);
}
```

</details>
<details>
<summary><b><code>api</code></b>: Querying several Discord bots</summary>

```rust,no_run
use topgg::Client;

#[tokio::main]
async fn main() {
let client = Client::new(env!("TOPGG_TOKEN").to_string());

let bots = client
.get_bots()
.limit(250)
.skip(50)
.username("shiro")
.certified(true)
.await;

for bot in bots {
println!("{:?}", bot);
}
}
```

</details>
<details>
<summary><b><code>api</code></b>: Posting your Discord bot's statistics</summary>

```rust,no_run
use topgg::{Client, Stats};
Expand All @@ -68,7 +119,9 @@ async fn main() {
}
```

### Checking if a user has voted your bot
</details>
<details>
<summary><b><code>api</code></b>: Checking if a user has voted for your Discord bot</summary>

```rust,no_run
use topgg::Client;
Expand All @@ -83,17 +136,19 @@ async fn main() {
}
```

### Autoposting with [serenity](https://crates.io/crates/serenity)
</details>
<details>
<summary><b><code>autoposter</code></b>, <b><code>serenity</code></b>: Automating the process of periodically posting your Discord bot's statistics with the <i><a href="https://crates.io/crates/serenity">serenity</a></i> library</summary>

In your `Cargo.toml`:

```toml
[dependencies]
# using serenity with guild caching disabled
topgg = { version = "1.4", features = ["autoposter", "serenity"] }
topgg = { version = "1.5", features = ["autoposter", "serenity"] }

# using serenity with guild caching enabled
topgg = { version = "1.4", features = ["autoposter", "serenity-cached"] }
topgg = { version = "1.5", features = ["autoposter", "serenity-cached"] }
```

In your code:
Expand Down Expand Up @@ -125,7 +180,7 @@ async fn main() {
let topgg_client = topgg::Client::new(env!("TOPGG_TOKEN").to_string());
let autoposter = Autoposter::serenity(&topgg_client, Duration::from_secs(1800));

let bot_token = env!("DISCORD_TOKEN").to_string();
let bot_token = env!("BOT_TOKEN").to_string();
let intents = GatewayIntents::GUILD_MESSAGES | GatewayIntents::GUILDS | GatewayIntents::MESSAGE_CONTENT;

let mut client = Client::builder(&bot_token, intents)
Expand All @@ -140,17 +195,19 @@ async fn main() {
}
```

### Autoposting with [twilight](https://twilight.rs)
</details>
<details>
<summary><b><code>autoposter</code></b>, <b><code>twilight</code></b>: Automating the process of periodically posting your Discord bot's statistics with the <i><a href="https://twilight.rs">twilight</a></i> library</summary>

In your `Cargo.toml`:

```toml
[dependencies]
# using twilight with guild caching disabled
topgg = { version = "1.4", features = ["autoposter", "twilight"] }
topgg = { version = "1.5", features = ["autoposter", "twilight"] }

# using twilight with guild caching enabled
topgg = { version = "1.4", features = ["autoposter", "twilight-cached"] }
topgg = { version = "1.5", features = ["autoposter", "twilight-cached"] }
```

In your code:
Expand All @@ -167,7 +224,7 @@ async fn main() {

let mut shard = Shard::new(
ShardId::ONE,
env!("DISCORD_TOKEN").to_string(),
env!("BOT_TOKEN").to_string(),
Intents::GUILD_MEMBERS | Intents::GUILDS,
);

Expand Down Expand Up @@ -196,13 +253,15 @@ async fn main() {
}
```

### Writing an [actix-web](https://actix.rs) webhook for listening to votes
</details>
<details>
<summary><b><code>actix-web</code></b>: Writing an <a href="https://actix.rs/"><code>actix-web</code></a> webhook for listening to your project's vote events</summary>

In your `Cargo.toml`:

```toml
[dependencies]
topgg = { version = "1.4", default-features = false, features = ["actix-web"] }
topgg = { version = "1.5", default-features = false, features = ["actix-web"] }
```

In your code:
Expand Down Expand Up @@ -241,13 +300,15 @@ async fn main() -> io::Result<()> {
}
```

### Writing an [axum](https://crates.io/crates/axum) webhook for listening to votes
</details>
<details>
<summary><b><code>axum</code></b>: Writing an <a href="https://crates.io/crates/axum"><code>axum</code></a> webhook for listening to your project's vote events</summary>

In your `Cargo.toml`:

```toml
[dependencies]
topgg = { version = "1.4", default-features = false, features = ["axum"] }
topgg = { version = "1.5", default-features = false, features = ["axum"] }
```

In your code:
Expand Down Expand Up @@ -288,13 +349,15 @@ async fn main() {
}
```

### Writing a [rocket](https://rocket.rs) webhook for listening to votes
</details>
<details>
<summary><b><code>rocket</code></b>: Writing a <a href="https://rocket.rs"><code>rocket</code></a> webhook for listening to your project's vote events</summary>

In your `Cargo.toml`:

```toml
[dependencies]
topgg = { version = "1.4", default-features = false, features = ["rocket"] }
topgg = { version = "1.5", default-features = false, features = ["rocket"] }
```

In your code:
Expand Down Expand Up @@ -333,13 +396,15 @@ fn main() {
}
```

### Writing a [warp](https://crates.io/crates/warp) webhook for listening to votes
</details>
<details>
<summary><b><code>warp</code></b>: Writing a <a href="https://crates.io/crates/warp"><code>warp</code></a> webhook for listening to your project's vote events</summary>

In your `Cargo.toml`:

```toml
[dependencies]
topgg = { version = "1.4", default-features = false, features = ["warp"] }
topgg = { version = "1.5", default-features = false, features = ["warp"] }
```

In your code:
Expand Down Expand Up @@ -376,3 +441,5 @@ async fn main() {
warp::serve(routes).run(addr).await
}
```

</details>
File renamed without changes.
Loading