This commit is contained in:
Daniel Olsen 2018-12-03 01:12:20 +00:00
commit 74da9e46b5
10 changed files with 4502 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.json

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM node:10-slim
WORKDIR /server
COPY . /server
RUN npm install
CMD [ "npm", "start" ]

4
config.json.example Normal file
View File

@ -0,0 +1,4 @@
{
"homeserver": HOMESERVER,
"token": TOKEN
}

23
index.ts Normal file
View File

@ -0,0 +1,23 @@
import x2i from "./x2i";
const config = require("./config.json");
const MatrixClient = require("matrix-bot-sdk").MatrixClient;
const AutojoinRoomsMixin = require("matrix-bot-sdk").AutojoinRoomsMixin;
const client = new MatrixClient(config.homeserver, config.token);
AutojoinRoomsMixin.setupOnClient(client);
client.on("room.message", (roomId, event) => {
if (!event["content"]) return;
if (event.unsigned.age > 1000 * 60) return;
if (event.sender === "@wug:dodsorf.as") return;
var converted = x2i(event.content.body);
if (converted === "") return;
client.sendNotice(roomId, converted);
});
client.start().then(() => console.log("Client started!"));

2957
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

22
package.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "vugg",
"version": "1.0.0",
"description": "conniebot clone for matrix",
"main": "index.js",
"scripts": {
"start": "nodemon --exitcrash --ignore *.sqlite -x ts-node index.ts"
},
"author": "Daniel",
"license": "ISC",
"dependencies": {
"matrix-bot-sdk": "^0.1.16",
"@types/js-yaml": "^3.11.2",
"@types/node": "^10.12.11",
"@types/xregexp": "^3.0.29",
"js-yaml": "^3.12.0",
"ts-node": "^7.0.1",
"typescript": "^3.2.1",
"xregexp": "^4.2.0",
"nodemon": "^1.18.7"
}
}

93
x2i/apie-keys.yaml Normal file
View File

@ -0,0 +1,93 @@
---
- - '"a:'
- ā́
- - '"e:'
-
- - '"i:'
- ī́
- - '"l.'
- ĺ̥
- - '"m.'
- ḿ̥
- - '"n.'
- ń̥
- - '"o:'
-
- - '"r.'
- ŕ̥
- - '"u:'
- ū́
- - g'h
- ǵʰ
- - gvh
- gʷʰ
- - x1.
- h̥₁
- - x2.
- h̥₂
- - x3.
- h̥₃
- - x4.
- h̥₄
- - x5.
- h̥₅
- - x@.
- h̥ₐ
- - xx.
- h̥ₓ
- - '"a'
- á
- - '"e'
- é
- - '"i'
- í
- - '"o'
- ó
- - '"u'
- ú
- - 'a:'
- ā
- - bh
-
- - dh
-
- - 'e:'
- ē
- - g'
- ǵ
- - gh
-
- - gv
-
- - 'i:'
- ī
- - k'
-
- - kv
-
- - l.
-
- - m.
-
- - n.
-
- - 'o:'
- ō
- - r.
-
- - 'u:'
- ū
- - x1
- h₁
- - x2
- h₂
- - x3
- h₃
- - x4
- h₄
- - x5
- h₅
- - x@
- hₐ
- - xx
- hₓ

143
x2i/index.ts Normal file
View File

