Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Clippy

on:
push:

jobs:
clippy:
name: cargo clippy
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- run: |
rustup toolchain install
- run: |
cargo clippy --workspace --all-targets --all-features -- -D warnings
13 changes: 5 additions & 8 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ jobs:
check_fmt:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
with:
toolchain: stable
- uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1
with:
command: fmt
args: -- --check
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- run: |
rustup toolchain install
- run: |
cargo fmt -- --check
11 changes: 4 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ jobs:
name: cargo test
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
with:
toolchain: stable
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- run: |
rustup toolchain install

- uses: michaelkaye/setup-matrix-synapse@main
with:
Expand All @@ -24,9 +23,7 @@ jobs:
"enable_registration": true
}

- uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1
with:
command: test
- run: cargo test
env:
RUST_BACKTRACE: 1
RUST_LOG: info,micro=trace,matrix=trace,ruma=trace,test=trace
10 changes: 8 additions & 2 deletions microbot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum MessengerError {
#[error("Bot has already been started")]
AlreadyStarted,
#[error(transparent)]
Builder(#[from] ClientBuildError),
Builder(Box<ClientBuildError>),
#[error(transparent)]
Client(#[from] matrix_sdk::Error),
#[error(transparent)]
Expand All @@ -54,6 +54,12 @@ pub enum MessengerError {
PrefixConfig(regex::Error),
}

impl From<ClientBuildError> for MessengerError {
fn from(err: ClientBuildError) -> Self {
MessengerError::Builder(Box::new(err))
}
}

#[derive(Debug, Deserialize)]
pub struct MatrixConfig {
pub url: String,
Expand Down Expand Up @@ -189,7 +195,7 @@ impl MatrixMessenger {
LoopCtrl::Continue
}
}).await
}.map_err(|err| MessengerError::Client(err))
}.map_err(MessengerError::Client)
));

Ok(())
Expand Down
27 changes: 0 additions & 27 deletions microbot/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,6 @@ pub(crate) struct CommandMessageParser {
command_pattern: Regex,
}

#[derive(Debug)]
pub(crate) struct CommandMessageParserError {
pub inner: regex::Error,
}

impl From<regex::Error> for CommandMessageParserError {
fn from(err: regex::Error) -> Self {
Self { inner: err }
}
}

impl std::fmt::Display for CommandMessageParserError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Failed to construct command message parser: {}",
self.inner
)
}
}

impl std::error::Error for CommandMessageParserError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.inner)
}
}

impl Default for CommandMessageParser {
fn default() -> Self {
Self {
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.95.0"
components = ["clippy", "rustfmt"]
10 changes: 4 additions & 6 deletions tests/tests/bot_conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tokio::sync::{
};
use tracing_subscriber::filter::EnvFilter;

static HOMESERVER: &'static str = "http://localhost:8008";
static HOMESERVER: &str = "http://localhost:8008";

// This test configures two bots and an initial sender that will send an initial command.
// In response to this command the two bots will command messages to the room triggering
Expand Down Expand Up @@ -49,23 +49,23 @@ async fn test_bot_conversation() {
rand::rng()
.sample_iter(&Alphanumeric)
.take(24)
.map(|b| char::from(b))
.map(char::from)
.collect::<String>()
);
let bot1 = format!(
"test-bot1-{}",
rand::rng()
.sample_iter(&Alphanumeric)
.take(24)
.map(|b| char::from(b))
.map(char::from)
.collect::<String>()
);
let bot2 = format!(
"test-bot2-{}",
rand::rng()
.sample_iter(&Alphanumeric)
.take(24)
.map(|b| char::from(b))
.map(char::from)
.collect::<String>()
);

Expand Down Expand Up @@ -164,8 +164,6 @@ async fn test_bot_conversation() {

handle1.abort();
handle2.abort();

()
})
.await
.expect("Failed to run bot test in time");
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/ignore_old_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rand::{distr::Alphanumeric, RngExt};
use tokio::sync::{mpsc, mpsc::Sender};
use tracing_subscriber::filter::EnvFilter;

static HOMESERVER: &'static str = "http://localhost:8008";
static HOMESERVER: &str = "http://localhost:8008";

#[tokio::test]
async fn test_ignores_old_messages() {
Expand All @@ -23,15 +23,15 @@ async fn test_ignores_old_messages() {
rand::rng()
.sample_iter(&Alphanumeric)
.take(24)
.map(|b| char::from(b))
.map(char::from)
.collect::<String>()
);
let receiver = format!(
"test-receiver-{}",
rand::rng()
.sample_iter(&Alphanumeric)
.take(24)
.map(|b| char::from(b))
.map(char::from)
.collect::<String>()
);

Expand Down
6 changes: 3 additions & 3 deletions tests/tests/receives_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rand::{distr::Alphanumeric, RngExt};
use tokio::sync::{mpsc, mpsc::Sender};
use tracing_subscriber::filter::EnvFilter;

static HOMESERVER: &'static str = "http://localhost:8008";
static HOMESERVER: &str = "http://localhost:8008";

#[tokio::test]
async fn test_receives_command() {
Expand All @@ -23,15 +23,15 @@ async fn test_receives_command() {
rand::rng()
.sample_iter(&Alphanumeric)
.take(24)
.map(|b| char::from(b))
.map(char::from)
.collect::<String>()
);
let receiver = format!(
"test-receiver-{}",
rand::rng()
.sample_iter(&Alphanumeric)
.take(24)
.map(|b| char::from(b))
.map(char::from)
.collect::<String>()
);

Expand Down
Loading