use ircbot::{bot, Context, Result, Server};
#[bot]
impl TlsBot {
#[command("ping")]
async fn ping(&self, ctx: Context) -> Result {
ctx.reply("pong!")
}
}
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let server: Server = Server::tls("irc.libera.chat:6697").into();
println!("tls_bot example compiled successfully.");
println!("Connecting for real is two lines:");
println!(" let bot = TlsBot::new(\"ircbot\", {server}, [\"#rust\"]).await?;");
println!(" bot.main_loop().await?;");
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use ircbot::testing::TestContext;
#[tokio::test]
async fn ping_replies_with_pong() {
let bot = TlsBot::default();
let mut tc = TestContext::channel("#test", "alice", "!ping");
bot.ping(tc.take_ctx()).await.unwrap();
assert_eq!(
tc.next_reply(),
Some("PRIVMSG #test :alice, pong!\r\n".to_string()),
);
}
}