kovi_plugin_live_agent/
lib.rs

1#![allow(clippy::too_many_arguments)]
2//! Momo QQ chat bot
3use std::{env, process::exit, sync::Arc};
4
5use exception::PluginError;
6use global_state::*;
7use kovi::PluginBuilder as plugin;
8pub mod agent;
9pub mod command;
10pub mod exception;
11pub mod global_state;
12pub mod group_notice;
13pub mod live;
14pub mod log;
15pub mod store;
16pub mod util;
17
18#[kovi::plugin]
19async fn main() {
20    if let Err(e) = global_state::init_global_state().await {
21        log_and_abort(e);
22    }
23
24    live::subscribe_live().await;
25
26    plugin::on_group_msg(move |e| async move {
27        agent::logger(Arc::clone(&e)).await;
28        util::sleep_rand_time().await;
29        command::act(Arc::clone(&e)).await;
30        live::local_query_handler(Arc::clone(&e)).await;
31        live::general_query_handler(Arc::clone(&e)).await;
32        agent::at_me_handler(Arc::clone(&e)).await;
33    });
34
35    plugin::on_all_notice(move |e| async move {
36        util::sleep_rand_time().await;
37        group_notice::act(e).await;
38    });
39
40    plugin::on_admin_msg(|_e| async move {});
41
42    plugin::on_private_msg(move |_e| async move {
43        // util::sleep_rand_time().await;
44        // no-op
45    });
46}
47
48fn log_and_abort(e: PluginError) {
49    std_error!("{}", e);
50    let bot = plugin::get_runtime_bot();
51    bot.disable_plugin("chat").unwrap();
52    exit(1);
53}