feat: add commands to main, guild/global command registration

This commit is contained in:
Ladislav Hano 2024-10-06 16:54:08 +02:00
parent dd0b1d652d
commit aadad9d0b8
2 changed files with 22 additions and 11 deletions

View file

@ -23,3 +23,4 @@ tenorv2 = { path = "./tenor-v2/tenorv2" }
[features] [features]
DEBUG = [] DEBUG = []
RELEASE = [] RELEASE = []
GUILD_COMMAND = []

View file

@ -5,13 +5,14 @@ use std::time::Duration;
use std::error; use std::error;
use std::env; use std::env;
use poise::samples::register_in_guild; use poise::samples::register_globally;
use poise::samples::register_in_guild;
use serenity::async_trait; use serenity::async_trait;
use serenity::prelude::GatewayIntents; use serenity::prelude::GatewayIntents;
use serenity::client::Context; use serenity::client::Context;
use serenity::model::gateway::Ready; use serenity::model::gateway::Ready;
use serenity::all::{EventHandler, GuildId, Message}; use serenity::all::{EventHandler, Message};
use serenity::Client; use serenity::Client;
use dotenv::dotenv; use dotenv::dotenv;
@ -82,7 +83,10 @@ async fn main() -> anyhow::Result<()> {
// create poise framework for registering commands // create poise framework for registering commands
let options: poise::FrameworkOptions<(), Box<dyn error::Error + Send + Sync>> = poise::FrameworkOptions { let options: poise::FrameworkOptions<(), Box<dyn error::Error + Send + Sync>> = poise::FrameworkOptions {
commands: vec![], commands: vec![
commands::say(),
commands::hug()
],
prefix_options: poise::PrefixFrameworkOptions { prefix_options: poise::PrefixFrameworkOptions {
prefix: Some("/".into()), prefix: Some("/".into()),
edit_tracker: Some(Arc::new(poise::EditTracker::for_timespan( edit_tracker: Some(Arc::new(poise::EditTracker::for_timespan(
@ -99,15 +103,21 @@ async fn main() -> anyhow::Result<()> {
..Default::default() ..Default::default()
}; };
let debug_guild_id = env::var("DEBUG_GUILD_ID")
.context("DEBUG_GUILD_ID not found in env")?
.parse::<u64>().unwrap();
let framework = poise::Framework::builder() let framework = poise::Framework::builder()
.setup(move |ctx, _ready, framework| { .setup(move |ctx, _ready, framework| {
Box::pin(async move { Box::pin(async move {
register_in_guild(ctx, &framework.options().commands, GuildId::new(debug_guild_id)).await?; #[cfg(feature="GUILD_COMMAND")] {
Ok(()) let debug_guild_id = env::var("DEBUG_GUILD_ID")
.context("DEBUG_GUILD_ID not found in env")?
.parse::<u64>().unwrap();
register_in_guild(ctx, &framework.options().commands, debug_guild_id).await?;
}
#[cfg(not(feature="GUILD_COMMAND"))] {
register_globally(ctx, &framework.options().commands).await?;
}
Ok(())
}) })
}) })
.options(options) .options(options)