Update for Nix module
This commit is contained in:
parent
677a97d5cc
commit
b374c6ed66
8 changed files with 262 additions and 39 deletions
54
src/main.rs
54
src/main.rs
|
@ -1,7 +1,8 @@
|
|||
mod commands;
|
||||
mod utils;
|
||||
|
||||
use std::env;
|
||||
use std::env::{self, VarError};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
@ -12,6 +13,7 @@ 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> {
|
||||
|
@ -19,12 +21,50 @@ async fn register(ctx: Context<'_>) -> Result<(), Error> {
|
|||
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<Self, VarError> {
|
||||
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() {
|
||||
// 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");
|
||||
|
||||
// Initialize the logger to use environment variables.
|
||||
//
|
||||
// In this case, a good default is setting the environment variable
|
||||
|
@ -59,12 +99,12 @@ async fn main() {
|
|||
so(),
|
||||
],
|
||||
prefix_options: poise::PrefixFrameworkOptions {
|
||||
prefix: Some(env::var("PREFIX").expect("Expected a prefix in the environment")),
|
||||
prefix: Some(ARGS.prefix.clone()),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.token(std::env::var("DISCORD_TOKEN").expect("Expected a token in the environment"))
|
||||
.token(&ARGS.discord_token)
|
||||
.intents(
|
||||
GatewayIntents::GUILD_MESSAGES
|
||||
| GatewayIntents::DIRECT_MESSAGES
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue