SockChat — A SneedChat client for the command line - A lightweight standalone SneedChat client for the terminal, written in Go

  • 🐕 I am attempting to get the site runnning as fast as possible. If you are experiencing slow page load times, please report it.

y a t s

MATI scientist
True & Honest Fan
kiwifarms.net
Joined
Jun 30, 2023
SockChat
A SneedChat client for the command line

death by ooperator.png
[Releases] [Wiki]
[Gitlab mirror | Gitgud mirror]​

I made a TUI chat client for the Farms using Go's very nice networking and concurrency features. I personally find my client connects and fetches new messages faster than the browser, and the socket connections seem a bit more resilient. There are a lot of factors involved with connection stability though, so take that last bit with a grain of salt.

Basic usage:
  • Windows: sockchat_windows_ARCH.exe --cookies="$COOKIES"
  • macOS: ./sockchat_macos --cookies="$COOKIES"
  • Linux: ./sockchat_linux_ARCH --cookies="$COOKIES"
Where $COOKIES is the raw cookies value from the site's header.

Use the network tab in your browser's dev tools to find the chat.ws connection on the forum's homepage. Your cookies are found in the request header. It looks a little something like this:
Code:
xf_tfa_trust=VALUE; xf_user=VALUE; xf_emoji_usage=VALUE; xf_csrf=VALUE; xf_session=VALUE

You don't need all of these values to be present. Whatever your browser uses to connect and log you in will work fine. If the connection fails, confirm the URL in your config.json file is up-to-date. The config.json file is generated with default values at first launch.

Notable features:
  • Tor support
  • Mention notifications
  • Chat logger
  • Read-only mode
  • Generic socks5 proxy support
Check out the development tracker to see what's in the works.

Screenshots may become outdated quickly. All of them, including ones from past versions, will be included here for the record.

2024-01-16 (Initial post):
bad_at_cropping.png
This one is my favorite.

2024-01-17 (Colors update):
user_colors.png

2024-01-18 (Unescaped strings):
unescaped.png

2024-01-25 (Timestamps):
timestamps.png
Syncing line alignment in 2 side-by-side text boxes wasn't worth the pain.

The source is public domain. Please use, modify, or distribute it however you like.
 
Last edited:
Thats a pretty cool idea, did using Go offer any advantages over something like Python or Node?
Python probably would have worked just as well. And I just don't like Node. It's not a very big nor complex program, so a Python version wouldn't be hard to make.

Go has nice concurrency features since Google wanted to make a nice compiled language for web services, so that's an advantage over Python I suppose.
 
I wrote something like this in Python and it was nicer than using the browser.
How are you getting the Kiwiflare token?

Can you color code the users?
 
  • Like
Reactions: slungus22
How are you getting the Kiwiflare token?
The cookies from the browser's request headers for the chat.ws request are all you need. They're provided as an argument when starting the program. From what I understand, KiwiFlare relies on sssg_clearance, which doesn't appear to be necessary for the chat WebSocket. This is probably why you can leave a chat window open for weeks.

Can you color code the users?
That's next on my list of things to do. It really does need some coloring and formatting.
 
which doesn't appear to be necessary for the chat WebSocket. This is probably why you can leave a chat window open for weeks.
I had a hunch that was the case when my client was open all day.

I ghetto rigged colors based on author id.
Python:
def get_color_from_id(author_id):
    colors = ["\033[91m", "\033[92m", "\033[93m", "\033[94m", "\033[95m", "\033[96m", "\033[96m"]
    color_choice = colors[author_id % len(colors)]
    return color_choice
Screenshot_20240116_222027.png
Getting a consistent input box in python in a bit of a pain because you have to start threading.
 
Getting a consistent input box in python in a bit of a pain because you have to start threading.
The UI library I'm using is really cool. It has some stuff for styling that I'll have to take a look at. Apparently I can render images with it (to some degree of quality), so that's something I'll figure out later on. The input field and the main chat scroller are in a container that works like a flex box. This makes tiling interfaces very easy.

Handling message edits seems like a big pain in the ass, and every redraw would probably need to read pointers to individual boxes for each message. This feels resource intensive.

Edit: For colors, I would just generate 3 random bytes (R, G, and B) for each user that gets processed and work from there. This gives 0xFF ^ 3 possible user colors. As I'm sure you're aware, each user that's online gets sent in a JSON "users" message, so I use the numerical IDs and the actual usernames as key/value pairs in a hashtable/dict (in Go, they're called a map). It would be easy to add a color field to the User structs.
 
Last edited:
Were you around for the massive user status spam in the websocket? I think it still does dump the active users in one message every so often. I ended up adding a blocklist based on user ID that just doesn't render the image.
Reproducible colors for users would be nice to better keep track of people. How does it handle connection drops?
 
ANSI colors and some formatting for improved readability have been added.

I was giving this some thought while out on a walk and I realized terminal color schemes may make some colors harder to see than others, which may cause problems with the hex codes. Aside from that, some ancient terminals (actively maintained ones, mind you) still don't do 8 bit colors, much less the 24-bit ones I'm proposing. The nice thing about the ANSI colors is that the user can custom set them (pywal is a nice utility for generating schemes from backgrounds that I personally use), which takes away a lot of guess work. So keep in mind that the colors in the screenshot below aren't indicative of what you will see on your end.

user_colors.png

I'll still do the fancier colors, but they will have to be opt-in. Next on my list of things to fix is the weird looking "&#xYZ;" HTML escaping.
 
Last edited:
  • Like
Reactions: Harvey Danger
@yats Yea I'm sure different terminals are gonna show colors differently, and possibly whether the terminal is using BASH, ZSH, etc. Another idea would be to take a few popular color schemes like Molokai, Eightys, etc and make a setting to change the color scheme for the Chat Client.
 
  • Like
Reactions: y a t s
Another idea would be to take a few popular color schemes like Molokai, Eightys, etc and make a setting to change the color scheme for the Chat Client.
Great idea; I like it a lot.

Now that I'm thinking about it, I should probably do theme/scheme files (probably just CSS, since it's easy and pretty forgiving) and let the user define custom ones as well. I can enable customizing more rendering stuff than just the ANSI colors that can already be set by the user, such as text formatting rules, which could be nice.

possibly whether the terminal is using BASH, ZSH
Probably not, but there could be some weird environment variables I'm not aware of. It's reassuring that Windows' built-in terminals (cmd.exe and powershell) support the standard 8 ANSI colors and apparently the bright ones too.

While we're on the subject, I use Zsh a lot more than Bash for testing and day-to-day stuff. If anyone encounters issues with a particular shell, please let me know.
 
I'll still do the fancier colors, but they will have to be opt-in. Next on my list of things to fix is the weird looking "&#xYZ;" HTML escaping.
Done. Much easier than I was anticipating.
2024-01-18 (Unescaped strings):
View attachment 5645927

I also made the JSON parsing a lot more efficient using decoder streams. The memory footprint is a tad smaller now :)
 
Last edited:
There are now prebuilt binaries for ease of use. I guess this marks the first proper release.
A lot of cool stuff has been added like a chat logger and read-only mode. I'm currently working on daemons.

Config is now done using a config.json file found in one of the following locations:
  • Linux: ~/.config/sockchat/config.json
  • macOS: ~/Library/Application Support/sockchat/config.json
  • Windows: %APPDATA%/sockchat/config.json
 
Back