feat(10grans): add make-it-rain
This commit is contained in:
parent
fcadc5addc
commit
58ef31356a
7 changed files with 60 additions and 3 deletions
29
commands/fediverse/makeitrain.js
Normal file
29
commands/fediverse/makeitrain.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
exports.runQuery = async function (roomId, event, notice) {
|
||||
if (config.fediverse.tipping === false) return matrixClient.sendHtmlNotice(roomId, `Tipping is not enabled.`, `<code>Tipping is not enabled.</code>`);
|
||||
const loadingString = `Making it rain for notice: ${notice}...`;
|
||||
const original = await matrixClient.sendHtmlNotice(roomId, `${loadingString}`, `<code>${loadingString}</code>`);
|
||||
const users = await fediverse.utils.getStatusMentions(notice, event, original);
|
||||
if (!users) return matrix.utils.editNoticeHTML(roomId, original, `<code>No eligible users found.</code>`);
|
||||
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, `<code>Raining ${rain(users)} 10grans on: 🌧${users.join(', ')}🌧</code>`);
|
||||
})
|
||||
.catch((e) => {
|
||||
matrix.utils.addReact(event, '❌');
|
||||
return matrix.utils.editNoticeHTML(roomId, original, `<code>${e}</code>`)
|
||||
});
|
||||
};
|
|
@ -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.`, `<code>Tipping is not enabled.</code>`);
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.fediverse.domain}/api/v1/statuses`,
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -10,6 +10,7 @@ exports.runQuery = function (roomId) {
|
|||
+ '+copy [post id] : repeat/repost/retweet<br>'
|
||||
+ '+reply [post id] [content] : reply to post<br>'
|
||||
+ '+tip [@user@fedi.url] [amount] : tip 10grans<br>'
|
||||
+ '+makeitrain [post id] : make it rain 10grans<br>'
|
||||
+ '+beg : beg for 10grans<br>'
|
||||
+ '+clap [post id] : favorite<br>'
|
||||
+ '+boo [post id] : unfavorite</blockquote>'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue