Compare commits
6 Commits
v0.2.2
...
720ecac8f8
Author | SHA1 | Date | |
---|---|---|---|
720ecac8f8 | |||
02837b00fe | |||
ffd977b6d5 | |||
208df18fe4 | |||
4b5d9e2cde | |||
0f8f580050 |
3288
Cargo.lock
generated
3288
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
16
Cargo.toml
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bebot"
|
name = "bebot"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
description = "Gitlab webhook bot that publishes events to Matrix"
|
description = "Gitlab webhook bot that publishes events to Matrix"
|
||||||
license = "GPL-3.0"
|
license = "AGPL-3.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Brian J. Tarricone <brian@tarricone.org>",
|
"Brian J. Tarricone <brian@tarricone.org>",
|
||||||
]
|
]
|
||||||
@@ -25,16 +25,16 @@ exclude = [
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
constant_time_eq = "0.3"
|
constant_time_eq = "0.4"
|
||||||
dateparser = "0.2"
|
dateparser = "0.2"
|
||||||
env_logger = "0.10"
|
env_logger = "0.11"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
http = "0.2"
|
http = "1.3"
|
||||||
log = { version = "0.4", features = ["std"] }
|
log = { version = "0.4", features = ["std"] }
|
||||||
matrix-sdk = { version = "0.6", features = ["anyhow", "markdown", "rustls-tls"], default-features = false }
|
matrix-sdk = { version = "0.13", features = ["anyhow", "markdown", "rustls-tls"], default-features = false }
|
||||||
quick-xml = { version = "0.30", features = ["serialize"] }
|
quick-xml = { version = "0.38", features = ["serialize"] }
|
||||||
regex = "1"
|
regex = "1"
|
||||||
reqwest = { version = "0.11", default-features = false, features = ["tokio-rustls", "rustls-tls-native-roots", "gzip"] }
|
reqwest = { version = "0.12", default-features = false, features = ["charset", "http2", "gzip", "rustls-tls-native-roots", "system-proxy"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
serde_regex = "1"
|
serde_regex = "1"
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
FROM rust:1.72-slim-bullseye AS builder
|
FROM rust:1.88-slim-bookworm AS builder
|
||||||
|
|
||||||
WORKDIR /bebot-build
|
WORKDIR /bebot-build
|
||||||
|
|
||||||
|
155
LICENSE
155
LICENSE
@@ -1,18 +1,5 @@
|
|||||||
bebot -- Gitlab webhook bot for Matrix
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
Copyright (C) 2023 Brian Tarricone <brian@tarricone.org>
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
@@ -20,17 +7,15 @@ GNU General Public License for more details.
|
|||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
software and other kinds of works.
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
The licenses for most software and other practical works are designed
|
||||||
to take away your freedom to share and change the works. By contrast,
|
to take away your freedom to share and change the works. By contrast,
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
share and change all versions of a program--to make sure it remains free
|
share and change all versions of a program--to make sure it remains free
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
software for all its users.
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
When we speak of free software, we are referring to freedom, not
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
@@ -39,44 +24,34 @@ them if you wish), that you receive source code or can get it if you
|
|||||||
want it, that you can change the software or use pieces of it in new
|
want it, that you can change the software or use pieces of it in new
|
||||||
free programs, and that you know you can do these things.
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
Developers that use our General Public Licenses protect your rights
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
you this License which gives you legal permission to copy, distribute
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
and/or modify the software.
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
A secondary benefit of defending all users' freedom is that
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
improvements made in alternate versions of the program, if they
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
receive widespread use, become available for other developers to
|
||||||
or can get the source code. And you must show them these terms so they
|
incorporate. Many developers of free software are heartened and
|
||||||
know their rights.
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
The GNU Affero General Public License is designed specifically to
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
ensure that, in such cases, the modified source code becomes available
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
An older license, called the Affero General Public License and
|
||||||
that there is no warranty for this free software. For both users' and
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
changed, so that their problems will not be attributed erroneously to
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
authors of previous versions.
|
this license.
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow.
|
modification follow.
|
||||||
@@ -85,7 +60,7 @@ modification follow.
|
|||||||
|
|
||||||
0. Definitions.
|
0. Definitions.
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
works, such as semiconductor masks.
|
works, such as semiconductor masks.
|
||||||
@@ -562,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey
|
|||||||
the Program, the only way you could satisfy both those terms and this
|
the Program, the only way you could satisfy both those terms and this
|
||||||
License would be to refrain entirely from conveying the Program.
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
Notwithstanding any other provision of this License, you have
|
||||||
permission to link or combine any covered work with a work licensed
|
permission to link or combine any covered work with a work licensed
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
under version 3 of the GNU General Public License into a single
|
||||||
combined work, and to convey the resulting work. The terms of this
|
combined work, and to convey the resulting work. The terms of this
|
||||||
License will continue to apply to the part which is the covered work,
|
License will continue to apply to the part which is the covered work,
|
||||||
but the special requirements of the GNU Affero General Public License,
|
but the work with which it is combined will remain governed by version
|
||||||
section 13, concerning interaction through a network will apply to the
|
3 of the GNU General Public License.
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
the GNU General Public License from time to time. Such new versions will
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
address new problems or concerns.
|
address new problems or concerns.
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
Each version is given a distinguishing version number. If the
|
||||||
Program specifies that a certain numbered version of the GNU General
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
Public License "or any later version" applies to it, you have the
|
Public License "or any later version" applies to it, you have the
|
||||||
option of following the terms and conditions either of that numbered
|
option of following the terms and conditions either of that numbered
|
||||||
version or of any later version published by the Free Software
|
version or of any later version published by the Free Software
|
||||||
Foundation. If the Program does not specify a version number of the
|
Foundation. If the Program does not specify a version number of the
|
||||||
GNU General Public License, you may choose any version ever published
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
by the Free Software Foundation.
|
by the Free Software Foundation.
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
If the Program specifies that a proxy can decide which future
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
public statement of acceptance of a version permanently authorizes you
|
public statement of acceptance of a version permanently authorizes you
|
||||||
to choose that version for the Program.
|
to choose that version for the Program.
|
||||||
|
|
||||||
@@ -648,41 +633,29 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||||||
Copyright (C) <year> <name of author>
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
If your software can interact with users remotely through a computer
|
||||||
notice like this when it starts in an interactive mode:
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
<program> Copyright (C) <year> <name of author>
|
interface could display a "Source" link that leads users to an archive
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
of the code. There are many ways you could offer source, and different
|
||||||
This is free software, and you are welcome to redistribute it
|
solutions will be better for different programs; see section 13 for the
|
||||||
under certain conditions; type `show c' for details.
|
specific requirements.
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
<https://www.gnu.org/licenses/>.
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
||||||
|
|
||||||
|
37
README.md
37
README.md
@@ -11,11 +11,17 @@ Currently-supported Gitlab event types:
|
|||||||
* Merge request events
|
* Merge request events
|
||||||
* Pipeline events (only publishes on failure for now)
|
* Pipeline events (only publishes on failure for now)
|
||||||
|
|
||||||
|
It can also watch for new messages in a mailing list (assuming that
|
||||||
|
mailing list is tracked by [The Mail
|
||||||
|
Archive](https://mail-archive.com/)), and publish notifications of new
|
||||||
|
messages to Matrix.
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
Bebot is written in Rust, and requires a Rust toolchain in order to
|
Bebot is written in Rust, and requires a Rust toolchain in order to
|
||||||
build. The usual `cargo build` or `cargo build --release` will do the
|
build. I'm actually not sure what Bebot's MSRV is, but as of this
|
||||||
trick.
|
writing, 1.72 worked. The usual `cargo build` or `cargo build
|
||||||
|
--release` will do the trick.
|
||||||
|
|
||||||
You can also build and install the latest released version of Bebot by
|
You can also build and install the latest released version of Bebot by
|
||||||
running `cargo install bebot`.
|
running `cargo install bebot`.
|
||||||
@@ -26,6 +32,8 @@ Bebot requires a configuration file in YAML format. See
|
|||||||
`sample-config.yaml` for all existing configuration options, as well as
|
`sample-config.yaml` for all existing configuration options, as well as
|
||||||
documentation on what each option does.
|
documentation on what each option does.
|
||||||
|
|
||||||
|
### Gitlab Hooks
|
||||||
|
|
||||||
When setting up the webhook in Gitlab, use the same `token` from the
|
When setting up the webhook in Gitlab, use the same `token` from the
|
||||||
configuration file in the webhook's "Secret token" field. You should
|
configuration file in the webhook's "Secret token" field. You should
|
||||||
only select "Push events", "Tag push events", "Issues events", "Merge
|
only select "Push events", "Tag push events", "Issues events", "Merge
|
||||||
@@ -42,6 +50,18 @@ output to stdout a YAML snippet that goes under the `repo_configs`
|
|||||||
section of the configuration file. If you run the script with no
|
section of the configuration file. If you run the script with no
|
||||||
arguments, it will print out usage details.
|
arguments, it will print out usage details.
|
||||||
|
|
||||||
|
### `mail-archive.com`
|
||||||
|
|
||||||
|
If you want Bebot to publish a Matrix message when a new email hits one
|
||||||
|
of your configured mailing lists, you need to provide a directory for
|
||||||
|
Bebot to store state, so it can keep track of what emails it has already
|
||||||
|
sent a Matrix message for. Otherwise, it will re-publish messages every
|
||||||
|
time you restart Bebot.
|
||||||
|
|
||||||
|
Remember that if you are running Bebot in a Docker container, you'll
|
||||||
|
need to mount a volume to store state so it persists across container
|
||||||
|
restarts and upgrades.
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
After you've done all that, simply run Bebot:
|
After you've done all that, simply run Bebot:
|
||||||
@@ -57,7 +77,18 @@ logging verbosity. (Try `debug`, `info`, `warn` `error`, or `off`.)
|
|||||||
|
|
||||||
A `Dockerfile` is also provided. When running the container it builds,
|
A `Dockerfile` is also provided. When running the container it builds,
|
||||||
mount the configuration file so it appears inside the container as
|
mount the configuration file so it appears inside the container as
|
||||||
`/bebot/config/bebot.yaml`.
|
`/bebot/config/bebot.yaml`. If you are publishing from
|
||||||
|
`mail-archive.com`, also remember to mount a state storage directory or
|
||||||
|
volume wherever you've specified in the configuration file.
|
||||||
|
|
||||||
Release images are [published to Docker
|
Release images are [published to Docker
|
||||||
Hub](https://hub.docker.com/r/kelnos/bebot).
|
Hub](https://hub.docker.com/r/kelnos/bebot).
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
I currently host Bebot on my [private Gitea
|
||||||
|
server](https://git.spurint.org/brian/bebot). Since I don't want to
|
||||||
|
deal with spam, I don't enable user registrations. If you'd like to
|
||||||
|
submit issues and/or merge requests, please [message me on
|
||||||
|
Matrix](https://matrix.to/#/@brian:tarricone.org) with your email
|
||||||
|
address and preferred username, and I'll create an account for you.
|
||||||
|
@@ -1,18 +1,18 @@
|
|||||||
// bebot
|
// bebot -- a Gitlab -> Matrix event publisher
|
||||||
// Copyright (C) 2023 Brian Tarricone <brian@tarricone.org>
|
// Copyright (C) 2023-2025 Brian Tarricone <brian@tarricone.org>
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU Affero General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::{collections::HashMap, fs::File, io::BufReader, path::PathBuf};
|
use std::{collections::HashMap, fs::File, io::BufReader, path::PathBuf};
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ fn load_blocking(path: &String) -> anyhow::Result<Config> {
|
|||||||
pub async fn load<S: AsRef<str>>(path: S) -> anyhow::Result<Config> {
|
pub async fn load<S: AsRef<str>>(path: S) -> anyhow::Result<Config> {
|
||||||
let p = String::from(path.as_ref());
|
let p = String::from(path.as_ref());
|
||||||
let config = tokio::task::spawn_blocking(move || {
|
let config = tokio::task::spawn_blocking(move || {
|
||||||
load_blocking(&p).with_context(|| format!("Failed to load config from {}", p))
|
load_blocking(&p).with_context(|| format!("Failed to load config from {p}"))
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
Ok(config)
|
Ok(config)
|
||||||
|
@@ -1,18 +1,20 @@
|
|||||||
// bebot
|
// bebot -- a Gitlab -> Matrix event publisher
|
||||||
// Copyright (C) 2023 Brian Tarricone <brian@tarricone.org>
|
// Copyright (C) 2023-2025 Brian Tarricone <brian@tarricone.org>
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU Affero General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#![allow(unused)]
|
||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
@@ -281,7 +283,7 @@ impl GitlabEventExt for GitlabEvent {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GitlabEvent::TagPush { .. } => find_publish_event!(publish_events, PublishEvent::TagPush { .. }).is_some(),
|
GitlabEvent::TagPush { .. } => find_publish_event!(publish_events, PublishEvent::TagPush).is_some(),
|
||||||
GitlabEvent::Issue { object_attributes, .. } => {
|
GitlabEvent::Issue { object_attributes, .. } => {
|
||||||
if let Some(PublishEvent::Issues { actions }) =
|
if let Some(PublishEvent::Issues { actions }) =
|
||||||
find_publish_event!(publish_events, PublishEvent::Issues { .. })
|
find_publish_event!(publish_events, PublishEvent::Issues { .. })
|
||||||
@@ -437,7 +439,7 @@ impl GitlabEventExt for GitlabEvent {
|
|||||||
.or(merge_request.as_ref().map(|mr| mr.title.clone()))
|
.or(merge_request.as_ref().map(|mr| mr.title.clone()))
|
||||||
.iter()
|
.iter()
|
||||||
.fold(format!("Pipeline **{}**", object_attributes.status), |accum, title| {
|
.fold(format!("Pipeline **{}**", object_attributes.status), |accum, title| {
|
||||||
format!("{}: {}", accum, title)
|
format!("{accum}: {title}")
|
||||||
});
|
});
|
||||||
vec![markdown_link(&title, &object_attributes.url)]
|
vec![markdown_link(&title, &object_attributes.url)]
|
||||||
} else {
|
} else {
|
||||||
@@ -451,7 +453,7 @@ impl GitlabEventExt for GitlabEvent {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn markdown_link(title: &String, url: &String) -> String {
|
fn markdown_link(title: &String, url: &String) -> String {
|
||||||
format!("[{}]({})", title, url)
|
format!("[{title}]({url})")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_ref(r#ref: &str) -> String {
|
pub fn parse_ref(r#ref: &str) -> String {
|
||||||
|
@@ -1,29 +1,28 @@
|
|||||||
// bebot
|
// bebot -- a Gitlab -> Matrix event publisher
|
||||||
// Copyright (C) 2023 Brian Tarricone <brian@tarricone.org>
|
// Copyright (C) 2023-2025 Brian Tarricone <brian@tarricone.org>
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU Affero General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use constant_time_eq::constant_time_eq;
|
use constant_time_eq::constant_time_eq;
|
||||||
use http::StatusCode;
|
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{
|
||||||
ruma::{events::room::message::RoomMessageEventContent, OwnedRoomOrAliasId},
|
ruma::{events::room::message::RoomMessageEventContent, OwnedRoomOrAliasId},
|
||||||
Client,
|
Client,
|
||||||
};
|
};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use warp::{filters::BoxedFilter, reply::Reply, Filter};
|
use warp::{filters::BoxedFilter, http::StatusCode, reply::Reply, Filter};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::GitlabWebhookConfig,
|
config::GitlabWebhookConfig,
|
||||||
@@ -41,7 +40,7 @@ pub fn build_gitlab_messages(event: &GitlabEvent) -> Vec<String> {
|
|||||||
format!(
|
format!(
|
||||||
"\\[{}\\] {}*{}* {}",
|
"\\[{}\\] {}*{}* {}",
|
||||||
project.path_with_namespace,
|
project.path_with_namespace,
|
||||||
refname.as_ref().map(|rn| format!("`{}` ", rn)).unwrap_or_default(),
|
refname.as_ref().map(|rn| format!("`{rn}` ")).unwrap_or_default(),
|
||||||
event.user(),
|
event.user(),
|
||||||
title,
|
title,
|
||||||
)
|
)
|
||||||
@@ -56,9 +55,9 @@ pub async fn handle_gitlab_event(
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let room = matrix::ensure_room_joined(matrix_client, room_id).await?;
|
let room = matrix::ensure_room_joined(matrix_client, room_id).await?;
|
||||||
for msg in build_gitlab_messages(&event) {
|
for msg in build_gitlab_messages(&event) {
|
||||||
debug!("Sending message to {}: {}", room_id, msg);
|
debug!("Sending message to {room_id}: {msg}");
|
||||||
let msg_content = RoomMessageEventContent::text_markdown(&msg);
|
let msg_content = RoomMessageEventContent::text_markdown(&msg);
|
||||||
room.send(msg_content, None).await?;
|
room.send(msg_content).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -68,7 +67,7 @@ pub fn build_route(config: GitlabWebhookConfig, matrix_client: Client) -> anyhow
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some((event, room)) = event_rx.recv().await {
|
while let Some((event, room)) = event_rx.recv().await {
|
||||||
if let Err(err) = handle_gitlab_event(event, &room, &matrix_client).await {
|
if let Err(err) = handle_gitlab_event(event, &room, &matrix_client).await {
|
||||||
warn!("Failed to handle payload: {}", err);
|
warn!("Failed to handle payload: {err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -105,10 +104,10 @@ pub fn build_route(config: GitlabWebhookConfig, matrix_client: Client) -> anyhow
|
|||||||
let config_key = project.web_url.replace("http://", "").replace("https://", "");
|
let config_key = project.web_url.replace("http://", "").replace("https://", "");
|
||||||
if let Some(repo_config) = config.repo_configs.get(&config_key) {
|
if let Some(repo_config) = config.repo_configs.get(&config_key) {
|
||||||
if !constant_time_eq(token.as_bytes(), repo_config.token.as_bytes()) {
|
if !constant_time_eq(token.as_bytes(), repo_config.token.as_bytes()) {
|
||||||
warn!("Invalid token for repo '{}'", config_key);
|
warn!("Invalid token for repo '{config_key}'");
|
||||||
warp::reply::with_status("Invalid token", StatusCode::FORBIDDEN)
|
warp::reply::with_status("Invalid token", StatusCode::FORBIDDEN)
|
||||||
} else {
|
} else {
|
||||||
debug!("payload: {:?}", event);
|
debug!("payload: {event:?}");
|
||||||
if let Some(room) = &repo_config.room.as_ref().or(config.default_room.as_ref()) {
|
if let Some(room) = &repo_config.room.as_ref().or(config.default_room.as_ref()) {
|
||||||
let publish_events = repo_config
|
let publish_events = repo_config
|
||||||
.publish_events
|
.publish_events
|
||||||
@@ -116,12 +115,12 @@ pub fn build_route(config: GitlabWebhookConfig, matrix_client: Client) -> anyhow
|
|||||||
.or(config.default_publish_events.as_ref());
|
.or(config.default_publish_events.as_ref());
|
||||||
if publish_events.map(|ecs| event.should_publish(ecs)).unwrap_or(true) {
|
if publish_events.map(|ecs| event.should_publish(ecs)).unwrap_or(true) {
|
||||||
if let Err(err) = event_tx.send((event, (*room).clone())).await {
|
if let Err(err) = event_tx.send((event, (*room).clone())).await {
|
||||||
warn!("Failed to enqueue payload: {}", err);
|
warn!("Failed to enqueue payload: {err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
warp::reply::with_status("OK", StatusCode::OK)
|
warp::reply::with_status("OK", StatusCode::OK)
|
||||||
} else {
|
} else {
|
||||||
info!("Channel not configured for repo '{}'", config_key);
|
info!("Channel not configured for repo '{config_key}'");
|
||||||
warp::reply::with_status(
|
warp::reply::with_status(
|
||||||
"Matrix room not configured for repo",
|
"Matrix room not configured for repo",
|
||||||
StatusCode::NOT_FOUND,
|
StatusCode::NOT_FOUND,
|
||||||
@@ -129,7 +128,7 @@ pub fn build_route(config: GitlabWebhookConfig, matrix_client: Client) -> anyhow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("Repo '{}' unconfigured", config_key);
|
info!("Repo '{config_key}' unconfigured");
|
||||||
warp::reply::with_status("Repo not configured", StatusCode::NOT_FOUND)
|
warp::reply::with_status("Repo not configured", StatusCode::NOT_FOUND)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,18 +1,18 @@
|
|||||||
// bebot
|
// bebot -- a Gitlab -> Matrix event publisher
|
||||||
// Copyright (C) 2023 Brian Tarricone <brian@tarricone.org>
|
// Copyright (C) 2023-2025 Brian Tarricone <brian@tarricone.org>
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU Affero General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
@@ -112,14 +112,14 @@ async fn handle_list(
|
|||||||
|
|
||||||
let rooms_f = room_ids.iter().map(|room_id| {
|
let rooms_f = room_ids.iter().map(|room_id| {
|
||||||
matrix::ensure_room_joined(matrix_client, room_id)
|
matrix::ensure_room_joined(matrix_client, room_id)
|
||||||
.map(move |res| res.with_context(|| format!("Failed to join Matrix room '{}'", room_id)))
|
.map(move |res| res.with_context(|| format!("Failed to join Matrix room '{room_id}'")))
|
||||||
});
|
});
|
||||||
let rooms = join_all(rooms_f)
|
let rooms = join_all(rooms_f)
|
||||||
.await
|
.await
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|room_res| match room_res {
|
.flat_map(|room_res| match room_res {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("{:#}", err);
|
warn!("{err:#}");
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
Ok(room) => vec![room],
|
Ok(room) => vec![room],
|
||||||
@@ -133,7 +133,7 @@ async fn handle_list(
|
|||||||
.get(url)
|
.get(url)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("Failed to fetch mail RSS feed from '{}'", url))
|
.with_context(|| format!("Failed to fetch mail RSS feed from '{url}'"))
|
||||||
.and_then(|response| {
|
.and_then(|response| {
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
Err(anyhow!(
|
Err(anyhow!(
|
||||||
@@ -148,10 +148,10 @@ async fn handle_list(
|
|||||||
let body = response
|
let body = response
|
||||||
.text()
|
.text()
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("Failed to decode RSS response body for '{}'", url))?;
|
.with_context(|| format!("Failed to decode RSS response body for '{url}'"))?;
|
||||||
let mail_rss = tokio::task::spawn_blocking(move || quick_xml::de::from_str::<MailRss>(&body))
|
let mail_rss = tokio::task::spawn_blocking(move || quick_xml::de::from_str::<MailRss>(&body))
|
||||||
.await?
|
.await?
|
||||||
.with_context(|| format!("Failed to parse RSS feed for '{}'", url))?;
|
.with_context(|| format!("Failed to parse RSS feed for '{url}'"))?;
|
||||||
let items = mail_rss
|
let items = mail_rss
|
||||||
.channel
|
.channel
|
||||||
.items
|
.items
|
||||||
@@ -167,7 +167,7 @@ async fn handle_list(
|
|||||||
"\\[{}\\] [{}]({})",
|
"\\[{}\\] [{}]({})",
|
||||||
list.name, item.title, item.link
|
list.name, item.title, item.link
|
||||||
));
|
));
|
||||||
room.send(msg, None)
|
room.send(msg)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("Failed to send message to room '{}'", room.room_id()))?;
|
.with_context(|| format!("Failed to send message to room '{}'", room.room_id()))?;
|
||||||
}
|
}
|
||||||
@@ -223,7 +223,7 @@ pub fn start_polling(config: MailArchiveConfig, matrix_client: Client) -> anyhow
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
warn!("{:#}", err);
|
warn!("{err:#}");
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(update_interval).await;
|
sleep(update_interval).await;
|
||||||
@@ -269,7 +269,7 @@ mod test {
|
|||||||
let f = File::open(format!("{}/test-data/maillist.xml", env!("CARGO_MANIFEST_DIR")))?;
|
let f = File::open(format!("{}/test-data/maillist.xml", env!("CARGO_MANIFEST_DIR")))?;
|
||||||
let r = BufReader::new(f);
|
let r = BufReader::new(f);
|
||||||
let mail_rss = quick_xml::de::from_reader::<_, MailRss>(r)?;
|
let mail_rss = quick_xml::de::from_reader::<_, MailRss>(r)?;
|
||||||
println!("{:#?}", mail_rss);
|
println!("{mail_rss:#?}");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
src/main.rs
16
src/main.rs
@@ -1,18 +1,18 @@
|
|||||||
// bebot
|
// bebot -- a Gitlab -> Matrix event publisher
|
||||||
// Copyright (C) 2023 Brian Tarricone <brian@tarricone.org>
|
// Copyright (C) 2023-2025 Brian Tarricone <brian@tarricone.org>
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU Affero General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#[macro_use(anyhow)]
|
#[macro_use(anyhow)]
|
||||||
extern crate anyhow;
|
extern crate anyhow;
|
||||||
@@ -34,6 +34,8 @@ use futures::future::join_all;
|
|||||||
use warp::Filter;
|
use warp::Filter;
|
||||||
|
|
||||||
async fn run() -> anyhow::Result<()> {
|
async fn run() -> anyhow::Result<()> {
|
||||||
|
info!("{} v{} starting...", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
let config_path = env::args()
|
let config_path = env::args()
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.ok_or_else(|| anyhow!("Config file should be passed as only parameter"))?;
|
.ok_or_else(|| anyhow!("Config file should be passed as only parameter"))?;
|
||||||
@@ -76,7 +78,7 @@ async fn main() {
|
|||||||
env_logger::init_from_env(lenv);
|
env_logger::init_from_env(lenv);
|
||||||
|
|
||||||
if let Err(err) = run().await {
|
if let Err(err) = run().await {
|
||||||
error!("{:#}", err);
|
error!("{err:#}");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,24 +1,24 @@
|
|||||||
// bebot
|
// bebot -- a Gitlab -> Matrix event publisher
|
||||||
// Copyright (C) 2023 Brian Tarricone <brian@tarricone.org>
|
// Copyright (C) 2023-2025 Brian Tarricone <brian@tarricone.org>
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// This program is distributed in the hope that it will be useful,
|
// This program is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU General Public License for more details.
|
// GNU Affero General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::{fmt, process::exit, time::Duration};
|
use std::{fmt, process::exit, time::Duration};
|
||||||
|
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{
|
||||||
config::SyncSettings,
|
config::SyncSettings,
|
||||||
room::Joined,
|
room::Room,
|
||||||
ruma::{OwnedRoomOrAliasId, OwnedUserId, RoomOrAliasId, UserId},
|
ruma::{OwnedRoomOrAliasId, OwnedUserId, RoomOrAliasId, UserId},
|
||||||
BaseRoom, Client,
|
BaseRoom, Client,
|
||||||
};
|
};
|
||||||
@@ -26,12 +26,8 @@ use serde::de;
|
|||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
|
|
||||||
async fn build_sync_settings(matrix_client: &Client) -> SyncSettings {
|
async fn build_sync_settings() -> SyncSettings {
|
||||||
let mut settings = SyncSettings::default().timeout(Duration::from_secs(30));
|
SyncSettings::default().timeout(Duration::from_secs(30))
|
||||||
if let Some(token) = matrix_client.sync_token().await {
|
|
||||||
settings = settings.token(token);
|
|
||||||
}
|
|
||||||
settings
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(config: &Config) -> anyhow::Result<Client> {
|
pub async fn connect(config: &Config) -> anyhow::Result<Client> {
|
||||||
@@ -41,21 +37,21 @@ pub async fn connect(config: &Config) -> anyhow::Result<Client> {
|
|||||||
.build()
|
.build()
|
||||||
.await?;
|
.await?;
|
||||||
client
|
client
|
||||||
|
.matrix_auth()
|
||||||
.login_username(&config.user_id, &config.password)
|
.login_username(&config.user_id, &config.password)
|
||||||
.initial_device_display_name("Bebot")
|
.initial_device_display_name("Bebot")
|
||||||
.send()
|
|
||||||
.await?;
|
.await?;
|
||||||
info!("Connected to matrix as {}; waiting for first sync", config.user_id);
|
info!("Connected to matrix as {}; waiting for first sync", config.user_id);
|
||||||
|
|
||||||
let settings = build_sync_settings(&client).await;
|
let settings = build_sync_settings().await;
|
||||||
client.sync_once(settings).await?;
|
client.sync_once(settings).await?;
|
||||||
info!("First matrix sync complete");
|
info!("First matrix sync complete");
|
||||||
|
|
||||||
let sync_client = client.clone();
|
let sync_client = client.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let settings = build_sync_settings(&sync_client).await;
|
let settings = build_sync_settings().await;
|
||||||
if let Err(err) = sync_client.sync(settings).await {
|
if let Err(err) = sync_client.sync(settings).await {
|
||||||
error!("Matrix sync failed: {}", err);
|
error!("Matrix sync failed: {err}");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -63,7 +59,7 @@ pub async fn connect(config: &Config) -> anyhow::Result<Client> {
|
|||||||
Ok(client)
|
Ok(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn ensure_room_joined(matrix_client: &Client, room_id: &OwnedRoomOrAliasId) -> anyhow::Result<Joined> {
|
pub async fn ensure_room_joined(matrix_client: &Client, room_id: &OwnedRoomOrAliasId) -> anyhow::Result<Room> {
|
||||||
fn room_matches(a_room: &BaseRoom, our_room: &OwnedRoomOrAliasId) -> bool {
|
fn room_matches(a_room: &BaseRoom, our_room: &OwnedRoomOrAliasId) -> bool {
|
||||||
let our_room_str = our_room.as_str();
|
let our_room_str = our_room.as_str();
|
||||||
a_room.room_id().as_str() == our_room_str
|
a_room.room_id().as_str() == our_room_str
|
||||||
@@ -85,11 +81,11 @@ pub async fn ensure_room_joined(matrix_client: &Client, room_id: &OwnedRoomOrAli
|
|||||||
.iter()
|
.iter()
|
||||||
.find(|a_room| room_matches(a_room, room_id))
|
.find(|a_room| room_matches(a_room, room_id))
|
||||||
{
|
{
|
||||||
invited.accept_invitation().await?;
|
invited.join().await?;
|
||||||
} else {
|
} else {
|
||||||
matrix_client.join_room_by_id_or_alias(room_id, &[]).await?;
|
matrix_client.join_room_by_id_or_alias(room_id, &[]).await?;
|
||||||
}
|
}
|
||||||
let settings = build_sync_settings(matrix_client).await;
|
let settings = build_sync_settings().await;
|
||||||
matrix_client.sync_once(settings).await?;
|
matrix_client.sync_once(settings).await?;
|
||||||
room = matrix_client
|
room = matrix_client
|
||||||
.joined_rooms()
|
.joined_rooms()
|
||||||
|
Reference in New Issue
Block a user