My Discord Bot Understands Strange Dice

Good Morning from my Robotics Lab! This is Shadow_8472, and today I’m coding Discord dice bot to a practical state. Let’s get started!

Discord Bot Communication Skills

When last I wrote about this bot, I described a custom development environment: a custom OCI container with Python with Discord.py installed and a directory mounted from the host machine. To update the bot, I save the new source file from the host and restart it from within the container.

Programming is boring to describe, so I’ll spare myself writing all the details. Long story short, I needed to translate user requests into a form the core function understood. I used Regular Expressions (Regex) to both separate intended inputs from potential garbage and to extract the kind and number of dice to roll. regex101.com [1] was of great help in testing these expressions.

On one minor note: I got the bot into a Git repository, but I am nothing but a bumbling beginner.

My goal for next time is to produce a container with my code internalized. I’m also scheming something that will let my group know when I’m “playing around with the source code” or the bot is running from within a production container.

Commenting System

Any good program has comments left by its developer – notes for future work on the project. Wise use of comments can speed up development.

by reminding a programmer where work left off or clearly marking off major sections. Working on the command line with the Nano text editor, colors are nicely highlighted, but with all the comments I’m leaving, a simple note left to myself looks no different than commented out code blocks yet to be implemented or scheduled for deletion.

#A simple comment is useful for a quick note.

Basic comments can be anything from programmer notes on how some code works to incomplete or defunct chunks of code that shouldn’t be executed yet/anymore. Programmers must use them unless the objective is for God alone to know how their programs work.

###################################
#A title marks out major sections.#
###################################

Note: In the editor, I’m using “verse” formatting to represent code. In a fixed width text like you will find in a terminal, the lines should be the same length.

Editors that color code parts of your code are nice, but source files begin to look the same after they’re several screens of scrolling. Marking off large groups of functions keeps them organized like chapters in a book. I like to use spam a bunch of comment characters (# in Python) for extra visibility while flipping between places in the code.

################################################
#A broken pattern marks out scheduled changes.#
The quick, brown fox jumped over the lazy dog.
The little dog laughed to see such a sight.
################################################
#The quick, brown fox got distracted.
#The cow jumped over the candlestick.
################################################
################################################

I’d be surprised if I’m the first to invent a way to partition off major blocks of code for redevelopment. Not only can I quickly revert to old code without much thought, its a landmark for showing which sections are actively being worked on.

3D Printing Corner

It’s been a few weeks since I said I wanted to print something each week. This week is no different, but at least I tried.

Gluing a 3D printed object together from smaller parts allows you to overcome print volume limitations of your printer, a valuable skill to have. As I was browsing Thingiverse for something Sonic the Hedgehog related to print, I found a model of Sonic someone split front to back to require almost no support material.

Slic3r was something else. I had a difficult time getting both front and back on the plate at the same time while avoiding the damaged section. Auto-generated Supports ended up in more places than they needed to be. Sonic’s pupil even needlessly generated one with a corner sticking out of his face. I had to shift the halves around multiple times to accommodate the skirt within the print area while still avoiding the damaged spot in the middle – a challenge, but one I accomplished nonetheless. Setting supports to snug cleaned up most wayward supports, but I had to paint on support blockers around Sonic’s cuffs and fingers.

Optimizing for few supports in this way has a major tradeoff: a much more difficult first layer. I didn’t have the patience, so I left the project for another week.

Takeaway

Basic projects are often less exciting than any creative techniques devised to work on them.

Final Question

How have you used comments in creative ways?

Work Cited

[1] F. Dib, regex101.com, [Online]. Available: https://regex101.com/ [Accessed Feb.

28, 2022]

Alternative 3D Slicing Arrangements

Good Morning from my Robotics Lab! This is Shadow_8472, and today, it’s been a busy week. Derpy needed work, but I still wanted to 3D print. Let’s get started!

New Computer Screen

A couple weeks ago, Derpy’s monitor failed. I pulled the graphics card and brought in a cathode-ray tube based monitor from the garage. Integrated graphics aren’t good enough for slicing 3D prints though.

Between bugging out from construction noise next door this week and taking evenings off to recover, a good chunk into the week passed before I made a move to switch back. My father and I took the opportunity for a deep dusting. With the graphics card physically removed, it wasn’t much more hassle to remove the outer cover… The radiator decoupled from the GPU chip in the heart of the graphics card, and we had couldn’t find any thermal paste to put it back together properly.

