28 Commits
1.1.2 ... 2.2

Author SHA1 Message Date
Daniel Løvbrøtte Olsen
b511388ae8 Merge branch 'develop' into 'master'
Add ability to run arbitrary script on matched text, add cherokee, update help messages and version

See merge request Dandellion/matrix-wug!11
2019-03-07 00:54:01 +00:00
Daniel Løvbrøtte Olsen
3770b228e7 Add ability to run arbitrary script on matched text, add cherokee, update help messages and version 2019-03-07 01:49:55 +01:00
Daniel Løvbrøtte Olsen
f82d415b3e Merge branch 'develop' into 'master'
Fix pie help command

See merge request Dandellion/matrix-wug!10
2019-03-01 01:54:10 +00:00
Daniel Løvbrøtte Olsen
46a288c041 Fix pie help command 2019-03-01 02:52:59 +01:00
Daniel Løvbrøtte Olsen
dc45ff0df3 Merge branch 'develop' into 'master'
2.1.1

See merge request Dandellion/matrix-wug!9
2019-03-01 01:47:00 +00:00
Daniel Løvbrøtte Olsen
bcb7b6339a Merge branch 'develop' of https://git.dodsorf.as/Dandellion/matrix-wug into develop 2019-03-01 02:45:28 +01:00
Daniel Løvbrøtte Olsen
388871958d Add Iñupiatun Orthography 2019-03-01 02:45:09 +01:00
Daniel Løvbrøtte Olsen
7c7f7bff0f Don't use // and [] in the output for i// 2019-03-01 01:31:30 +01:00
Daniel Løvbrøtte Olsen
05897831ed Merge branch 'master' into 'develop'
Master

See merge request Dandellion/matrix-wug!8
2019-02-28 13:25:25 +00:00
Daniel Løvbrøtte Olsen
2f999368a3 Update readme 2019-02-28 14:24:44 +01:00
Daniel Løvbrøtte Olsen
1d34c6118b Merge branch 'develop' into 'master'
2.0.1

See merge request Dandellion/matrix-wug!7
2019-02-28 13:12:14 +00:00
Daniel Løvbrøtte Olsen
daa52c41d0 Update readme 2019-02-28 14:11:38 +01:00
Daniel Løvbrøtte Olsen
c51c945660 Add help message for Inuktitut Syllabics 2019-02-28 14:09:26 +01:00
Daniel Løvbrøtte Olsen
641669f243 Merge branch 'develop' into 'master'
Release 2.0

See merge request Dandellion/matrix-wug!6
2019-02-28 13:01:13 +00:00
Daniel Løvbrøtte Olsen
eb61eb1617 Merge branch 'develop' of https://git.dodsorf.as/Dandellion/matrix-wug into develop 2019-02-28 13:57:47 +01:00
Daniel Løvbrøtte Olsen
7a7b9606cd version bump 2019-02-28 13:57:30 +01:00
Daniel Løvbrøtte Olsen
8ba54948b4 Reorder i keys 2019-02-28 13:56:17 +01:00
Daniel Løvbrøtte Olsen
771b8dba3d Add Inuktitut Syllabics 2019-02-28 13:08:25 +01:00
Daniel Løvbrøtte Olsen
13d76e06f3 Update .gitlab-ci.yml 2019-02-27 13:51:28 +00:00
Daniel Løvbrøtte Olsen
66ef8c5c40 Update .gitlab-ci.yml 2019-02-27 13:51:11 +00:00
Daniel Løvbrøtte Olsen
8e36cc67bb Add .gitlab-ci.yml 2019-02-27 13:49:49 +00:00
Daniel Løvbrøtte Olsen
46019faa9d fix dockerfile 2019-02-27 14:44:13 +01:00
Daniel Løvbrøtte Olsen
f4a1354eaa Update nix-shell to node-10 2019-02-27 14:42:43 +01:00
Daniel Løvbrøtte Olsen
e54be5da02 Simplify compiling and running 2019-02-27 14:36:13 +01:00
Daniel Løvbrøtte Olsen
7063a47da0 Merge branch 'develop' into 'master'
Develop

