-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,499 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.git | ||
node_modules | ||
config | ||
lib | ||
logs | ||
storage | ||
db | ||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
config/* | ||
!config/default.yaml | ||
lib/ | ||
storage/ | ||
|
||
/.idea | ||
|
||
/db | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "mjolnir", | ||
"version": "0.1.0", | ||
"description": "A moderation tool for Matrix", | ||
"main": "lib/index.js", | ||
"repository": "[email protected]: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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
Oops, something went wrong.