diff --git a/.gitignore b/.gitignore index 95b863a..45930ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config.json node_modules +build \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..0c47dd2 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,6 @@ +image: node:10-slim + +build: + script: + - npm install + - npm build diff --git a/Dockerfile b/Dockerfile index aee081a..1bd4c2d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,5 +4,6 @@ WORKDIR /server COPY . /server RUN npm install +RUN mkdir build && npm run build CMD [ "npm", "start" ] diff --git a/index.ts b/index.ts index 5408922..04a08f2 100644 --- a/index.ts +++ b/index.ts @@ -1,4 +1,4 @@ -const version = "1.1.3.1"; +const version = "2.0.0"; import x2i from "./x2i"; import { existsSync } from "fs"; diff --git a/package.json b/package.json index 45d8334..db087bc 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "Language bot for matrix", "main": "index.js", "scripts": { - "start": "nodemon --exitcrash --ignore *.sqlite -x ts-node index.ts" + "build": "tsc", + "start": "node build/index.js" }, "author": "Daniel", "license": "ISC", diff --git a/shell.nix b/shell.nix index d8ae26e..127c52e 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,7 @@ with import {}; stdenv.mkDerivation { name = "node"; - buildInputs = [ nodejs ]; + buildInputs = [ nodejs-10_x ]; shellHook = '' export PATH="$PWD/node_modules/.bin/:$PATH" ''; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..2463c80 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "outDir": "build" + }, + "files": [ + "index.ts" + ] +} \ No newline at end of file diff --git a/x2i/i-keys.yaml b/x2i/i-keys.yaml new file mode 100644 index 0000000..19bc2e5 --- /dev/null +++ b/x2i/i-keys.yaml @@ -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: + - "[łŁ&]" + - "ᖦ" \ No newline at end of file diff --git a/x2i/index.js b/x2i/index.js deleted file mode 100644 index f22c733..0000000 --- a/x2i/index.js +++ /dev/null @@ -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) + "(?.*?)" + 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; diff --git a/x2i/index.ts b/x2i/index.ts index 73717fd..580e9ee 100644 --- a/x2i/index.ts +++ b/x2i/index.ts @@ -47,6 +47,9 @@ const matchType: { [key: string]: IMatchInstructions } = { z: { keys: readKeys("./x2i/z2i-keys.yaml"), }, + i: { + keys: readKeys("./x2i/i-keys.yaml"), + }, }; /**