{"id":1108,"date":"2022-08-29T12:00:00","date_gmt":"2022-08-29T19:00:00","guid":{"rendered":"https:\/\/letsbuildroboticswithshadow8472.com\/?p=1108"},"modified":"2022-08-29T11:46:44","modified_gmt":"2022-08-29T18:46:44","slug":"i-upgraded-my-python-discord-bot","status":"publish","type":"post","link":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/2022\/08\/29\/i-upgraded-my-python-discord-bot\/","title":{"rendered":"I Upgraded My Python Discord Bot"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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\u2019s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project History<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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\u2019ll also be keeping an old version around to act as a \u201cstable\u201d branch which will have its code integrated into the container itself instead of relying on an attached volume.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">During this week\u2019s 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Total Rewrite<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There is a meme out there where a programmer can write a program such that only he and God know how it works \u2013 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This time, however, I\u2019m 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\u2019t 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Worth noting is that I\u2019m starting to make git commits to savestate my progress. I\u2019m not worrying about proper form right now, but I\u2019m counting on improving over time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Settings Files<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The ability to save\/load data \u2013while not strictly needed for a simple dice bot\u2013 is an important skill to develop. My brief research showed that while there\u2019s 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\u2019ve invented my own scheme before, and it wasn\u2019t fun.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Takeaway<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s 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\u2019d have to say most of the time I spend coding is trying to understand what I just wrote. I still haven\u2019t completed all the features I need, so the plan is to cover the rest of this revamp in next week\u2019s post.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Question<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">What were you working on the first time you successfully extracted a part of your program into a separate document?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Works Cited<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">[1] Shadow_8472, &#8220;My Discord Bot Understands Strange Dice,&#8221; Feb. 28, 2022. <em>letsbuildroboticswithshadow8472<\/em>, [Online]. Available: <a rel=\"noreferrer noopener\" href=\"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/2022\/02\/28\/my-discord-bot-understands-strange-dice\/\" target=\"_blank\">https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/2022\/02\/28\/my-discord-bot-understands-strange-dice\/<\/a> [Accessed Aug. 29, 2022].<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019s 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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/2022\/08\/29\/i-upgraded-my-python-discord-bot\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;I Upgraded My Python Discord Bot&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[92],"tags":[159,158,157],"class_list":["post-1108","post","type-post","status-publish","format-standard","hentry","category-discord-bot","tag-dice-bot","tag-discord-bot","tag-python"],"_links":{"self":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts\/1108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/comments?post=1108"}],"version-history":[{"count":3,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts\/1108\/revisions"}],"predecessor-version":[{"id":1110,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/posts\/1108\/revisions\/1110"}],"wp:attachment":[{"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/media?parent=1108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/categories?post=1108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/letsbuildroboticswithshadow8472.com\/index.php\/wp-json\/wp\/v2\/tags?post=1108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}