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/notifications`,
|
2021-01-17 12:58:02 +03:00
|
|
|
headers: { Authorization: `Bearer ${registrar.fediverse_auth.access_token}` },
|
2019-07-04 00:27:39 +03:00
|
|
|
}).then((notifications) => {
|
|
|
|
const event = fs.readFileSync('notification.json', 'utf8');
|
|
|
|
fs.writeFileSync('notification.json', notifications.data[0].created_at, 'utf8');
|
|
|
|
|
|
|
|
if (event !== notifications.data[0].created_at) {
|
|
|
|
if (notifications.data[0].type === 'follow') {
|
|
|
|
matrixClient.sendHtmlNotice(room.roomId,
|
|
|
|
'',
|
2020-06-28 10:07:58 +03:00
|
|
|
`<b><a href="${registrar.config.fediverse.domain}/${notifications.data[0].account.id}">
|
2019-07-04 00:27:39 +03:00
|
|
|
${notifications.data[0].account.acct}</a></b>
|
|
|
|
<font color="#03b381"><b>has followed you.</b></font>
|
2020-05-16 20:26:11 +03:00
|
|
|
<br><i>${notifications.data[0].account.note}</i>`);
|
2019-07-04 00:27:39 +03:00
|
|
|
} else if (notifications.data[0].type === 'favourite') {
|
|
|
|
matrixClient.sendHtmlNotice(room.roomId,
|
|
|
|
'',
|
2020-06-28 10:07:58 +03:00
|
|
|
`<b><a href="${registrar.config.fediverse.domain}/${notifications.data[0].account.id}">
|
2019-07-04 00:27:39 +03:00
|
|
|
${notifications.data[0].account.acct}</a></b>
|
2020-05-16 19:48:12 +03:00
|
|
|
<font color="#03b381"><b>has <a href="${notifications.data[0].status.uri}">favorited</a>
|
2019-07-04 00:27:39 +03:00
|
|
|
your post:</b></font>
|
2020-05-16 20:26:11 +03:00
|
|
|
<br><blockquote><i><b>${notifications.data[0].status.content}</i></b></blockquote>`);
|
2019-07-04 00:27:39 +03:00
|
|
|
} else if (notifications.data[0].type === 'mention') {
|
|
|
|
matrixClient.sendHtmlNotice(room.roomId,
|
|
|
|
'',
|
2020-06-28 10:07:58 +03:00
|
|
|
`<b><a href="${registrar.config.fediverse.domain}/${notifications.data[0].account.id}">
|
2019-07-04 00:27:39 +03:00
|
|
|
${notifications.data[0].account.acct}</a></b>
|
2020-05-16 19:48:12 +03:00
|
|
|
<font color="#03b381"><b>has <a href="${notifications.data[0].status.uri}">mentioned</a>
|
2020-05-16 20:50:16 +03:00
|
|
|
you:</b></font><br><blockquote><i><b>${notifications.data[0].status.content}
|
2020-12-27 12:27:48 +03:00
|
|
|
<br>(id: ${notifications.data[0].status.id}) ${registrar.media.visibilityEmoji(notifications.data[0].status.visibility)}</i></b>
|
2020-05-16 20:50:16 +03:00
|
|
|
</blockquote>`);
|
2019-07-04 00:27:39 +03:00
|
|
|
} else if (notifications.data[0].type === 'reblog') {
|
|
|
|
matrixClient.sendHtmlNotice(room.roomId,
|
|
|
|
'',
|
2020-06-28 10:07:58 +03:00
|
|
|
`<b><a href="${registrar.config.fediverse.domain}/${notifications.data[0].account.id}">
|
2019-07-04 00:27:39 +03:00
|
|
|
${notifications.data[0].account.acct}</a></b>
|
2020-05-16 19:48:12 +03:00
|
|
|
<font color="#03b381"><b>has <a href="${notifications.data[0].status.uri}">repeated</a>
|
2019-07-04 00:27:39 +03:00
|
|
|
your post:</b></font><br>
|
2020-05-16 20:26:11 +03:00
|
|
|
<blockquote><i><b>${notifications.data[0].status.content}</i></b></blockquote>`);
|
2019-07-04 00:27:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 8000);
|
|
|
|
};
|