修改了部分bot代码

This commit is contained in:
:NoBody: committed 2026-03-26 20:33:08 +08:00
1 parent 821168a770
commit bbbdd9eac5
10 files changed
+164 -19

No files matched your search

+29 -4
View File
@@ -1,4 +1,5 @@
use crate::bot::define::{AttendanceBot, MessageEnum};
use crate::bot::command_parser::parse_command;
use crate::bot::define::{AttendanceHandler, MessageEnum};
use anyhow::{Result, anyhow};
use async_trait::async_trait;
use std::sync::{Mutex, OnceLock};
@@ -17,9 +18,9 @@ fn global_channel() -> &'static (MessageTx, Mutex<Option<MessageRx>>) {
})
}
pub struct Bot;
pub struct CommandHandler;
impl Bot {
impl CommandHandler {
pub fn new() -> Self {
Self
}
@@ -29,8 +30,32 @@ impl Bot {
}
}
async fn bot_command_processor(command: AsRef<str>) -> Result<()> {
let command = command.as_ref();
let ast = parse_command(command)?;
let command = ast.command.as_str();
match command {
"!echo" => {}
_ => {
return Err(anyhow!("unknown command: {}", command));
}
}
let arguments = ast.arguments;
let options = ast.options;
for argument in arguments {
log::trace!("Argument: {}", argument);
}
for (k, v) in options {
log::trace!("Option: {}={}", k, v);
}
Ok(())
}
#[async_trait]
impl AttendanceBot for Bot {
impl AttendanceHandler for CommandHandler {
async fn handle_commands(&self) -> Result<JoinHandle<()>> {
let rx = {
let (_tx, rx_slot) = global_channel();