rss2twitter icon indicating copy to clipboard operation
rss2twitter copied to clipboard

[FR] - Filtering .Text

Open khalwat opened this issue 4 years ago • 5 comments

The RSS feed we're using rss2twitter on recently started using the @ sign in the feed (sometimes in the title, sometimes in the text).

This resulted in our Twitter app getting suspended for "spamming" because it was @ messaging various Twitter handles, depending on whether a real account ended up inadvertently getting tagged.

I figured I would ask you first how you think it might be best to handle this. I was thinking about optional search/replace pairs in the config or such.

Thoughts?

khalwat avatar May 19 '21 03:05 khalwat

For now, I did a hot fix in main.go:

// format cleans text (removes html tags) and shrinks result
func format(inp string, max int) string {
        // Add a space after any @ symbols so we don't accidentally tag people
        res := strings.ReplaceAll(striphtmltags.StripTags(inp), "@", "@ ")
        if len([]rune(res)) > max {
                snippet := []rune(res)[:max]
                // go back in snippet and found first space
                for i := len(snippet) - 1; i >= 0; i-- {
                        if snippet[i] == ' ' {
                                snippet = snippet[:i]
                                break
                        }
                }
                res = string(snippet) + " ..."
        }
        return res
}

khalwat avatar May 19 '21 03:05 khalwat

maybe a couple of options like --no-mention-text and --no-mention-title and each one will strings.ReplaceAll("@","",-1) for the corresponding element?

umputun avatar May 19 '21 03:05 umputun

What I ended up doing above was changing @ to @. because in our case, they were using the @ sign as part of the text or title (without intending to tag anyone, since it's an RSS feed and not a Tweet), e.g.:

@Wallmart

I initially was going to change it to " at " or "(at)" but didn't want to waste the characters in a tweet.

So with the above hotfix, it'll look like this:

@.Wallmart

...which still reads okay, but doesn't tag anyone (the . acts as a stop for their algo)

Now that I think about it, just adding a space would do it too:

@ Wallmart

(I just changed it to that)

khalwat avatar May 19 '21 03:05 khalwat

I think this is the best just to drop it all together as @ has such a special meaning.

Another alternative we can try is to replace @ with some unicode symbol that resembles it. something like © or Ω or maybe ☺︎

umputun avatar May 19 '21 03:05 umputun

Well, the @ symbol only has a special meaning in a Tweet if it is followed by a [a-zA-Z0-9] (any letter or number) -- anything else, including a space, and it's just another character.

So writing:

Meet you @ the store

...is totally fine, and will never tag anyone.

Anyway part of the reason for posting was just to let you know this was a thing, depending on what is coming through your RSS feed :)

khalwat avatar May 19 '21 04:05 khalwat