2.1.1 #16

Merged
Dandellion merged 5 commits from develop into master 2019-03-01 02:47:01 +01:00
10 changed files with 382 additions and 104 deletions
Showing only changes of commit 641669f243 - Show all commits

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

@ -1,4 +1,4 @@
const version = "1.1.3.1"; const version = "2.0.0";
import x2i from "./x2i"; import x2i from "./x2i";
import { existsSync } from "fs"; import { existsSync } from "fs";

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"
]
}

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:
- "[łŁ&]"
- "ᖦ"

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

@ -47,6 +47,9 @@ const matchType: { [key: string]: IMatchInstructions } = {
z: { z: {
keys: readKeys("./x2i/z2i-keys.yaml"), keys: readKeys("./x2i/z2i-keys.yaml"),
}, },
i: {
keys: readKeys("./x2i/i-keys.yaml"),
},
}; };
/** /**