vortaroboto

Log | Files | Refs | README

commit 9168235cef32b008b8d547dbb58263d8612e3f8c
parent e8c546019315613e2da4c50274ea6d03c45fa2ec
Author: tomvig38@gmail.com <tomvig38@gmail.com>
Date:   Tue, 19 Oct 2021 07:01:59 +0000

Aldonu log-o kaj privata mesaĝo
Diffstat:
MCargo.lock | 37+++++++++++++++++++++++++++++++++++++
MCargo.toml | 2++
Msrc/main.rs | 18++++++++++++++++--
3 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -3,6 +3,17 @@ version = 3 [[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -58,6 +69,17 @@ dependencies = [ ] [[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + +[[package]] name = "encoding" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -787,6 +809,19 @@ dependencies = [ ] [[package]] +name = "simple_logger" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7de33c687404ec3045d4a0d437580455257c0436f858d702f244e7d652f9f07" +dependencies = [ + "atty", + "chrono", + "colored", + "log", + "winapi", +] + +[[package]] name = "slab" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1014,9 +1049,11 @@ version = "0.1.0" dependencies = [ "futures", "irc", + "log", "reqwest", "serde", "serde_json", + "simple_logger", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml @@ -12,3 +12,5 @@ futures = "0.3.17" reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.68" +log = "0.4" +simple_logger = "1.13.0" diff --git a/src/main.rs b/src/main.rs @@ -1,6 +1,9 @@ use futures::prelude::*; use irc::client::prelude::*; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; + +use log::{debug, info}; +use simple_logger::SimpleLogger; const NICK: &'static str = "vortaroboto"; const TROVI_URL: &'static str = "http://www.simplavortaro.org/api/v1/trovi"; @@ -69,6 +72,9 @@ async fn difinu(vorto: &str) -> Result<Trovo, String> { #[tokio::main] async fn main() -> irc::error::Result<()> { + + SimpleLogger::new().with_level(log::LevelFilter::Debug).init().unwrap(); + let config = Config { nickname: Some(NICK.to_owned()), server: Some("irc.libera.chat".to_owned()), @@ -83,8 +89,16 @@ async fn main() -> irc::error::Result<()> { let sender = client.sender(); while let Some(message) = stream.next().await.transpose()? { + debug!("{}", message); match message.command { Command::PRIVMSG(ref target, ref msg) => { + let is_channel = target.starts_with('#'); + let target = if is_channel { + target + } else { + message.source_nickname().unwrap_or(target) + }; + if msg.contains(client.current_nickname()) { sender.send_privmsg(target, format!( "Saluton ! Mi estas {} la roboto kiun vi povas demandi pri vortoj kaj tradukoj ! Tajpu !helpu por pli'sciiĝi !", @@ -93,7 +107,7 @@ async fn main() -> irc::error::Result<()> { } if let Some(cmd) = msg.strip_prefix('!') { if let Some(answer) = handle_command(cmd).await { - let r = match (target.starts_with('#'), message.source_nickname()) { + let r = match (is_channel, message.source_nickname()) { (true, Some(n)) => format!("{}:\r\n{}", n, answer), _ => answer, };