I Went From Command Line to Discord Voice on Raspberry Pi

Good Morning from my Robotics Lab! This is Shadow_8472 with a side project of the week. Let’s get started!

Starting From the Basics

I found myself in need of a separate Discord account connected to a voice server this past week. With one account on my main computer and myself unable to use Discord mobile, I chose to work with my Raspberry Pi 400. I downloaded a build of Debian 12 for the Pi, flashed it with balenaEtcher, and it booted to the command line with no Internet access.

I was challenging myself by trying to maintain a conversation while setting things up. As I lacked a free Ethernet connection, that meant working with Wi-Fi. I only got as far as failing to get wpa_supplicant up while only using far fewer tools than were assumed by the tutorials I was using. In the end, I moved a connection over from my main computer temporarily.

Desktop Environment

The MATE desktop environment has been good to me for my old laptop. Once I got it installed on the Pi, even it felt a bit heavy – a note for next time, I suppose. I was able to easily connect to Wi-Fi and restore my desktop’s Ethernet.

Firefox went on next because Discord doesn’t have a client for ARM processors outside the same Android app I cannot use, but the browser version loaded. It didn’t see my USB microphone, and neither did Firefox even after bumbling around with allowing web pages to see my mic. Only then did I find and enable the PulseAudio daemon so Firefox could see my mic and pass it to Discord.

pulseaudio --start

Since I was working quick and sloppy as root, I had to use the following instead:

pulseaudio --system

Takeaway

I can tell my skills are improving. I believe a full Arch install may be in my future.

Note

An interesting problem I keep running into is the system clock. Extreme low-end computers frequently don’t include the circuitry to measure time while power is otherwise off because of monetary cost and circuit board real estate. This week, it meant I had to reboot after connecting to Ethernet, though I could probably have found a way to manually set it.

Final Question

What is the craziest project you’ve ever done starting with a command line?

I look forward hearing your answers on in the comments below or on my Discord server.

I Upgraded My Python Discord Bot (Week2)

Good Morning from my Robotics Lab! This is Shadow_8472 and today, I am adding some features to my Discord dice bot. Be sure to catch last week’s post before reading this one. Let’s get started!

My Golden Standard

Dice come in many forms. Outside of specialty die collecting, the hobby of role play games will tend to land you with the widest variety to determine success/failure of fictional characters as their real-world players throw them into the hands of the equally fictional Random Number God (RNG*). Most people are familiar with cubic dice with faces valued one to six, but both the shape (read: number of sides) and the faces can be changed.

The role play system Gensys and its Star Wars themed ancestors go so far as to use as many as three types of pips on their narrative dice – it’s even possible to get both a “success” and “advantage” from the same face! There exists a dice roller by SkyJedi on GitHub for this system, but I would like a bot I can look at and understand. It serves as my gold standard, but I can settle for bronze.

*(officially RNG means Random Number Generator)

About My Bot

This bot constitutes my first major project where I have a discrete engine I will likely re-use later, so I’ve done my best to keep the engine clean at the expense of no time to redo the main bot’s .py file. The biggest question I had to ask myself over and over again was this: Engine or implementation? Is this feature specific to this function, or does it belong in the engine? I defined my engine’s role to begin after input has been screened, and lasting until it’s returned the structured results. I also included a separate tally function for summing the results.

Part way through testing, one of my friends tried subtracting one term from another. I had to re-write a good chunk of the otherwise mostly working engine, but I came out with a product that can pass common mathematical operators without choking.

I finished this week with a presentable bot. I didn’t get all the features I was after, but it will work for my upcoming Star Trek themed game. My main must-have feature is a set of “challenge dice” with the faces 1, 2, 0, 0, C, C. Multiple pip types was an important feature on this engine

Tricks Learned Along the Way

In no particular order, I taught myself a trick or two.

Space-indented comments:
Debugging is all about wall of text. At one point, I had a function with a triple for-loop to split input strings into tokens another function could evaluate one at a time. Six hours I bickered with it until success. That victory is in part thanks to my idea to indent debug messages based on how many nested loops each one was in. On my way to a break, inspiration hit and within five minutes, I had replaced the whole thing with only three lines of code.

When to Spaghetti Code:
Programming is an art form. Just as sketch work is drawn/painted over, so too are new features written quickly and sloppily, made to work, added to, tweaked, extended, and eventually depreciated as early code is replaced by a more elegant solution. Messy code is hard to develop, but a little more isn’t going to ruin your day if it’s that little bit more to round off a major version before a deadline. As you code, you will pick up better ways to do things, and you will want to go over your old code as you are able.

