diff options
| author | Max Audron <audron@cocaine.farm> | 2025-05-06 16:17:35 +0200 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2025-05-06 16:19:30 +0200 |
| commit | b6350162b4c70abb896613e4ebea65ca1661450d (patch) | |
| tree | 2e55e0477b4d2f7a646a97f92ee1362db769f75e /src | |
| parent | add nix build and module (diff) | |
update dependencies
Diffstat (limited to 'src')
| -rw-r--r-- | src/hooks/mod.rs | 6 | ||||
| -rw-r--r-- | src/hooks/pet.rs | 5 | ||||
| -rw-r--r-- | src/hooks/sed/parser.rs | 1 | ||||
| -rw-r--r-- | src/hooks/wolfram_alpha.rs | 14 |
4 files changed, 17 insertions, 9 deletions
diff --git a/src/hooks/mod.rs b/src/hooks/mod.rs index 822f839..d70af9c 100644 --- a/src/hooks/mod.rs +++ b/src/hooks/mod.rs @@ -3,6 +3,7 @@ //! # Implementing hooks use anyhow::Result; +use base64::{alphabet, engine, Engine}; use irc::client::prelude::*; mod intensify; @@ -31,6 +32,9 @@ pub fn about(bot: &crate::Bot, msg: Message) -> Result<()> { Ok(()) } +const ENGINE: engine::GeneralPurpose = + engine::GeneralPurpose::new(&alphabet::URL_SAFE, engine::general_purpose::NO_PAD); + /// Listen to AUTHENTICATE messages and perform SASL authentication pub fn sasl(bot: &crate::Bot, msg: Message) -> Result<()> { match msg.command { @@ -48,7 +52,7 @@ pub fn sasl(bot: &crate::Bot, msg: Message) -> Result<()> { let initial_data = mechanism.initial(); - bot.irc_client.send_sasl(base64::encode(initial_data))?; + bot.irc_client.send_sasl(ENGINE.encode(initial_data))?; bot.irc_client.send(Command::CAP( None, irc_proto::command::CapSubCommand::END, diff --git a/src/hooks/pet.rs b/src/hooks/pet.rs index d11f562..990329d 100644 --- a/src/hooks/pet.rs +++ b/src/hooks/pet.rs @@ -2,8 +2,7 @@ use anyhow::{Context, Result}; use irc::client::prelude::*; use macros::privmsg; -use rand::seq::SliceRandom; -use rand::thread_rng; +use rand::{prelude::IndexedRandom, rng}; const PET_RESPONSE: [&str; 5] = [ "purrs", @@ -22,7 +21,7 @@ pub fn pet(bot: &crate::Bot, msg: Message) -> Result<()> { msg.response_target() .context("failed to get response target")?, PET_RESPONSE - .choose(&mut thread_rng()) + .choose(&mut rng()) .context("failed choosing a pet response")?, )?; }) diff --git a/src/hooks/sed/parser.rs b/src/hooks/sed/parser.rs index 815803c..61e719d 100644 --- a/src/hooks/sed/parser.rs +++ b/src/hooks/sed/parser.rs @@ -121,6 +121,7 @@ bitflags! { /// s allow . to match \n /// U swap the meaning of x* and x*? /// x ignore whitespace and allow line comments (starting with `#`) + #[derive(Debug, Clone, PartialEq, PartialOrd)] struct Flags: u32 { const GLOBAL = 0b00000001; const CASE_INSENSITIVE = 0b00000010; diff --git a/src/hooks/wolfram_alpha.rs b/src/hooks/wolfram_alpha.rs index 9f56df4..d0ab81e 100644 --- a/src/hooks/wolfram_alpha.rs +++ b/src/hooks/wolfram_alpha.rs @@ -180,7 +180,7 @@ mod tests { use crate::hooks::wolfram_alpha::clean_result_text; - use super::{get_input_query, get_wa_user_short_url, wa_query}; + use super::{get_input_query, wa_query}; use anyhow::{Error, Result}; use mockito::{self, Matcher}; @@ -273,13 +273,17 @@ mod tests { #[tokio::test] async fn test_query_with_result_with_wrong_json_parsing() -> Result<(), Error> { let body = include_str!("../../tests/resources/wolfram_alpha_api_response_wrong_json.json"); - let _m = mockito::mock("GET", Matcher::Any) + + let mut server = mockito::Server::new_async().await; + + let _m = server + .mock("GET", Matcher::Any) // Trimmed down version of a full WA response: .with_body(body) - .create(); - mockito::start(); + .create_async() + .await; - let res = wa_query("what is a url", None, Some(&mockito::server_url())).await?; + let res = wa_query("what is a url", None, Some(&server.url())).await?; assert_eq!(res, "No results."); Ok(()) } |
