From 56ce1ccd5e279c67750aada8dd41e94b9444d755 Mon Sep 17 00:00:00 2001 From: vulet Date: Sun, 17 May 2020 00:48:12 +0800 Subject: [PATCH] feat(cmd): add 10grans ez-tip && fix(cmd): media attachment && style(cmd): default format: markdown --- commands/flood.js | 12 +++++++++--- commands/notify.js | 8 ++++---- commands/plemara.js | 2 +- commands/reply.js | 2 +- commands/tip.js | 21 +++++++++++++++++++++ main.js | 7 +++++-- notification.json | 1 + registrar.js | 1 + timeline.json | 1 + 9 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 commands/tip.js diff --git a/commands/flood.js b/commands/flood.js index 3e81ad2..d682713 100644 --- a/commands/flood.js +++ b/commands/flood.js @@ -16,8 +16,11 @@ exports.runQuery = function (matrixClient, room, registrar) { '', `${events.data[0].account.acct}
${events.data[0].content}
+ ${events.data[0].media_attachments.map(media => + ``+`${media.description}`+'' + ).join('
')} (id: ${events.data[0].id}) -

`); + `); } else { matrixClient.sendHtmlNotice(room.roomId, '', @@ -26,8 +29,11 @@ exports.runQuery = function (matrixClient, room, registrar) { has repeated:
${events.data[0].reblog.account.acct}
${events.data[0].content}
- (id: ${events.data[0].id}) -

`); + ${events.data[0].media_attachments.map(media => + ``+`Proxied image, no description available.`+'' + ).join('
')} +
(id: ${events.data[0].id}) + `); } } }); diff --git a/commands/notify.js b/commands/notify.js index 6667a0c..dc969fa 100644 --- a/commands/notify.js +++ b/commands/notify.js @@ -24,7 +24,7 @@ exports.runQuery = function (matrixClient, room, registrar) { '', `
${notifications.data[0].account.acct} - has favorited + has favorited your post:
${notifications.data[0].status.content}
`); } else if (notifications.data[0].type === 'mention') { @@ -32,16 +32,16 @@ exports.runQuery = function (matrixClient, room, registrar) { '', `
${notifications.data[0].account.acct} - has mentioned + has mentioned you:
${notifications.data[0].status.content} -
[id: ${notifications.data[0].status.id}]

`); +
(id: ${notifications.data[0].status.id})

`); } else if (notifications.data[0].type === 'reblog') { matrixClient.sendHtmlNotice(room.roomId, '', `
${notifications.data[0].account.acct} - has repeated + has repeated your post:
${notifications.data[0].status.content}
`); } diff --git a/commands/plemara.js b/commands/plemara.js index 85719a8..550e7e4 100644 --- a/commands/plemara.js +++ b/commands/plemara.js @@ -5,7 +5,7 @@ exports.runQuery = function (matrixClient, room, userInput, registrar) { method: 'POST', url: `${registrar.config.fediverse}/api/v1/statuses`, headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, - data: { status: userInput }, + data: { status: userInput, content_type: `text/markdown` }, }).then((response) => { matrixClient.sendHtmlNotice(room.roomId, '', diff --git a/commands/reply.js b/commands/reply.js index 5c66849..3f40162 100644 --- a/commands/reply.js +++ b/commands/reply.js @@ -5,7 +5,7 @@ exports.runQuery = function (matrixClient, room, address, flaggedInput, registra method: 'POST', url: `${registrar.config.fediverse}/api/v1/statuses`, headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, - data: { status: flaggedInput, in_reply_to_id: address }, + data: { status: flaggedInput, in_reply_to_id: address, content_type: `text/markdown` }, }).then((response) => { matrixClient.sendHtmlNotice(room.roomId, '', diff --git a/commands/tip.js b/commands/tip.js new file mode 100644 index 0000000..44cb095 --- /dev/null +++ b/commands/tip.js @@ -0,0 +1,21 @@ +const axios = require('axios'); + +exports.runQuery = function (matrixClient, room, address, flaggedInput, registrar) { + axios({ + method: 'POST', + url: `${registrar.config.fediverse}/api/v1/statuses`, + headers: { Authorization: `Bearer ${registrar.config.fediverseToken}` }, + data: { status: `@10grans@fedi.cc tip `+ flaggedInput + ` to `+address }, + }).then((response) => { + matrixClient.sendHtmlNotice(room.roomId, + '', + ` +
Tipping ${response.data.content}
+ (id: ${response.data.id}) +

`); + }) + .catch((e) => { + matrixClient.sendHtmlNotice(room.roomId, + '', `${e}`); + }); +}; \ No newline at end of file diff --git a/main.js b/main.js index 350c518..ef9b8c0 100644 --- a/main.js +++ b/main.js @@ -2,14 +2,13 @@ const sdk = require('matrix-js-sdk'); const axios = require('axios'); const registrar = require('./registrar.js'); -const homeServer = 'https://civseed.com/_matrix/client/r0/login'; const auth = { type: 'm.login.password', user: registrar.config.matrixUser, password: registrar.config.matrixPass, }; -axios.post(homeServer, auth).then((response) => { +axios.post(`${registrar.config.matrixServer}/_matrix/client/r0/login`, auth).then((response) => { CreateClient(response.data.access_token); }).catch((e) => { console.log(e); @@ -88,6 +87,10 @@ let CreateClient = (token) => { registrar.reply.runQuery(matrixClient, room, address, flaggedInput, registrar); } + if (command === 'tip') { + registrar.tip.runQuery(matrixClient, room, address, flaggedInput, registrar); + } + if (command === 'unfren') { registrar.unfren.runQuery(matrixClient, room, userInput, registrar); } diff --git a/notification.json b/notification.json index e69de29..a5631fe 100644 --- a/notification.json +++ b/notification.json @@ -0,0 +1 @@ +2020-05-16T15:16:56.000Z \ No newline at end of file diff --git a/registrar.js b/registrar.js index 0a43106..da697cd 100644 --- a/registrar.js +++ b/registrar.js @@ -11,6 +11,7 @@ module.exports = { redact: require('./commands/redact.js'), notify: require('./commands/notify.js'), reply: require('./commands/reply.js'), + tip: require('./commands/tip.js'), unfren: require('./commands/unfren.js'), unpin: require('./commands/unpin.js'), }; diff --git a/timeline.json b/timeline.json index e69de29..520f7fa 100644 --- a/timeline.json +++ b/timeline.json @@ -0,0 +1 @@ +2020-05-16T16:28:32.000Z \ No newline at end of file