feat(cmd): add pin/unpin commands

This commit is contained in:
vulet 2019-09-05 20:36:26 -04:00
parent ee32965255
commit 0aced7e54c
3 changed files with 44 additions and 0 deletions

18
commands/pin.js Normal file
View file

@ -0,0 +1,18 @@
const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses/${userInput}/pin`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
'',
`Pinned:
<blockquote>${registrar.config.fediverse}/${userInput}`);
})
.catch((e) => {
matrixClient.sendHtmlNotice(room.roomId,
'', `${e}`);
});
};

18
commands/unpin.js Normal file
View file

@ -0,0 +1,18 @@
const axios = require('axios');
exports.runQuery = function (matrixClient, room, userInput, registrar) {
axios({
method: 'POST',
url: `${registrar.config.fediverse}/api/v1/statuses/${userInput}/unpin`,
headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` },
}).then((response) => {
matrixClient.sendHtmlNotice(room.roomId,
'',
`Unpinned:
<blockquote>${registrar.config.fediverse}/${userInput}`);
})
.catch((e) => {
matrixClient.sendHtmlNotice(room.roomId,
'', `${e}`);
});
};

View file

@ -68,6 +68,10 @@ let CreateClient = (token) => {
registrar.help.runQuery(matrixClient, room);
}
if (command === 'pin') {
registrar.pin.runQuery(matrixClient, room, userInput, registrar);
}
if (command === 'plemara') {
registrar.plemara.runQuery(matrixClient, room, userInput, registrar);
}
@ -87,6 +91,10 @@ let CreateClient = (token) => {
if (command === 'unfren') {
registrar.unfren.runQuery(matrixClient, room, userInput, registrar);
}
if (command === 'unpin') {
registrar.unpin.runQuery(matrixClient, room, userInput, registrar);
}
}
});