在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):chr-1x/ananas开源软件地址(OpenSource Url):https://github.com/chr-1x/ananas开源编程语言(OpenSource Language):Python 100.0%开源软件介绍(OpenSource Introduction):AnanasWhat is Ananas?Ananas allows you to write simple (or complicated!) mastodon bots without having to rewrite config file loading, interval-based posting, scheduled posting, auto-replying, and so on. Some bots are as simple as a configuration file:
But it's easy to write one with customized behavior:
Run multiple bots on multiple instances out of a single config file:
And use the DEFAULT section to share common configuration options between them:
Getting started
The Simply give it a config file and it'll load your bots and close them safely when it receives a keyboard interrupt, SIGINT, SIGTERM, or SIGKILL.
If you haven't specified a client id/secret or access token, the script will
exit unless you run it with the ConfigurationThe following fields are interpreted by the PineappleBot base classs and will work for every bot: class: the fully-specified python class that the runner script should instantiate to start your bot. e.g. "ananas.default.TraceryBot" domain ¹: the domain of the instance to run the bot on. Must support https connections. Only include the domain, no protocol or slashes. e.g. "mastodon.social" client_id ¹, client_secret ¹: the tokens that the instance uses to identify what client this bot is posting from/as. Will be used to determine what's displayed underneath all the posts made by this bot. access_token ¹: the access token used to authenticate API requests with the instance. Make sure this is secret, don't distribute config files with this field filled out or people will be able to post under the account this token was created with. admin: the full username (without leading @) of the user to DM error reports to.
Can be left unspecified, but is useful for keeping an eye on the health of the
bot without constantly monitoring the script logs. e.g. ¹: Filled out automatically if the bot is run in interactive mode. Additional fields are specific to the type of bot, refer to the documentation for the bot's class for more information about the fields it expects. Writing BotsCustom bot classes should be subclasses of DecoratorsIn order for the bot to do anything, you should add a method decorated with at least one of the following decorators: @ananas.reply: Calls the decorated function when the bot is mentioned by any
other user. Decorator takes no parameters, but should only be called on
functions matching this signature: @ananas.interval(secs): Calls the decorated function every @ananas.schedule(**kwargs): Allows you to schedule, cron-style, the
decorated function. Accepted keywords are "second", "minute", "hour",
"day_of_week" or "day_of_month" (but not both), "month", and "year". If any of
these keywords are not specified, they will be treated like cron treats an *,
that is, as long as the time matches the other values, any value will be
accepted. Speaking of which, the cron-like syntax "*" as well as "*/3" are
both accepted, and will expand to the expected thing: for example,
@ananas.hourly(minute=0), @ananas.daily(hour=0, minute=0): Shortcuts for
@ananas.error_reporter: specifies custom behavior for reporting errors. The
decorated function should match this signature: Overrideable FunctionsYou can also define the following functions and they will be called at the relevant points in the bot's lifecycle: init(self): called before the configuration file has been loaded, so that you can set default values for config fields in case the config file doesn't specify them. start(self): called after all of the internal PineappleBot initialization is complete and the mastodon API is ready to use. A good place to load files specified in the config, post a startup notice, or otherwise do bot-specific setup. stop(self): called when the bot has received a shutdown signal and needs to stop. The config file will be saved after this, so if you need to make any last minute changes to the config, do that here. Configuration FieldsAll of the configuration fields for the current bot are available through the
These can be read (to get the user's configuration data) or written to (to affect the config file on next save) or deleted (to remove that field from the config file). You can call You can also call Note that if you call Distributing BotsYou can distribute bots however you want; as long as the class is available in
some module in python's If you think your bot might be generally useful to other people, feel free to create a pull request on this repository to get it added to the collection of default bots. Questions? Ping me on Mastodon at |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论