From 6fe3c992e757a83fe16a7e75c2421270521d9f76 Mon Sep 17 00:00:00 2001 From: vulet Date: Sat, 4 Jul 2020 01:05:39 +0800 Subject: [PATCH] feat(fedi): add status query --- commands/status.js | 19 +++++++++++++++++++ main.js | 5 +++++ registrar.js | 7 ++++--- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 commands/status.js diff --git a/commands/status.js b/commands/status.js new file mode 100644 index 0000000..bf512ad --- /dev/null +++ b/commands/status.js @@ -0,0 +1,19 @@ +const axios = require('axios'); + +exports.runQuery = function (matrixClient, room, userInput, registrar) { + axios({ + method: 'GET', + url: `${registrar.config.fediverse.domain}/api/v1/statuses/${userInput}`, + headers: { Authorization: `Bearer ${registrar.config.fediverse.token}` }, + }).then((response) => { + matrixClient.sendHtmlNotice(room.roomId, + '', + `${response.data.account.acct} +
${response.data.content}
+ ${response.data.media_attachments.map(media => + `${media.description}`) + .join('
')} + (id: ${response.data.id}) +
`); + }); +}; diff --git a/main.js b/main.js index fbdfaeb..7fe0c7a 100644 --- a/main.js +++ b/main.js @@ -131,6 +131,11 @@ let CreateClient = (token, user_id) => { if (command === 'media') { registrar.media.runQuery(matrixClient, room, userInput, registrar); } + + if (command === 'status') { + registar.status.runQuery(matrixClient, room, userInput, registrar); + } + } }); diff --git a/registrar.js b/registrar.js index 4c9cf12..5421471 100644 --- a/registrar.js +++ b/registrar.js @@ -6,8 +6,8 @@ module.exports = { copy: require('./commands/copy.js'), flood: require('./commands/flood.js'), fren: require('./commands/fren.js'), - help: require('./commands/help.js'), - pin: require('./commands/pin.js'), + help: require('./commands/help.js'), + pin: require('./commands/pin.js'), plemara: require('./commands/plemara.js'), redact: require('./commands/redact.js'), notify: require('./commands/notify.js'), @@ -19,5 +19,6 @@ module.exports = { archive: require('./commands/archive.js'), nitter: require('./commands/nitter.js'), invidious: require('./commands/invidious.js'), - media: require('./commands/media.js') + media: require('./commands/media.js'), + status: require('./commands/status.js') };