• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

duxovni/imagebot: mastodon image posting bot

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

duxovni/imagebot

开源软件地址(OpenSource Url):

https://github.com/duxovni/imagebot

开源编程语言(OpenSource Language):

Python 100.0%

开源软件介绍(OpenSource Introduction):

mastodon image bot

A mastodon bot to post cute fanart at regular intervals.

The bot is written in Python 3 and uses Mastodon.py, pybooru and beautifulsoup4. It's based on https://github.com/sipb/mastodon-bot-autoresponder and https://gist.github.com/puphime/8ee151ab0c16945aefbd290be20252ff .

The bot will periodically post random images from Danbooru matching a user-defined set of tags. It also deletes posts when requested to by the maintainer (just reply to a post with the string "$delete"), and forwards any messages it receives to its maintainer as DMs.

Configuration

The bot is configured in a JSON file that looks like this:

{
    "base_url": "https://botsin.space",
    "client_id": "0dd...65d",
    "client_secret": "a7e...6b7",
    "access_token": "9af...d33",

    "post_interval": 30,

    "required_tags": ["rating:s"],
    "forbidden_tags": ["comic", "animated", "sexual_harassment", "nazi", "guro"],

    "message": "I'm just a bot, but I'll forward your message in a DM to my human maintainer:",
    "maintainer": "[email protected]",

    "state_file": "/home/mastodon/imagebot/state"
}

All keys are mandatory.

  • The first group contains information about connecting to the API and authenticating to it.
  • The second group contains the interval in minutes to wait between posting new images.
  • The third group contains a set of tags to search for, and a set of unwanted tags to filter out of the search results. The rating:s tag restricts the search to images that have been tagged as "safe" by Danbooru's users. In practice, this doesn't always necessarily mean safe-for-work, but the images generally don't have full nudity or explicit sexual content. If you remove this tag from the search criteria, you'll probably want to tweak the code to mark the images as NSFW on Mastodon.
  • The fourth group contains the message to respond with when users toot at the bot, and the mastodon handle of the bot's maintainer for passing on messages.
  • The last group contains the path to the state file, which contains informations that lets the bot remember which messages it's already replied to (this cannot be empty, but the file doesn't have to exist the first time you run the bot).

Installation

This should really be packaged as a proper Python package, but I haven't done that. If you want to run this bot:

# 1. clone this repo
git clone [email protected]:duxovni/imagebot.git

# 2. set up a virtual environment for Python and activate it
virtualenv -p python3 env
source env/bin/activate

# 3. install the dependencies
pip install Mastodon.py beautifulsoup4 pybooru python-magic

# 4. use tokentool to register the bot as an app on your server,
# then authenticate to it (don't worry, it's not hard, there's a nice
# interactive text interface)
python tokentool.py

# 5. create a config file and edit it appropriately
cp sample_config.json config.json
nano config.json

# 6. run the bot!
python imagebot.py -c config.json



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
rmanzoku/ansible-kerokero.rororo.xyz: Mastodon instance provisioning playbook发布时间:2022-08-18
下一篇:
shleeable/mastodonideas发布时间:2022-08-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap