2018-12-03 02:12:20 +01:00
|
|
|
|
import x2i from "./x2i";
|
|
|
|
|
|
|
|
|
|
const config = require("./config.json");
|
|
|
|
|
|
|
|
|
|
const MatrixClient = require("matrix-bot-sdk").MatrixClient;
|
|
|
|
|
const AutojoinRoomsMixin = require("matrix-bot-sdk").AutojoinRoomsMixin;
|
|
|
|
|
|
|
|
|
|
const client = new MatrixClient(config.homeserver, config.token);
|
|
|
|
|
AutojoinRoomsMixin.setupOnClient(client);
|
|
|
|
|
|
2019-02-26 01:21:08 +01:00
|
|
|
|
const myself = client.getUserId()
|
2018-12-03 02:12:20 +01:00
|
|
|
|
|
2019-02-26 01:21:08 +01:00
|
|
|
|
client.on("room.message", handle);
|
|
|
|
|
|
|
|
|
|
async function handle(roomId, event) {
|
2018-12-03 02:12:20 +01:00
|
|
|
|
if (!event["content"]) return;
|
2019-02-26 01:21:08 +01:00
|
|
|
|
|
|
|
|
|
console.log("Got message!");
|
|
|
|
|
|
|
|
|
|
if (event.unsigned.age > 1000 * 60) { console.log("Message was old!"); return; };
|
|
|
|
|
if (event.sender === await myself) { console.log("Wait a minute... That's me!"); return;};
|
|
|
|
|
|
|
|
|
|
if (event.content.body === "!xhelp") {help(roomId); return;};
|
|
|
|
|
if (event.content.body === "!xdebug") {debug(roomId); return;};
|
|
|
|
|
|
|
|
|
|
console.log("Trying to convert the message!");
|
2018-12-03 02:12:20 +01:00
|
|
|
|
|
|
|
|
|
var converted = x2i(event.content.body);
|
|
|
|
|
if (converted === "") return;
|
|
|
|
|
|
|
|
|
|
client.sendNotice(roomId, converted);
|
2019-02-26 01:21:08 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function help(roomId) {
|
|
|
|
|
var helpmessage = `Hi I can help you translate X-SAMPA, Z-SAMPA to IPA, and transcribe into proto-indo european notation!
|
|
|
|
|
Use (x/z/p) together with either / or [] as delimeters
|
|
|
|
|
x/hello/ z[or like this!] or p/waow/ 😀`;
|
|
|
|
|
|
|
|
|
|
client.sendNotice(roomId, helpmessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function debug(roomId) {
|
|
|
|
|
var helpmessage = `Hi my name is ${await myself}, and I want to help you debug me!`;
|
|
|
|
|
|
|
|
|
|
client.sendNotice(roomId, helpmessage);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-03 02:12:20 +01:00
|
|
|
|
|
|
|
|
|
client.start().then(() => console.log("Client started!"));
|