I Upgraded My Python Discord Bot

Good Morning from my Robotics Lab! This is Shadow_8472 and today, I am tailoring my simple Discord dice bot for an upcoming role play. Let’s get started!

Project History

A while back, I built a very simple dice bot for Discord [1]. In its current form, it can be used for rolling an integer number of dice with another integer number of sides (3d6, for example) provided at runtime. A lot of effort also went into learning the Buildah/Podman OCI container implementation so I could clean up afterwords if something got messy. In the end, I managed a container with a mounted volume I could reprogram on the fly without entering the container.

Containerization with Podman/Cockpit has been treating me very kindly. This week, I was able to add environment variables on container creation, allowing me to work a bot token and branch label into the container itself. I also created separate development/production branches for short-term testing and long-term operation respectively, though in effect, I’ll also be keeping an old version around to act as a “stable” branch which will have its code integrated into the container itself instead of relying on an attached volume.

During this week’s work, I figured out how to test code segments directly in the interpreter. I also played around with separating core functions out of the main .py program file, and found they imported cleanly into the live interpreter. As a result, my debugging efficiency improved quite a bit.

Total Rewrite

There is a meme out there where a programmer can write a program such that only he and God know how it works – after a time, only God will know. A good programmer will return to such a problem with ideas for a more elegant solution, though it usually means rewriting from scratch. The core dice rolling functions for my first dice bot were hacked together and barely able to roll an arbitrary set of XdN dice where X in the number of dice and N is the number of sides.

This time, however, I’m programming for a game with non-standard dice faces. No way was I going to shove that into my old bot core. Instead, I spent around eight to ten hours crafting a new monstrosity I can reuse for other bots in the future and handles multiple types of die pips on a side at once. I focused on hacking it into my existing bot code (which I have yet to fully decipher), but it wasn’t so bad. What I do know is that I obsoleted several bits of code and about half as many comments intended for future work on that ugly line of development.

My new functions begin with the assumption that N can be defined as a list of sides, which in-turn list their respective kinds/counts of pips. For when N is int type (integer), I have some code to build a die face-by-face in that format. All the dice are loaded into a list, and that list is passed off to another function to actually roll the dice and tally up the results.

Worth noting is that I’m starting to make git commits to savestate my progress. I’m not worrying about proper form right now, but I’m counting on improving over time.

Settings Files

The ability to save/load data –while not strictly needed for a simple dice bot– is an important skill to develop. My brief research showed that while there’s any number of ways a Python programmer may implement settings, a somewhat standardized and end-user friendly method is using .ini files. While I may not use them this week in this project, I will want to remember this side goal. I’ve invented my own scheme before, and it wasn’t fun.

Takeaway

It’s really difficult to communicate all the little challenges that come up without looking/feeling like an idiot half the time because I missed something and another half because of the jargon. I’d have to say most of the time I spend coding is trying to understand what I just wrote. I still haven’t completed all the features I need, so the plan is to cover the rest of this revamp in next week’s post.

Final Question

What were you working on the first time you successfully extracted a part of your program into a separate document?

Works Cited

[1] Shadow_8472, “My Discord Bot Understands Strange Dice,” Feb. 28, 2022. letsbuildroboticswithshadow8472, [Online]. Available: https://letsbuildroboticswithshadow8472.com/index.php/2022/02/28/my-discord-bot-understands-strange-dice/ [Accessed Aug. 29, 2022].

I Archived Two Old Hard Disks

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

Who doesn’t have a few hard drives from previous computers laying around? Not my family anyway. The first one I dealt with is a Quantum Fireball KX with my father’s name written on it. More importantly: it uses a legacy PATA connection for data, and with the transition away from SATA to M.2 well underway, the time for preservation is now.

My early attempts revolved around a PCI card for a PATA adapter. Long story short: I was never able to boot with the Fireball hooked into my system. I tried different combinations on the jumper pins along with position on the cable. I was never able to access the BIOS. All I got was a freeze mid-power-on-beep or a failed attempt to boot to the hard disk after hearing it spinning up. I verified the card and cable by testing them with CD/DVD reader/burners also from the PATA era.

Aware that the Fireball might be burned out, we ordered a multi-adapter so I could connect it over USB – without having to fight for the BIOS. It mounted right up. I used rsync to dump the contents to GoldenOakLibry, my family’s network storage. Along the way, I came across devhints.io [1]. It looks like an amazing resource. It helped me out wrangling rsync quickly. It has one of the highly exclusive places in my bookmarks list. My only complaint is how interesting Mr. Cruz made his site to cite. Most importantly, I wrote out a sticky note about when and where I dumped the drive.

