Cyberdon - Send posts to Mastodon/Iceshrimp via your console

I was feeling a bit bored again, so I decided to play around with Bash and create another useless tool. Cyberdon - a Bash script that allows you to send messages via Mastodon or Iceshrimp through the console. That’s pretty much all Cyberdon can do. But hey, isn’t that great? Instead of throwing the script in the trash, I thought I’d post it here. Maybe someone will appreciate it!


Setup

To use Cyberdon, you will need an Access Key, which you can create in your account settings by creating a new “App”.

To use this silly tool, simply copy the code below into a text editor of your choice and save it as “cyberdon.sh” (or any other name you prefer).

Code

#!/bin/bash

RED='\033[0;31m'
GREEN='\033[0;92m'
NC='\033[0m' 

send_post() {
    local instance=$1
    local api_key=$2
    local post=$3
    response=$(curl -sS -X POST -H "Authorization: Bearer $api_key" -d "status=$post" "https://$instance/api/v1/statuses")
    if [[ $response == *"error"* ]]; then
        error_message=$(echo "$response" | grep -o 'error[^,]*' | cut -d':' -f2)
        echo "${RED}Error:${NC} $error_message"
    else
        clear
printf "${RED}\n"
base64 -d <<<"H4sIAG/HlWUAA4VNQQrDMAy75xW6pYWAjrn1MBZoD+tgyQYFg2EPaM+FPn52PjCBZCELG/gHBYKpqhHMbj1jHkb1vUeACEKKKcoH5CEpHiRzJ8SN9to0BVEBRgtSvHQgrW/QXU3til+kf+zze+J5KxvaXFC32soDy3p/1/ZaSsUPEzCh270AAAA=" | gunzip
printf "${NC}\n"
        echo -e "${GREEN}Sended${NC}"
        sleep 2
        clear
    fi
}
clear
printf "${RED}\n"
base64 -d <<<"H4sIAKnGlWUAA9WTvW7bMBDH9z7FIYuXQNyDIojjejDyMWQLQICipYslVKFUkkoqoEPQqUOHfLhBHqJP5SfpkZItNZEyNAaCEmdRuv/xdx+EAXqWEH3e14TN+tDnZBx4b/Sg0AMUPrl7COGOcSGacmrBb1w0xFZ7XvIayEakcVeB+7lj5Ah5LYTkDEdOH4nQERl4kY0oUcj7gMyXxOrSGiI/rvGwFhhrnZv9+RQaYNMi5yz0rTqi2K1JteAS1R+7onGyJrvgL4GUyYdA6Ha2T0T/0gq0+wfxqJ9WZF7ouZR2MV5HA8wrONB4hWqBsawOolxb/JpeFplUNojyy1dvuV0uPfESawuzx1hDDAgJ3zbeWFr5WcvAJC+Bq+XP1fIGzqbjTydT+rr5n+1209R3mFRz1HGu9sAmCIeSmjeRTgsLF7mGopxnqUlStYBcwYk0NqdYIGUWoUk03UTgR+RQLXQckWrgCCvQ+KVMNcYBTDRKiyBB4TXsjItiB1IFMoryUlkwaC2lMd25/w018gqhykvdwQcwU0VpIbWQoCa4iqFUGbo2fGicLlIrM8p0kZWoIgy60OV738TW7ff65Wngn/BvqxmaQ64ef3h7WD3ee7sjg491XpicH07PjmenR/Dekxiyp04j3Q5/3Q7ZG+ZGSR7ecHwAeb995N2WkX8AdtnKVgsIAAA=" | gunzip
printf "${NC}\n"
sleep 1
read -p "Your Cyberlink (e.g. corteximplant.com): " instance
read -p "Accses-Key: " api_key
clear
while true; do
printf "${RED}\n"
base64 -d <<<"H4sIAG/HlWUAA4VNQQrDMAy75xW6pYWAjrn1MBZoD+tgyQYFg2EPaM+FPn52PjCBZCELG/gHBYKpqhHMbj1jHkb1vUeACEKKKcoH5CEpHiRzJ8SN9to0BVEBRgtSvHQgrW/QXU3til+kf+zze+J5KxvaXFC32soDy3p/1/ZaSsUPEzCh270AAAA=" | gunzip
printf "${NC}\n"
    echo "Choom, what do you want to do?"
    echo "1. Send post"
    echo "2. Exit"

    read -p "Choose (1-2): " choice

    case $choice in
        1)
            read -p "Your msg: " post
            send_post $instance $api_key "$post"
            ;;
        2)
            break
            ;;
        *)
            echo "${RED}Choomba, invalid input. Enter a valid number (1-2).${NC}"
            ;;
    esac
done

To get this fun quirk to work, open a terminal program of your choice and navigate to the location where you saved the .sh file. Give the file the necessary permissions by typing “chmod +x cyberdon.sh”. Then, simply type “./cyberdon.sh” in your console, and the fun begins!

The code is quite messy. Feel free to do whatever you want with it!

7 Likes

Nice little tool :purple_heart:

So as you saw on corteximplant.com, I got this to work. However, when I try to run it against nightcity.bar, it fails with “Error: this mehtod requires an authenticated user” message. I’ve generated an API key for my NCB alt, but what else do I need it to do in order to work? I am logged into NCB through my browser also.

Interestingly, I get the same error message in Moshidon when I try to view NCB’s local timeline from my corteximplant.com account.

Any idears?

Hmm, I guess I’ll have to take a closer look at this. It seems like I might need to examine the script and make some tweaks to the URL in order to make it work with Iceshrimp :smiley:

1 Like

