![]() ![]() You need to post images or other media.It is merely a shitpost bot who posts hourly, daily, etc.Similarly, bots made with mastobot will be able to listen to events and trigger some actions when a certain event occurs. It takes input, catches certain routes, and gives output. Your bot keeps track of some users it's following.Your bot answers some questions people ask it or.Your bot replies to or interacts with certain posts on its home timeline or.Install via setuptoolsĬlone and cd into this repo, python setup.py install -user. Mastobot is such a good name, it took me eight seconds to come up with it. In this one, it will favboost and reply "brilliant meme!" to a post on its home timeline that resembles a brainsize meme. on_home_update ( "(:hacker_:\s) ", validation = REGEX ) def nice_hacker_font ( status ): return Reply ( "nice hacker font you have", visibility = DIRECT ) bot. on_home_update ( looks_like_brainsize_meme, validation = EVALUATE ) def compliment_meme ( status ): return # invoke when re.search("(:hacker_:\s) ", status_dict) is not None. match ( "^:brain :", ln ): count = 1 if brain_count > 2 : # looks like brainsize meme return True return False # if looks_like_brainsize_meme(status_dict) = True, # invoke compliment_meme. splitlines () brain_count = 0 for ln in lines : if re. Advanced usage from mastobot import * import re bot = Bot ( instance_url = "", access_token = "your_access_token", ) def looks_like_brainsize_meme ( content : str ): lines = content. on_mention ( "hi" ) def respond_to_hi ( status ): name = status. See? Three (3) characters saved! Examples Basic usage from mastobot import Bot bot = Bot ( instance_url = "", access_token = "your_access_token", ). Moreover, Mastobot wraps awkward Mastodon.py dict objects into fancy NamedTuples, which grants you the power to access attributes via dots ( obj.attr), not brackets and quoted strings ( obj). Instead, you can save yourself from this cloggy syntax and spaghetti-prone code structure with Mastobot, because it takes care of listener registration and event handling, allowing bot devs to build modularized 2nd-level (1 level of indent) blocks of code. Mastobot exists to get rid of this problem. See, as attempts are made to expand the amount of event handlers, complexity quickly accumulates. status_reply ( ntf, post ( req )) elif content. status_reply ( ntf, get ( req )) elif content. class Listener ( StreamListener ): def on_notification ( self, ntf ): if ntf = "mention" : content = html_to_text ( ntf ) req = content. Here is a code excerpt, using the stock Mastodon.py library, which is undoubtedly amazing but somewhat painful to write clean code with. You're welcome to contribute if you do (see HACKING.md). It also aims to be beginner-friendly, even (especially) those who don't understand decorators. Just write your own bot from scratch if you want juicy features. Mastobot is suitable for bots which do not require intensive interaction, e.g. Consider your use cases before adopting this library (consult §Use cases). Nothing in this project is set in stone except that it's for cheap bots only. ![]()
0 Comments
Leave a Reply. |