The second drive (branded Deskstar, SATA connector) took way too long. I was the fool for putting it over Wi-Fi, and I paid for it. Several times, rsync would appear to stall as it got to a larger file. A couple such times, I figured the drive was overheating due to no circulation so I stopped rsync, powered it off, and let it cool down. The breakthrough was pulling up a utility to show my network data.

There was a rather important incident I feel inclined to report before wrapping up. At one point, I accidentally caught a cord connected to the adapter. The drive tumbled off my desk, but I barely managed to catch it after a fumble or two. My worst fear was that of a “head crash,” where the read-write head contacts the spinning platter, leaving a scratch and destroying the data on it. If anything, the slow Wi-Fi speed worked in my favor, because the head was off where it won’t do any harm during an impact.

Takeaway

Data preservation is a chore. In retrospect, I should have performed this procedure exclusively over a wired connection – I should have investigated the possibility of mounting it to GoldenOakLibry directly.

Final Question

What kinds of “digital chores” turned out more memorable than you’d have cared for?

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

Work Cited

[1] R. Cruz “Rsync cheatsheet”devhints.io, [Online]. Available:https://devhints.io/rsync [Accessed: Aug 22, 2022].

I’m Incompatible Because Policy?!

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

I’ve been interested in having the basics of a smartphone again for a while now. I was planning on diving into Android Debug Bridge for this month’s large project, but my PinePhone showed up again after a couple years. For the unaware, the PinePhone is basically a Linux computer in the profile of a smartphone.

My PinePhone is the second edition released: it understandably has early adopter issues like slow load times and needing to about live on a charger when not in use. It came preloaded with Ubuntu Touch; while I could see myself using it (should it actually work), I’m not particularly impressed. I need text, call, and picture capabilities. It’s not able to do any of those right now.

I installed my current SIM card. Now, this SIM was sold locked to an LG Stylo 5 smartphone for the duration of the initial contract (now expired). My PinePhone sees the name of my provider, but anything involving data over the cellular network escapes me for the time being. I will need to contact my mobile service provider.

Aside from mobile data, something is off with my camera app. Pair that with my mediocre response to Ubuntu Touch, and now I want to try a different OS. I’m a fan of KDE, so I went to the Pine64 PinePhone OS index [1] and downloaded/flashed one marked KDE to a microSD card (one of my good ones; rest in peace abandoned project PiCore – I’ll do better next time). I totally missed that the image was a factory test, but at least I was able to verify that both my cameras work but cellular data is still a bust.

Take 2: postmarketOS is a mobile distribution with an option for Plasma Mobile. I was tossed between multiple websites before locating the actual download link. Dolphin file viewer calculates Shasums, flashing SD cards has almost become second nature at this point, and then it’s a matter of booting for the first time.

Plasma Mobile imitates Android about as well as KDE imitates Windows. It felt almost like coming home. Response time was improved, the camera worked, and the layout felt more familiar than not. The system time zone settings were a little harder to find. Overall, it offers a bit less stability than Ubuntu Touch, but the upsides more than make up for it.

I spent a day or so with tech support. Phones these days come with multiple locks and they can often be confused for each other. There is the lock that binds the phone to its original carrier. There is the lock screen to authenticate the user. There is also the lock binding the SIM to the phone body. My phone was locked, but the SIM must have noticed it was in a strange host and blown some sort of digital fuse. I can’t say I wasn’t warned.

Takeaway

I’m mad. My phone should be technologically compatible with their network. I have the skills to self-support my local hardware, but tech support won’t work with me on the equipment beyond my control. I’m hoping it’s the fuse hypothesis and that someone in-store can service the SIM without dumping me for the sake of the phone.

Final Question

What tech support disaster have you experienced or observed?

Works Cited

“PinePhone Software Releases,”wiki.pine64.org, July 24, 2022. [Online]. Available:https://wiki.pine64.org/index.php/PinePhone_Software_Releases [Accessed Aug. 15, 2022].

I Printed A Filament Duster

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

My 3D printer has been stubborn at finishing prints since I was finishing up a Chess set for a kid spending his summer in the hospital. Just as it finishes up, it stops extruding material. Since then, I have tried a few times to print a combined filament guide and duster from Thingiverse [1]. It’s time to take another crack at it.

