47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
const sdk = require("matrix-js-sdk");
|
|
const matrixcs = require("matrix-js-sdk/lib/matrix");
|
|
const request = require('request');
|
|
matrixcs.request(request);
|
|
|
|
const startupTime = Date.now();
|
|
|
|
const myUserId = "@glowy:glowers.club"
|
|
const myAccessToken = "syt_TotallyMyRealAccessTokenAndNotAFake";
|
|
const matrixClient = sdk.createClient({
|
|
baseUrl: "https://glowers.club",
|
|
accessToken: myAccessToken,
|
|
userId: myUserId
|
|
});
|
|
|
|
|
|
const Dice = require('./index.js');
|
|
const dice = new Dice(matrixClient)
|
|
|
|
matrixClient.on("Room.timeline", function(event, room, toStartOfTimeline) {
|
|
if (event.getTs() >= startupTime && event.getType() == "m.room.message" && event.getContent().body != null) {
|
|
|
|
if (event.getContent().body.indexOf("!help") == 0) {
|
|
const helpMessage = "Commands:\n"+dice.getHelp();
|
|
const formattedHelpMessage = "Commands:<br />"+dice.getFormattedHelp();
|
|
|
|
const content = {
|
|
"format": "org.matrix.custom.html",
|
|
"body": helpMessage,
|
|
"formatted_body": formattedHelpMessage,
|
|
"msgtype": "m.text"
|
|
};
|
|
matrixClient.sendEvent(room.roomId, "m.room.message", content, "", (err, res) => {
|
|
if (err != null) {
|
|
console.error(err);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
|
|
|
|
dice.handleMessage(event, room);
|
|
}
|
|
});
|
|
|
|
matrixClient.startClient();
|