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
|
||||
|
||||
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.
|
||||
Or change the room-creation code in `src/ppfunMatrixBridge.js` in the `connectRooms` method.
|
||||
Some things are hardcoded there.
|
||||
Some things are hardcoded in `src/ppfunMatrixBridge.js`, check it out if there are problems.
|
||||
And the URL where to fetch chunks from pixelplanet is hardcoded in `src/pixelplanet/loadChunk.js`.
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -10,10 +10,10 @@
|
|||
"author": "hf",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"canvas": "^2.8.0",
|
||||
"matrix-appservice-bridge": "^3.2.0",
|
||||
"node-fetch": "^3.1.0",
|
||||
"ws": "^8.4.0"
|
||||
"canvas": "^2.9.3",
|
||||
"matrix-appservice-bridge": "^4.0.2",
|
||||
"node-fetch": "^3.2.8",
|
||||
"ws": "^8.8.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"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
|
||||
# the url of the application service, its set to 8009 per default
|
||||
url: http://localhost:8009
|
||||
# the pp prefix is hardcoded
|
||||
# the pp prefix is hardcoded, don't change it
|
||||
sender_localpart: pp
|
||||
namespaces:
|
||||
users:
|
||||
|
|
|
@ -39,6 +39,69 @@ export default class MString {
|
|||
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) {
|
||||
return (chr === ' ' || chr === '\t' || chr === '\n');
|
||||
}
|
||||
|
@ -49,15 +112,20 @@ export default class MString {
|
|||
* moves iter to last closing braked if it is enclosure
|
||||
*/
|
||||
checkIfEnclosure(zIsLink) {
|
||||
const yStart = this.iter + 1;
|
||||
let yStart = this.iter + 1;
|
||||
|
||||
let yEnd = yStart;
|
||||
const escapePositions = [];
|
||||
while (this.txt[yEnd] !== ']') {
|
||||
const chr = this.txt[yEnd];
|
||||
if (chr === '\\') {
|
||||
// escape character
|
||||
escapePositions.push(yEnd);
|
||||
yEnd += 2;
|
||||
continue;
|
||||
}
|
||||
if (yEnd >= this.txt.length
|
||||
|| chr === '\n'
|
||||
|| chr === '['
|
||||
|| chr === '('
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
@ -102,7 +170,17 @@ export default class MString {
|
|||
if (!zIsLink) {
|
||||
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;
|
||||
return [y, z];
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
import MString from './MString.js';
|
||||
|
||||
const paraElems = ['*', '~', '+', '_'];
|
||||
function parseMParagraph(text) {
|
||||
const pArray = [];
|
||||
let pStart = text.iter;
|
||||
|
@ -40,6 +41,14 @@ function parseMParagraph(text) {
|
|||
pArray.push(['l', null, `https://pixelplanet.fun/${coords}`]);
|
||||
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 === ':') {
|
||||
/*
|
||||
* 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) {
|
||||
const intent = this.matrixBridge.getIntent(userId);
|
||||
await intent.ensureProfile(name);
|
||||
intent.sendText(roomId, msg);
|
||||
try {
|
||||
const intent = this.matrixBridge.getIntent(userId);
|
||||
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) {
|
||||
try {
|
||||
await intent.setPowerLevel(room_id, `@${this.prefix}_admin:pixelplanet.fun`, 100);
|
||||
await intent.setPowerLevel(room_id, '@hf:pixelplanet.fun', 100);
|
||||
} catch {
|
||||
console.warn(`Couldn't give @pp_admin or @hf admin rights for ${alias}`);
|
||||
}
|
||||
await this.makeAdminInRoom(`@${this.prefix}_admin:pixelplanet.fun`, room_id);
|
||||
await this.makeAdminInRoom('@hf:pixelplanet.fun', room_id);
|
||||
console.log(`Mapped ${ppfun_name} | ${ppfun_id} to ${alias} | ${room_id}`);
|
||||
this.mToProomMap.set(room_id, ppfun_id);
|
||||
this.pToMroomMap.set(ppfun_id, room_id);
|
||||
|
|
Loading…
Reference in New Issue