diff --git a/commands/fediverse/makeitrain.js b/commands/fediverse/makeitrain.js new file mode 100644 index 0000000..a5961a7 --- /dev/null +++ b/commands/fediverse/makeitrain.js @@ -0,0 +1,29 @@ +exports.runQuery = async function (roomId, event, notice) { + if (config.fediverse.tipping === false) return matrixClient.sendHtmlNotice(roomId, `Tipping is not enabled.`, `Tipping is not enabled.`); + const loadingString = `Making it rain for notice: ${notice}...`; + const original = await matrixClient.sendHtmlNotice(roomId, `${loadingString}`, `${loadingString}`); + const users = await fediverse.utils.getStatusMentions(notice, event, original); + if (!users) return matrix.utils.editNoticeHTML(roomId, original, `No eligible users found.`); + const rain = (users) => { + amount = users.length * 0.00000001337 + if (users.length === 1) return amount * 10000 + if (users.length <= 5) return amount * 1000 + if (users.length <= 10) return amount * 100 + if (users.length <= 100) return amount * 10 + return amount + } + axios({ + method: 'POST', + url: `${config.fediverse.domain}/api/v1/statuses`, + headers: { Authorization: `Bearer ${fediverse.auth.access_token}` }, + data: { status: `@10grans@fedi.cc makeitrain ${rain(users)} to ${users.join(' ')}` }, + }) + .then(() => { + matrix.utils.addReact(event, '✅'); + return matrix.utils.editNoticeHTML(roomId, original, `Raining ${rain(users)} 10grans on: 🌧${users.join(', ')}🌧`); + }) + .catch((e) => { + matrix.utils.addReact(event, '❌'); + return matrix.utils.editNoticeHTML(roomId, original, `${e}`) + }); +}; diff --git a/commands/fediverse/tip.js b/commands/fediverse/tip.js index d75932d..b9ac597 100644 --- a/commands/fediverse/tip.js +++ b/commands/fediverse/tip.js @@ -1,4 +1,5 @@ -exports.runQuery = function (roomId, address, flaggedInput, event) { +exports.runQuery = function (roomId, event, address, flaggedInput) { + if (config.fediverse.tipping === false) return matrixClient.sendHtmlNotice(roomId, `Tipping is not enabled.`, `Tipping is not enabled.`); axios({ method: 'POST', url: `${config.fediverse.domain}/api/v1/statuses`, diff --git a/commands/fediverse/utils.js b/commands/fediverse/utils.js index 7232554..a0a5993 100644 --- a/commands/fediverse/utils.js +++ b/commands/fediverse/utils.js @@ -141,3 +141,25 @@ module.exports.unfollow = (roomId, account, event, original) => { matrix.utils.sendError(event, roomId, e); }); }; + +module.exports.getStatusMentions = (notice, event, original) => { + const posters = []; + const prefix = '@'; + const users = axios({ + method: 'GET', + url: `${config.fediverse.domain}/api/v1/statuses/${notice}`, + headers: { Authorization: `Bearer ${fediverse.auth.access_token}` }, + }).then((notice) => { + const citizens = []; + citizens.push(notice.data.account.acct); + for (let i = 0; i < notice.data.mentions.length; i++) citizens.push(notice.data.mentions[i].acct); + const filtered = citizens.filter(users => !config.fediverse.username.includes(users)) + for (let i = 0; i < filtered.length; i++) posters.push(prefix.concat(filtered[i])); + return posters; + }) + .catch((e) => { + matrix.utils.addReact(event, '❌'); + matrix.utils.sendError(event, roomId, e); + }); + return users; +}; diff --git a/commands/help.js b/commands/help.js index 678e7f1..44904dd 100644 --- a/commands/help.js +++ b/commands/help.js @@ -10,6 +10,7 @@ exports.runQuery = function (roomId) { + '+copy [post id] : repeat/repost/retweet
' + '+reply [post id] [content] : reply to post
' + '+tip [@user@fedi.url] [amount] : tip 10grans
' + + '+makeitrain [post id] : make it rain 10grans
' + '+beg : beg for 10grans
' + '+clap [post id] : favorite
' + '+boo [post id] : unfavorite' diff --git a/config.example.js b/config.example.js index fac0ba1..3524c62 100644 --- a/config.example.js +++ b/config.example.js @@ -12,6 +12,7 @@ module.exports = { password: '', client_name: 'ligh7hau5', subject: '', + tipping: false, mimetypes: { whitelist: [], blacklist: [] diff --git a/registrar.js b/registrar.js index 817f90c..a4540d5 100644 --- a/registrar.js +++ b/registrar.js @@ -36,6 +36,7 @@ module.exports = { flood: require('./commands/fediverse/flood.js'), follow: require('./commands/fediverse/follow.js'), help: require('./commands/help.js'), + makeitrain: require('./commands/fediverse/makeitrain.js'), mordy: require('./commands/fediverse/mordy.js'), notify: require('./commands/fediverse/notify.js'), pin: require('./commands/fediverse/pin.js'), diff --git a/utils.js b/utils.js index cc453f7..234d3a2 100644 --- a/utils.js +++ b/utils.js @@ -30,8 +30,8 @@ const eventHandler = (args, roomId, command, event) => { case 'help': case 'flood': case 'notify': args.push(roomId); break; - case 'tip': - args.push(roomId, address, flaggedInput); + case 'tip': case 'makeitrain': + args.push(roomId, event, address, flaggedInput); break; case 'archive': case 'rearchive': args.push(roomId, userInput, !!~command.indexOf('re')); @@ -99,6 +99,7 @@ module.exports.handleReact = async (event) => { if (reaction.key === '🔁') command = 'copy'; if (reaction.key === '👏') command = 'clap'; if (reaction.key === '🗑️️') command = 'redact'; + if (reaction.key === '🌧️') command = 'makeitrain'; eventHandler(args, roomId, command, event); }; @@ -127,5 +128,6 @@ module.exports.selfReact = async (event) => { if (type === 'status' || type === 'reblog' || type === 'mention') { addReact(event, '🔁'); addReact(event, '👏'); + if (config.fediverse.tipping === true) addReact(event, '🌧️'); } };