Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle boosts. Suggest editing toots too. #5

Merged
merged 3 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Based on [a bot I used to use on Twitter called Please Caption](https://twitter.

The difference with this bot is as you can send direct messages to statuses (toots) on Mastodon you can have a less spammy bot that messages privately.

Mastodon also lets you 'Delete & re-draft' toots so you can easily add the text descriptions back in.
Mastodon also lets you 'Delete & re-draft' toots so you can easily add the text descriptions back in. An alternative approach with Mastodon v4 is editing toots, but you have to remove the image and add it again before you can add text descriptions.

## How does the bot work?

You can [follow the bot on @PleaseCaption@botsin.space](https://botsin.space/@PleaseCaption).

When you post any media (images and videos) without text descriptions it will respond with a message.
When you post any media (images and videos) without text descriptions, or boost such toots, it will respond with a message.

## Installing the bot

Expand Down
16 changes: 10 additions & 6 deletions js/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ const {
getRelationships
} = require('./mastodon' )

function sendPrivateStatus (inReplyToId, username) {
function sendPrivateStatus (inReplyToId, username, reblog) {
const params = {
in_reply_to_id: inReplyToId,
status: `${username} ${getRandomText()}`,
status: `${username} ${getRandomText(reblog)}`,
visibility: 'direct'
}
return sendStatus(params)
}

function doesMessageHaveUnCaptionedImages(message) {
const mediaAttachments = message.data.media_attachments
if (message.reblog) {
return doesMessageHaveUnCaptionedImages(message.reblog)
}

const mediaAttachments = message.media_attachments
const hasMediaAttachments = mediaAttachments.length > 0

if (!hasMediaAttachments) {
Expand Down Expand Up @@ -137,7 +141,7 @@ function sendMessagesToTimeline() {
if (message.event === 'update') {
console.info('Message ID: ', message.data.id)

if (!doesMessageHaveUnCaptionedImages(message)) {
if (!doesMessageHaveUnCaptionedImages(message.data)) {
return
}

Expand All @@ -146,10 +150,10 @@ function sendMessagesToTimeline() {
return
}

const messageId = message.data.id
const messageId = message.data.reblog ? message.data.reblog.id : message.data.id;
const username = '@' + message.data.account.acct

sendPrivateStatus(messageId, username).then(result => {
sendPrivateStatus(messageId, username, message.data.reblog).then(result => {
console.info('Sent message to: ', result.id)
}).catch(console.error)
}
Expand Down
6 changes: 3 additions & 3 deletions js/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"Help make Mastodon more accessible by adding descriptions to your media!"
],
"deleteredraft": [
"Not too late to delete and re-draft.",
"You can choose 'Delete & re-draft' and add them.",
"If you want to add them, choose 'Delete & re-draft'."
"Not too late to delete and re-draft. Or, edit, remove and re-add media, and add captions.",
"You can choose 'Delete & re-draft' and add them, or if it's easier, 'Edit', remove and re-add the media.",
"If you want to add them, choose (1) 'Delete & re-draft' or (2) 'Edit', remove, then add."
]
}

Expand Down
2 changes: 1 addition & 1 deletion js/mastodon.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function deleteStatus (id) {
}

function followUser (accountId) {
return mastodonClient.post(`accounts/${accountId}/follow`, { reblogs: false })
return mastodonClient.post(`accounts/${accountId}/follow`, { reblogs: true })
.then(resp => resp.data.id)
}

Expand Down
24 changes: 24 additions & 0 deletions js/reblogGrammar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"origin": [
"#words# #emojis# \n\n#deleteredraft#"
],
"emojis": [
"📷", "📸", "🤳", "🎥", "📹", "♻️", "🆙", "👆", "☝️", "", "", "", "", ""
],
"words": [
"Oops, you boosted something without media captions!",
"Hey, your boosted toot's media don't all have descriptions!",
"Psst, you boosted something that's missing descriptions",
"Your boosted toot's media doesn't have descriptions, just so you know!",
"Blind and/or partially sighted people may have trouble with the toot you boosted",
"It makes Mastodon more accessible when media have captions. This boost doesn't."
],
"deleteredraft": [
"The author can delete and re-draft. Or, edit, remove and re-add media, and add captions.",
"The author can choose 'Delete & re-draft' and add them, or if it's easier, 'Edit', remove and re-add the media.",
"If the author wants to add them, they can choose (1) 'Delete & re-draft' or (2) 'Edit', remove, then add."
]
}



14 changes: 9 additions & 5 deletions js/text.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const tracery = require('tracery-grammar')
const rawGrammar = require('./grammar.json')
const processedGrammar = tracery.createGrammar(rawGrammar)
processedGrammar.addModifiers(tracery.baseEngModifiers)
const grammar = tracery.createGrammar(require('./grammar.json'))
grammar.addModifiers(tracery.baseEngModifiers)
const reblogGrammar = tracery.createGrammar(require('./reblogGrammar.json'))
reblogGrammar.addModifiers(tracery.baseEngModifiers)

function getRandomText () {
const text = processedGrammar.flatten("#origin#")
function getRandomText (reblog) {
if (reblog) {
return reblogGrammar.flatten('#origin#')
}
const text = grammar.flatten('#origin#')
return text
}

Expand Down