Initial commit

This commit is contained in:
파링 2026-01-05 22:54:32 +09:00
commit 8c6f7d4379
Signed by: paring
SSH key fingerprint: SHA256:8uCHhCpn/gVOLEaTolmbub9kfM6XBxWkIWmHxUZoWWk
21 changed files with 4184 additions and 0 deletions

63
src/bot/main.rs Normal file
View 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(())
}