Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Started loading bot credentials from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Oct 6, 2018
1 parent 89eb74e commit c2b60f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
yarn.lock
client_secret.json
bot_credentials.json
credentials.json
package-lock.json
privateRooms.json
Expand Down
56 changes: 31 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,40 @@ function getNewToken(oAuth2Client, callback) {
const client = sdk.createClient("https://matrix.org");

function authenticated(auth) {
client.login(
"m.login.password",
{
user: process.env.BOT_USER,
password: process.env.BOT_PASSWORD
},
(err, data) => {
if (err) {
console.log("Error:", err);
}
fs.readFile("bot_credentials.json", (err, content) => {
if (err) return console.log("Error loading bot credentials", err);

console.log(`Logged in ${data.user_id} on device ${data.device_id}`);
const client = sdk.createClient({
baseUrl: "https://matrix.org",
accessToken: data.access_token,
userId: data.user_id,
deviceId: data.device_id
});
content = JSON.parse(content);

client.on("Room.timeline", (event, room, toStartOfTimeline) => {
chatBot.handleNewMember(event, room, toStartOfTimeline, client);
pointsBot.handlePointGiving(auth, event, room, toStartOfTimeline, client);
chatBot.handleResponse(event, room, toStartOfTimeline, client);
});
client.login(
"m.login.password",
{
user: content.username,
password: content.password
},
(err, data) => {
if (err) {
console.log("Error:", err);
}

console.log(`Logged in ${data.user_id} on device ${data.device_id}`);
const client = sdk.createClient({
baseUrl: "https://matrix.org",
accessToken: data.access_token,
userId: data.user_id,
deviceId: data.device_id
});

client.startClient(0);
}
);
client.on("Room.timeline", (event, room, toStartOfTimeline) => {
chatBot.handleNewMember(event, room, toStartOfTimeline, client);
pointsBot.handlePointGiving(auth, event, room, toStartOfTimeline, client);
chatBot.handleResponse(event, room, toStartOfTimeline, client);
});

client.startClient(0);
}
);
});
}

// Zeit NOW workaround
Expand Down

0 comments on commit c2b60f1

Please sign in to comment.