[Drugwars] Introducing Mike: Real time battle notifications on Discord

in #utopian-io5 years ago (edited)


Somebody attacks you on @drugwars? Better call mike!


Mike

mike is a Discord bot sends notifications to your discord handle if you get attacked in the @drugwars game. Currently, when somebody attacks you, you have 5-20 minutes of reaction times based on the army of the attacker.

Imagine you're at the office and focusing into your work, and suddenly @ngc attacks you to wipe out your army. The first thing to do is spending in-game resources so they're not exposed for stealing. However, you have still units and you have two options:

  • Fight and die
  • Send your troops to another easy opponent so they don't die.

In order to react fast to that kind of situations, Mike sends notifications (delay time: 5-10 seconds) to your Discord handle. An instance of the bot is currently live at a new Discord Server free to use for any player.

Usage

After joining the discord server send this command in the #bot-commands channel:


$subscribe <player_name>

And you're all set. You can subscribe up to 10 different players. If you want to unsubscribe from a player, you can use $unsubscribe <player_name> and you can see all your subscriptions with $subscriptions.


Help screen


Tech talk: Discord bots, Steem and Non blocking I/O

All the data is streamed from the blockchain, almost real-time.

Since discord.py uses an asyncio eventloop, all functionality of the bot should work with async libraries to avoid blocking calls. The current state of the python libraries for steem is not well in the non-blocking world so using steem-python, beem, or lightsteem was not feasible.

@inertia's amazing meeseeker comes into the play to solve that problem. Since it's possible to subscribe custom jsons with meeseeker, utilizing it helped me remove lots of boilerplate code, and staying in the asyncio loop without any blocking code. (aioredis)


If you want to have a private mike for your own joy in your discord server, you can install the bot on your own.

Installation


$ (sudo) pip install drugwars_mike

Configuration and Running


mike uses meeseeker to stream custom json operations. If you don't have a meeseker yet, you need to install it.

An Example command to run meeseker to have custom json channels:


MEESEEKER_PUBLISH_OP_CUSTOM_ID=true MEESEEKER_EXPIRE_KEYS=300 meeseeker sync

Environment parameters:


VariableDescriptionRequired
MIKE_BOT_TOKENDiscord bot tokenTrue
MIKE_BATTLE_LOG_CHANNEL_IDChannel ID for battle logsFalse
MIKE_DBConnection URI for DBTrue
MIKE_REDIS_HOSTRedis hostTrue
MIKE_REDIS_PORTRedis portTrue


You can run mike by typing:

$ MIKE_BOT_TOKEN=<token> MIKE_DB=sqlite:///mydatabase.db MIKE_REDIS_HOST=localhost MIKE_REDIS_PORT=6379 mike

Repository and License

Repository is located at github/emre/mike and it's licensed under MIT.

Disclaimer

Even though mike works perfectly at the moment, there is no guarantee that it will notify you every time. Due to potential bugs or lags in the backend blockchain streaming, you may miss some notifications. However, I will be doing my best to keep it always working.

Vote for my witness

This is yet another free of charge tool I have developed for the Steem community. If you like what I do, consider casting a vote on via Steemconnect or on steemit.com

Sort:  

Thank you for your contribution. I have to admit that I spent quite some time learning how to play this game, and it is fun!

I have some concerns about the performance. If there are quite a number of subscribers, does this Python library have impact on the server or does it have delays on sending notifications? You might want to have a separate queue for sending notification. The await still blocks the function execution.

Great to see you have tests! You could add some unit tests for historic data, as they are immutable on the steem blockchain which is great to test the TxListener.handle_operation() which I think it is important.

Your code looks great and it is a text-book example for learning Python, Steem Blockchain and how to create a discord bot. Thanks for that.

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? Chat with us on Discord.

[utopian-moderator]

Thank you for your review, @justyy! Keep up the good work!

Also, special thanks to @crokkon, @bitcoinjake09, @louis88 for the initial testing on the bot. :-)

Magic Dice has rewarded your post with a 79% upvote. Thanks for playing Magic Dice.

Excellent!
I don't think the discord link works?

Awesome work, could have come really handy abt an hr ago

Well, you had one battle. There will be more :-)

Agreed, I was thinking about how to build one right after that battle. Atleast a script to just buy units if thr is an attack. Glad you build one on discord. Are you scanning the blockchain to check for attacks?

That's great. Really spices up battles - and very annoying for attackers :D

Posted using Partiko Android

Magic Dice has rewarded your post with a 6% upvote. Thanks for playing Magic Dice.

Hi @emrebeyler!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

You can always call upon @fenrir78 for some support 😂

This is awesome, thank you! :)

Coin Marketplace

STEEM 0.37
TRX 0.12
JST 0.040
BTC 70162.45
ETH 3540.43
USDT 1.00
SBD 4.79