See merge request Dandellion/matrix-wug!5
2019-02-27 12:55:37 +00:00
Daniel Løvbrøtte Olsen
1cb6d03765 version bump 2019-02-27 13:54:49 +01:00
Daniel Løvbrøtte Olsen
db06cde48a change order 2019-02-27 13:51:16 +01:00
Daniel Løvbrøtte Olsen
c6b03d35c0 colons are supposed to be there 2019-02-27 13:49:00 +01:00
14 changed files with 650 additions and 126 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
config.json config.json
node_modules node_modules
build

6
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,6 @@
image: node:10-slim
build:
script:
- npm install
- npm build

View File

@@ -4,5 +4,6 @@ WORKDIR /server
COPY . /server COPY . /server
RUN npm install RUN npm install
RUN mkdir build && npm run build
CMD [ "npm", "start" ] CMD [ "npm", "start" ]

View File

@@ -21,7 +21,15 @@ For the PIE notation:
This is best learned by experimenting. This is best learned by experimenting.
These conversions were originally taken from [xsduan/conniebot](https://github.com/xsduan/conniebot). But have later divirged a bit. Inuktitut Syllabics: https://en.wikipedia.org/wiki/Inuktitut_syllabics
Iñupiatun Orthography:
* & for miniscule ł
* l% and n% for ł and ñ each
* g^, l^, &^ (or l%^ and l^%) n^, and r^ for ġ ḷ ł̣ ŋ ȓ each
These conversions were originally taken from [xsduan/conniebot](https://github.com/xsduan/conniebot), and the discord bot Tuugaalikkuluk (thanks!) But have later divirged a bit.
To use the bot I run an instance at [@wug:dodsorf.as](https://matrix.to/#/@wug:dodsorf.as), you can invite it to a room or DM it to use the converter. Or you can read the setup instructions below to host your own! To use the bot I run an instance at [@wug:dodsorf.as](https://matrix.to/#/@wug:dodsorf.as), you can invite it to a room or DM it to use the converter. Or you can read the setup instructions below to host your own!

View File

@@ -1,12 +1,9 @@
const version = "1.1.2"; const version = "2.2.0";
import x2i from "./x2i"; import x2i from "./x2i";
import { existsSync } from "fs"; import { existsSync } from "fs";
const config = (existsSync("./config.json")) ? require("./config.json") : {}; const config = (existsSync("./config.json")) ? require("./config.json") : {};
console.log(process.env.MATRIXDEV_HOMESERVER);
console.log(process.env.MATRIXDEV_TOKEN);
const MatrixClient = require("matrix-bot-sdk").MatrixClient; const MatrixClient = require("matrix-bot-sdk").MatrixClient;
const AutojoinRoomsMixin = require("matrix-bot-sdk").AutojoinRoomsMixin; const AutojoinRoomsMixin = require("matrix-bot-sdk").AutojoinRoomsMixin;
@@ -29,6 +26,9 @@ async function handle(roomId, event) {
if (event.sender === await myself) { console.log("Wait a minute... That's me!"); return;}; if (event.sender === await myself) { console.log("Wait a minute... That's me!"); return;};
if (event.content.body === "!xhelp" || event.content.body === (await client.getUserProfile(await myself)).displayname + ": help") {help(roomId); return;}; if (event.content.body === "!xhelp" || event.content.body === (await client.getUserProfile(await myself)).displayname + ": help") {help(roomId); return;};
if (event.content.body === "!xik") {xik(roomId); return;};
if (event.content.body === "!xpie") {xpie(roomId); return;};
if (event.content.body === "!xchr") {xchr(roomId); return;};
if (event.content.body === "!xdebug") {debug(roomId); return;}; if (event.content.body === "!xdebug") {debug(roomId); return;};
console.log("Trying to convert the message!"); console.log("Trying to convert the message!");
@@ -41,11 +41,62 @@ async function handle(roomId, event) {
function help(roomId) { function help(roomId) {
var message = `Hi I can help you translate X-SAMPA, Z-SAMPA to IPA, and transcribe into proto-indo european notation! var message = `Hi I am a general language bot!
Use (x/z/p) together with either / or [] as delimeters To use me, type a key together with either / or [] as delimeters
x/"hEloU/ z[or\` 5aIk DIz] p/mreghnom/ 😀
Find my source at https://github.com/Dali99/matrix-wug`; x - X-SAMPA - https://en.wikipedia.org/wiki/X-SAMPA
z - Z-SAMPA - http://www.kneequickie.com/kq/Z-SAMPA
p - Proto-Indo-European Notation (see !xpie)
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
Find my source at https://github.com/Dali99/matrix-wug
EXAMPLES:
x/"hEloU/ - /ˈhɛloʊ/
z[or\` 5aIk DIz] - [oɽ ɫaɪk ðɪz]
`;
client.sendNotice(roomId, message);
}
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.
There's probably more, but this is best learned by experimenting (or reading https://github.com/dali99/matrix-wug/blob/master/x2i/apie-keys.yaml)
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);
}
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.
Write the wanted syllables down, but separate them by a dot (.)
Thanks to Tuugaalikkuluk for the encoding
EXAMPLES:
chr/tsa.la.gi ga.wo.ni.hi.s.di/ - ᏣᎳᎩ ᎦᏬᏂᎯᏍᏗ`;
client.sendNotice(roomId, message); client.sendNotice(roomId, message);
} }

View File

@@ -4,7 +4,8 @@
"description": "Language bot for matrix", "description": "Language bot for matrix",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "nodemon --exitcrash --ignore *.sqlite -x ts-node index.ts" "build": "tsc",
"start": "node build/index.js"
}, },
"author": "Daniel", "author": "Daniel",
"license": "ISC", "license": "ISC",

View File

@@ -1,7 +1,7 @@
with import <nixpkgs> {}; with import <nixpkgs> {};
stdenv.mkDerivation { stdenv.mkDerivation {
name = "node"; name = "node";
buildInputs = [ nodejs ]; buildInputs = [ nodejs-10_x ];
shellHook = '' shellHook = ''
export PATH="$PWD/node_modules/.bin/:$PATH" export PATH="$PWD/node_modules/.bin/:$PATH"
''; '';

8
tsconfig.json Normal file
View File

@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "build"
},
"files": [
"index.ts"
]
}

View File

@@ -1,4 +1,12 @@
--- ---
- - '"l.:'
- l̥̄́
- - '"m.:'
- m̥̥̄́
- - '"n.:'
- n̥̄́
- - '"r.:'
- r̥̄́
- - '"a:' - - '"a:'
- ā́ - ā́
- - '"e:' - - '"e:'
@@ -91,11 +99,3 @@
- hₐ - hₐ
- - xx - - xx
- hₓ - hₓ
- - '"l.':
- l̥̄́
- - '"m.':
- m̥̥̄́
- - '"n.':
- n̥̄́
- - '"r.':
- r̥̄́

134
x2i/chr.ts Normal file
View File

@@ -0,0 +1,134 @@
export function convert(input: string)
{
console.log("Converting to cherokee!!!");
var c=" ";
var i=0;
var j=0;
var k=0;
var flag=0;
var rom=input+" ";
const cons=["g","k","h","l","m","n","q","s","d","t","c","j","w","y","qu","qw","gw","kw","dl","tl","ts","ch","dz"];
const vowel=["a","e","i","o","u","v"];
const syl=[["Ꭶ","Ꭸ","","","",""],["Ꭷ","Ꭸ","","","",""],["Ꭽ","","Ꭿ","Ꮀ","Ꮁ","Ꮂ"],["","Ꮄ","Ꮅ","Ꮆ","","Ꮈ"],["Ꮉ","Ꮊ","","Ꮌ","","Ᏽ"],["Ꮎ","Ꮑ","","","Ꮔ","Ꮕ"],["Ꮖ","Ꮗ","Ꮘ","Ꮙ","Ꮚ","Ꮛ"],["Ꮜ","","","Ꮠ","Ꮡ",""],["Ꮣ","","Ꮧ","","","Ꮫ"],["","Ꮦ","Ꮨ","","","Ꮫ"],["Ꮳ","Ꮴ","Ꮵ","","","Ꮸ"],["Ꮳ","Ꮴ","Ꮵ","","","Ꮸ"],["Ꮹ","Ꮺ","Ꮻ","Ꮼ","Ꮽ",""],["Ꮿ","Ᏸ","Ᏹ","Ᏺ","",""],["Ꮖ","Ꮗ","Ꮘ","Ꮙ","Ꮚ","Ꮛ"],["Ꮖ","Ꮗ","Ꮘ","Ꮙ","Ꮚ","Ꮛ"],["Ꮖ","Ꮗ","Ꮘ","Ꮙ","Ꮚ","Ꮛ"],["Ꮖ","Ꮗ","Ꮘ","Ꮙ","Ꮚ","Ꮛ"],["Ꮬ","","","Ꮰ","Ꮱ",""],["Ꮭ","","","Ꮰ","Ꮱ",""],["Ꮳ","Ꮴ","Ꮵ","","","Ꮸ"],["Ꮳ","Ꮴ","Ꮵ","","","Ꮸ"],["Ꮳ","Ꮴ","Ꮵ","","","Ꮸ"]];
while (rom.length>1) {
i=0;
while(isAlpha(rom[i])) {
i=i+1;
}
if (i==0) {
if (rom[0]=="#") break;
c=c+rom[0];
rom=rom.slice(1);
}
else if (i==1) {
if (rom[0].toLowerCase()=='a') {
c=c+'';
if(rom[1]=="."&& isAlpha(rom[2])) rom=rom.slice(2)
else rom=rom.slice(1);
}
else if (rom[0].toLowerCase()=='e') {
c=c+'';
if(rom[1]=="."&& isAlpha(rom[2])) rom=rom.slice(2);
else rom=rom.slice(1);
}
else if (rom[0].toLowerCase()=='i') {
c=c+'';
if(rom[1]=="."&& isAlpha(rom[2])) rom=rom.slice(2);
else rom=rom.slice(1);
}
else if (rom[0].toLowerCase()=='o') {
c=c+'Ꭳ';
if(rom[1]=="."&& isAlpha(rom[2])) rom=rom.slice(2);
else rom=rom.slice(1);
}
else if (rom[0].toLowerCase()=='u') {
c=c+'Ꭴ';
if(rom[1]=="."&& isAlpha(rom[2])) rom=rom.slice(2);
else rom=rom.slice(1);
}
else if (rom[0].toLowerCase()=='v') {
c=c+'';
if(rom[1]=="."&& isAlpha(rom[2])) rom=rom.slice(2);
else rom=rom.slice(1);
}
else if (rom[0].toLowerCase()=='s') {
c=c+'Ꮝ';
if(rom[1]=="."&& isAlpha(rom[2])) rom=rom.slice(2);
else rom=rom.slice(1);
}
else {
c=c+rom.slice(0,2);;
rom=rom.slice(2);;
};
}
else if (i==2) {
j=0;
k=0;
flag=0;
for (var j = 0; j < 14; j++) {
if (rom[0].toLowerCase()==cons[j]) {
for (var k = 0; k < 6; k++) {
if (rom[1].toLowerCase()==vowel[k]) {
flag=1;
break;
};
};
};
if(flag) break;
};
if(flag) {
c=c+syl[j][k];
if(rom[2]=="."&& isAlpha(rom[3])) rom=rom.slice(3);
else rom=rom.slice(2);
}
else {
c=c+rom.slice(0, 3);
rom=rom.slice(3);
};
}
else if (i==3) {
j=0;
k=0;
flag=0;
for (j = 14; j < 23; j++) {
if (rom.slice(0,2).toLowerCase()==cons[j]) {
for (k = 0; k < 6; k++) {
if (rom[2].toLowerCase()==vowel[k]) {
flag=1;
break;
};
};
};
if(flag) break;
};
if(flag) {
c=c+syl[j][k];
if(rom[3]=="." && isAlpha(rom[4])) rom=rom.slice(4);
else rom=rom.slice(3);
}
else if (rom.slice(0,3).toLowerCase()=="nah") {
c=c+"";
if(rom[3]=="." && isAlpha(rom[4])) rom=rom.slice(4);
else rom=rom.slice(3);
}
else if (rom.slice(0,3).toLowerCase()=="hna") {
c=c+"Ꮏ";
if(rom[3]=="." && isAlpha(rom[4])) rom=rom.slice(4);
else rom=rom.slice(3);
}
else {
c=c+rom.slice(0, 4);
rom=rom.slice(4);
};
}
else {
c=c+rom.slice(0,i+1);
rom=rom.slice(i+1);
};
};
return c;
}
function isAlpha(ch: string){
return /^[A-Z]$/i.test(ch);
}

359
x2i/i-keys.yaml Normal file
View File

@@ -0,0 +1,359 @@
---
- raw:
- "[nN][n][g][iI][iI]"
- "ᙲ"
- raw:
- "[nN][n][g][uU][uU]"
- "ᙴ"
- raw:
- "[nN][n][g][aA][aA]"
- "ᙶ"
- raw:
- "[nN][gG][iI][iI]"
- "ᖐ"
- raw:
- "[nN][gG][uU][uU]"
- "ᖒ"
- raw:
- "[nN][gG][aA][aA]"
- "ᖔ"
- raw:
- "[nN][n][g][iI]"
- "ᙱ"
- raw:
- "[nN][n][g][uU]"
- "ᙳ"
- raw:
- "[nN][n][g][aA]"
- "ᙵ"
- raw:
- "[qQ][qQ][iI][iI]"
- "ᖅᑮ"
- raw:
- "[qQ][qQ][uU][uU]"
- "ᖅᑰ"
- raw:
- "[qQ][qQ][aA][aA]"
- "ᖅᑳ"
- raw:
- "[nN][n][g]"
- "ᖖ"
- raw:
- "[pP][iI][iI]"
- "ᐲ"
- raw:
- "[pP][uU][uU]"
- "ᐴ"
- raw:
- "[pP][aA][aA]"
- "ᐹ"
- raw:
- "[tT][iI][iI]"
- "ᑏ"
- raw:
- "[tT][uU][uU]"
- "ᑑ"
- raw:
- "[tT][aA][aA]"
- "ᑖ"
- raw:
- "[kK][iI][iI]"
- "ᑮ"
- raw:
- "[kK][uU][uU]"
- "ᑰ"
- raw:
- "[kK][aA][aA]"
- "ᑳ"
- raw:
- "[gG][iI][iI]"
- "ᒌ"
- raw:
- "[gG][uU][uU]"
- "ᒎ"
- raw:
- "[gG][aA][aA]"
- "ᒑ"
- raw:
- "[mM][iI][iI]"
- "ᒦ"
- raw:
- "[mM][uU][uU]"
- "ᒨ"
- raw:
- "[mM][aA][aA]"
- "ᒫ"
- raw:
- "[nN][iI][iI]"
- "ᓃ"
- raw:
- "[nN][uU][uU]"
- "ᓅ"
- raw:
- "[nN][aA][aA]"
- "ᓈ"
- raw:
- "[nN][gG][iI]"
- "ᖏ"
- raw:
- "[nN][gG][uU]"
- "ᖑ"
- raw:
- "[nN][gG][aA]"
- "ᖓ"
- raw:
- "[sS][iI][iI]"
- "ᓰ"
- raw:
- "[sS][uU][uU]"
- "ᓲ"
- raw:
- "[sS][aA][aA]"
- "ᓵ"
- raw:
- "[lL][iI][iI]"
- "ᓖ"
- raw:
- "[lL][uU][uU]"
- "ᓘ"
- raw:
- "[lL][aA][aA]"
- "ᓛ"
- raw:
- "[jJyY][iI][iI]"
- "ᔩ"
- raw:
- "[jJyY][uU][uU]"
- "ᔫ"
- raw:
- "[jJyY][aA][aA]"
- "ᔮ"
- raw:
- "[vV][iI][iI]"
- "ᕖ"
- raw:
- "[vV][uU][uU]"
- "ᕘ"
- raw:
- "[vV][aA][aA]"
- "ᕚ"
- raw:
- "[rR][iI][iI]"
- "ᕇ"
- raw:
- "[rR][uU][uU]"
- "ᕉ"
- raw:
- "[rR][aA][aA]"
- "ᕌ"
- raw:
- "[qQ][iI][iI]"
- "ᖀ"
- raw:
- "[qQ][uU][uU]"
- "ᖂ"
- raw:
- "[qQ][aA][aA]"
- "ᖄ"
- raw:
- "[qQ][qQ][iI]"
- "ᖅᑭ"
- raw:
- "[qQ][qQ][uU]"
- "ᖅᑯ"
- raw:
- "[qQ][aA][aA]"
- "ᖅᑲ"
- raw:
- "[łŁ&][iI][iI]"
- "ᖡ"
- raw:
- "[łŁ&][uU][uU]"
- "ᖣ"
- raw:
- "[łŁ&][aA][aA]"
- "ᖥ"
- raw:
- "[iI][iI]"
- "ᐄ"
- raw:
- "[uU][uU]"
- "ᐆ"
- raw:
- "[aA][aA]"
- "ᐋ"
- raw:
- "[pP][iI]"
- "ᐱ"
- raw:
- "[pP][uU]"
- ""
- raw:
- "[pP][aA]"
- ""
- raw:
- "[tT][iI]"
- "ᑎ"
- raw:
- "[tT][uU]"
- "ᑐ"
- raw:
- "[tT][aA]"
- "ᑕ"
- raw:
- "[kK][iI]"
- ""
- raw:
- "[kK][uU]"
- ""
- raw:
- "[kK][aA]"
- ""
- raw:
- "[gG][iI]"
- "ᒋ"
- raw:
- "[gG][uU]"
- ""
- raw:
- "[gG][aA]"
- "ᒐ"
- raw:
- "[mM][iI]"
- "ᒥ"
- raw:
- "[mM][uU]"
- "ᒧ"
- raw:
- "[mM][aA]"
- ""
- raw:
- "[nN][iI]"
- "ᓂ"
- raw:
- "[nN][uU]"
- "ᓄ"
- raw:
- "[nN][aA]"
- "ᓇ"
- raw:
- "[nN][gG]"
- "ᖕ"
- raw:
- "[sS][iI]"
- "ᓯ"
- raw:
- "[sS][uU]"
- "ᓱ"
- raw:
- "[sS][aA]"
- "ᓴ"
- raw:
- "[lL][iI]"
- "ᓕ"
- raw:
- "[lL][uU]"
- "ᓗ"
- raw:
- "[lL][aA]"
- "ᓚ"
- raw:
- "[jJyY][iI]"
- "ᔨ"
- raw:
- "[jJyY][uU]"
- "ᔪ"
- raw:
- "[jJyY][aA]"
- "ᔭ"
- raw:
- "[vV][iI]"
- "ᕕ"
- raw:
- "[vV][uU]"
- "ᕗ"
- raw:
- "[vV][aA]"
- "ᕙ"
- raw:
- "[rR][iI]"
- "ᕆ"
- raw:
- "[rR][uU]"
- "ᕈ"
- raw:
- "[rR][aA]"
- "ᕋ"
- raw:
- "[qQ][iI]"
- "ᕿ"
- raw:
- "[qQ][uU]"
- "ᖁ"
- raw:
- "[qQ][aA]"
- "ᖃ"
- raw:
- "[łŁ&][iI]"
- "ᖠ"
- raw:
- "[łŁ&][uU]"
- "ᖢ"
- raw:
- "[łŁ&][aA]"
- "ᖤ"
- raw:
- "[iI]"
- "ᐃ"
- raw:
- "[uU]"
- "ᐅ"
- raw:
- "[aA]"
- "ᐊ"
- raw:
- "[pP]"
- "ᑉ"
- raw:
- "[pP]"
- "ᑉ"
- raw:
- "[tT]"
- "ᑦ"
- raw:
- "[kK]"
- "ᒃ"
- raw:
- "[gG]"
- "ᒡ"
- raw:
- "[mM]"
- "ᒻ"
- raw:
- "[nN]"
- "ᓐ"
- raw:
- "[sS]"
- "ᔅ"
- raw:
- "[lL]"
- "ᓪ"
- raw:
- "[jJyY]"
- "ᔾ"
- raw:
- "[vV]"
- "ᕝ"
- raw:
- "[rR]"
- "ᕐ"
- raw:
- "[qQ]"
- "ᖅ"
- raw:
- "[łŁ&]"
- "ᖦ"

39
x2i/ik-keys.yaml Normal file
View File

@@ -0,0 +1,39 @@
---
- - l^%
- ł̣
- - l%^
- ł̣
- - L^%
- Ł̣
- - L%^
- Ł̣
- - g^
- ġ
- - G^
- Ġ
- - l^
-
- - l%
- ł
- - L^
-
- - L%
- Ł
- - '&^'
- ł̣
- - N%
- Ñ
- - N^
- Ŋ
- - n%
- ñ
- - n^
- ŋ
- - r^
- ȓ
- - R^
- Ȓ
- - '&'
- ł

View File

@@ -1,101 +0,0 @@
"use strict";
exports.__esModule = true;
var fs = require("fs");
var yaml = require("js-yaml");
var OuterXRegExp = require("xregexp");
var regex = OuterXRegExp("(?:(^|[`\\p{White_Space}])) # must be preceded by whitespace or surrounded by code brackets\n ([A-Za-z]*) # key, to lower (2)\n ([/[]) # bracket left (3)\n (\\S|\\S.*?\\S) # body (4)\n ([/\\]]) # bracket right (5)\n (?=$|[`\\p{White_Space}\\pP]) # must be followed by a white space or punctuation", "gmx");
var defaultMatchAction = function (left, match, right) { return left + match + right; };
var matchType = {
p: {
join: function (_, match) { return "*" + match; },
keys: readKeys("./x2i/apie-keys.yaml")
},
x: {
keys: readKeys("./x2i/x2i-keys.yaml")
},
z: {
keys: readKeys("./x2i/z2i-keys.yaml")
}
};
/**
* Read translation keys from file. Escapes strings first.
*
* @param fpath File to key definitions. (yaml, utf8)
* @returns Compiled keys.
*/
function readKeys(fpath) {
return yaml
.safeLoad(fs.readFileSync(fpath, "utf8"))
.map(compileKey)
.filter(Boolean);
}
/**
* Compiles a plain object into a regexp thing.
*
* @param entry Regex and replacement pair, or delimited match object.
*/
function compileKey(entry) {
if (Array.isArray(entry)) {
var key = entry[0], val = entry[1];
return [OuterXRegExp(OuterXRegExp.escape(key)), val, "all"];
}
// don't escape key
if ("raw" in entry) {
var _a = entry.raw, key = _a[0], val = _a[1];
return [OuterXRegExp(key), val, "all"];
}
// is a dict
try {
var _b = entry.delimiters, left = _b[0], right = _b[1], translations_1 = entry.translations;
return [
OuterXRegExp(OuterXRegExp.escape(left) + "(?<inside>.*?)" + OuterXRegExp.escape(right)),
function (m) { return OuterXRegExp.replaceEach(m.inside, translations_1.map(compileKey)); },
"all"
];
}
catch (e) {
console.log(entry + " is not an array or a proper object, ignoring");
}
}
/**
* Convert four-tuple of Strings into a specified "official" representation
*
* @param key What kind of conversion key is appropriate
* @param left Left bracket
* @param match Body
* @param right Right bracket
* @returns Converted item, if any.
*/
function force(key, left, match, right) {
var lowerKey = key.toLowerCase();
if (!(lowerKey in matchType))
return;
var _a = matchType[lowerKey], keys = _a.keys, join = _a.join;
if (keys) {
var action = join || defaultMatchAction;
// need to use `as (RegExp | string)[][]` because the provided typings are too generic
return action(left, OuterXRegExp.replaceEach(match, keys), right);
}
}
exports.force = force;
/**
* Grab all x2i strings in message string.
*
* @param content Full message that may or may not contain x2i strings
* @returns Converted representations
*/
function x2i(content) {
var results = [];
OuterXRegExp.forEach(content, regex, function (match) {
var parts = match.slice(2, 6);
if (parts.length === 4) {
var k = parts[0], l = parts[1], m = parts[2], r = parts[3];
var converted = force(k, l, m, r); // eg x, [, text, ]
if (converted) {
results.push(converted);
}
}
});
return results.join(" ");
}
exports["default"] = x2i;

View File

@@ -21,8 +21,9 @@ type CompiledReplacer = [
]; ];
interface IMatchInstructions { interface IMatchInstructions {
keys: CompiledReplacer[]; keys?: CompiledReplacer[];
join?(left: string, match: string, right: string): string; join?(left: string, match: string, right: string): string;
matchFunction?: Function;
} }
const regex = OuterXRegExp( const regex = OuterXRegExp(
@@ -35,8 +36,19 @@ const regex = OuterXRegExp(
"gmx"); "gmx");
const defaultMatchAction = (left: string, match: string, right: string) => left + match + right; const defaultMatchAction = (left: string, match: string, right: string) => left + match + right;
const defaultMatchFunction = (match: string, keys: ([RegExp, string | ((m: {[key: string]: string;}) => string), string][])) => OuterXRegExp.replaceEach(match, keys as (RegExp | string)[][])
import * as chr from "./chr";
const matchType: { [key: string]: IMatchInstructions } = { const matchType: { [key: string]: IMatchInstructions } = {
chr: {
join: (_, match) => `- ${match}`,
matchFunction: chr.convert,
},
ik: {
join: (_, match) => `- ${match}`,
keys: readKeys("./x2i/ik-keys.yaml"),
},
p: { p: {
join: (_, match) => `*${match}`, join: (_, match) => `*${match}`,
keys: readKeys("./x2i/apie-keys.yaml"), keys: readKeys("./x2i/apie-keys.yaml"),
@@ -47,6 +59,10 @@ const matchType: { [key: string]: IMatchInstructions } = {
z: { z: {
keys: readKeys("./x2i/z2i-keys.yaml"), keys: readKeys("./x2i/z2i-keys.yaml"),
}, },
i: {
join: (_, match) => `- ${match}`,
keys: readKeys("./x2i/i-keys.yaml"),
},
}; };
/** /**
@@ -111,11 +127,12 @@ export function force(key: string, left: string, match: string, right: string) {
const lowerKey = key.toLowerCase(); const lowerKey = key.toLowerCase();
if (!(lowerKey in matchType)) return; if (!(lowerKey in matchType)) return;
const { keys, join } = matchType[lowerKey]; const { keys, join, matchFunction } = matchType[lowerKey];
if (keys) { if (keys || matchFunction) {
const action = join || defaultMatchAction; const action = join || defaultMatchAction;
const doFunction = matchFunction || defaultMatchFunction;
// need to use `as (RegExp | string)[][]` because the provided typings are too generic // need to use `as (RegExp | string)[][]` because the provided typings are too generic
return action(left, OuterXRegExp.replaceEach(match, keys as (RegExp | string)[][]), right); return action(left, doFunction(match, keys), right);
} }
} }