ligh7hau5/commands/flood.js

42 lines
2 KiB
JavaScript
Raw Normal View History

2019-07-04 00:27:39 +03:00
const axios = require('axios');
const fs = require('fs');
exports.runQuery = function (matrixClient, room, registrar) {
setInterval(() => {
axios({
method: 'GET',
2020-06-28 10:07:58 +03:00
url: `${registrar.config.fediverse.domain}/api/v1/timelines/home`,
headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` },
2019-07-04 00:27:39 +03:00
}).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,
'',
2020-06-28 10:07:58 +03:00
`<b><a href="${registrar.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,
'',
2020-06-28 10:07:58 +03:00
`<b><a href="${registrar.config.fediverse.domain}/${events.data[0].account.id}">
2019-07-04 00:27:39 +03:00
${events.data[0].account.acct}</a>
2020-06-28 10:07:58 +03:00
<font color="#7886D7">has <a href="${registrar.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);
};