move context command to fend subcommand

This commit is contained in:
Masato Imai
2024-10-08 02:05:47 +00:00
parent c65bc40bdf
commit e1f54a3b7e
2 changed files with 37 additions and 17 deletions

View File

@ -14,6 +14,41 @@ pub async fn register(ctx: Context<'_>) -> Result<(), Error> {
Ok(())
}
#[poise::command(
prefix_command,
slash_command,
subcommands("context"),
subcommand_required
)]
pub async fn fend(_: Context<'_>) -> Result<(), Error> {
Ok(())
}
#[poise::command(
prefix_command,
slash_command,
subcommands("reset"),
subcommand_required
)]
pub async fn context(_: Context<'_>) -> Result<(), Error> {
Ok(())
}
#[poise::command(prefix_command, slash_command)]
pub async fn reset(ctx: Context<'_>) -> Result<(), Error> {
let id = ctx.author().id.get();
let mut data = ctx.data().context.lock().await;
let context = create_context();
save_context(&context, id);
data.insert(id, context);
ctx.reply("success").await.unwrap();
Ok(())
}
#[poise::command(prefix_command, slash_command)]
pub async fn calc(ctx: Context<'_>, expr: String) -> Result<(), Error> {
ctx.defer().await.unwrap();
@ -66,18 +101,3 @@ pub async fn calc(ctx: Context<'_>, expr: String) -> Result<(), Error> {
Ok(())
}
#[poise::command(prefix_command, slash_command)]
pub async fn reset_context(ctx: Context<'_>) -> Result<(), Error> {
let id = ctx.author().id.get();
let mut data = ctx.data().context.lock().await;
let context = create_context();
save_context(&context, id);
data.insert(id, context);
ctx.reply("success").await.unwrap();
Ok(())
}

View File

@ -2,7 +2,7 @@ mod commands;
mod context;
use anyhow::Result;
use commands::{calc, register, reset_context};
use commands::{calc, fend, register};
use context::restore_contexts;
use std::{
collections::{HashMap, HashSet},
@ -44,7 +44,7 @@ async fn main() -> Result<()> {
})
})
.options(poise::FrameworkOptions {
commands: vec![register(), calc(), reset_context()],
commands: vec![register(), calc(), fend()],
prefix_options: PrefixFrameworkOptions {
prefix: Some(prefix),
..Default::default()