feat(cmd): Add Mordekai

This commit is contained in:
vulet 2020-05-21 07:02:27 +08:00
parent 173ecf9103
commit e95cefafb9
4 changed files with 34 additions and 0 deletions

3
.gitignore vendored
View file

@ -1,3 +1,6 @@
# Patches
*.patch
# Logs # Logs
logs logs
*.log *.log

26
commands/mordy.js Normal file
View file

@ -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,
'',
`<b>
<blockquote><i>${response.data.content}<br>
(id: ${response.data.id}</a>)
</blockquote><br>`);
})
.catch((e) => {
matrixClient.sendHtmlNotice(room.roomId,
'', `${e}`);
});
};

View file

@ -102,6 +102,10 @@ let CreateClient = (token) => {
if (command === 'unpin') { if (command === 'unpin') {
registrar.unpin.runQuery(matrixClient, room, userInput, registrar); registrar.unpin.runQuery(matrixClient, room, userInput, registrar);
} }
if (command === 'mordy') {
registrar.mordy.runQuery(matrixClient, room, userInput, registrar);
}
} }
}); });

View file

@ -15,4 +15,5 @@ module.exports = {
tip: require('./commands/tip.js'), tip: require('./commands/tip.js'),
unfren: require('./commands/unfren.js'), unfren: require('./commands/unfren.js'),
unpin: require('./commands/unpin.js'), unpin: require('./commands/unpin.js'),
mordy: require('./commands/mordy.js'),
}; };