- Added string formatter - Added Strings struct for passing strings from file - Refactored /info and /quest * to use formatter BREAKING CHANGE: Changed DiscordConfig fields
77 lines
2.2 KiB
Rust
77 lines
2.2 KiB
Rust
use std::sync::{Arc, Mutex};
|
|
|
|
use clap::Parser;
|
|
use dotenvy::dotenv;
|
|
use poise::serenity_prelude as serenity;
|
|
use squad_quest::config::Config;
|
|
|
|
use crate::{commands::error_handler, config::{ConfigImpl, DiscordConfig}, error::Error, strings::Strings};
|
|
|
|
mod commands;
|
|
mod cli;
|
|
mod config;
|
|
mod account;
|
|
mod error;
|
|
mod strings;
|
|
|
|
const CONFIG_PATH: &str = "cfg/config.toml";
|
|
const DISCORD_TOKEN: &str = "DISCORD_TOKEN";
|
|
|
|
#[derive(Debug)]
|
|
struct Data {
|
|
pub config: Config,
|
|
pub discord: Arc<Mutex<DiscordConfig>>,
|
|
pub strings: Strings,
|
|
}
|
|
type Context<'a> = poise::Context<'a, Data, Error>;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
dotenv().unwrap();
|
|
|
|
let cli = cli::Cli::parse();
|
|
let config = Config::load(cli.config.clone().unwrap_or(CONFIG_PATH.into()));
|
|
let (discord, strings) = config.discord_impl().unwrap_or_else(|_| {
|
|
config.init_impl().unwrap();
|
|
config.discord_impl().unwrap()
|
|
});
|
|
|
|
let token = std::env::var(DISCORD_TOKEN).expect("missing DISCORD_TOKEN");
|
|
let intents = serenity::GatewayIntents::non_privileged();
|
|
|
|
let framework = poise::Framework::builder()
|
|
.options(poise::FrameworkOptions {
|
|
on_error: |err| Box::pin(error_handler(err)),
|
|
commands: vec![
|
|
commands::quest::quest(),
|
|
commands::register(),
|
|
commands::info(),
|
|
commands::init::init(),
|
|
commands::answer::answer(),
|
|
commands::social::social(),
|
|
commands::account::scoreboard(),
|
|
commands::account::balance(),
|
|
commands::account::reset(),
|
|
commands::map::unlock(),
|
|
commands::map::r#move(),
|
|
],
|
|
..Default::default()
|
|
})
|
|
.setup(|ctx, _ready, framework| {
|
|
Box::pin(async move {
|
|
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
|
Ok(Data {
|
|
config,
|
|
discord: Arc::new(Mutex::new(discord)),
|
|
strings,
|
|
})
|
|
})
|
|
})
|
|
.build();
|
|
|
|
let client = serenity::ClientBuilder::new(token, intents)
|
|
.framework(framework)
|
|
.await;
|
|
client.unwrap().start().await.unwrap();
|
|
}
|
|
|