@ -0,0 +1,143 @@
import * as fs from "fs";
import * as yaml from "js-yaml";
import * as OuterXRegExp from "xregexp";
interface IRawReplaceKey {
raw: ReplaceKey;
}
interface INestedKey {
delimiters: [string, string];
translations: Replacer[];
}
type ReplaceKey = [string, string];
type Replacer = ReplaceKey | INestedKey | IRawReplaceKey;
type CompiledReplacer = [
RegExp,
string | ((m: { [key: string]: string }) => string),
string
];
interface IMatchInstructions {
keys: CompiledReplacer[];
join?(left: string, match: string, right: string): string;
}
const regex = OuterXRegExp(
`(?:(^|[\`\\p{White_Space}])) # must be preceded by whitespace or surrounded by code brackets
([A-Za-z]*) # key, to lower (2)
([/[]) # bracket left (3)
(\\S|\\S.*?\\S) # body (4)
([/\\]]) # bracket right (5)
(?=$|[\`\\p{White_Space}\\pP]) # must be followed by a white space or punctuation`,
"gmx");
const defaultMatchAction = (left: string, match: string, right: string) => left + match + right;
const matchType: { [key: string]: IMatchInstructions } = {
p: {
join: (_, match) => `*${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: string) {
return yaml
.safeLoad(fs.readFileSync(fpath, "utf8"))
.map(compileKey)
.filter(Boolean) as CompiledReplacer[];
}
/**
* Compiles a plain object into a regexp thing.
*
* @param entry Regex and replacement pair, or delimited match object.
*/
function compileKey(entry: Replacer): CompiledReplacer | undefined {
if (Array.isArray(entry)) {
const [key, val] = entry;
return [OuterXRegExp(OuterXRegExp.escape(key)), val, "all"];
}
// don't escape key
if ("raw" in entry) {
const [key, val] = entry.raw;
return [OuterXRegExp(key), val, "all"];
}
// is a dict
try {
const {
delimiters: [left, right],
translations,
} = entry;
return [
OuterXRegExp(`${OuterXRegExp.escape(left)}(?<inside>.*?)${OuterXRegExp.escape(right)}`),
m => OuterXRegExp.replaceEach(
m.inside,
translations.map(compileKey) as (RegExp | string)[][],
),
"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.
*/
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 action = join || defaultMatchAction;
// need to use `as (RegExp | string)[][]` because the provided typings are too generic
return action(left, OuterXRegExp.replaceEach(match, keys as (RegExp | string)[][]), right);
}
}
/**
* Grab all x2i strings in message string.
*
* @param content Full message that may or may not contain x2i strings
* @returns Converted representations
*/
export default function x2i(content: string) {
const results: string[] = [];
OuterXRegExp.forEach(content, regex, match => {
const parts = match.slice(2, 6);
if (parts.length === 4) {
const [k, l, m, r] = parts;
const converted = force(k, l, m, r); // eg x, [, text, ]
if (converted) {
results.push(converted);
}
}
});
return results.join(" ");
}

325
x2i/x2i-keys.yaml Normal file
View File

@ -0,0 +1,325 @@
---
- - d`z`
- ɖ͡ʐ
- - t`s`
- ʈ͡ʂ
- - '|\|\'
- ǁ
- - _B_L
- ˩˨
- - _H_T
- ˦˥
- - _R_F
- ˧˦˧
- - G\_<
- ʛ
- - J\_<
- ʄ
- - <F>
- \↘
- - <R>
- \↗
- - _?\
- ˤ
- - b_<
- ɓ
- - d_<
- ɗ
- - dK\
- d͡ɮ
- - dz\
- d͡ʑ
- - dz`
- d͡ʐ
- - g_<
- ɠ
- - r\`
- ɻ
- - ts\
- t͡ɕ
- - ts`
- t͡ʂ
- - tK
- t͡ɬ
- - ts
- t͡s
- - tS
- t͡ʃ
- - '!\'
- 'ǃ'
- - -\
-
- - 3\
- ɞ
- - :\
- ˑ
- - <\
- ʢ
- - =\
- ǂ
- - '>\'
- ʡ
- - '@\'
- ɘ
- - '@`'
- ɚ
- - )
- ͡
- - \?\
- ʕ
- - '|\'
- ǀ
- - '||'
-
- - '_"'
- ̈
- - _-
- ̠
- - _0
- ̥
- - _=
- ̩
- - _>
- ʼ
- - _+
- ̟
- - _/
- ̌
- - _\
- ̂
- - _^
- ̯
- - _A
- ̘
- - _a
- ̺
- - _B
- ˩
- - _c
- ̜
- - _d
- ̪
- - _e
- ̴
- - _F
- ˥˩
- - _G
- ˠ
- - _H
- ˦
- - _h
- ʰ
- - _j
- ʲ
- - _k
- ̰
- - _L
- ˨
- - _l
- ˡ
- - _M
- ˧
- - _m
- ̻
- - _N
- ̼
- - _n
-
- - _O
- ̹
- - _o
- ̞
- - _q
- ̙
- - _R
- ˩˥
- - _r
- ̝
- - _T
- ˥
- - _t
- ̤
- - _v
- ̬
- - _w
- ʷ
- - _X
- ̆
- - _x
- ̽
- - _}
- ̚
- - _~
- ̃
- - B\
- ʙ
- - d`
- ɖ
- - dz
- d͡z
- - dZ
- d͡ʒ
- - G\
- ɢ
- - gb
- g͡b
- - h\
- ɦ
- - H\
- ʜ
- - I\
-
- - j\
- ʝ
- - J\
- ɟ
- - K\
- ɮ
- - kp
- k͡p
- - l\
- ɺ
- - L\
- ʟ
- - l`
- ɭ
- - M\
- ɰ
- - N\
- ɴ
- - n`
- ɳ
- - Nm
- ŋ͡m
- - O\
- ʘ
- - p\
- ɸ
- - r\
- ɹ
- - R\
- ʀ
- - r`
- ɽ
- - s\
- ɕ
- - s`
- ʂ
- - t`
- ʈ
- - U\
- ᵿ
- - v\
- ʋ
- - x\
- ɧ
- - X\
- ħ
- - z\
- ʑ
- - z`
- ʐ
- - '!'
-
- - '"'
- ˈ
- - '%'
- ˌ
- - '&'
- ɶ
- - "'"
- ʲ
- - '-'
- ''
- - '1'
- ɨ
- - '2'
- ø
- - '3'
- ɜ
- - '4'
- ɾ
- - '5'
- ɫ
- - '6'
- ɐ
- - '7'
- ɤ
- - '8'
- ɵ
- - '9'
- œ
- - ':'
- ː
- - '='
- ̩
- - '@'
- ə
- - '.'
- '.'
- - '?'
- ʔ
- - \^
-
- - '`'
- ˞
- - A
- ɑ
- - B
- β
- - C
- ç
- - D
- ð
- - E
- ɛ
- - F
- ɱ
- - g
- ɡ
- - G
- ɣ
- - H
- ɥ
- - I
- ɪ
- - J
- ɲ
- - K
- ɬ
- - L
- ʎ
- - M
- ɯ
- - 'N'
- ŋ
- - O
- ɔ
- - P
- ʋ
- - Q
- ɒ
- - R
- ʁ
- - S
- ʃ
- - T
- θ
- - U
- ʊ
- - V
- ʌ
- - W
- ʍ
- - X
- χ
- - 'Y'
- ʏ
- - Z
- ʒ
- - '{'
- æ
- - '}'
- ʉ
- - '~'
- ̃

