mirror of
https://github.com/supleed2/nanobot.git
synced 2024-12-22 06:05:50 +00:00
Basic serenity-rs/poise
bot
This commit is contained in:
parent
155cafc53e
commit
944a950724
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
/target
|
||||
Secrets*.toml
|
||||
|
|
3309
Cargo.lock
generated
Normal file
3309
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
11
Cargo.toml
11
Cargo.toml
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "nanobot"
|
||||
name = "nano"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
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
|
||||
|
||||
[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"
|
||||
|
|
55
src/main.rs
55
src/main.rs
|
@ -1,3 +1,54 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use anyhow::Context as _;
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue