const axios = require('axios'); const fs = require('fs'); exports.runQuery = function (matrixClient, room, registrar) { setInterval(() => { axios({ method: 'GET', url: `${registrar.config.fediverse}/api/v1/timelines/home`, headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, }).then((events) => { const event = fs.readFileSync('timeline.json', 'utf8'); fs.writeFileSync('timeline.json', events.data[0].created_at, 'utf8'); if (event !== events.data[0].created_at) { if (events.data[0].reblog === null) { matrixClient.sendHtmlNotice(room.roomId, '', `${events.data[0].account.acct}
${events.data[0].content}
${events.data[0].media_attachments.map(media => ``+`${media.description}`+'' ).join('
')} (id: ${events.data[0].id})
`); } else { matrixClient.sendHtmlNotice(room.roomId, '', ` ${events.data[0].account.acct} has repeated:
${events.data[0].reblog.account.acct}
${events.data[0].content}
${events.data[0].media_attachments.map(media => ``+`Proxied image, no description available.`+'' ).join('
')}
(id: ${events.data[0].id})
`); } } }); }, 8000); };