926
x2i/z2i-keys.yaml Normal file
View File

@ -0,0 +1,926 @@
---
- - O\
- ʘ
- - p_!
- ʘ
- - b_!
- ᶢʘ
- - m_!
- ᵑʘ
- - m_0_!
- ᵑ̊ʘ
- - =\
- ǀ
- - t_!
- ǀ
- - d_!
- ᶢǀ
- - n_!
- ᵑǀ
- - n_0_!
- ᵑ̊ǀ
- - '|\|\'
- ǁ
- - t_l_!
- ǁ
- - d_l_!
- ᶢǁ
- - n_l_!
- ᵑǁ
- - n_0_l_!
- ᵑ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- _K
- ̰
- - _l\
- ͔
- - _l
- ˡ
- - _L
- ̀
- - _m
- ̻
- - _M
- ̄
- raw:
- (.)_n\\
- ⁿ$1
- - _n
-
- - _N\
- ̼̻
- - _N
- ̼
- - _o
- ̞
- - _O
- ̹
- - _P\
-
- - _P
- ̪
- - _q
- ̙
- - _r\
- ͕
- - _r
- ̝
- - _R
- ̌
- - _T
- ̋
- - _t\
- ̪͆
- - _t
- ̤
- raw:
- (.)_v\\
- ₍$1̬₎
- raw:
- (.)_\(v
- ₍$1̬
- - _v)
- ̬₎
- - _v
- ̬
- - _V\
- "˯"
- raw:
- (.)_V
- ˬ$1
- raw:
- (.)_w\\
- ʷ$1
- - _w
- ʷ
- - _W\
-
- - _W
-
- - _x
- ̽
- - _X
- ̆
- - _y
- ͉
- - _Y
- ͈
- raw:
- (.)_0\\
- ₍$1̥₎
- raw:
- (.)_\(0
- ₍$1̥
- - _0)
- ̥₎
- - _0
- ̥
- - _7
- ǁ
- - _8
- ̣
- - _9
- ͚
- - _!
- "!"
- - _"
- ̈
- - _%\
- ʢ
- - _+
- ̟
- - _-
- ̠
- - _/
- ̌
- - _;
-
- - _=\
- "˭"
- - _=
- ̩
- - "="
- ̩
- - _>
- ʼ
- - _?\
- ˁ
- - _?
- ˀ
- - _\\
- -\\
- - _\
- ̂
- - _^
- ̯
- - _}
- ̚
- - _~\
- ͊
- - _`
- ̢
- - _~
- ̃
- - "~"
- ̃
- - "'"
- ʲ
- - _(
- "₍"
- - _)
- "₎"
- - _1
- "¹"
- - _2
- "²"
- - _3
- "³"
- - _4
- "⁴"
- - _5
- "⁵"
- - _6
- "⁶"
- - +a
-
- -
-
- - '+6'
-
- - +A
-
- - +{
-
- -
-
- -
-
- -
-
- - +Q
-
- - +b
-
- - +B
-
- - +c
-
- - +s\
-
- - +D
-
- - +d
-
- - +e
-
- - +@
-
- - +E
-
- -
-
- - '+3'
-
- - +f
-
- - +J\
-
- - +g
-
- - +G
- ˠ
- - +h\
- ʱ
- - +h
- ʰ
- - +H
-
- - +i\
-
- - +i
-
- -
-
- - '+1'
-
- - +I\
-
- - +I
-
- -
-
- - +j\
-
- - +j
- ʲ
- - +k
-
- - +l`
-
- - +l
- ˡ
- - +L\
-
- - +m
-
- - +F
-
- - +M\
-
- - +n`
-
- - +n
-
- - +J
-
- - +N\
-
- - +N
-
- - +o
-
- - +O
-
- -
-
- - '+8'
-
- - +p\
-
- - +p"
-
- - +p
-
- - +r\`
- ʵ
- - +r\
- ʴ
- - +r
- ʳ
- - +R
- ʶ
- - +s`
-
- - +s
- ˢ
- - +S
-
- - +t
-
- - +T
- ᶿ
- - +u\
-
- - +u
-
- -
-
- - +M
-
- - +}
-
- -
-
- - +U
-
- -
-
- raw:
- \+[Pv]\\
-
- - +V
-
- - +v
-
- - +w
- ʷ
- - +x
- ˣ
- - +X
-
- -
- ʸ
- - +y
- ʸ
- - +z`
-
- - +z\
-
- - +z
-
- - +Z
-
- - ++
- "⁺"
- - +-
- "⁻"
- - +=
- "⁼"
- - +(
- "⁽"
- - +)
- "⁾"
- - '+:'
- "˸"
- - '+0'
- ̊
- - +?\
- ˤ
- - +?
- ˀ
- - a
- a
- - ä
- æ
- - a\
- ä
- - â
- ɐ
- - å
- ɶ
- - A\
- ɐ̠
- - A
- ɑ
- - Â
- ä
- - Å
- ɒ
- - b\
-
- - b
- b
- - B\
- ʙ
- - B
- β
- - c\`
- ɽ͡r
- - c\
-
- - c
- c
- - C\
- ""
- - C
- ç
- - d`
- ɖ
- - d\`
- ᴅ̢
- - d\
-
- - d
- d
- - D`
- ɻ̝
- - D\
- ʓ
- - D
- ð
- - e\
- ʢ̞
- - e
- e
- - ë
- ɤ
- - ê
- ɘ
- - E\
-
- - E
- ɛ
- - Ë
- ʌ
- - Ê
- ɜ
- - f\
- ʩ
- - F\
- "Ɬ"
- - f
- f
- - F
- ɱ
- - g
- ɡ
- - g\
- "¡̆"
- - G\
- ɢ
- - G
- ɣ
- - h\
- ɦ
- - h
- h
- - H\
- ʜ
- - H
- ɥ
- - i\
- ɨ
- - ï
- ɯ
- - î
- ɨ
- - i
- i
- - I\
-
- - Ï
- ɯ̽
- - Î
-
- - I
- ɪ
- - j\
- ʝ
- - J\
- ɟ
- - j
- j
- - J
- ɲ
- - k
- k
- - K`
-
- - K\`
- ɭ̝
- - K\
- ɮ
- - K
- ɬ
- - l`
- ɭ
- - l\`
- ɺ̢
- - l\
- ɺ
- - L\
- ʟ
- - l
- l
- - L
- ʎ
- - m\
- ɯ̽
- - M\
- ɰ
- - m
- m
- - M
- ɯ
- - n`
- ɳ
- - ñ
- ɲ
- - 'n'
- 'n'
- - N\
- ɴ
- - 'N'
- ŋ
- - o\
-
- - o
- o
- - ö
- ø
- - ô
- ɵ
- - O
- ɔ
- - Ö
- œ
- - Ô
- ɞ
- - p\
- ɸ
- - p
- p
- - P\
- β̞
- - P
- ʋ
- - q\
- "Ɬ̠"
- - Q\
- "Ɬ̠̬"
- - q
- q
- - Q
- ɒ
- - r\`
- ɻ
- - r\
- ɹ
- - r`
- ɽ
- - r
- r
- - R\
- ʀ
- - R
- ʁ
- - s`
- ʂ
- - s\
- ɕ
- - s
- s
- - S\
- ʪ
- - S
- ʃ
- - t`
- ʈ
- - t\
- ʭ
- - t
- t
- - T`
- ɻ̝̊
- - T\
- ʆ
- - T
- θ
- - u\
- ʉ
- - u
- u
- - û
- ʉ
- - ü
- 'y'
- - U\
- ᵿ
- - U
- ʊ
- - Û
- ᵿ
- - Ü
- ʏ
- - v\
- ʋ
- - v
- v
- - V\
- ʟ̝
- - V
- ʌ
- - W\
- ⱱ̟
- - W
- ʍ
- - w\
- ʬ
- - w
- w
- - x\
- ɧ
- - x
- x
- - X\
- ħ
- - X
- χ
- - y\
- ʁ̞
- - 'y'
- 'y'
- - Y\
- ʟ̠
- - 'Y'
- ʏ
- - z`
- ʐ
- - z\
- ʑ
- - z
- z
- - Z\
- ʫ
- - Z
- ʒ
- - ^\
-
- - '.'
- '.'
- - '"'
- ˈ
- - ','
- ˌ
- - '%\'
- я
- - '%'
- ˌ
- - '@`'
- ɚ
- - '@\'
- ɘ
- - '@'
- ə
- - '{'
- æ
- - '}'
- ʉ
- - _<\
- "↓"
- - _>\
- "↑"
- - _<
- ʼ↓
- - <\
- ʢ
- - '>\'
- ʡ
- delimiters: ['<', '>']
translations:
- - '1'
- ˩
- - '2'
- ˨
- - '3'
- ˧
- - '4'
- ˦
- - '5'
- ˥
- - '1'
- ɨ
- - 2\
- ø̽
- - '2'
- ø
- - 3\
- ɞ
- - 3`
- ɝ
- - '3'
- ɜ
- - 4\
- ɢ̆
- - '4'
- ɾ
- - 5\
- "ꬸ"
- - '5'
- ɫ
- - 6\
- ʎ̝
- - '6'
- ɐ
- - 7\
- ɤ̽
- - '7'
- ɤ
- - 8\
- ɥ̝̊
- - '8'
- ɵ
- - 9\
- ʡ̮
- - '9'
- œ
- - '0'
- Ø
- - ":"
- ː
- - :\
- ˑ
- - '?\'
- ʕ
- - '?'
- ʔ
- - \^
- ğ
- - ^
-
- - "!"
-
- - '&\'
- ɶ̈
- - '&'
- ɶ
- - '#\`'
- ɖ̆
- - '#\'
-
- - '*\'
- \*
- - $\
- ʀ̟
- - $
- ͢
- - )
- ͡
- - (
- ͜
- - -\\
- \\
- - -\
-
- - '-'
- ''
- - '||'
-
- - '|'
- '|'
- - '`'
- ˞
- - ;
- ¡