The Magic Frog in French (Development Update #4) by helo

in #utopian-io6 years ago

Repository:

https://github.com/mktcode/the-magic-frog

image.png

New Features

  • Testing options in an immutable world
  • Formatting output for winning post
  • Curators by Story for proper reward
  • dotenv, making our lifes easier
  • eslint is the new master in town

Testing the bot for its output

The bot script that votes, makes daily posts and in the end distributes the SBD after selecting a winner is key in the magic frog project. To be able to repetitively test the output when the stories end, I needed a way to prevent actions on the blockchain from occurring. I then proceeded to create a new environment variable BOT_PROD=false and set it to false when I'm developing.

I proceeded by encompassing all blockchain actions within an if statement:
image.png

Formatting output for winning post

Knowing that the French story was coming to an end, I prepared the bot to produce the winning log and SBD distributions in a markdown way.

Some adaptations were needed, for example we did not need percentage to be push on the stack before, now we do.
image.png

It does not look like much in the shell, but wait to see what happens on Steemit or Busy!
image.png

Checkout the results of the winning announcement post for a reveal of the efforts I put in.

Curators by Story for proper reward

Curator calculations are simple for the Hall-of-fame on the portal, but for rewarding curators when the story ends, we needed to pass the story number we want the curators from. That meant to extend the API and pass a new parameter from the bot.

From the-magic-story-machine side: image.png

From the-magic-link API side either from all stories or just a specific one: image.png

dotenv, making our lifes easier

I implemented dotenv in all 3 repositories, it's one thing less to remember to source the environment variables before running the scripts and a more standardised way that will simplify development as we bring more people on board. (A Portuguese frog coming soon! @sapo-magico)

To get this running is a 2 step process to get your process.env.VARIABLES automagically loaded from a .env file.

  • run this command to install: npm i dotenv --save
  • insert this at the top of you main js file: require('dotenv').config();

eslint and the new master in town

Following a suggestion from @gregory.latinier on a development article from master @mkt, I decided to implement eslint on all 3 repositories of the project. A lot of changes ensued.

To get started after the installation using npm install eslint --save-dev, you need to run the configuration wizard ./node_modules/.bin/eslint --init then supplement the configuration file with you project specific requirements.

image.png

I added a new script command so that we can easily lint the code by doing this: npm run lint

There was a lot of refactoring to stop eslint from complaining issuing errors. Just like below: [no-loop-func] [no-prototype-builtins] [prefer-const]
image.png

A few more rules made me switch things around. [prefer-destructuring] for the account variable and [radix] add the base 10 as an extra parameter of parseInt, who knew that was needed? :

For the-magic-frog I had to ignore a few directories since they are generated on the fly and should not be linted.

Previous contributions in this series

How to contribute

Simple! 1. fork, 2. modify, 3. submit a pull request to the official repository.

Repositories

Proof of work

GitHub Account

https://github.com/gluneau

To see the changes in action... PARTICIPATE!

Visit:
the-magic-frog.com or
fr.the-magic-frog.com

Sort:  

Thank you for your contribution. It is nice to see the Eslint modern syntax, which makes the JS prettier. Is there any reason to explicitly pass 10 to parseInt?

+1 for the async/await.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

I would really like your advise on how I could make the overall presentation of my post of very high quality.

Also what is your option as to what should be considered a high volume of work.

Thanks for your review @justyy.

Right here @justyy, it's the radix rule of eslint:

Cool, thanks!

Thank you for your review, @justyy!

So far this week you've reviewed 2 contributions. Keep up the good work!

Hi @helo! We are @steem-ua, a new Steem dApp, computing UserAuthority for all accounts on Steem. We are currently in test modus upvoting quality Utopian-io contributions! Nice work!

Thanks @steem-ua, say hi to @scipio for me. I love his work.

Likewise @helo! :-)

Hey @helo
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 17 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 12 SBD worth and should receive 64 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

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.029
BTC 58010.39
ETH 2457.12
USDT 1.00
SBD 2.34