With some electrically non-conductive paste on order, I felt my desk was overdue for a cleaning, Special thanks to my whole family for helping out in some capacity or another. I sorted the stuff into Keep, Trash, and ??????!. Keep stayed with the desk, Trash got sorted for disposal, and the rest tagged for dispersal according to where it belonged. My father and I further took the opportunity to remove my monitor shelf, dust the desktop thoroughly, and polish it.

I also addressed the cable management situation. With no electronics at Derpy’s workstation, I was free to swap out the power strip for something with a bit longer of a cord (I swiped it from the 3D printer, which had plenty of cord). As I re-assembled my desk, I was sure to tuck my cables at least somewhat out of sight.

A Light Mode Program on a Dark Mode Theme

This section on down to the side project started off as the combined 3D printing corner/side project sections before it grew to half the post at one point.

With Derpy down for service this week, I couldn’t 3D print. Instead, I explored the option of using PrusaSlic3r on my Manjaro workstation.

My graphical package manager presented me with three versions: an out of date version lacking features I’m after from official repositories, an AUR (Arch User Repository) beta version from git, and one AUR entry with a good version number but included GTK-2 in the name. I chose the GTK-2 one, and it appeared to work perfectly, save for that it defaulting to light mode.

There was no dark mode override in the options. The documentation said Linux versions of Slic3r hook into the global theme, which I most definitely have set to dark. No matter how much I played KDE’s themes in System Settings, Slic3r refused to play nicely. I tried switching to the AUR version labeled git, but it didn’t even compile (two attempts).

Assistance With Diagnostics

During research, I came across some discouraging bits about themes not always working on bleeding edge systems. I was about to give up when I brought this matter up on Engineer Man’s Discord server.

Server regular localhost took notice and suggested I install lxappearance, a theme manager designed with the LXDE desktop environment in mind. It too popped up running light mode, but was exposing its own theme selector on the Widget tab. Hitting Apply didn’t have any apparent system-wide effects until I restarted the graphical package manager into my chosen dark theme.

I rebuilt the GTK-2 version of Slic3r, and it greeted me with dark mode. During the 70 minute wait though, I researched the why of the situation. I pinned the culprit to GTK. Aside from its association with GNOME, I had the hardest time piecing together its purpose with certainty. I figured it was some incompatibility with KDE, and I was half-right.

It Works, but Why?

Lxappearance was actually my biggest clue. With both it and KDE’s theme manager open side by side, I noticed a button under System Settings > Global Theme > Application Style called Configure GNOME/GTK Application Style. It led to an unassuming dropdown menu titled GTK theme with a nondescript preview button. The dropdown had the same list from lxappearance.

Researching GTK has no shortage of results, but what does GTK do? As far as I can tell, GTK stands for GNOME ToolKit. I know KDE doesn’t use GTK at its core, so I conducted my research looking for whatever counterpart I it did use: Qt.

I ran a combined search on GTK vs Qt and learned about their combined history. Qt is to KDE what GTK is to GNOME. Qt is older, but GTK was fully opened up first and became more widely adopted. GTK and Qt serve the purpose of drawing the parts of user interfaces you use, but don’t think about – from buttons to save windows. When developers use them, they provide a unified appearance an end-user can easily configure.

Side Project (Blog Site Building)

I’ve begun research into improving the presentation of this blog. It’s hard to know where to begin. I’m working on four and a half years on the job and I have still to formalize my niche. There are blogs out there for privacy. There are blogs out there for technology and Linux. There are fewer blogs out there for home robotics and AI. This blog is all of those, to an extent. That’s why I’m consolidating my niche to Home Computing for the Privacy-Minded Roboticist. I don’t expect things to change all of a sudden, because I’m still technically covering the supporting technologies: namely Linux. But I want to aim to be doing more with actual robotics from here on.

Over the next several weeks, I intend to make small changes to the site, starting with the “About the Author” page. I’m also working on a community Discord server so we can finally get the conversation going in a place where I don’t need the patience to get WordPress forums going at this present time.

Takeaway

Even though I was out and about, I still managed to find stuff to write about. That said, modular systems can be a bit of both a blessing and a curse at times. Feature A may be implemented any number of times – each can work equally well and provide redundancy in case one project goes unmaintained/unforked, but clashing systems can lead to confusion when an end-user finds himself diagnosing the wrong backbone without realizing there are multiple in the first place.

Final Question

What do you think of my stated niche: Home Computing for the Privacy-Minded Roboticist?

Work Cited

[1] B. King, “What’s the Difference Between GTK+ and Qt?,” makeuseof.com, Feb 20, 2019. [Online]. Available: https://www.makeuseof.com/tag/difference-gtk-qt/. [Accessed Febrewary 21, 2022].

Containerized Development Environment

