ligh7hau5/commands/fediverse/flood.js

40 lines
1.9 KiB
JavaScript
Raw Normal View History

exports.runQuery = function (matrixClient, room) {
2019-07-04 00:27:39 +03:00
setInterval(() => {
axios({
method: 'GET',
url: `${config.fediverse.domain}/api/v1/timelines/home`,
headers: { Authorization: `Bearer ${fediverse_auth.access_token}` },
2019-07-04 00:27:39 +03:00
}).then((events) => {
let lastEvent = JSON.parse(localStorage.getItem('timeline'));
localStorage.setItem('timeline', JSON.stringify(events.data[0].created_at, null, 2));
if (lastEvent !== events.data[0].created_at) {
2019-07-04 00:27:39 +03:00
if (events.data[0].reblog === null) {
matrixClient.sendHtmlNotice(room.roomId,
'',
`<b><a href="${config.fediverse.domain}/notice/${events.data[0].id}">${events.data[0].account.acct}</a>
2020-12-27 12:27:48 +03:00
<blockquote><i>${events.data[0].content}</i><br>
${events.data[0].media_attachments.map(media =>
`<a href="${media.remote_url}">`+`${media.description}`+'</a>'
).join('<br>')}
2020-12-27 12:27:48 +03:00
(id: ${events.data[0].id}) ${registrar.media.visibilityEmoji(events.data[0].visibility)}
</blockquote>`);
2019-07-04 00:27:39 +03:00
} else {
matrixClient.sendHtmlNotice(room.roomId,
'',
`<b><a href="${config.fediverse.domain}/${events.data[0].account.id}">
2019-07-04 00:27:39 +03:00
${events.data[0].account.acct}</a>
<font color="#7886D7">has <a href="${config.fediverse.domain}/notice/${events.data[0].id}">repeated</a>:
2019-07-04 00:27:39 +03:00
<blockquote><a href="${events.data[0].reblog.account.url}">${events.data[0].reblog.account.acct}</a></blockquote>
<blockquote>${events.data[0].content}<br>
${events.data[0].media_attachments.map(media =>
`<a href="${media.remote_url}">`+`Proxied image, no description available.`+'</a>'
).join('<br>')}
2020-12-27 12:27:48 +03:00
<br>(id: ${events.data[0].id}) ${registrar.media.visibilityEmoji(events.data[0].visibility)}
</blockquote>`);
2019-07-04 00:27:39 +03:00
}
}
});
}, 8000);
};