Clean Your Code Regularly:
I don’t know why I need to remind myself this, but I have a hard time deleting massive code blocks once a functional replacement has been coded. It feels good being able to revert quickly, but I’m working over SSH in a terminal window, and scrolling through uncollapsible blocks of code all the time isn’t fun. My advice is to comment out the old code being removed and make sure your program still works before removing it all together and verifying that it still works. The same goes for massive chunks of debug code built up over a long debugging session. If a whole file needs a major quality bump, I found it helpful to make a big block of comment I can move functions above as I perfect them.

Git Is a Tool to Practice:
I am using Git locally on this project. Right now, my skill level is git add and git commit. Meaningful comments will come with time as will checking out a previous version will come with time. I’m not working with an online repository, so I don’t need to worry about push or pull, though I am aware of them. In the meantime, I keep a special place for my most recent stable version.

The Development Cycle Loops:
The development cycle doesn’t end with release. Early versions will be flawed. Even now, I’m considering using those picture icons to the dice output. Always a new feature. Support code can take even longer to wrestle into existence if the clean implementation re-writes half the engine.

Takeaway

I would like to stress that I’m finding it difficult to write about writing code. Tangible progress is often non-linear. There are a lot more options than when you’re working with someone else’s program. In some ways, writing a program is more like writing a story than wrestling a Windows game into working on Linux. Once you’ve figured out the interface to set up your canvass, you are in full command of the ideas you express.

Final Question

What do you think of this “Lessons Learned” format?

My Father Hacked Discord onto Debian 11

Good Morning from my Robotics Lab! This is Shadow_8472 with a side project of the week. Let’s get started!

Forcing Discord

I worked with my father on his Debian 11 (Bullseye) computer this week. The program he’s been missing the most has been Discord, the chat platform. The official .deb package relies on a library package called libappindicator (or similar) despite it being depreciated. Ironically, this happened so long ago, the change has now made it to the stable branch of Debian. Discord, PLEASE look into this!

Feeling optimistic, we redownloaded Discord and installed it with dpkg. The Apt package manager wasn’t happy with this arrangement, and wanted us to

sudo apt-get --fix-broken install

where it said it was going to remove Discord. We launched Discord anyway; it worked.

The missing dependency would still be a problem though, so I looked into reinstalling while telling apt to ignore it. Before I finished researching that solution though, I found a repository on GitHub set up by user Guna [1]. This individual replaced the dependency, a procedure I have tried and not succeeded at. You can read more about the repository’s precautions under in SECURITY.md under the project’s root level directory. Many thanks.

Projects Around LXDE

LXDE is a desktop environment aimed specifically at people who don’t want to spend excessive system resources on a flashy user interface. Our experience with it would suggest it is not for beginners as a few annoying tidbits require beating into submission.

The first annoyance we fixed was the panel along the bottom hiding itself. While looking through some the panel’s settings as part of an unrelated issue I spotted a relevant tic box to make it stay.

While multiple desktops may be a great way to organize a swarm of windows, not everyone thinks in terms of them. LXDE came configured with a mess of shortcuts you can accidentally trigger, leaving yourself stranded in the wrong desktop workspace. To fix this, we followed a guide [2] to a file called ~/.config/openbox/lxde-rc.xml and specified 1 desktop instead of 2.

Similarly, volume and mute keys are often taken for granted. While following a guide on wiki.lxde.org [3], we copied a block of configuration code into the same ~/.config/openbox/lxde-rc.xml file as above and modified it per instructions for PulseAudio. In theory, it links appropriate keyboard button presses to corresponding events within the system. Mute cooperated, but the volume keys refused to work until we were almost zeroed in on the problem. Our problem vanished while playing around with commands based off where the script was actually trying to set the volume. At least it sticks around through a reboot.

Takeaway

There remains one thing we have yet to figure out: getting Ctrl+Alt+t to open a terminal. A keyboard shortcut list from around 2020 listed it, but perhaps something changed since then.

Final Question

Let me know what you think: Why might LXDE have solved itself? What is with the terminal keyboard shortcut not working? I look forward to hearing from you in the comments below or over on my Discord server.

Works Cited

[1] Guna, “discord-debian-bullseye” github.com, Feb. 18, 2022. [Online]. Available: https://github.com/gunalabs/discord-debian-bullseye [Accessed: May 16, 2022].

[2] “Help:Configuration”openbox.org, May 1, 2018. [Online]. Available:http://openbox.org/wiki/Help:Configuration#Desktops [Accessed: May 16, 2022].

[3] “LXDE:Quesions”wiki.lxde.org, Feb 27, 2017. [Online]. Avalable: https://wiki.lxde.org/en/LXDE:Questions#How_do_I_make_my_special_keyboard_buttons_.28mute.2C_volume.2C_screen_brightness_….29_work.3F [Accessed: May 16, 2022].