Good Morning from my Robotics Lab! This is Shadow_8472, and today I am building my own dice bot for Discord using containers. Let’s get started!

Overview

In last week’s post, I learned how difficult a Discord dice roller is to find that is either already in a container or suitable to install into one. However, I did develop my skills along the way, and I believe I’m ready to make a bot of my own from scratch.

Development Environment

None of my machines had Python on them (except perhaps excluding the odd Raspberry Pi I have laying around), so the first order of business was to set up my own environment inside a container. There are a number of base images for running Python, but for development, I chose the latest official Python.

Podman pull python:latest

I went back and forth several times with the geometry of my bot project. I ended up stashing my work last week into a directory and making another to hold this round. When I was done, I had three files of consequence: Dockerfile, requirements.txt file, and a directory called home.

When I tell Buildah to make an image, it first goes to the Dockerfile:

FROM python:latest
COPY requirements.txt .
RUN python -m pip install -r requirements.txt

This takes the Python image, copies in requirements.txt, and references it to install any dependencies that don’t come with Python by default, namely as discord.py. As such, requirements.txt had a single line:

discord

Container base images leave out a lot of quality of life programs one might expect on a normal Linux install, like a text editor. That’s where the home directory comes in.

podman run -t -v /home/shadow8472/<bot project>/home:/root:Z -i dice_development:latest /bin/bash

This command has Podman use that image to make a container, mount that home directory into the container as /root (:Z is to tell SELinux it’s all good), and start a bash shell. From here, I can

podman attach <container name>
cd /root

and run the bot’s .py file. With the shared directory, I can edit it from the relative comfort of the host computer, ButtonMash, and go straight to running it inside the container. Best of all, the container will keep running with the bot if my connection to the host is broken, like if the network drops out or if I willingly close the terminal window. When I want to keep working, I can reattach the container.

Login token as environment variable: will my mental innovation of using the dockerfile to assemble it into a format Python understands work?

Development

I don’t have many comments about the actual development of the bot. It’s been a while since I actually programmed, and it’s been longer still since Python. I learned the basics of async programming a few years ago, and discord.py is building on that introduction, but I’m not setting out to master it just yet.

On my way to first stable “release,” I was coding up a loop meant to fill an array with die rolls. A bit of C++ grammar slipped in, and only after asking around did I identify it on my own and fix it. Another time, I coded an echo! function to practice passing command extensions into my code.

Most of my time went into constantly overhauling the internal logic. My early prototype was hardcoded to build its output string one die at a time, but I had to rework the back end to store the dice as they came in so I could sum them up and display that separately. All this was done while trying to keep it in a near-functional state.

But there are times a feature needs invasive re-working. I have some code in my comments that eliminates string manipulation from a function that should only be dealing with numbers. I’ve tried learning a popular version control system called Git in the past, but I can feel that I might actually stick with it this time. I’ve started reviewing commands, but I have yet to start using it as of writing.

Side Project

My week started off rough. I found my Derpy Chips workstation with a blank screen when I went to pull up last week’s post for some last minute proofreading. Initial diagnostics showed the screen blanks 0-30 seconds after making a picture from waking up. I got some help pouring over journalctrl and Xorg logs, but everything looked normal. The problem persisted through rebooting, pulling the GPU (graphics card), booting to an external drive, driving the monitor with my laptop, and even using a DVI cable instead of an HDMI. Final diagnostics turned up a dying backlight. I re-enlisted a personal museum piece –a vintage cathode ray tube model– to fill in until a suitable replacement can be procured.

3D Printing

Turns out that while I can play Minecraft just fine on integrated graphics, Slic3r pushes a few too many polygons for a smooth experience. I can’t run the old monitor off the graphics card because the card doesn’t have a VGA connector. Until I get a replacement monitor –or at the very least an adapter– I’ll be stuck with printing pre-made .stl objects or else installing Slic3r on another workstation.

What I did instead this week was make my own profile picture for the dice bot. I found a few dice I used to role play with and set them up in my photo booth. I even used a bead from printing the Z-braces to support a die in the back. I tweaked the picture a bit in GIMP to make it look more like the actual dice before uploading it for my friends’ enjoyment. It was not fun to fight the .jpg compression the entire way.

Takeaway

Programming is a completely different side of technology than systems management. It’s been a rewarding experience assembling my own environment to work in. It will need even more tweaking if/when I need to adapt it for use with an IDE, but those are for people who either already know everything that’s going or or those who don’t care to learn what’s going on at a basic level.

Final Question

Async functions are weird. I am after a small function to both log and send a response message. How do I pass an async call to another function? Am I even asking the right question?

I Buildah Discord Bot

