use color_eyre::eyre;
use serenity::model::id::GuildId;
use structopt::StructOpt;
use uwubot::{Bot, Config};
#[derive(Debug, StructOpt)]
struct Args {
#[structopt(env)]
bot_token: String,
#[structopt(short, long, env)]
client_id: u64,
#[structopt(subcommand)]
subcommand: Option<Subcommand>,
}
#[derive(Debug, StructOpt)]
enum Subcommand {
Guild(GuildSubcommand),
}
#[derive(Debug, StructOpt)]
enum GuildSubcommand {
Register {
#[structopt(short, long, env)]
guild_id: u64,
},
Delete {
#[structopt(short, long, env)]
guild_id: u64,
#[structopt(short, long, env)]
command_id: u64,
},
Get {
#[structopt(short, long, env)]
guild_id: u64,
},
}
impl From<Args> for Config {
fn from(args: Args) -> Self {
let Args {
bot_token,
client_id,
..
} = args;
Self {
bot_token,
client_id,
}
}
}
#[tokio::main]
async fn main() -> eyre::Result<()> {
color_eyre::install()?;
let mut config = Args::from_args();
let subcmd = config.subcommand.take();
let bot = Bot::new(config);
match subcmd {
Some(Subcommand::Guild(GuildSubcommand::Register { guild_id })) => {
bot.register_slash_commands_guild(GuildId(guild_id)).await?
}
Some(Subcommand::Guild(GuildSubcommand::Delete {
guild_id,
command_id,
})) => {
bot.delete_slash_commands_guild(GuildId(guild_id), command_id)
.await?;
return Ok(());
}
Some(Subcommand::Guild(GuildSubcommand::Get { guild_id })) => {
bot.list_slash_commands_guild(GuildId(guild_id)).await?;
return Ok(());
}
None => bot.register_slash_commands_global().await?,
}
bot.run().await?;
Ok(())
}