ligh7hau5/commands/fediverse/notify.js

48 lines
2.4 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/notifications`,
headers: { Authorization: `Bearer ${fediverse_auth.access_token}` },
}).then((events) => {
let lastEvent = JSON.parse(localStorage.getItem('notifications'));
localStorage.setItem('notifications', JSON.stringify(events.data[0].created_at, null, 2));
if (lastEvent !== events.data[0].created_at) {
if (events.data[0].type === 'follow') {
2019-07-04 00:27:39 +03:00
matrixClient.sendHtmlNotice(room.roomId,
'',
`<b><a href="${config.fediverse.domain}/${events.data[0].account.id}">
${events.data[0].account.acct}</a></b>
2019-07-04 00:27:39 +03:00
<font color="#03b381"><b>has followed you.</b></font>
<br><i>${events.data[0].account.note}</i>`);
} else if (events.data[0].type === 'favourite') {
2019-07-04 00:27:39 +03:00
matrixClient.sendHtmlNotice(room.roomId,
'',
`<b><a href="${config.fediverse.domain}/${events.data[0].account.id}">
${events.data[0].account.acct}</a></b>
<font color="#03b381"><b>has <a href="${events.data[0].status.uri}">favorited</a>
2019-07-04 00:27:39 +03:00
your post:</b></font>
<br><blockquote><i><b>${events.data[0].status.content}</i></b></blockquote>`);
} else if (events.data[0].type === 'mention') {
2019-07-04 00:27:39 +03:00
matrixClient.sendHtmlNotice(room.roomId,
'',
`<b><a href="${config.fediverse.domain}/${events.data[0].account.id}">
${events.data[0].account.acct}</a></b>
<font color="#03b381"><b>has <a href="${events.data[0].status.uri}">mentioned</a>
you:</b></font><br><blockquote><i><b>${events.data[0].status.content}
<br>(id: ${events.data[0].status.id}) ${registrar.media.visibilityEmoji(events.data[0].status.visibility)}</i></b>
2020-05-16 20:50:16 +03:00
</blockquote>`);
} else if (events.data[0].type === 'reblog') {
2019-07-04 00:27:39 +03:00
matrixClient.sendHtmlNotice(room.roomId,
'',
`<b><a href="${config.fediverse.domain}/${events.data[0].account.id}">
${events.data[0].account.acct}</a></b>
<font color="#03b381"><b>has <a href="${events.data[0].status.uri}">repeated</a>
2019-07-04 00:27:39 +03:00
your post:</b></font><br>
<blockquote><i><b>${events.data[0].status.content}</i></b></blockquote>`);
2019-07-04 00:27:39 +03:00
}
}
});
}, 8000);
};