DevLog: The Evolution of @reminder.ping - My `!RemindMe` Bot

in Hive Learners4 months ago (edited)

This Devlog is the first part of explaining y process developing @reminder.ping! The !RemindMe Bot for Hive Blockchain! You can check its announcement post here! I'll make a detailed post for how to use it later. إن شاء الله

Stage 1: The Beginning – Grabbing the Idea and Running With It

So, it all started with a simple idea: A reminder bot for HIVE, where people could drop a !RemindMe comment, and they’d get a ping back at their requested time. This is inspired by a bot that does the same on Reddit. I always wanted one for our blockchain!

Developing it wasn't easy though...

First hurdle: how do I even listen to comments on the blockchain efficiently without constantly hammering the API? In my first attempt, I used to fetch one block at a time... I knew I’d need to process blocks in batches to keep things efficient.

I threw together a listener script that parsed comments. The API gave me information in JSON format, so I was able to parse them well, but I quickly realized I was missing a critical piece—timestamps. That’s when the block_timestamp came into play. The comments data didn't have a timestamp value. Just take it from the block itself. Problem solved!


Stage 2: Taming Time Parsing

Next came the hard part—time parsing. People don’t speak "computer" when it comes to time. They say things like “in 2 days” or “next Friday.” So I needed my bot to understand both relative times (like "in 3 hours") and specific dates ("on the 12th of April").

Initially, I built a function to parse time strings manually using regex, tackling cases like "in {number} {unit}". But soon enough, I hit a wall when it came to handling actual dates. I solved that with dateutil.parser. That library became my go-to for parsing those more complex date formats. The bot could now recognize both relative and specific times. Well, to a certain degree, anyway. There's still room to improve.


Stage 3: The Refining Process – Regex and Time Formats

Okay, cool, I had dateutil.parser handling time parsing, but there were still some edge cases I hadn’t covered. For example, what if someone said "on the 12th" without specifying a month? Or "on 5th of July"? That’s when I really had to dive deep into regex, making sure it could catch patterns like:

  • “on {amount}st/nd/rd/th”
  • Optional "of {month}" after the date.

I threw this regex at the time string and only passed it to dateutil.parser if the string matched these patterns. This made sure I didn’t overload the parser with random junk. That regex saved me from parsing nonsense. On the other hand, it also prevented parsing some legitimate patterns. I should improve on this in later versions!


Stage 4: Dealing with Midnight and Missing Times

Here's a fun one: When someone provides a specific date to the !RemindMe bot it defaults to 00:00:00 (midnight) of the chosen date. I didn't like that. So, if the time didn’t include hours, minutes, or seconds, I made sure the bot needed to fill in the blanks using the block’s timestamp to keep things accurate. That way, if someone said "on the 12th of April," but didn't provide a time, my bot would replace midnight with the exact time from the block the comment was posted in.


Stage 5: Crossing the Year Barrier

Another fun issue popped up—what if someone set a reminder for a month that had already passed this year? I needed the bot to push that reminder into the next year. So, if someone said "on July 5th" but it's currently August, the bot needed to set the reminder for July 5th next year. Simple, right? After catching this bug, I added logic that checks if the parsed month is in the past and bumps the year forward if needed.


Stage 6: Error Handling and Replies

One of my biggest pet peeves was when the bot failed silently. So, I made sure to add robust error handling across the board. If the time string couldn’t be parsed, the bot would kindly reply with a message saying, "Couldn't parse the time. Please use a valid format like 'in 2 hours' or 'on 12th of April'."

Nothing's more frustrating than not knowing why something failed, so this was a huge quality-of-life improvement. Again, even this still needs improvements.

And since timing is important for a reminder bot, I added a 3-second delay before each successful reply, just to space things out and prevent overloading the blockchain with too many comments in a short span.


Stage 7: Making It All Work Together

At this point, the code was a whole lot smarter. The bot now:

  1. Listens for !RemindMe comments.
  2. Extracts the relevant time strings (both relative and specific).
  3. Uses custom regex and dateutil.parser to handle all sorts of time formats.
  4. Ensures times in the past are treated as if they’re in the future.
  5. Handles (some) errors by replying to users if something goes wrong.
  6. Adds a neat delay between comments to avoid spamming.

Oh, and let's not forget, the whole thing now runs based on a blacklist to avoid annoying users who don't want to be reminded by the bot.


Stage 8: What’s Next?

So, yeah, that’s the begining journey. From simple beginnings to building a much smarter bot, this has been a wild ride. After all these updates, I needed to make sure the bot worked from a server. But that's a story for another Devlog.

Desclaimer: Honestly, I couldn’t have gotten here without help from AI. It did most of the coding, but I made sure I learned every step along the way. It's amazing what ChatGPT can do for problem-solving!

Thanks for following along, and stay tuned for more updates!


- This devlog was co-written with ChatGPT AI. The post's image was generated with Ideogram!

Posted Using InLeo Alpha

Posted Using InLeo Alpha

Sort:  

You did amazingly well. We are glad to know ChatGPT was of great help. AI is here to transform our lives and we admire that you channelled its resources to building this bot. Well done. We'll be looking forward to more of your Devlog. Congrats on this one.

Thanks for reading... If you have any suggestion, feel free to post it here. I'm in the process of compiling ideas for future implementation.

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.