Basic serenity-rs/poise bot

This commit is contained in:
Aadi Desai 2023-09-12 00:43:57 +01:00
parent 155cafc53e
commit 944a950724
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
4 changed files with 3373 additions and 3 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target /target
Secrets*.toml

3309
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
[package] [package]
name = "nanobot" name = "nano"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
description = "Discord bot to authenticate and de-anonymise users" description = "Discord bot to authenticate and de-anonymise users"
@ -11,3 +11,12 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
anyhow = "1.0.75"
poise = "0.5.5"
shuttle-poise = "0.25.0"
shuttle-runtime = "0.25.0"
shuttle-secrets = "0.25.0"
shuttle-shared-db = { version = "0.25.0", features = ["postgres-rustls"] }
sqlx = { version = "0.7.1", features = ["runtime-tokio-rustls", "postgres"] }
tracing = "0.1.37"
tokio = "1.26.0"

View file

@ -1,3 +1,54 @@
fn main() { use anyhow::Context as _;
println!("Hello, world!"); use poise::serenity_prelude as serenity;
struct Data {} // User data, which is stored and accessible in all command invocations
type Error = Box<dyn std::error::Error + Send + Sync>;
/// Buttons to (de-)register application commands globally or by guild
#[poise::command(prefix_command)]
async fn register(ctx: poise::Context<'_, Data, Error>) -> Result<(), Error> {
poise::builtins::register_application_commands_buttons(ctx).await?;
Ok(())
} }
/// Send (customisable) verification introduction message in specified channel
#[poise::command(slash_command)]
async fn setup(
ctx: poise::Context<'_, Data, Error>,
#[description = "Channel to send verification introduction message in"]
#[channel_types("Text", "News")]
channel: serenity::GuildChannel,
) -> Result<(), Error> {
let resp = format!("You selected channel: {}", channel);
ctx.say(resp).await?;
Ok(())
}
#[shuttle_runtime::main]
async fn poise(
#[shuttle_secrets::Secrets] secret_store: shuttle_secrets::SecretStore,
// #[shuttle_shared_db::Postgres] _pool: sqlx::PgPool,
) -> shuttle_poise::ShuttlePoise<Data, Error> {
Ok(poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![register(), setup()],
..Default::default()
})
.token(
secret_store
.get("DISCORD_TOKEN")
.context("DISCORD_TOKEN not found")?,
)
.intents(serenity::GatewayIntents::non_privileged())
.setup(|_, _, _| Box::pin(async { Ok(Data {}) }))
.build()
.await
.map_err(shuttle_runtime::CustomError::new)?
.into())
}
// Links for info:
// https://github.com/serenity-rs/poise
// https://github.com/serenity-rs/poise/tree/current/examples
// https://github.com/shuttle-hq/shuttle-examples/blob/main/poise/hello-world/src/main.rs
// https://github.com/rust-community-discord/ferrisbot-for-discord/blob/main/src/main.rs#L154