2020-07-18 18:11:21 +02:00
|
|
|
|
const version = "2.4.1";
|
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") : {};
|
|
|
|
|
|
2018-12-03 02:12:20 +01:00
|
|
|
|
const MatrixClient = require("matrix-bot-sdk").MatrixClient;
|
|
|
|
|
const AutojoinRoomsMixin = require("matrix-bot-sdk").AutojoinRoomsMixin;
|
|
|
|
|
|
2019-03-01 01:31:30 +01:00
|
|
|
|
const homeserver = (config.homeserver || process.env.WUG_HOMESERVER || process.env.MATRIXDEV_HOMESERVER);
|
2019-02-27 01:21:39 +01:00
|
|
|
|
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;};
|
2020-07-16 18:53:50 +02:00
|
|
|
|
if (event.content.msgtype === "m.notice") { return; };
|
2019-02-26 01:21:08 +01:00
|
|
|
|
|
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-03-01 02:45:09 +01:00
|
|
|
|
if (event.content.body === "!xik") {xik(roomId); return;};
|
2019-03-01 02:52:59 +01:00
|
|
|
|
if (event.content.body === "!xpie") {xpie(roomId); return;};
|
2019-03-07 01:49:55 +01:00
|
|
|
|
if (event.content.body === "!xchr") {xchr(roomId); return;};
|
2019-03-15 01:16:51 +01:00
|
|
|
|
if (event.content.body === "!xnav") {xnav(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-03-07 01:49:55 +01:00
|
|
|
|
var message = `Hi I am a general language bot!
|
|
|
|
|
To use me, type a key together with either / or [] as delimeters
|
2019-02-27 01:21:39 +01:00
|
|
|
|
|
2019-03-01 02:45:09 +01:00
|
|
|
|
x - X-SAMPA - https://en.wikipedia.org/wiki/X-SAMPA
|
2020-07-16 18:34:21 +02:00
|
|
|
|
z - Z-SAMPA - https://web.archive.org/web/20191116002807/http://kneequickie.com/kq/Z-SAMPA
|
|
|
|
|
p - Proto-Indo-European Notation - https://gist.github.com/xsduan/8ebd580be71214c57aa554ec9050916c
|
2019-03-07 01:49:55 +01:00
|
|
|
|
i - Inuktitut Syllabics - https://en.wikipedia.org/wiki/Inuktitut_syllabics
|
|
|
|
|
ik - Iñupiatun Orthographies (see !xik)
|
|
|
|
|
chr - Cherokee (see !xchr) - https://en.wikipedia.org/wiki/Cherokee_syllabary
|
2019-03-15 01:16:51 +01:00
|
|
|
|
nav - Navajo (see !xnav)
|
2020-07-18 18:07:38 +02:00
|
|
|
|
hi - Hiragana, mainly https://en.wikipedia.org/wiki/Nihon-shiki_romanization and hepburn, but also with other unofficial styles
|
2019-02-28 14:09:26 +01:00
|
|
|
|
|
2019-03-07 01:49:55 +01:00
|
|
|
|
Find my source at https://github.com/Dali99/matrix-wug
|
|
|
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
x/"hEloU/ - /ˈhɛloʊ/
|
|
|
|
|
z[or\` 5aIk DIz] - [oɽ ɫaɪk ðɪz]
|
|
|
|
|
`;
|
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
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 02:45:09 +01:00
|
|
|
|
function xpie(roomId) {
|
|
|
|
|
var message = `This is a fun PIE notation
|
|
|
|
|
|
|
|
|
|
a preceding " is acute accent
|
|
|
|
|
a following : is the macron
|
|
|
|
|
a following . is the syllabicity marker
|
|
|
|
|
h always becomes superscript and v is superscript w.
|
|
|
|
|
Palato-velars are marked with a following ' and x1, x2, x3 etc. yields the laryngeals, with x@ for the subscript a laryngeal, and xx for an unknown laryngeal.
|
|
|
|
|
|
2020-07-16 18:34:21 +02:00
|
|
|
|
There's probably more, but this is best learned by experimenting (or reading https://gist.github.com/xsduan/8ebd580be71214c57aa554ec9050916c)
|
2019-03-01 02:45:09 +01:00
|
|
|
|
|
|
|
|
|
Thanks to conniebot (xsduan) for the encoding`;
|
|
|
|
|
|
|
|
|
|
client.sendNotice(roomId, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function xik(roomId) {
|
|
|
|
|
var message = `There are several distinct Iñupiatun orthographies, and I can type all of them.
|
|
|
|
|
& for miniscule ł
|
|
|
|
|
l% and n% for ł and ñ each
|
|
|
|
|
g^, l^, &^ (or l%^ and l^%) n^, and r^ for ġ ḷ ł̣ ŋ ȓ each
|
|
|
|
|
|
|
|
|
|
Thanks to Tuugaalikkuluk for the encoding`;
|
|
|
|
|
|
|
|
|
|
client.sendNotice(roomId, message);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-07 01:49:55 +01:00
|
|
|
|
function xchr(roomId) {
|
|
|
|
|
var message = `I'm sadly not smart enough to know which syllable to use in certain situations.
|
|
|
|
|
That means you have to help me out a little.
|
2019-03-14 23:32:30 +01:00
|
|
|
|
Write the wanted syllables down, but separate them by a dot (.) or an apostrophe (')
|
2019-03-07 01:49:55 +01:00
|
|
|
|
|
|
|
|
|
Thanks to Tuugaalikkuluk for the encoding
|
|
|
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
chr/tsa.la.gi ga.wo.ni.hi.s.di/ - ᏣᎳᎩ ᎦᏬᏂᎯᏍᏗ`;
|
|
|
|
|
|
|
|
|
|
client.sendNotice(roomId, message);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 01:16:51 +01:00
|
|
|
|
function xnav(roomId) {
|
|
|
|
|
var message = `My navajo encoding is as follows:
|
|
|
|
|
Caron after a vowel gives it an acute accent: o^ → ó, A^ → Á
|
|
|
|
|
At sign after a vowel gives it an ogonek: a@ → ą, E@ → Ę
|
|
|
|
|
Percentage sign after a vowel gives it both an ogonek and an acute accent: a% → ą́, I% → Į́ and after an l, it makes ł: l% → ł
|
|
|
|
|
You can also "stack the symbols" for an ogonek and an accute accent: (a^@, a@^) → ą́
|
|
|
|
|
Single quotation mark is converted to the glottal stop/ejective mark (’)
|
|
|
|
|
For a plain quotation mark, you can type '^
|
|
|
|
|
|
|
|
|
|
Thanks to Tuugaalikkuluk for the encoding`;
|
|
|
|
|
|
|
|
|
|
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!"));
|