#osu #bot #handler #tokio #blazing #bancho-bot #banchobot

nasus

nasus 是一个快速的 osu BanchoBot 处理器 📬

6 个版本

0.2.1 2023 年 5 月 15 日
0.2.0 2023 年 2 月 20 日
0.1.3 2023 年 2 月 16 日

#6#blazing

每月 34 次下载

MIT 许可证

11KB
214

nasus

nasus 是一个 osu BanchoBot 处理器 📬

示例

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    use nasus::{BanchoConfig, CmdIn, CmdOut, Nasus};

    let config = BanchoConfig {
        username: "Auracle".to_string(),
        irc_token: "IRC Token".to_string(),
        host: "irc.ppy.sh".to_string(),
        port: 6667,
        bot: false,
    };
    let mut nasus = Nasus::new(config).await?;

    loop {
        nasus.work().await?;

        match nasus.inputs.pop() {
            Some(cmd_in) => match cmd_in {
                CmdIn::AuthSuccess { message } => println!("{}", message),
                CmdIn::AuthFailure { message } => println!("{}", message),
                CmdIn::ReceivePM {
                    sender,
                    receiver,
                    message,
                    action,
                } => {
                    println!("{}: {}", sender, message);

                    let replies = match action {
                        true => "I see what you did there",
                        false => "I'm not a bot, I swear!",
                    };
                    let cmd_out = CmdOut::SendPM {
                        receiver: sender,
                        message: replies.to_string(),
                    };
                    nasus.write_command(cmd_out).await?;
                    println!("{}: {}", receiver, replies);
                }
                _ => {}
            },
            None => {}
        };

        match nasus.outputs.pop() {
            Some(cmd_out) => match cmd_out {
                CmdOut::SendPM { receiver, message } => println!("{}: {}", receiver, message),
                _ => {}
            },
            None => {}
        };
    }
}

命令

我们从 BanchoBot 收到的命令是 CmdIn

AuthSuccess { message: String }
AuthFailure { message: String }
MOTDStart { message: String }
MOTDMiddle { message: String }
MOTDEnd { message: String }
Quit { user: String }
UserNotFound
ReceivePM {
    sender: String
    receiver: String
    message: String
    action: bool
}
Ping
Pong

我们发送给 BanchoBot 的命令是 CmdOut

Login { username: String, irc_token: String }
SendPM { receiver: String, message: String }
Ping
Pong

依赖项

~3–9MB
~72K SLoC