weechat-relay-rs is a pure-Rust library for interfacing with a WeeChat Relay, including sending commands and receiving messages. This repo also hosts weechat-relay-cli, a minimal terminal application for testing, debugging, and scripting with weechat-relay-rs. All code is safe Rust, and the library only depends on the standard library and nom.
WeeChat, the extensible chat client, can operate as a "relay" for other clients to connect to as "remote interfaces". This allows users to pick their own interface for their desktop, browser, mobile device, etc.. To use this functionality, the client must use WeeChat's custom Relay protocol.
Because the protocol is entirely bespoke, and does not use any sort of generalized representation (e.g., XML, JSON, protobufs, etc.), clients cannot rely on popular, well-established libraries for parsing or representing WeeChat relay commands and messages. The protocol was not written to be cleanly abstracted, and in a lot of ways simply exposes the relay's underlying C representations. This means that even simple interactions can be cumbersome to get working, with subtle edge cases cropping up in unexpected ways. A library that is (hopefully) correct should make it a lot easier to get up and running.
The protocol makes heavy use of complicated structures with many types and various constraints. Aside from the obvious advantages of memory safety, the compile-time type checks make Rust a language well-suited to consuming the relay protocol, preventing bugs that might otherwise occur in rare edge-cases at run-time.
The library is "complete" in the sense that it should be able to handle all commands and messages currently possible in the latest WeeChat (other than compressed messages), but is very much incomplete in that the API is not yet stable. It is currently published as something good enough to get fully working code, but there are still rough edges that were left in to get it working quickly. Feel free to use it, but if you do so, understand that future updates will likely break your code.
The CLI tool is not meant to be used as a full WeeChat client, but instead, to play around with the library and WeeChat. You can also use it to do some basic shell scripting that interfaces with a WeeChat relay. It takes as input, either in a prompt or from a supplied file or pipe, WeeChat relay commands in essentially their raw form (parsed locally for basic correctness before sending), and prints any response messages in a mostly-human-readable layout, with the message ID followed by one message object per line.
The the CLI doesn't support compression, but otherwise, it can do most things a WeeChat client can.
Aside from the normal WeeChat relay commands, there are a few commands to interact with the application rather than the relay, currently signified by starting with an underscore (_
):
_get [n]
: Get n messages from the relay. Most commands expect 0 or 1 messages in response, and the CLI will wait as appropriate for that many messages, but if you want to use thesync
command, messages will start coming in asynchronously, so you'll have to use_get
to see them all. You'll probably want to set the--timeout
option if you want to use this, else you'll be waiting a while to do anything if there were fewer messages available than you requested._sleep [n]
: Sleep n seconds before sending the next command. Can be useful when running commands from a file._quit
: Quit the client. If running commands from a file, the application will also quit normally once it gets to the end of the file.
Run the executable with -h
to see all the invocation options.
An example session:
cargo run --features cli -- --host "127.0.0.1:9001" --init "my weechat password"
> (before) info version
(before)
inf: ("version": "3.6")
> input core.weechat /upgrade
> (after) info version
(after)
inf: ("version": "3.7.1")
> _quit
With the --script
option or a pipe, you can use hooks from your package manager to automatically upgrade WeeChat when the package upgrades, set up a cron
job to automatically update channel topics, or anything else you can think of with a shell, all run from your WeeChat instance (no need for separate bot accounts to manage).
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.