ligh7hau5/main.js

145 lines
4.4 KiB
JavaScript
Raw Normal View History

2019-07-04 00:27:39 +03:00
const sdk = require('matrix-js-sdk');
const axios = require('axios');
const registrar = require('./registrar.js');
const auth = {
type: 'm.login.password',
2020-06-28 10:07:58 +03:00
user: registrar.config.matrix.user,
password: registrar.config.matrix.password,
2019-07-04 00:27:39 +03:00
};
2020-06-28 10:07:58 +03:00
axios.post(`${registrar.config.matrix.domain}/_matrix/client/r0/login`, auth).then((response) => {
CreateClient(response.data.access_token, response.data.user_id);
2019-07-04 00:27:39 +03:00
}).catch((e) => {
console.log(e);
});
2020-06-28 10:07:58 +03:00
let CreateClient = (token, user_id) => {
2019-07-04 00:27:39 +03:00
const matrixClient = sdk.createClient({
2020-06-28 10:07:58 +03:00
baseUrl: registrar.config.matrix.domain,
2019-07-04 00:27:39 +03:00
accessToken: token,
2020-06-28 10:07:58 +03:00
userId: user_id,
2019-07-04 00:27:39 +03:00
timelineSupport: true,
});
matrixClient.on('RoomMember.membership', (event, member) => {
2020-06-28 10:07:58 +03:00
if (member.membership === 'invite' && member.userId === matrixClient.credentials.userId) {
2019-07-04 00:27:39 +03:00
matrixClient.joinRoom(member.roomId).done(() => {
console.log('Auto-joined %s', member.roomId);
});
}
2020-06-28 10:07:58 +03:00
if (member.membership === 'leave' && member.userId === matrixClient.credentials.userId) {
matrixClient.forget(member.roomId).then(() => {
console.log('Kicked %s', member.roomId);
});
}
2019-07-04 00:27:39 +03:00
});
matrixClient.on('Room.timeline', (event, room, toStartOfTimeline) => {
if (toStartOfTimeline) return;
if (event.getType() !== 'm.room.message') return;
2020-06-28 10:07:58 +03:00
if (event.getSender() === matrixClient.credentials.userId) return;
2019-07-04 00:27:39 +03:00
if (event.event.unsigned.age > 10000) return;
if (event.event.content.body.charAt(0) === '+') {
console.log(`Logs: ${event.event.sender} - ${event.event.content.body}`);
const args = event.event.content.body.slice(1).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const userInput = args.join(' ');
const flaggedInput = userInput.substr(userInput.indexOf(' ') + 1);
const address = args.slice(0, 1).join(' ').replace(/"/g, '');
if (command === 'boo') {
registrar.boo.runQuery(matrixClient, room, userInput, registrar);
}
2020-05-16 20:31:10 +03:00
if (command === 'beg') {
registrar.beg.runQuery(matrixClient, room, registrar);
}
2019-07-04 00:27:39 +03:00
if (command === 'clap') {
registrar.clap.runQuery(matrixClient, room, userInput, registrar);
}
if (command === 'copy') {
registrar.copy.runQuery(matrixClient, room, userInput, registrar);
}
if (command === 'flood') {
registrar.flood.runQuery(matrixClient, room, registrar);
}
if (command === 'fren') {
2019-07-06 20:46:28 +03:00
registrar.fren.runQuery(matrixClient, room, userInput, registrar);
2019-07-04 00:27:39 +03:00
}
if (command === 'help') {
registrar.help.runQuery(matrixClient, room);
}
2019-09-06 03:36:26 +03:00
if (command === 'pin') {
registrar.pin.runQuery(matrixClient, room, userInput, registrar);
}
2019-07-04 00:27:39 +03:00
if (command === 'plemara') {
registrar.plemara.runQuery(matrixClient, room, userInput, registrar);
}
if (command === 'notify') {
registrar.notify.runQuery(matrixClient, room, registrar);
}
if (command === 'redact') {
registrar.redact.runQuery(matrixClient, room, userInput, registrar);
}
if (command === 'reply') {
registrar.reply.runQuery(matrixClient, room, address, flaggedInput, registrar);
}
if (command === 'tip') {
registrar.tip.runQuery(matrixClient, room, address, flaggedInput, registrar);
}
2019-07-04 00:27:39 +03:00
if (command === 'unfren') {
registrar.unfren.runQuery(matrixClient, room, userInput, registrar);
}
2019-09-06 03:36:26 +03:00
if (command === 'unpin') {
registrar.unpin.runQuery(matrixClient, room, userInput, registrar);
}
2020-05-21 02:02:27 +03:00
if (command === 'mordy') {
registrar.mordy.runQuery(matrixClient, room, userInput, registrar);
}
2020-05-26 21:06:34 +03:00
if (command === 'archive') {
registrar.archive.runQuery(matrixClient, room, userInput, false, registrar);
}
if (command === 'rearchive') {
registrar.archive.runQuery(matrixClient, room, userInput, true, registrar);
2020-05-26 21:06:34 +03:00
}
2020-06-23 23:22:30 +03:00
if (command === 'nitter') {
registrar.nitter.runQuery(matrixClient, room, userInput, registrar);
}
2020-06-25 14:32:36 +03:00
if (command === 'invidious') {
registrar.invidious.runQuery(matrixClient, room, userInput, registrar);
}
2020-07-03 12:10:55 +03:00
if (command === 'media') {
registrar.media.runQuery(matrixClient, room, userInput, registrar);
}
2020-07-03 20:05:39 +03:00
if (command === 'status') {
2020-07-03 20:13:00 +03:00
registrar.status.runQuery(matrixClient, room, userInput, registrar);
2020-07-03 20:05:39 +03:00
}
2019-07-04 00:27:39 +03:00
}
});
matrixClient.startClient();
module.exports = matrixClient;
};