From e95cefafb97e2fd41cfc08a42dbe86b9e17bfb48 Mon Sep 17 00:00:00 2001 From: vulet Date: Thu, 21 May 2020 07:02:27 +0800 Subject: [PATCH] feat(cmd): Add Mordekai --- .gitignore | 3 +++ commands/mordy.js | 26 ++++++++++++++++++++++++++ main.js | 4 ++++ registrar.js | 1 + 4 files changed, 34 insertions(+) create mode 100644 commands/mordy.js diff --git a/.gitignore b/.gitignore index 8d25863..0cc8fb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Patches +*.patch + # Logs logs *.log diff --git a/commands/mordy.js b/commands/mordy.js new file mode 100644 index 0000000..be0c2bd --- /dev/null +++ b/commands/mordy.js @@ -0,0 +1,26 @@ +const axios = require('axios'); + +exports.runQuery = function (matrixClient, room, userInput, registrar) { + axios({ + method: 'POST', + url: `${registrar.config.fediverse}/api/v1/statuses`, + headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, + data: { + status: `@mordekai ${userInput}`, + content_type: `text/markdown`, + visibility: 'unlisted', + expires_in: '7200' + }, + }).then((response) => { + matrixClient.sendHtmlNotice(room.roomId, + '', + ` +
${response.data.content}
+ (id: ${response.data.id}) +

`); + }) + .catch((e) => { + matrixClient.sendHtmlNotice(room.roomId, + '', `${e}`); + }); +}; diff --git a/main.js b/main.js index 3c42b2d..5a18e38 100644 --- a/main.js +++ b/main.js @@ -102,6 +102,10 @@ let CreateClient = (token) => { if (command === 'unpin') { registrar.unpin.runQuery(matrixClient, room, userInput, registrar); } + + if (command === 'mordy') { + registrar.mordy.runQuery(matrixClient, room, userInput, registrar); + } } }); diff --git a/registrar.js b/registrar.js index 760869a..85b9840 100644 --- a/registrar.js +++ b/registrar.js @@ -15,4 +15,5 @@ module.exports = { tip: require('./commands/tip.js'), unfren: require('./commands/unfren.js'), unpin: require('./commands/unpin.js'), + mordy: require('./commands/mordy.js'), };