Steem Twitter Bot Update: Markdown parser, new commands, basic settings and keywords

in #utopian-io8 years ago (edited)

header

Click here to test this bot.

About a week ago, I introduced Steem Twitter Bot, a project that is, I must admit, quite awkward. If you don't know what it is, it basically aims to make it easy for people to interact with the Steem blockchain through Twitter direct messages. If you want to know why I started working on this project, you can check my first post about it here. First of all, I want to thank the users who decided to give this bot a try. It currently has 6 followers, that's 5 more than what I thought it would have ! Thank you for messing around with it, reporting some bugs to me and giving me some new ideas that would have never crossed my mind. I've had some people telling me that the bot didn't work. It turns out that I misread Twitter's documentation about direct messages. You need to follow the account for it to work, sorry for the inconvenience ! For developers, this post talks about the updates that came through the pull request #1. Also, please forgive me if some explanations sound weird. I have been having the flu for 6 days now and it's making it hard for me to write explanations without getting tired too quickly, resulting in most of them getting shortened. If a part of the post is really too hard to understand, you can still ask about it in the comments ! So now that I've said everything I wanted to say, let's take a look at what's new !

What's new ?

  • Markdown parser

Posts are now parsed before being printed. The parser has been created to make it easier for a user to read the text of a post. Before, it would be printed as the raw text (in Markdown/HTML). Now, words supposed to be in bold are in bold, same for italic. Since Twitter doesn't support styling, those characters are actually Mathematical Alphanumeric Symbols. The problem is that some systems don't support those symbols, which is why I added the possibility to turn them off.

parseTo.png

The parser itself is too big to be shown in a screenshot. You can find it in the parse function from the ./utils/markdownParser.js file if you want to have a look (most of the regular expressions used are variations of regular expressions from famous Markdown parsers). Another function from this file is parseTo which is mainly used by the parser and by the help command. This function is what makes characters bold, italic and/or striked. If styling is not allowed, it won't do anything. Two arrays are used in this function. The mathRefs array contains italic characters as its properties and bold italic characters as its associated values. The refs array contains simple characters as its properties. Each character has an object as its value containing its bold and italic versions.
  • New commands

Let's start with the commands that were added, which are 'comments', 'replies' and 'set'. The 'comments' command prints comments made by a specific user. The 'replies' command prints replies to a specific user. The 'set' command lets the user change some settings for his account. Be careful, this command doesn't work in the same way as others, type 'help set' to learn how to use it ! One subcommand has been added: 'previous'. It simply is the opposite subcommand to 'next'.

image.png

I'm using the public SteemData database to get the comments from and replies to a user. You can see on the screenshot above how it works using the official MongoDB package. It's my first time working with a MongoDB database, I'm more used to working with MySQL and Microsoft SQL. I must say that I like the querying process of MongoDB better ! This is the code for comments, the one for replies is very similar so I won't bother you with it.

image.png

On the screenshot above, you can see the logic used for the 'set' command. It works but it is far from being good. I will have to change it soon because more settings will come and I don't want it to check for each setting separately like it does right now. That's definitely a weak part of the code. As for the 'previous' subcommand, since its code looks like the 'next' subcommand code, I won't talk about it, nothing new really.
  • Basic settings

This is related to the 'set' command introduced above. Right now, two settings are available for users to mess around with: 'steem_account' and 'styling'. The 'steem_account' setting sets a default Steem username, it will be used if no parameter is passed to one of the following commands: blog, feed, comments, replies. The 'styling' setting turns on/off styling for bold and italic characters.

image.png

You can see on this screenshot the part of the code that takes care of the settings. The getSettings function is called once when the bot starts to read the save file ./data/settings.json and put its content in the settings variable. If no file exists, it simply creates it. The saveSettings function is called whenever a setting is changed and saves the setting in the settings object as well as in the ./data/settings.json file.
  • Commands/subcommands keywords

Commands and subcommands now have keywords associated to them. For example, instead of writing 'created gaming' to get a list of newly created posts in #gaming, you can write 'new gaming' or even 'c gaming' ! Those keywords are listed when getting help for a specific command or subcommand.

image.png

The switch has been modified to take these changes into account. To any developer reading this, I'm not sure if that's a good way to approach the keywords or if it's more of a hack. Please, tell me if you have a better idea !

Contributions

If you want to contribute to this project or talk about an issue it has, feel free to visit its GitHub page. You can also clone it and follow the instructions wrote there to get it running. My social medias are listed at the end of the README.md file. If you add me on Steam, tell me the reason why on my wall, otherwise I won't accept your friend request.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.

[utopian-moderator]

keep up the good work !

Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 4 of all contributions awarded today. You can find the TOP DAILY TRUFFLE PICKS HERE.

I upvoted your contribution because to my mind your post is at least 41 SBD worth and should receive 116 votes. It's now up to the lovely Steemit community to make this come true.

I am TrufflePig, an Artificial Intelligence Bot that helps minnows and content curators using Machine Learning. If you are curious how I select content, you can find an explanation here!

Have a nice day and sincerely yours,
trufflepig
TrufflePig

Hey @ragepeanut I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.076
BTC 63599.33
ETH 1666.79
USDT 1.00
SBD 0.43