I’ll see what I can figure out also. Figured I’d also post my zsh version in case anybody wants that. I made it slightly more interactive to allow the user to pick what instance they want to post to so I don’t have to enter the instance and API key every time because I’m lazy like that. :smiley:

@revengeday - I did some more research and testing, and I’m still at a loss. The documentation that I found doesn’t even mention the base API endpoints, and looking at the code hasn’t divulged any additional hoops to jump through. As far as I can tell, it should be the exact same as the Mastodon endpoints.

I did find a github issue but the accepted answer gives some contradictory information and I can’t see how to implement it (because the Iceshrimp API doesn’t give enough information to make the GET /oauth/authorize call that is mentioned).

This was the only thing that I could find, other than the documentation that is referenced in that response.

Here’s my zsh version, if anybody wants it. I also added a bit in there that allows you to choose between either corteximplant or nightcity.bar. You’ll just need to go in and edit the script to add your API key for each server (assuming you have accounts on both of them). Just replace [REDACTED] with the appropriate API key and you’re good to go!

#!/bin/zsh

RED='\033[0;31m'
GREEN='\033[0;92m'
NC='\033[0m' 

send_post() {
    local instance=$1
    local api_key=$2
    local post=$3
   
    response=$(curl -sS -X POST -H "Authorization: Bearer $api_key" -d "status=$post" "https://$instance/api/v1/statuses")
    if [[ $response == *"error"* ]]; then
        error_message=$(echo "$response" | grep -o 'error[^,]*' | cut -d':' -f2)
        echo "${RED}Error:${NC} $error_message"
    else
        clear
	printf "${RED}\n"
	base64 -d <<<"H4sIAG/HlWUAA4VNQQrDMAy75xW6pYWAjrn1MBZoD+tgyQYFg2EPaM+FPn52PjCBZCELG/gHBYKpqhHMbj1jHkb1vUeACEKKKcoH5CEpHiRzJ8SN9to0BVEBRgtSvHQgrW/QXU3til+kf+zze+J5KxvaXFC32soDy3p/1/ZaSsUPEzCh270AAAA=" | gunzip
	printf "${NC}\n"
        echo -e "${GREEN}Sended${NC}"
        sleep 2
        clear
    fi
}

clear
printf "${RED}\n"
base64 -d <<<"H4sIAKnGlWUAA9WTvW7bMBDH9z7FIYuXQNyDIojjejDyMWQLQICipYslVKFUkkoqoEPQqUOHfLhBHqJP5SfpkZItNZEyNAaCEmdRuv/xdx+EAXqWEH3e14TN+tDnZBx4b/Sg0AMUPrl7COGOcSGacmrBb1w0xFZ7XvIayEakcVeB+7lj5Ah5LYTkDEdOH4nQERl4kY0oUcj7gMyXxOrSGiI/rvGwFhhrnZv9+RQaYNMi5yz0rTqi2K1JteAS1R+7onGyJrvgL4GUyYdA6Ha2T0T/0gq0+wfxqJ9WZF7ouZR2MV5HA8wrONB4hWqBsawOolxb/JpeFplUNojyy1dvuV0uPfESawuzx1hDDAgJ3zbeWFr5WcvAJC+Bq+XP1fIGzqbjTydT+rr5n+1209R3mFRz1HGu9sAmCIeSmjeRTgsLF7mGopxnqUlStYBcwYk0NqdYIGUWoUk03UTgR+RQLXQckWrgCCvQ+KVMNcYBTDRKiyBB4TXsjItiB1IFMoryUlkwaC2lMd25/w018gqhykvdwQcwU0VpIbWQoCa4iqFUGbo2fGicLlIrM8p0kZWoIgy60OV738TW7ff65Wngn/BvqxmaQ64ef3h7WD3ee7sjg491XpicH07PjmenR/Dekxiyp04j3Q5/3Q7ZG+ZGSR7ecHwAeb995N2WkX8AdtnKVgsIAAA=" | gunzip
printf "${NC}\n"
sleep 1
#read -p "Your Cyberlink (e.g. corteximplant.com): " instance
#read -p "Accses-Key: " api_key
    echo "Which ■■■■■■■■ do you want to use?"
    echo "1. CORTEXIMPLANT"
    echo "2. Night City Bar"
    echo "3. Jack out (CANCEL)"
    read "dtchoice?Netrun on: "
    case $dtchoice in
        1) instance=corteximplant.com
           api_key=[REDACTED]
           ;;
        2) instance=nightcity.bar
           api_key=[REDACTED]
           ;;
        3) exit
           ;;
        *)
            echo "${RED}Choomba, invalid input. Enter a valid number (1-2).${NC}"
            ;;
    esac

clear
while true; do
    printf "${RED}\n"
    base64 -d <<<"H4sIAG/HlWUAA4VNQQrDMAy75xW6pYWAjrn1MBZoD+tgyQYFg2EPaM+FPn52PjCBZCELG/gHBYKpqhHMbj1jHkb1vUeACEKKKcoH5CEpHiRzJ8SN9to0BVEBRgtSvHQgrW/QXU3til+kf+zze+J5KxvaXFC32soDy3p/1/ZaSsUPEzCh270AAAA=" | gunzip
    printf "${NC}\n"
    echo "Choom, what do you want to do?"
    echo "1. Send post"
    echo "2. Exit"

    read "choice?Choose (1-2): "

    case $choice in
        1)
            read "post?Your msg: "
            send_post $instance $api_key "$post"
            #send_post "$post"
            ;;
        2)
            break
            ;;
        *)
            echo "${RED}Choomba, invalid input. Enter a valid number (1-2).${NC}"
            ;;
    esac
done
1 Like