japanese? translated = translate_toot ( toot, token ) if translated japanese_toots << end end end # Loop through the Japanese toots and start replying japanese_toots. public_timeline ( limit : 25 ) # Find all of the Japanese toots and translate them japanese_toots = token = get_token ( translator_token ) toots. new ( base_url: '', bearer_token: mastodon_token ) # Grab the 25 most recent toots from the Public Timeline toots = mastodon. # Connect to mastodon mastodon = Mastodon :: REST :: Client. Reply to the Japanese toots with the Translator API translation.Connect to Microsoft and get a fresh access token.Connect to Mastodon and grab some toots to chew on.With that in place, we can set up our basic program logic. status != "200 OK" return false end return response. headers = "Bearer " + token end rescue return false end if response. get ( translation_url ) do | response | response. without_tags translation_url = "" + "text=" + toot_content + "&to=en&from=ja" begin response = Curl. # If there's an issue with the connection, we return `false` def translate_toot ( toot, token ) toot_content = toot. body_str end # Connects to the API and translate the toot's content. headers = translator_token end return response. post ( token_url ) do | response | response. # Gets an access token for the Translator API def get_token ( translator_token ) token_url = "" response = Curl. Create your secret token with this this tool.Just need the Ruby script to use a token to toot as our translation bot’s This would normally be handled whenever a user connects to your “Mastodon app”,īut since we are just building a bot (and not acting on behalf of a user) we ToĬonnect to a Mastodon instance, you need to authenticate as a user via Oauth. Well-documented, and works pretty nicely for this silly task. Mastodon privdes a nice Ruby gem on their GitHub. To follow along, setup an account with Microsoft, and get a token for the This by using a Clippy image as the bot’s avatar. It’s not very accurateįor Japanese (or at least, it doesn’t seem to be), so I decided to poke fun at To get this working, I would need some way of translating the toots. Would reply to any toots in Japanese with a translated English version of the I decided to take a tongue-in-cheek approach, and create a translation bot that Why should they care? Just continue using it like you have been, and It’s a bit odd that so many people were complaining about the Japanese users on Timeline suddenly being filled with Hiragana and the like. This caused several users to be very annoyed by their Service was being flooded by excited Japanese users, sending out their “toots” In the aftermath, a popular Japaneseīlog published an article describing the service. Recently gained quite a bit of popularity. Mastodon, the GNU Social compatible microblogging platform, This post I walk through the process of creating a Ruby script to work with This was a useful learning experience, and in Because of the recent influx of Japanese users on Mastodon, I wrote a bot to
0 Comments
Leave a Reply. |