shuttling
This commit is contained in:
parent
9d5b56344e
commit
7125859750
11 changed files with 1074 additions and 2910 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
/target
|
||||
/Secrets.toml
|
||||
|
|
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="RsMainFunctionNotFound" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
1047
Cargo.lock
generated
1047
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -8,5 +8,10 @@ edition = "2021"
|
|||
[dependencies]
|
||||
poise = "0.5.6"
|
||||
serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "model", "rustls_backend", "utils"]}
|
||||
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }
|
||||
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread", "rt"] }
|
||||
env_logger = "0.10.0"
|
||||
shuttle-secrets = "0.30.0"
|
||||
shuttle-poise = "0.30.0"
|
||||
shuttle-runtime = "0.30.0"
|
||||
anyhow = "1.0.75"
|
||||
tracing = "0.1.40"
|
||||
|
|
1
Secrets.toml
Normal file
1
Secrets.toml
Normal file
|
@ -0,0 +1 @@
|
|||
DISCORD_TOKEN = 'MTE2NTU5NDA3NDQ3MzAzNzgyNA.GCjpKR.ZD6w2nrUntDpmPGAboYoZH4aR30mKC2TMaaBmM'
|
24
src/main.rs
24
src/main.rs
|
@ -6,10 +6,11 @@ use serenity::client::EventHandler;
|
|||
use serenity::model::id::UserId;
|
||||
use std::collections::HashSet;
|
||||
use std::convert::Into;
|
||||
|
||||
use shuttle_secrets::SecretStore;
|
||||
use shuttle_poise::ShuttlePoise;
|
||||
struct Data {} // User data, which is stored and accessible in all command invocations
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
pub struct Data {}
|
||||
struct ReadyHandler;
|
||||
|
||||
#[async_trait]
|
||||
|
@ -23,8 +24,12 @@ impl EventHandler for ReadyHandler {
|
|||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
#[shuttle_runtime::main]
|
||||
async fn poise(
|
||||
#[shuttle_secrets::Secrets]
|
||||
secret_store: SecretStore
|
||||
) -> ShuttlePoise<Data, Error> {
|
||||
|
||||
let options = poise::FrameworkOptions {
|
||||
commands: vec![
|
||||
commands::lfg::lfg(),
|
||||
|
@ -53,10 +58,11 @@ async fn main() {
|
|||
},
|
||||
..Default::default()
|
||||
};
|
||||
let discord_token = secret_store.get("DISCORD_TOKEN").unwrap();
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.options(options)
|
||||
.token(std::env::var("DISCORD_TOKEN").unwrap())
|
||||
.token(discord_token)
|
||||
.intents(
|
||||
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT,
|
||||
)
|
||||
|
@ -65,9 +71,11 @@ async fn main() {
|
|||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
Ok(Data {})
|
||||
})
|
||||
});
|
||||
|
||||
framework.run().await.unwrap();
|
||||
})
|
||||
.build()
|
||||
.await
|
||||
.map_err(shuttle_runtime::CustomError::new)?;
|
||||
Ok(framework.into())
|
||||
}
|
||||
async fn event_handler(
|
||||
_ctx: &serenity::Context,
|
||||
|
|
3
y/.gitignore
vendored
3
y/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
/target
|
||||
.shuttle-storage
|
||||
Secrets*.toml
|
2823
y/Cargo.lock
generated
2823
y/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
14
y/Cargo.toml
14
y/Cargo.toml
|
@ -1,14 +0,0 @@
|
|||
[package]
|
||||
name = "zmp-bot"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.68"
|
||||
poise = "0.5.2"
|
||||
shuttle-poise = "0.30.0"
|
||||
shuttle-runtime = "0.30.0"
|
||||
shuttle-secrets = "0.30.0"
|
||||
tracing = "0.1.37"
|
||||
tokio = "1.26.0"
|
16
y/README.md
16
y/README.md
|
@ -1,16 +0,0 @@
|
|||
# Poise Hello World Bot with Shuttle
|
||||
|
||||
In this example we will deploy a Poise/Serenity bot with Shuttle that responds to the `/hello` command with `world!`. To run this bot we need a valid Discord Token. To get started log in to the [Discord developer portal](https://discord.com/developers/applications).
|
||||
|
||||
1. Click the New Application button, name your application and click Create.
|
||||
2. Navigate to the Bot tab in the lefthand menu, and add a new bot.
|
||||
3. On the bot page click the Reset Token button to reveal your token. Put this token in your `Secrets.toml`. It's very important that you don't reveal your token to anyone, as it can be abused. Create a `.gitignore` file to omit your `Secrets.toml` from version control.
|
||||
4. For the sake of this example, you also need to scroll down on the bot page to the Message Content Intent section and enable that option.
|
||||
|
||||
To add the bot to a server we need to create an invite link.
|
||||
|
||||
1. On your bot's application page, open the OAuth2 page via the lefthand panel.
|
||||
2. Go to the URL Generator via the lefthand panel, and select the `bot` scope as well as the `Send Messages` permission in the Bot Permissions section.
|
||||
3. Copy the URL, open it in your browser and select a Discord server you wish to invite the bot to.
|
||||
|
||||
For more information please refer to the [Discord docs](https://discord.com/developers/docs/getting-started) as well as the [Poise docs](https://docs.rs/poise) for more examples.
|
|
@ -1,42 +0,0 @@
|
|||
use anyhow::Context as _;
|
||||
use poise::serenity_prelude as serenity;
|
||||
use shuttle_poise::ShuttlePoise;
|
||||
use shuttle_secrets::SecretStore;
|
||||
|
||||
struct Data {} // User data, which is stored and accessible in all command invocations
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
||||
/// Responds with "world!"
|
||||
#[poise::command(slash_command)]
|
||||
async fn hello(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.say("world!").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[shuttle_runtime::main]
|
||||
async fn poise(#[shuttle_secrets::Secrets] secret_store: SecretStore) -> ShuttlePoise<Data, Error> {
|
||||
// Get the discord token set in `Secrets.toml`
|
||||
let discord_token = secret_store
|
||||
.get("DISCORD_TOKEN")
|
||||
.context("'DISCORD_TOKEN' was not found")?;
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![hello()],
|
||||
..Default::default()
|
||||
})
|
||||
.token(discord_token)
|
||||
.intents(serenity::GatewayIntents::non_privileged())
|
||||
.setup(|ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
Ok(Data {})
|
||||
})
|
||||
})
|
||||
.build()
|
||||
.await
|
||||
.map_err(shuttle_runtime::CustomError::new)?;
|
||||
|
||||
Ok(framework.into())
|
||||
}
|
Loading…
Add table
Reference in a new issue