Add ability to run arbitrary script on matched text, add cherokee, update help messages and version
This commit is contained in:
parent
46a288c041
commit
3770b228e7
33
index.ts
33
index.ts
|
@ -1,4 +1,4 @@
|
|||
const version = "2.1.2";
|
||||
const version = "2.2.0";
|
||||
import x2i from "./x2i";
|
||||
import { existsSync } from "fs";
|
||||
|
||||
|
@ -28,6 +28,7 @@ async function handle(roomId, event) {
|
|||
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;};
|
||||
|
||||
console.log("Trying to convert the message!");
|
||||
|
@ -40,17 +41,22 @@ async function handle(roomId, event) {
|
|||
|
||||
|
||||
function help(roomId) {
|
||||
var message = `Hi I can help you translate X-SAMPA, Z-SAMPA to IPA!
|
||||
Use (x/z/p/i/ik) together with either / or [] as delimeters
|
||||
x/"hEloU/ z[or\` 5aIk DIz] p/mreghnom/ 😀
|
||||
var message = `Hi I am a general language bot!
|
||||
To use me, type a key together with either / or [] as delimeters
|
||||
|
||||
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 Orthography (see !xik)
|
||||
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`;
|
||||
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);
|
||||
}
|
||||
|
@ -82,6 +88,19 @@ 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);
|
||||
}
|
||||
|
||||
async function debug(roomId) {
|
||||
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}`;
|
||||
|
|
|
@ -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=[["Ꭶ","Ꭸ","Ꭹ","Ꭺ","Ꭻ","Ꭼ"],["Ꭷ","Ꭸ","Ꭹ","Ꭺ","Ꭻ","Ꭼ"],["Ꭽ","Ꭾ","Ꭿ","Ꮀ","Ꮁ","Ꮂ"],["Ꮃ","Ꮄ","Ꮅ","Ꮆ","Ꮇ","Ꮈ"],["Ꮉ","Ꮊ","Ꮋ","Ꮌ","Ꮍ","Ᏽ"],["Ꮎ","Ꮑ","Ꮒ","Ꮓ","Ꮔ","Ꮕ"],["Ꮖ","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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);
|
||||
}
|
17
x2i/index.ts
17
x2i/index.ts
|
@ -21,8 +21,9 @@ type CompiledReplacer = [
|
|||
];
|
||||
|
||||
interface IMatchInstructions {
|
||||
keys: CompiledReplacer[];
|
||||
keys?: CompiledReplacer[];
|
||||
join?(left: string, match: string, right: string): string;
|
||||
matchFunction?: Function;
|
||||
}
|
||||
|
||||
const regex = OuterXRegExp(
|
||||
|
@ -35,8 +36,15 @@ const regex = OuterXRegExp(
|
|||
"gmx");
|
||||
|
||||
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 } = {
|
||||
chr: {
|
||||
join: (_, match) => `- ${match}`,
|
||||
matchFunction: chr.convert,
|
||||
},
|
||||
ik: {
|
||||
join: (_, match) => `- ${match}`,
|
||||
keys: readKeys("./x2i/ik-keys.yaml"),
|
||||
|
@ -119,11 +127,12 @@ export function force(key: string, left: string, match: string, right: string) {
|
|||
const lowerKey = key.toLowerCase();
|
||||
if (!(lowerKey in matchType)) return;
|
||||
|
||||
const { keys, join } = matchType[lowerKey];
|
||||
if (keys) {
|
||||
const { keys, join, matchFunction } = matchType[lowerKey];
|
||||
if (keys || matchFunction) {
|
||||
const action = join || defaultMatchAction;
|
||||
const doFunction = matchFunction || defaultMatchFunction;
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue