mirror of
https://github.com/supleed2/nanobot.git
synced 2024-11-09 20:25:48 +00:00
Switch to custom service
This commit is contained in:
parent
9ecd3722cb
commit
b761e7f7fc
26
src/main.rs
26
src/main.rs
|
@ -49,6 +49,14 @@ struct ManualMember {
|
|||
#[shuttle_runtime::main]
|
||||
async fn poise(
|
||||
#[shuttle_secrets::Secrets] secret_store: shuttle_secrets::SecretStore,
|
||||
#[shuttle_shared_db::Postgres] pool: sqlx::PgPool,
|
||||
) -> Result<service::NanoBot, shuttle_runtime::Error> {
|
||||
// Run SQLx Migrations
|
||||
sqlx::migrate!()
|
||||
.run(&pool)
|
||||
.await
|
||||
.map_err(shuttle_runtime::CustomError::new)?;
|
||||
|
||||
// Load secrets
|
||||
let au_ch_id = secret_store
|
||||
.get("AU_CHANNEL_ID")
|
||||
|
@ -75,6 +83,20 @@ async fn poise(
|
|||
.parse()
|
||||
.expect("MEMBER_ID not valid u64");
|
||||
|
||||
// Build Axum Router
|
||||
use axum::routing::{get, post};
|
||||
let router = axum::Router::new()
|
||||
.route("/", get(routes::hello_world))
|
||||
.route(
|
||||
"/verify",
|
||||
post({
|
||||
let pool = pool.clone();
|
||||
let key = secret_store
|
||||
.get("VERIFY_KEY")
|
||||
.context("VERIFY_KEY not found")?;
|
||||
move |body| routes::verify(pool, body, key)
|
||||
}),
|
||||
);
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![
|
||||
cmds::cmds(),
|
||||
|
@ -119,6 +141,10 @@ async fn poise(
|
|||
})
|
||||
});
|
||||
|
||||
// Return NanoBot
|
||||
Ok(service::NanoBot { router, discord })
|
||||
}
|
||||
|
||||
async fn event_handler(
|
||||
ctx: &serenity::Context,
|
||||
event: &poise::Event<'_>,
|
||||
|
|
Loading…
Reference in a new issue