When last I lost patience with my printer, I left its corner adjustments fully tightened down. Needless to say, filament doesn’t stick the best when this happens. I also had a .gcode file loaded with a few changes: the part was in another spot in the bed because of visible wear on the bed, a little cap was omitted as I already have a couple good ones, there is a rectangular structure inspired by a purge block used by multi-filament printers because maybe it’s getting lazy toward the end of the job or something (good luck if nothing else). And as if that weren’t enough, I installed one of my defective filament guides and tied a microfiber to the filament using strings of filament from previous bed level tests.

One more thing –and this is probably the one that actually did it– the print head apart and gave the e-step motor as good of a cleaning as I could get with another microfiber cloth, the long end of an Allen wrench, and a bit of creativity. Once I was convinced I was well past the point of diminishing returns, I put the printer back together and it came out first try.

Weary of a lame sendoff to a project I’ve had multiple weeks ending in failure, I did a bit more background research on 3D printing:

Additive manufacturing caught popular attention in the early 2010’s. Advice shared among 3D printing hobbyists from this period should be followed with caution as widely spread advice, like oiling your filament for lubrication, may have come out as a bad idea in more recent years (for example: oil burning in extruder, making bed adhesion more difficult, and soaking into/destroying filaments). It is for this reason that I am using a dry sponge to dust my filament.

Takeaway

This part took way too long to fabricate. It is my hope that it will silently do its work in preventing so many jams in the long run. I may never know if it is actually of any use. I’d need to alternate between using two identical machines in the same room. That’s not likely to happen unless the one I have is already constantly busy, which would give less time for dust to settle on open spools of filament to begin with. I’m just glad the device is finally in place.

Final Question

What projects have you completed where you may never know how beneficial or useless they are in the end?

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

Work Cited

For my initial post, I was been unable to locate a link to the part I used.

[1] Sleven67, “Dust filter plus filament guide monoprice maker select plus,” Thingiverse.com, Oct. 23, 2020. [Online]. Available: https://www.thingiverse.com/thing:4632282. [Accessed Aug. 11, 2022].

I Made Copies of Archived Floppies

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

The process of archival maintenance can be tedious and repetitive. As disk formats change, it becomes harder to locate adapters for disks with old connection standards. For today’s project, I worked with a USB floppy reader.

It all started when my mother’s Designer Ruby embroidery machine wasn’t as broken as she thought. The machine is quite old by this point, and while discussing what thumb drives we might have that aren’t too big for it to see, my father and I were quickly able to trial an SD card over an adapter (didn’t work) and an external 3¼ floppy disk reader. It wasn’t long before we were pouring over a stash of floppies from a previous embroidery machine and rediscovering old patterns.

My mother spent an afternoon copying the archive to a thumb drive, but a few files were appearently corrupt. I tried to access them on Linux, but the floppy drive was making an unusual pattern of sounds as it accessed the first trouble file. Instead, I very carefully crafted a dd command to dump the contents to an image in my Downloads directory. I repeated the process for each floppy, then mounted it into my file system for extraction.

Out of curiosity, I looked up how it was possible for a user to mount a USB stick if Linux is running mount, a privileged command, underneath the graphics. Long story short, I saw it before while researching an open source driver for our uninterruptible power supplies. Daemons are a type of privileged program that can act on behalf of an underprivileged program without giving it wide, open access to root level permissions. Udisksctl is one such command line utility.

Mounting the disk images proved problematic, producing several errors. Assuming they were permissions related, I tried using udiskctl to mount them as myself instead of root, but instead renamed them with .img and mounted them with Dolphin, a graphical file manager. Turns out the errors really were badly corrupted files, and they still refused to copy out of the disk images, even with the correct permissions. At least it was cleaner this way.

I originally thought I had saved around three of the nine missing files, but one or two of the recovered ones turned upon inspection. I am happy to report that I was able recover the one pattern my mother wanted most. The entire archive will soon end up on GoldenOakLibry, my family’s network storage.

Takeaway

The possibility remains that further attempts at recovery may be viable. Given that the bulk of the collection was archived successfully before I got involved, I will have to ask her if the last few patterns are worth it. In any case, it was nice seeing some of those patterns I remember being stitched out by machine all those years ago. It reminds me of 3D printing in the present day.

Final Question

Have you ever dealt with aging technology to move an archive forward in terms of technological time?

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