autojoin rooms with pp_admin, update packages, update MarkdownParser
This commit is contained in:
parent
e5e6d21257
commit
efeed17537
|
@ -51,9 +51,7 @@ pm2 log ppfun-bridge
|
||||||
## Room Creation
|
## Room Creation
|
||||||
|
|
||||||
The bridge automatically creates matrix rooms for all public pixelplanet channels available and makes the '@pp_admin:pixelplanet.fun' user admin.
|
The bridge automatically creates matrix rooms for all public pixelplanet channels available and makes the '@pp_admin:pixelplanet.fun' user admin.
|
||||||
You want to create this admin user first to be able to login as it.
|
Some things are hardcoded in `src/ppfunMatrixBridge.js`, check it out if there are problems.
|
||||||
Or change the room-creation code in `src/ppfunMatrixBridge.js` in the `connectRooms` method.
|
|
||||||
Some things are hardcoded there.
|
|
||||||
And the URL where to fetch chunks from pixelplanet is hardcoded in `src/pixelplanet/loadChunk.js`.
|
And the URL where to fetch chunks from pixelplanet is hardcoded in `src/pixelplanet/loadChunk.js`.
|
||||||
|
|
||||||
|
|
||||||
|
|
1196
ppfun-bridge/package-lock.json
generated
1196
ppfun-bridge/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -10,10 +10,10 @@
|
||||||
"author": "hf",
|
"author": "hf",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"canvas": "^2.8.0",
|
"canvas": "^2.9.3",
|
||||||
"matrix-appservice-bridge": "^3.2.0",
|
"matrix-appservice-bridge": "^4.0.2",
|
||||||
"node-fetch": "^3.1.0",
|
"node-fetch": "^3.2.8",
|
||||||
"ws": "^8.4.0"
|
"ws": "^8.8.1"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"bufferutil": "^4.0.6",
|
"bufferutil": "^4.0.6",
|
||||||
|
|
|
@ -3,7 +3,7 @@ hs_token: CHANGE_THIS_TO_SOME_LONG_RANDOM_STRING
|
||||||
as_token: CHANGE_THIS_TO_SOME_DIFFERENT_LONG_RANDOM_STRING
|
as_token: CHANGE_THIS_TO_SOME_DIFFERENT_LONG_RANDOM_STRING
|
||||||
# the url of the application service, its set to 8009 per default
|
# the url of the application service, its set to 8009 per default
|
||||||
url: http://localhost:8009
|
url: http://localhost:8009
|
||||||
# the pp prefix is hardcoded
|
# the pp prefix is hardcoded, don't change it
|
||||||
sender_localpart: pp
|
sender_localpart: pp
|
||||||
namespaces:
|
namespaces:
|
||||||
users:
|
users:
|
||||||
|
|
|
@ -39,6 +39,69 @@ export default class MString {
|
||||||
return (this.iter < this.txt.length);
|
return (this.iter < this.txt.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skipSpaces(skipNewlines = false) {
|
||||||
|
for (;this.iter < this.txt.length; this.iter += 1) {
|
||||||
|
const chr = this.txt[this.iter];
|
||||||
|
if (chr !== ' ' && chr !== '\t' && (!skipNewlines || chr !== '\n')) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
countRepeatingCharacters() {
|
||||||
|
const chr = this.getChar();
|
||||||
|
let newIter = this.iter + 1;
|
||||||
|
for (;newIter < this.txt.length && this.txt[newIter] === chr;
|
||||||
|
newIter += 1
|
||||||
|
);
|
||||||
|
return newIter - this.iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
moveToNextLine() {
|
||||||
|
const lineEnd = this.txt.indexOf('\n', this.iter);
|
||||||
|
if (lineEnd === -1) {
|
||||||
|
this.iter = this.txt.length;
|
||||||
|
} else {
|
||||||
|
this.iter = lineEnd + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getLine() {
|
||||||
|
const startLine = this.iter;
|
||||||
|
this.moveToNextLine();
|
||||||
|
return this.txt.slice(startLine, this.iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
getIndent(tabWidth) {
|
||||||
|
let indent = 0;
|
||||||
|
while (this.iter < this.txt.length) {
|
||||||
|
const chr = this.getChar();
|
||||||
|
if (chr === '\t') {
|
||||||
|
indent += tabWidth;
|
||||||
|
} else if (chr === ' ') {
|
||||||
|
indent += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.iter += 1;
|
||||||
|
}
|
||||||
|
return indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
goToCharInLine(chr) {
|
||||||
|
let { iter } = this;
|
||||||
|
for (;
|
||||||
|
iter < this.txt.length && this.txt[iter] !== '\n'
|
||||||
|
&& this.txt[iter] !== chr;
|
||||||
|
iter += 1
|
||||||
|
);
|
||||||
|
if (this.txt[iter] === chr) {
|
||||||
|
this.iter = iter;
|
||||||
|
return iter;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static isWhiteSpace(chr) {
|
static isWhiteSpace(chr) {
|
||||||
return (chr === ' ' || chr === '\t' || chr === '\n');
|
return (chr === ' ' || chr === '\t' || chr === '\n');
|
||||||
}
|
}
|
||||||
|
@ -49,15 +112,20 @@ export default class MString {
|
||||||
* moves iter to last closing braked if it is enclosure
|
* moves iter to last closing braked if it is enclosure
|
||||||
*/
|
*/
|
||||||
checkIfEnclosure(zIsLink) {
|
checkIfEnclosure(zIsLink) {
|
||||||
const yStart = this.iter + 1;
|
let yStart = this.iter + 1;
|
||||||
|
|
||||||
let yEnd = yStart;
|
let yEnd = yStart;
|
||||||
|
const escapePositions = [];
|
||||||
while (this.txt[yEnd] !== ']') {
|
while (this.txt[yEnd] !== ']') {
|
||||||
const chr = this.txt[yEnd];
|
const chr = this.txt[yEnd];
|
||||||
|
if (chr === '\\') {
|
||||||
|
// escape character
|
||||||
|
escapePositions.push(yEnd);
|
||||||
|
yEnd += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (yEnd >= this.txt.length
|
if (yEnd >= this.txt.length
|
||||||
|| chr === '\n'
|
|| chr === '\n'
|
||||||
|| chr === '['
|
|
||||||
|| chr === '('
|
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +170,17 @@ export default class MString {
|
||||||
if (!zIsLink) {
|
if (!zIsLink) {
|
||||||
z = this.txt.slice(zStart, zEnd);
|
z = this.txt.slice(zStart, zEnd);
|
||||||
}
|
}
|
||||||
const y = this.txt.slice(yStart, yEnd);
|
|
||||||
|
let y = '';
|
||||||
|
// remove escape characters
|
||||||
|
for (let iter = 0; iter < escapePositions.length; iter += 1) {
|
||||||
|
const escapePosition = escapePositions[iter];
|
||||||
|
y += this.txt.slice(yStart, escapePosition);
|
||||||
|
yStart = escapePosition + 1;
|
||||||
|
}
|
||||||
|
if (yStart < yEnd) {
|
||||||
|
y += this.txt.slice(yStart, yEnd);
|
||||||
|
}
|
||||||
|
|
||||||
this.iter = zEnd;
|
this.iter = zEnd;
|
||||||
return [y, z];
|
return [y, z];
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
import MString from './MString.js';
|
import MString from './MString.js';
|
||||||
|
|
||||||
|
const paraElems = ['*', '~', '+', '_'];
|
||||||
function parseMParagraph(text) {
|
function parseMParagraph(text) {
|
||||||
const pArray = [];
|
const pArray = [];
|
||||||
let pStart = text.iter;
|
let pStart = text.iter;
|
||||||
|
@ -40,6 +41,14 @@ function parseMParagraph(text) {
|
||||||
pArray.push(['l', null, `https://pixelplanet.fun/${coords}`]);
|
pArray.push(['l', null, `https://pixelplanet.fun/${coords}`]);
|
||||||
pStart = text.iter;
|
pStart = text.iter;
|
||||||
}
|
}
|
||||||
|
} else if (paraElems.includes(chr)) {
|
||||||
|
/*
|
||||||
|
* bold, cursive, underline, etc.
|
||||||
|
*/
|
||||||
|
if (pStart !== text.iter) {
|
||||||
|
pArray.push(text.slice(pStart));
|
||||||
|
}
|
||||||
|
pStart = text.iter + 1;
|
||||||
} else if (chr === ':') {
|
} else if (chr === ':') {
|
||||||
/*
|
/*
|
||||||
* pure link
|
* pure link
|
||||||
|
|
|
@ -230,10 +230,36 @@ class PPfunMatrixBridge {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* send message to matrix
|
||||||
|
* This also registers a new user if none exist
|
||||||
|
*/
|
||||||
async sendMatrix(name, userId, msg, roomId) {
|
async sendMatrix(name, userId, msg, roomId) {
|
||||||
const intent = this.matrixBridge.getIntent(userId);
|
try {
|
||||||
await intent.ensureProfile(name);
|
const intent = this.matrixBridge.getIntent(userId);
|
||||||
intent.sendText(roomId, msg);
|
await intent.ensureProfile(name);
|
||||||
|
intent.sendText(roomId, msg);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`Got error on sending message to matrix: ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* make a user admin in a room
|
||||||
|
*/
|
||||||
|
async makeAdminInRoom(userId, roomId) {
|
||||||
|
try {
|
||||||
|
const userIntent = this.matrixBridge.getIntent(userId);
|
||||||
|
await userIntent.join(roomId);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`Couldn't join room ${roomId} with user ${userId}: ${err.message}`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const intent = this.matrixBridge.getIntent();
|
||||||
|
await intent.setPowerLevel(roomId, userId, 100);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`Couldn't give ${userId} admin rights for ${roomId}: ${err.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -278,12 +304,8 @@ class PPfunMatrixBridge {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (room_id) {
|
if (room_id) {
|
||||||
try {
|
await this.makeAdminInRoom(`@${this.prefix}_admin:pixelplanet.fun`, room_id);
|
||||||
await intent.setPowerLevel(room_id, `@${this.prefix}_admin:pixelplanet.fun`, 100);
|
await this.makeAdminInRoom('@hf:pixelplanet.fun', room_id);
|
||||||
await intent.setPowerLevel(room_id, '@hf:pixelplanet.fun', 100);
|
|
||||||
} catch {
|
|
||||||
console.warn(`Couldn't give @pp_admin or @hf admin rights for ${alias}`);
|
|
||||||
}
|
|
||||||
console.log(`Mapped ${ppfun_name} | ${ppfun_id} to ${alias} | ${room_id}`);
|
console.log(`Mapped ${ppfun_name} | ${ppfun_id} to ${alias} | ${room_id}`);
|
||||||
this.mToProomMap.set(room_id, ppfun_id);
|
this.mToProomMap.set(room_id, ppfun_id);
|
||||||
this.pToMroomMap.set(ppfun_id, room_id);
|
this.pToMroomMap.set(ppfun_id, room_id);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user