feat(e2ee): introduce OLM encryption. refactor(storage): moved from fs to localstorage. refactor(config): added as global to registrar. chore(npm): upgraded matrix-js-sdk from 2.4.6 release to 9.5.1 release.
This commit is contained in:
parent
0cd373fb8a
commit
67b88f9c96
28 changed files with 264 additions and 1413 deletions
38
main.js
38
main.js
|
@ -1,15 +1,15 @@
|
|||
const registrar = require('./registrar.js');
|
||||
const auth = require('./auth.js');
|
||||
global.registrar = require('./registrar.js');
|
||||
|
||||
registrar.matrix_auth.access_token ? auth.matrixTokenLogin() : auth.getMatrixToken();
|
||||
if (!registrar.fediverse_auth.access_token && registrar.config.fediverse.username) auth.registerFediverseApp();
|
||||
matrix_auth.access_token ? auth.matrixTokenLogin() : auth.getMatrixToken();
|
||||
if (!fediverse_auth.access_token && config.fediverse.username) auth.registerFediverseApp();
|
||||
|
||||
matrixClient.on('RoomMember.membership', (event, member) => {
|
||||
if (member.membership === 'invite' && member.userId === matrixClient.credentials.userId) {
|
||||
matrixClient.joinRoom(member.roomId).done(() => {
|
||||
matrixClient.joinRoom(member.roomId).then(() => {
|
||||
console.log('Auto-joined %s', member.roomId);
|
||||
});
|
||||
}
|
||||
|
||||
if (member.membership === 'leave' && member.userId === matrixClient.credentials.userId) {
|
||||
matrixClient.forget(member.roomId).then(() => {
|
||||
console.log('Kicked %s', member.roomId);
|
||||
|
@ -17,14 +17,15 @@ matrixClient.on('RoomMember.membership', (event, member) => {
|
|||
}
|
||||
});
|
||||
|
||||
matrixClient.on('Room.timeline', (event, room, toStartOfTimeline) => {
|
||||
matrixClient.on('Room.timeline', async function (event, room, member, toStartOfTimeline) {
|
||||
if (toStartOfTimeline) return;
|
||||
if (event.isEncrypted()) await event._decryptionPromise;
|
||||
if (event.getType() !== 'm.room.message') return;
|
||||
if (event.getSender() === matrixClient.credentials.userId) return;
|
||||
if (event.event.unsigned.age > 10000) return;
|
||||
if (event.event.content.body.charAt(0) === '+') {
|
||||
console.log(`Logs: ${event.event.sender} - ${event.event.content.body}`);
|
||||
let args = event.event.content.body.slice(1).trim().split(/ +/g);
|
||||
if (event.getContent().body.charAt(0) === '+') {
|
||||
console.log(`Logs: ${event.event.sender} - ${event.getContent().body}`);
|
||||
let args = event.getContent().body.slice(1).trim().split(/ +/g);
|
||||
let command = args.shift().toLowerCase();
|
||||
const userInput = args.join(' ');
|
||||
const flaggedInput = userInput.substr(userInput.indexOf(' ') + 1);
|
||||
|
@ -35,19 +36,19 @@ matrixClient.on('Room.timeline', (event, room, toStartOfTimeline) => {
|
|||
switch(command) {
|
||||
case 'config':
|
||||
return;
|
||||
case 'help': case 'beg': case 'flood': case 'notify':
|
||||
args.push(matrixClient, room, registrar);
|
||||
case 'help': case 'beg': case 'flood': case 'asdf':
|
||||
args.push(matrixClient, room);
|
||||
break;
|
||||
case 'tip':
|
||||
args.push(matrixClient, room, address, flaggedInput, registrar);
|
||||
args.push(matrixClient, room, address, flaggedInput);
|
||||
break;
|
||||
case 'archive': case 'rearchive':
|
||||
args.push(matrixClient, room, userInput, !!~command.indexOf('re'), registrar);
|
||||
args.push(matrixClient, room, userInput, !!~command.indexOf('re'));
|
||||
command = 'archive';
|
||||
break;
|
||||
case 'post': case 'reply': case 'media': case 'mediareply':
|
||||
case 'random': case 'randomreply': case 'randommedia': case 'randommediareply':
|
||||
args.push(matrixClient, room, userInput, registrar, {
|
||||
args.push(matrixClient, room, userInput, {
|
||||
isReply: !!~command.indexOf('reply'),
|
||||
hasMedia: !!~command.indexOf('media'),
|
||||
hasSubject: !!~command.indexOf('random'),
|
||||
|
@ -57,17 +58,16 @@ matrixClient.on('Room.timeline', (event, room, toStartOfTimeline) => {
|
|||
case 'proxy':
|
||||
try {
|
||||
const url = new URL(userInput);
|
||||
command = registrar.config.invidious.domains.includes(url.hostname)
|
||||
? 'invidious'
|
||||
: registrar.config.nitter.domains.includes(url.hostname)
|
||||
command = config.invidious.domains.includes(url.hostname)
|
||||
? 'invidious'
|
||||
: config.nitter.domains.includes(url.hostname)
|
||||
? 'nitter'
|
||||
: 'proxy';
|
||||
} catch(e) {}
|
||||
//fallthrough
|
||||
default:
|
||||
args.push(matrixClient, room, userInput, registrar);
|
||||
args.push(matrixClient, room, userInput);
|
||||
}
|
||||
|
||||
registrar[command] && registrar[command].runQuery.apply(null, args);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue