README.md

8454dcd1674dfb48ab4ee615134e2d4d5fc04fa7
weechat-matrix-rs/README.md rendered · source · history · blame · raw

243 lines · 8987 bytes

  1[![build-test-release](https://github.com/poljar/weechat-matrix-rs/actions/workflows/release.yml/badge.svg?event=push)](https://github.com/poljar/weechat-matrix-rs/actions/workflows/release.yml)
  2[![#weechat-matrix](https://img.shields.io/badge/matrix-%23weechat--matrix:termina.org.uk-blue.svg?style=flat-square)](https://matrix.to/#/!twcBhHVdZlQWuuxBhN:termina.org.uk?via=termina.org.uk&via=matrix.org)
  3[![license](https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square)](https://github.com/poljar/weechat-matrix-rs/blob/master/LICENSE)
  4
  5# What is weechat-matrix?
  6
  7[Weechat](https://weechat.org/) is an extensible chat client.
  8
  9[Matrix](https://matrix.org/blog/home) is an open network for secure,
 10decentralized communication.
 11
 12weechat-matrix-rs is a Rust plugin for Weechat that lets Weechat communicate
 13over the Matrix protocol. This is a Rust rewrite of the
 14[weechat-matrix](https://github.com/poljar/weechat-matrix) Python script.
 15
 16# Project status
 17
 18This project is a work in progress and doesn't do much yet. It can connect
 19to a Matrix server and send messages.
 20
 21It is not an IRC relay or bridge: IRC clients connected through WeeChat's relay
 22plugin cannot use Matrix rooms as IRC channels. Remote WeeChat interfaces using
 23WeeChat relay protocols can access plugin buffers, but Matrix features that
 24rewrite already-printed lines, such as message edits and redactions, depend on
 25the remote client supporting WeeChat relay line-update events.
 26
 27If you are interested in helping out take a look at the issue tracker.
 28
 29# Build
 30
 31Install Rust and the native build dependencies first. On Debian or Ubuntu a
 32typical build environment needs:
 33
 34    sudo apt install build-essential clang libclang-dev libsqlite3-dev pkg-config
 35
 36Other distributions use different package names, but the important native
 37pieces are a C/C++ compiler, `clang`/`libclang`, and SQLite development headers.
 38The `weechat-sys` dependency has a bundled WeeChat plugin header
 39(`weechat-plugin.h`) fallback. If you want to build against the exact WeeChat
 40API installed on your system, install the matching development package
 41(`weechat-dev` on Debian/Ubuntu) or point `WEECHAT_PLUGIN_FILE` at the full
 42path to that header:
 43
 44    export WEECHAT_PLUGIN_FILE=/usr/include/weechat/weechat-plugin.h
 45
 46If `bindgen` reports that `stddef.h`, `libclang`, or `libLLVM` is missing, check
 47that the `clang` command-line tools, C/C++ compiler headers, and matching
 48`libclang` package are installed. On minimal distributions the library package
 49alone may not provide the compiler include paths that `bindgen` needs.
 50
 51After the dependencies are installed the plugin can be compiled with:
 52
 53    cargo build --release
 54
 55If you are developing on weechat-matrix-rs, use debug builds which are faster at
 56the expense of plugin performance:
 57
 58    cargo build
 59
 60On Linux this creates a `libmatrix.so` file in the `target/release/`
 61(`target/debug` for dev builds) folder. Rename it to `matrix.so` and copy it to
 62your WeeChat plugin directory.
 63
 64`make install` installs the plugin systemwide:
 65
 66    sudo make install
 67
 68On Debian-like multiarch systems this installs the release build to:
 69
 70    /usr/lib/${DEB_HOST_MULTIARCH}/weechat/plugins/matrix.so
 71
 72On other systems it defaults to:
 73
 74    /usr/lib/weechat/plugins/matrix.so
 75
 76Set `WEECHAT_PLUGIN_DIR` if your distribution uses another system plugin
 77directory:
 78
 79    sudo make install WEECHAT_PLUGIN_DIR=/path/to/weechat/plugins
 80
 81To install only for the current user, use:
 82
 83    make install-user
 84
 85This installs the release build to:
 86
 87    ${XDG_DATA_HOME:-$HOME/.local/share}/weechat/plugins/matrix.so
 88
 89Use `PROFILE=debug` for a debug build:
 90
 91    make install-user PROFILE=debug
 92
 93The matching uninstall targets are:
 94
 95    sudo make uninstall
 96    make uninstall-user
 97
 98On older WeeChat setups the plugin directory may instead live under
 99`$WEECHAT_HOME/plugins`, commonly `~/.weechat/plugins/`. Create the directory if
100needed and copy the renamed plugin there.
101
102On macOS the built library extension is usually `.dylib`. WeeChat may need this
103extension enabled before it loads the plugin:
104
105    /set weechat.plugin.extension ".so,.dll,.dylib"
106
107Rename `target/release/libmatrix.dylib` to `matrix.dylib` before copying it to
108your WeeChat plugin directory.
109
110# Debian / Ubuntu package
111
112A `.deb` package can be built using `cargo-deb`. This requires
113[Rust installed](https://rustup.rs/) (via rustup, the recommended method).
114
115First ensure `cargo-deb` is available:
116
117    cargo install cargo-deb
118
119Then build the package with:
120
121    make deb
122
123The resulting `.deb` package is placed in `target/debian/`. Install it with:
124
125    sudo dpkg -i target/debian/weechat-matrix-rs_*.deb
126
127# Loading the plugin
128
129Restart WeeChat after installing the plugin, or load it manually:
130
131    /plugin load matrix
132
133Check that it is loaded with:
134
135    /plugin list
136
137If WeeChat cannot find the plugin, check that the file is named `matrix.so`
138(`matrix.dylib` on macOS), that it is in a directory from WeeChat's plugin
139search path, and that `.so`/`.dylib` is enabled in
140`weechat.plugin.extension`.
141
142# Configuration
143
144Configuration is completed primarily through the Weechat interface. First start
145WeeChat, make sure the plugin is loaded, and then issue the following commands
146_(replace the placeholders in brackets [] with your own details)_:
147
1481. Add a server _(make sure the url includes the scheme e.g. 'https://matrix.org')_:
149
150       /matrix server add [server-name] [server-url]
151
1522. Set your username and password:
153
154       /set matrix-rust.server.[server-name].username [username]
155       /set matrix-rust.server.[server-name].password [password]
156
157   If the homeserver advertises single sign-on, leave the password empty to use
158   it. WeeChat will print a login URL when you connect.
159
160   The SSO callback listens on `127.0.0.1:29325` on the WeeChat host. When
161   WeeChat runs on another machine, create an SSH tunnel before connecting so
162   the browser's localhost callback reaches it:
163
164       ssh -L 29325:127.0.0.1:29325 user@weechat-host
165
1663. Now try to connect. The first connection can take a few minutes while the
167   client syncs the account:
168
169       /matrix connect [server-name]
170
1714. Automatically connect to the server:
172
173       /set matrix-rust.server.[server-name].autoconnect on
174
1755. If everything works, save the configuration:
176
177       /save
178
179To hide join/leave noise from users who have not been active recently, add a WeeChat
180filter for Matrix smart-filter tags:
181
182       /filter add matrix_smart * matrix_smart_filter *
183
184The inactivity delay defaults to five minutes and can be changed with:
185
186       /set matrix-rust.look.smart_filter_delay 300000
187
188# Matrix Spaces
189
190Room buffers expose Matrix parent Spaces as WeeChat local variables. Switch to a
191room buffer that belongs to a Space and run:
192
193       /buffer listvar
194
195Look for `space`, `space_id`, `spaces`, and `space_ids`. The singular variables
196hold the first parent Space name and room id; the plural variables contain all
197known parent Spaces as comma-separated lists.
198
199The buflist plugin will not reorganize Matrix rooms under Spaces by itself.
200These variables are available to scripts and custom buflist formats. For
201example, to prefix Matrix room names with their first parent Space:
202
203       /set buflist.format.name "${if:${space}?${space}/${name}:${name}}"
204       /buflist refresh
205
206Remove that prefix again with:
207
208       /unset buflist.format.name
209
210# Storage
211
212The plugin keeps Matrix state and encryption data in
213`$WEECHAT_HOME/matrix-rust/<server>/`. It keeps the Matrix SDK event cache in
214`$WEECHAT_HOME/matrix-rust/<server>-cache/`.
215
216If the cache grows or causes too much disk I/O, disconnect WeeChat and remove
217only the `-cache` directory. Do not remove the main server directory unless you
218want to reset stored Matrix state.
219Nick prefix colors for Matrix power levels can be changed with:
220
221       /set matrix-rust.color.nick_prefix_admin lightgreen
222       /set matrix-rust.color.nick_prefix_moderator lightmagenta
223       /set matrix-rust.color.nick_prefix_power yellow
224
225Existing nicklist entries may need a member update or plugin restart before the new colors are visible.
226
227
228# Helpful Commands
229
230`/help matrix` will print information about the `/matrix` command.
231
232`/matrix help [command]` will print information for subcommands, such as `/matrix help server`.
233
234Room buffers accept normal message input after `/matrix connect [server-name]`
235has completed.
236
237`/matrix media download <mxc-uri> [file]` downloads Matrix media through the logged-in client, including homeservers that require authenticated media. It refuses to overwrite an existing file. When `[file]` is omitted, the media id is saved with the configured prefix, which defaults to `matrix-media-`:
238
239       /set matrix-rust.media.download_prefix matrix-media-
240
241The prefix may include a directory and supports `~`, `$XDG_STATE_HOME`, and `${XDG_STATE_HOME}`. Parent directories are created automatically:
242
243       /set matrix-rust.media.download_prefix "$XDG_STATE_HOME/weechat-matrix/media/matrix-media-"