diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml new file mode 100644 index 0000000..08e6ff7 --- /dev/null +++ b/.forgejo/workflows/release.yml @@ -0,0 +1,54 @@ +name: Python Package CI/CD + +on: + workflow_dispatch: + push: + tags: + - "*" + +jobs: + setup: + name: Setup and Test + container: + image: node:20-bookworm + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + apt update + apt install -y python3-venv + + - name: Set up Python environment + run: | + python3 -V + python3 -m venv venv + . ./venv/bin/activate + pip install -U pip + pip install .[all] + + publish: + name: Publish to PyPI + container: + image: node:20-bookworm + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + apt update + apt install -y python3-venv + + - name: Publish to PyPI + run: | + python3 -m venv venv + . ./venv/bin/activate + pip install -U hatchling twine build + python -m build . + python -m twine upload --username __token__ --password ${PYPI_TOKEN} dist/* + env: + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} diff --git a/.gitignore b/.gitignore index 6740af6..0a8a9f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ venv/ __pycache__/ *.pyc -config.yaml \ No newline at end of file +config.yaml +dist/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8089469 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2024 Private.coffee Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..bfaebc7 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# Matrix-Roomba + +[![Support Private.coffee!](https://shields.private.coffee/badge/private.coffee-support%20us!-pink?logo=coffeescript)](https://private.coffee) +[![PyPI](https://shields.private.coffee/pypi/v/matrix-roomba)](https://pypi.org/project/matrix-roomba/) +[![PyPI - Python Version](https://shields.private.coffee/pypi/pyversions/matrix-roomba)](https://pypi.org/project/matrix-roomba/) +[![PyPI - License](https://shields.private.coffee/pypi/l/matrix-roomba)](https://pypi.org/project/matrix-roomba/) +[![Latest Git Commit](https://shields.private.coffee/gitea/last-commit/privatecoffee/matrix-roomba?gitea_url=https://git.private.coffee)](https://git.private.coffee/privatecoffee/matrix-roomba) + +Roomba is a moderation bot for Matrix, designed to help manage rooms and enforce content policies. The bot can block/unblock rooms, shut down rooms, and notify users of shutdowns. It integrates with Synapse's administrative API and supports optional encryption through Pantalaimon. + +## Installation + +```bash +pip install matrix-roomba +``` + +Create a configuration file in `config.yaml` based on the [config.dist.yaml](config.dist.yaml) provided in the repository. + +At the very least, you need to provide the following configuration: + +```yaml +homeserver: "https://matrix.example.com" +user_id: "@roomba:example.com" +access_token: "YOUR_ACCESS_TOKEN" +moderation_room_id: "!moderation_room_id:example.com" +``` + +Ensure that the bot user is an admin on the homeserver, as it needs to be able to moderate rooms. Also add the user to the moderation room before starting the bot. + +We recommend using pantalaimon as a proxy, because the bot itself does not support end-to-end encryption. + +You can start the bot by running: + +## Usage + +1. Start the bot: + +```bash +roomba +``` + +2. Send a message to the moderation room to get a list of available commands: + +``` +!roomba +``` + +### Commands + +In the moderation room, send commands to manage rooms: + +- Block a room: !roomba block +- Unblock a room: !roomba unblock +- Shutdown a room: !roomba shutdown [--purge] +- For help: !roomba + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..70622cb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,40 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.metadata] +allow-direct-references = true + +[project] +name = "matrix-roomba" +version = "0.1.0" + +authors = [{ name = "Private.coffee Team", email = "support@private.coffee" }] + +description = "A Matrix bot that helps you shut down rooms" +readme = "README.md" +license = { file = "LICENSE" } +requires-python = ">=3.10" + +packages = ["src/matrix_roomba"] + +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] + +dependencies = [ + "matrix-nio", + "pyyaml" +] + +[project.urls] +"Homepage" = "https://git.private.coffee/PrivateCoffee/matrix-roomba" +"Bug Tracker" = "https://git.private.coffee/PrivateCoffee/matrix-roomba/issues" + +[project.scripts] +roomba = "matrix_roomba.bot:main" + +[tool.hatch.build.targets.wheel] +packages = ["src/matrix_roomba"] diff --git a/src/matrix_roomba/__init__.py b/src/matrix_roomba/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot.py b/src/matrix_roomba/bot.py similarity index 100% rename from bot.py rename to src/matrix_roomba/bot.py