Good Morning from my Robotics Lab! This is Shadow_8472, and today I am working on a dice bot for a role play on Discord for a few friends. Let’s get started!

Seeking a Container

Many projects are like a tree in terms of having a general sense of progression up from the root and the fine details take most of the work to perfect. This week, my project was a rose bush. I have an end-goal in mind, but I want to run it from a container, a technology I still haven’t fully introduced myself to.

My plan started out simple: find a Discord dice bot already in a container and get it on the server. DockerHub, a sizable repository of OCI (Open Container Initiative) container images. (Most places call them Docker Containers due to its popularity over the past ten+ years. Searches for help should be worded accordingly.) I located about the only one that met all my simple criteria and made myself a bot account for it.

Discord bot accounts are more similar to human accounts than I gave them credit for. The only big differences are that bot accounts log in with a token instead of a username/password and the interface is different to accommodate a program instead of a human. Just as you only interface with your account to make posts, so too does a bot interface with its account to make posts. Give the login to someone or something else, and Discord shouldn’t care.

Long story short, the bot was set up to use an environment variable when using the image to make a container. Once I got it logged in, it ran into other problems I wasn’t prepared to diagnose.

Learning to Build Containers

With my only obvious option a bust, I set my sights on a Discord dice roller I’ve used in the past made by SkyJedi for the Star Wars tabletop RPG’s and a generic spinoff called Genesys. The game I’ll be running is GURPS, which focuses on using 6-sided dice. Plus it has an interesting turn counter system for combat I’d like to try using. The rest is fluff to me this time around, so long as I get it working.

A quick tell of an intense week is when I spend a whole day watching tutorials on the same subject over and over again until I find one at my level. This was one of those weeks. I remember there being one breakthrough video right at my beginner level that let me go back and follow the logic of more advanced tutorials that previously dazed me. During this intense study session, I puzzled together how to use Buildah at a beginner level, what a Dockerfile does, and went from muck to murk in my understanding of Javascript.

Buildah is a for making OCI containers Podman can later run and another tool I haven’t yet explored can edit. Like Podman, Buildah’s corner of their ecosystem aims to replace Docker commands one for one. It’s a win for people switching from Docker, and a win for newcomers like me who can look back at pertinent Docker documentation.

Docker –at least– takes a layered approach to making containers. Using a Dockerfile (one word, also its file name with no extension) lets you build start with a base image and build it up layer by layer, one command at a time. Parts can then be swapped out and the image rebuilt as needed.

The Star Wars dice bot is written in Javascript. If there’s one thing I learned about Javascript this week, it’s that there are several “frameworks” for both front-end development (used to make things look nice for users) and back-end development (used for internal logic). More specifically: I needed to look into NodeJS, a back-end framework. Node has a few different base images on DockerHub, so I worked with the full one with the intent to swap it out for smaller ones for a much smaller image.

Assembling My Own Containers

It took a very special set of circumstances during my self-study for containers to really click. First, I’ve been working through the Podman plugin for Cockpit. Individual images and containers are presented in an intuitive way. Each container has tabs for info, logs, and console access. The life cycle of a container is tied to executing a single command, but if that command is to start a shell, I can interact directly with the container like I would at any other command line. I could test commands from there, and if I got something right, I could add it to the Dockerfile for my next iteration.

I was actually able to find SkyJedi’s Discord server and contact him directly. He wasn’t familiar with containers enough to help me, but he did direct me to a much simpler bot of his I was rapidly able to package into a Node container – and later a Node:Alpine container.

The difference was login token. No matter what I tried, the full dice bot would not accept its login token. I was not able to figure this out, though I came quite close.

Side Project

I’m considering a new weekly segment where I work with my 3D printer a little bit each week. This week, I printed up a calibration cube using everything I’ve learned so far. It’s still far from perfect. I still need to tune in my Z-braces, as I can tell from some faint ringing I can more easily feel by running my thumbnail across it. I still need to calibrate my E-steps, a process I may need to repeat a few times as I come up with interesting, new ways to improve my printer.

Takeaway

After all that, I looked ahead at a the database I’d need to deal with once I get the bot logging in, and I’m almost certain now that my time will be better served making my own bot in Python. Of minor interest, I was able to learn the curl command better. Rocky Linux apparently doesn’t come with wget, the terminal program I usually use to download files. Curl –on the other hand– copies the contents of links to the stream. When directed to a file, it does the same job as Wget. A cool trick I pulled off involved manually following a redirect link.

Final Question

I feel like a rose bush gardener with nothing to show for his work but the tools he’s learned to use along the way. What projects have you farmed up a bunch of dead ends on?