Skip to content

neiam/twitbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

twitbot

A Matrix bot that rewrites Twitter/X links to xcancel.com.

When a message in a joined room contains a twitter.com, x.com, or fixupx.com link, the bot replies with the same message with those links replaced by xcancel.com equivalents.

Configuration

All configuration is via environment variables.

Variable Flag Required Description
MATRIX_HOMESERVER --homeserver Yes URL of your Matrix homeserver (e.g. https://matrix.org)
MATRIX_USERNAME --username Yes Bot account user ID (e.g. @twitbot:matrix.org)
MATRIX_PASSWORD --password Yes Bot account password
MATRIX_INVITE_USER --invite-user No If set, the bot will automatically accept room invites from this user ID
REPLY_PREFIX --reply-prefix No If set, replies contain only the replaced links preceded by this string (e.g. fixed:). Without it the full message is echoed with links swapped in place.

Running

MATRIX_HOMESERVER=https://matrix.example.com \
MATRIX_USERNAME=@twitbot:example.com \
MATRIX_PASSWORD=secret \
MATRIX_INVITE_USER=@you:example.com \
REPLY_PREFIX="fixed:" \
cargo run --release

Or equivalently with flags:

cargo run --release -- \
  --homeserver https://matrix.example.com \
  --username @twitbot:example.com \
  --password secret \
  --invite-user @you:example.com \
  --reply-prefix "fixed:"

Building

Requires Rust 1.80+ (uses LazyLock).

cargo build --release

Container deployment

Images are published to ghcr.io/neiam/twitbot. Pull and run:

podman run --rm \
  -e MATRIX_HOMESERVER=https://matrix.example.com \
  -e MATRIX_USERNAME=@twitbot:example.com \
  -e MATRIX_PASSWORD=secret \
  -e MATRIX_INVITE_USER=@you:example.com \
  -e MATRIX_JOIN_ROOM='#room:example.com' \
  -e REPLY_PREFIX='fixed:' \
  ghcr.io/neiam/twitbot:latest

Or with an env file:

podman run --rm --env-file .env ghcr.io/neiam/twitbot:latest

To build locally instead:

podman build -t ghcr.io/neiam/twitbot:latest .

Quadlet (systemd)

A twitbot.container Quadlet unit is included. To install it as a user service:

# Create the env file with your secrets
mkdir -p ~/.config/twitbot
cat > ~/.config/twitbot/env <<EOF
MATRIX_HOMESERVER=https://matrix.example.com
MATRIX_USERNAME=@twitbot:example.com
MATRIX_PASSWORD=secret
MATRIX_INVITE_USER=@you:example.com
MATRIX_JOIN_ROOM=#room:example.com
REPLY_PREFIX=fixed:
EOF
chmod 600 ~/.config/twitbot/env

# Install the unit
cp twitbot.container ~/.config/containers/systemd/

# Reload and start
systemctl --user daemon-reload
systemctl --user enable --now twitbot

Example

User: check out https://twitter.com/user/status/123456

twitbot: check out https://xcancel.com/user/status/123456

About

A Matrix bot to make twitter links usable by non-lusers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors