commit cad41df0764babaa8f687ad7e3c7852f8e2d8087
parent 478d73696fbce19246c224c167e9e3c3ebcc77cc
Author: Marcel <mtrnord1@gmail.com>
Date: Tue, 20 Jun 2017 10:20:34 +0200
Use config file instead of env
Signed-off-by: Marcel <mtrnord1@gmail.com>
Diffstat:
4 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -60,4 +60,5 @@ typings/
.idea/
lib/
package-lock.json
-user_data.json
-\ No newline at end of file
+user_data.json
+config.json
+\ No newline at end of file
diff --git a/README.md b/README.md
@@ -4,10 +4,8 @@
A simple riot bot which provides Status about Weblate
# Tests
+First make sure you fill a ``config.json`` like the config.example.json.
```
1. npm install
-2. npm run start "USERNAME" "PASSWORD"
-3. kill npm run start after it got the poll rules
-4. npm test
-```
-``npm run start`` is required as it generates the needed token file. Using "USERNAME" and "PASSWORD" on npm test will propably work too.
-\ No newline at end of file
+2. npm test
+```
+\ No newline at end of file
diff --git a/config.example.json b/config.example.json
@@ -0,0 +1,6 @@
+{
+ "username": "@User:example.org",
+ "password": "matrixPassword12345#",
+ "weblateApiRoot": "https://translate.riot.im/api/",
+ "weblate_token": "IGIEJEW§$IWOJIEFJWOIFJO"
+}
+\ No newline at end of file
diff --git a/src/login.js b/src/login.js
@@ -2,7 +2,7 @@ import matrix_sdk from 'matrix-js-sdk';
import fs from 'mz/fs';
import node_fs from 'fs';
-const env_args = process.argv.splice(process.execArgv.length + 2);
+import config from '../config.json';
export default class Login {
constructor() {};
@@ -17,20 +17,20 @@ export default class Login {
if (valid_json.hasOwnProperty("access_token")){
return this.useToken(valid_json["access_token"], valid_json["user_id"], valid_json["home_server"]);
} else {
- return this.useEnv();
+ return this.usePassword();
}
} else {
- return this.useEnv();
+ return this.usePassword();
}
};
- useEnv = () => {
+ usePassword = () => {
const matrixClient = matrix_sdk.createClient({
baseUrl: "https://matrix.org",
- userId: env_args[0]
+ userId: config["username"]
});
- matrixClient.loginWithPassword(env_args[0], env_args[1]).then( data => {
+ matrixClient.loginWithPassword(config["username"], config["password"]).then( data => {
console.log(data);
fs.writeFile('user_data.json', JSON.stringify(data), 'utf8')
.then(() => {