2019-02-27 13:48:42 +01:00
|
|
|
|
const version = "1.1.3";
|
2018-12-03 02:12:20 +01:00
|
|
|
|
import x2i from "./x2i";
|
2019-02-27 01:21:39 +01:00
|
|
|
|
import { existsSync } from "fs";
|
2018-12-03 02:12:20 +01:00
|
|
|
|
|
2019-02-27 01:21:39 +01:00
|
|
|
|
const config = (existsSync("./config.json")) ? require("./config.json") : {};
|
|
|
|
|
|
|
|
|
|
console.log(process.env.MATRIXDEV_HOMESERVER);
|
|
|
|
|
console.log(process.env.MATRIXDEV_TOKEN);
|
2018-12-03 02:12:20 +01:00
|
|
|
|
|
|
|
|
|
const MatrixClient = require("matrix-bot-sdk").MatrixClient;
|
|
|
|
|
const AutojoinRoomsMixin = require("matrix-bot-sdk").AutojoinRoomsMixin;
|
|
|
|
|
|
2019-02-27 01:21:39 +01:00
|
|
|
|
const homeserver = (config.homeserver || process.env.WUG_HOMESERVER || process.env.MATRIXDEV_HOMESERVER);
|
|
|
|
|
const token = (config.token || process.env.WUG_TOKEN || process.env.MATRIXDEV_TOKEN);
|
2019-02-26 23:18:36 +01:00
|
|
|
|
|
|
|
|
|
const client = new MatrixClient(homeserver, token);
|
2018-12-03 02:12:20 +01:00
|
|
|
|
AutojoinRoomsMixin.setupOnClient(client);
|
|
|
|
|
|
2019-02-27 01:21:39 +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;};
|
|
|
|
|
|
2019-02-27 01:21:39 +01:00
|
|
|
|
if (event.content.body === "!xhelp" || event.content.body === (await client.getUserProfile(await myself)).displayname + ": help") {help(roomId); return;};
|
2019-02-26 01:21:08 +01:00
|
|
|
|
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) {
|
2019-02-27 01:21:39 +01:00
|
|
|
|
var message = `Hi I can help you translate X-SAMPA, Z-SAMPA to IPA, and transcribe into proto-indo european notation!
|
2019-02-26 01:21:08 +01:00
|
|
|
|
Use (x/z/p) together with either / or [] as delimeters
|
2019-02-27 01:21:39 +01:00
|
|
|
|
x/"hEloU/ z[or\` 5aIk DIz] p/mreghnom/ 😀
|
|
|
|
|
|
|
|
|
|
Find my source at https://github.com/Dali99/matrix-wug`;
|
2019-02-26 01:21:08 +01:00
|
|
|
|
|
2019-02-27 01:21:39 +01:00
|
|
|
|
client.sendNotice(roomId, message);
|
2019-02-26 01:21:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function debug(roomId) {
|
2019-02-27 01:21:39 +01:00
|
|
|
|
var message = `Hi my name is ${await myself}, and I want to help you debug me!
|
|
|
|
|
I run version ${version} 💝 and currently reside in ${roomId}`;
|
2019-02-26 01:21:08 +01:00
|
|
|
|
|
2019-02-27 01:21:39 +01:00
|
|
|
|
client.sendNotice(roomId, message);
|
2019-02-26 01:21:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-03 02:12:20 +01:00
|
|
|
|
|
|
|
|
|
client.start().then(() => console.log("Client started!"));
|