Initial commit
This commit is contained in:
commit
8c6f7d4379
21 changed files with 4184 additions and 0 deletions
63
src/bot/main.rs
Normal file
63
src/bot/main.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use std::{str::FromStr, sync::Arc};
|
||||
|
||||
use anyhow::Context;
|
||||
use dashmap::DashMap;
|
||||
use figment::{
|
||||
Figment,
|
||||
providers::{Env, Format, Toml},
|
||||
};
|
||||
use secrecy::ExposeSecret;
|
||||
use serenity::{
|
||||
Client,
|
||||
all::{GatewayIntents, Token},
|
||||
};
|
||||
use sqlx::{migrate, postgres::PgPoolOptions};
|
||||
|
||||
use crate::{config::Config, handler::Handler};
|
||||
|
||||
mod commands;
|
||||
mod config;
|
||||
mod db;
|
||||
mod handler;
|
||||
mod modal;
|
||||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let config: Config = Figment::new()
|
||||
.merge(Toml::file("config.toml"))
|
||||
.merge(Env::prefixed("PB_"))
|
||||
.extract()?;
|
||||
|
||||
info!("config: {config:?}");
|
||||
|
||||
let db = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(config.db.url.expose_secret())
|
||||
.await
|
||||
.context("unable to connect to database")?;
|
||||
|
||||
let migrator = migrate!("./migrations");
|
||||
migrator.run(&db).await.context("failed to migrate")?;
|
||||
|
||||
info!("migrated database");
|
||||
|
||||
let mut client = Client::builder(
|
||||
Token::from_str(config.bot.token.expose_secret()).unwrap(),
|
||||
GatewayIntents::GUILD_MESSAGES | GatewayIntents::GUILD_MESSAGE_REACTIONS,
|
||||
)
|
||||
.event_handler(Arc::new(Handler {
|
||||
db,
|
||||
message_lock: Arc::new(DashMap::new()),
|
||||
}))
|
||||
.await
|
||||
.expect("Err creating client");
|
||||
|
||||
client.start().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue