release 0.1.0
This commit is contained in:
parent
4b3ba6b516
commit
35b4509238
18 changed files with 399 additions and 1 deletions
95
main.js
Normal file
95
main.js
Normal file
|
@ -0,0 +1,95 @@
|
|||
const sdk = require('matrix-js-sdk');
|
||||
const axios = require('axios');
|
||||
const registrar = require('./registrar.js');
|
||||
|
||||
const homeServer = 'https://civseed.com/_matrix/client/r0/login';
|
||||
const auth = {
|
||||
type: 'm.login.password',
|
||||
user: registrar.config.matrixUser,
|
||||
password: registrar.config.matrixPass,
|
||||
};
|
||||
|
||||
axios.post(homeServer, auth).then((response) => {
|
||||
CreateClient(response.data.access_token);
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
let CreateClient = (token) => {
|
||||
const matrixClient = sdk.createClient({
|
||||
baseUrl: registrar.config.matrixServer,
|
||||
accessToken: token,
|
||||
userId: registrar.config.userId,
|
||||
timelineSupport: true,
|
||||
});
|
||||
|
||||
matrixClient.on('RoomMember.membership', (event, member) => {
|
||||
if (member.membership === 'invite' && member.userId === registrar.config.userId) {
|
||||
matrixClient.joinRoom(member.roomId).done(() => {
|
||||
console.log('Auto-joined %s', member.roomId);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
matrixClient.on('Room.timeline', (event, room, toStartOfTimeline) => {
|
||||
if (toStartOfTimeline) return;
|
||||
if (event.getType() !== 'm.room.message') return;
|
||||
if (event.getSender() === registrar.config.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}`);
|
||||
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);
|
||||
}
|
||||
|
||||
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') {
|
||||
registrar.fren.runQuery(matrixClient, room, registrar);
|
||||
}
|
||||
|
||||
if (command === 'help') {
|
||||
registrar.help.runQuery(matrixClient, room);
|
||||
}
|
||||
|
||||
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 === 'unfren') {
|
||||
registrar.unfren.runQuery(matrixClient, room, userInput, registrar);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
matrixClient.startClient();
|
||||
module.exports = matrixClient;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue