mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Absolute bare minimum for a bot
This commit is contained in:
parent
49be5b7711
commit
ed6f37be2b
8
.dockerignore
Normal file
8
.dockerignore
Normal file
@ -0,0 +1,8 @@
|
||||
.git
|
||||
node_modules
|
||||
config
|
||||
lib
|
||||
logs
|
||||
storage
|
||||
db
|
||||
*.db
|
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,3 +1,12 @@
|
||||
config/*
|
||||
!config/default.yaml
|
||||
lib/
|
||||
storage/
|
||||
|
||||
/.idea
|
||||
|
||||
/db
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@ -0,0 +1,15 @@
|
||||
FROM node:alpine
|
||||
COPY . /tmp/src
|
||||
RUN cd /tmp/src \
|
||||
&& npm install \
|
||||
&& npm run build \
|
||||
&& mv lib/ /mjolnir/ \
|
||||
&& mv node_modules / \
|
||||
&& cd / \
|
||||
&& rm -rf /tmp/*
|
||||
|
||||
ENV NODE_ENV=production
|
||||
ENV NODE_CONFIG_DIR=/data/config
|
||||
|
||||
CMD node /mjolnir/index.js
|
||||
VOLUME ["/data"]
|
59
README.md
59
README.md
@ -1,2 +1,59 @@
|
||||
# mjolnir
|
||||
A moderation tool for Matrix
|
||||
|
||||
A moderation tool for Matrix.
|
||||
|
||||
## Features
|
||||
|
||||
TODO: Describe what all this means.
|
||||
|
||||
Phase 1:
|
||||
* [ ] Ban users
|
||||
* [ ] ACL servers
|
||||
* [ ] Update lists with new bans/ACLs
|
||||
* [ ] "Ban on sight" mode (rather than proactive)
|
||||
|
||||
Phase 2:
|
||||
* [ ] Synapse antispam module
|
||||
* [ ] Riot hooks (independent of mjolnir?)
|
||||
* [ ] Support community-defined scopes? (ie: no hardcoded config)
|
||||
* [ ] Vet rooms on startup option
|
||||
|
||||
## Docker (preferred)
|
||||
|
||||
Mjolnir does not yet have its own image published.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/matrix-org/mjolnir.git
|
||||
cd mjolnir
|
||||
|
||||
docker build -t mjolnir .
|
||||
|
||||
# Copy and edit the config. It is not recommended to change the data path.
|
||||
mkdir -p /etc/mjolnir
|
||||
cp config/default.yaml /etc/mjolnir/production.yaml
|
||||
nano /etc/mjolnir/production.yaml
|
||||
|
||||
docker run --rm -it -v /etc/mjolnir:/data mjolnir
|
||||
```
|
||||
|
||||
## Build it
|
||||
|
||||
This bot requires `yarn` and Node 10.
|
||||
|
||||
```bash
|
||||
git clone https://github.com/matrix-org/mjolnir.git
|
||||
cd mjolnir
|
||||
|
||||
yarn install
|
||||
yarn build
|
||||
|
||||
# Copy and edit the config. It *is* recommended to change the data path.
|
||||
cp config/default.yaml config/development.yaml
|
||||
nano config/development.yaml
|
||||
|
||||
node lib/index.js
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
TODO. It's a TypeScript project with a linter.
|
||||
|
11
config/default.yaml
Normal file
11
config/default.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
# Where the homeserver is located (client-server URL)
|
||||
homeserverUrl: "https://matrix.org"
|
||||
|
||||
# The access token for the bot to use
|
||||
accessToken: "YOUR_TOKEN_HERE"
|
||||
|
||||
# The directory the bot should store various bits of information in
|
||||
dataPath: "/data/storage"
|
||||
|
||||
# Whether the bot should autojoin rooms it is invited to or not
|
||||
autojoin: true
|
25
package.json
Normal file
25
package.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "mjolnir",
|
||||
"version": "0.1.0",
|
||||
"description": "A moderation tool for Matrix",
|
||||
"main": "lib/index.js",
|
||||
"repository": "git@github.com:matrix-org/mjolnir.git",
|
||||
"author": "The Matrix.org Foundation C.I.C.",
|
||||
"license": "Apache-2.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"lint": "tslint --project ./tsconfig.json --type-check -t stylish",
|
||||
"start:dev": "yarn build && node lib/index.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "11",
|
||||
"tslint": "^5.20.0",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"config": "^3.2.2",
|
||||
"js-yaml": "^3.13.1",
|
||||
"matrix-bot-sdk": "^0.4.0-beta.5"
|
||||
}
|
||||
}
|
26
src/config.ts
Normal file
26
src/config.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import * as config from "config";
|
||||
|
||||
interface IConfig {
|
||||
homeserverUrl: string;
|
||||
accessToken: string;
|
||||
dataPath: string;
|
||||
autojoin: boolean;
|
||||
}
|
||||
|
||||
export default <IConfig>config;
|
45
src/index.ts
Normal file
45
src/index.ts
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import * as path from "path";
|
||||
import {
|
||||
AutojoinRoomsMixin,
|
||||
LogService,
|
||||
MatrixClient,
|
||||
RichConsoleLogger,
|
||||
SimpleFsStorageProvider
|
||||
} from "matrix-bot-sdk";
|
||||
import config from "./config";
|
||||
|
||||
LogService.setLogger(new RichConsoleLogger());
|
||||
|
||||
const storage = new SimpleFsStorageProvider(path.join(config.dataPath, "bot.json"));
|
||||
const client = new MatrixClient(config.homeserverUrl, config.accessToken, storage);
|
||||
|
||||
if (config.autojoin) {
|
||||
AutojoinRoomsMixin.setupOnClient(client);
|
||||
}
|
||||
|
||||
client.on("room.message", async (roomId, event) => {
|
||||
if (!event['content']) return;
|
||||
|
||||
const content = event['content'];
|
||||
if (content['msgtype'] === 'm.text' && content['body'] === '!mjolnir') {
|
||||
await client.sendNotice(roomId, "Hello world!");
|
||||
}
|
||||
});
|
||||
|
||||
client.start().then(() => LogService.info("index", "Bot started!"));
|
18
tsconfig.json
Normal file
18
tsconfig.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"target": "es2015",
|
||||
"noImplicitAny": false,
|
||||
"sourceMap": true,
|
||||
"outDir": "./lib",
|
||||
"types": [
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*"
|
||||
]
|
||||
}
|
31
tslint.json
Normal file
31
tslint.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"extends": "tslint:recommended",
|
||||
"rules": {
|
||||
"ordered-imports": false,
|
||||
"no-trailing-whitespace": "error",
|
||||
"max-classes-per-file": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"object-literal-sort-keys": "off",
|
||||
"no-any": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"arrow-return-shorthand": true,
|
||||
"no-magic-numbers": true,
|
||||
"prefer-for-of": true,
|
||||
"typedef": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"await-promise": true,
|
||||
"curly": true,
|
||||
"no-empty": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"no-invalid-this": true,
|
||||
"no-string-throw": {
|
||||
"severity": "warning"
|
||||
},
|
||||
"no-unused-expression": true,
|
||||
"prefer-const": true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user