mod commands; mod utils; use std::env::{self, VarError}; use lazy_static::lazy_static; type Error = Box; type Context<'a> = poise::Context<'a, Data, Error>; // type PrefixContext<'a> = poise::PrefixContext<'a, Data, Error>; // User data, which is stored and accessible in all command invocations pub struct Data {} use commands::{challenge::*, kanji::*, meta::*, owner::*}; use poise::serenity_prelude as serenity; use poise::serenity_prelude::model::gateway::GatewayIntents; use clap::Parser; #[poise::command(prefix_command)] async fn register(ctx: Context<'_>) -> Result<(), Error> { poise::builtins::register_application_commands_buttons(ctx).await?; Ok(()) } #[derive(Parser)] #[clap(author, version, about)] struct Arguments { #[clap(long, help = "Website domain", default_value = "tegakituesday.com")] pub domain: String, #[clap(long = "token", help = "Discord token")] pub discord_token: String, #[clap(long, help = "Traditional text command prefix, including space, if any", default_value = "-h")] pub prefix: String, #[clap(long, help = "Path to Hugo project where site rebuilds")] pub hugo: String, #[clap(long = "guilds", help = "Guild data JSON file", default_value = "guilds.json")] pub guild_data: String, } impl Arguments { fn from_dotenv() -> Result { Ok(Self { domain: env::var("DOMAIN")?, discord_token: env::var("DISCORD_TOKEN")?, prefix: env::var("PREFIX")?, hugo: env::var("HUGO")?.into(), guild_data: env::var("GUILD_DATA")?.into(), }) } } lazy_static! { static ref ARGS: Arguments = { match env::args().count() { 1 => { // This will load the environment variables located at `./.env`, relative to // the CWD. See `./.env.example` for an example on how to structure this. dotenv::dotenv().expect("Failed to load .env file"); Arguments::from_dotenv().unwrap() }, _ => Arguments::parse(), } }; } #[tokio::main] async fn main() { // Initialize the logger to use environment variables. // // In this case, a good default is setting the environment variable // `RUST_LOG` to `debug`. let framework = poise::Framework::builder() .options(poise::FrameworkOptions { commands: vec![ register(), // owner sleep(), setsubmissionchannel(), setsuggestionchannel(), setannouncementrole(), announce(), announcechallenge(), // challenge challenge(), submit(), images(), imagedelete(), suggest(), // meta help(), // kanji i(), joyo(), jinmeiyo(), kyoiku(), jlpt(), hyogai(), so(), ], prefix_options: poise::PrefixFrameworkOptions { prefix: Some(ARGS.prefix.clone()), ..Default::default() }, ..Default::default() }) .token(&ARGS.discord_token) .intents( GatewayIntents::GUILD_MESSAGES | GatewayIntents::DIRECT_MESSAGES | GatewayIntents::MESSAGE_CONTENT | GatewayIntents::GUILDS, ) .setup(move |_ctx, _ready, _framework| Box::pin(async move { Ok(Data {}) })); framework.run().await.unwrap(); }