mastobots

package module
v0.0.0-...-2a8a1f7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mastobots

en ja

A customizable Mastodon bot that periodically retrieves RSS feed items containing specified keywords, analyzes them in Japanese (using Sudachi) or English (using Prose), and then posts automatically-generated Japanese comments. It also responds to mentions and provides weather information.

RSS feed items are stored in a MySQL database and analyzed for relevant keywords. Japanese items are parsed with Sudachi, and English items are processed using Prose, but all posts are generated in Japanese.

Populate RSS items into the database beforehand using tools such as feedAggregator.

Configure multiple bots simultaneously via the config.yml file.

Dependencies

Install the following before running:

  • MySQL
  • A Sudachi HTTP API reachable over the LAN that returns every Sudachi -a field (POST /v1/analyze)

Features

  • Supports Japanese and English RSS feed items (all posts in Japanese).
  • Highly customizable posting intervals, comments, and keywords.
  • Responds positively or negatively to mentions containing the keyword "いい" plus a bot-specific suffix.
  • Automatically follows users who mention it with the word "フォロー" (follow).
  • Provides weather forecasts for requested location and time (current, today, tomorrow, day after tomorrow) using OpenWeatherMap. Mention "体感" (feels-like) to get perceived temperature.
  • Configurable sleeping/waking hours. The bot is inactive during sleep hours. Set identical times to stay active continuously.
  • With LivesWithSun set to true, sleep cycles synchronize to local sunrise/sunset based on latitude/longitude (Yahoo! YOLP API required).
  • Randomly timed posts enabled via RandomFrequency and defined in RandomToots.
  • Run the bot for a limited time using the -p <minutes> option.

Usage

  1. Import the schema (database_tables.sql) into your MySQL database and periodically populate RSS items (e.g., using feedAggregator).
  2. In cmd/mastobots, run go build to compile the mastobots binary.
  3. Copy config.yml.example to config.yml and edit accordingly.
  4. Set SudachiAPIURL in config.yml to the Sudachi HTTP API analysis endpoint (for example, http://sudachi-host:8080/v1/analyze). Adjust SudachiAPITimeout if necessary. The actual config.yml is excluded from version control.
  5. Launch the bot with ./mastobots. Using systemd or screen for background execution is recommended.

Set NumConcurrentLangJobs no higher than the API's SUDACHI_API_MAX_CONCURRENT to reduce queueing and timeouts inside the API. Sudachi split mode B is used.

Credits

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActivateBots

func ActivateBots(bots []*Persona, db DB, p int) (err error)

ActivateBots は、botたちを活動させる。

func Initialize

func Initialize() (bots []*Persona, db DB, err error)

Initialize は、config.ymlに従ってbotとデータベース接続を初期化する。

Types

type DB

type DB struct {
	*sql.DB
}

DB は、データベース接続を格納する。

type Item

type Item struct {
	ID      int
	Title   string
	URL     string
	Content string
	Summary string
	Keyword string
	Updated time.Time
}

Item は、itemsテーブルの行データを格納する

type Notifications

type Notifications []*mastodon.Notification

func (Notifications) Len

func (ns Notifications) Len() int

func (Notifications) Less

func (ns Notifications) Less(i, j int) bool

func (Notifications) Swap

func (ns Notifications) Swap(i, j int)

type OWForcast

type OWForcast struct {
	Dt        int64       `json:"dt"`
	Temp      interface{} `json:"temp"`
	FeelsLike interface{} `json:"feels_like"`
	Pressure  int         `json:"pressure"`
	Humidity  int         `json:"humidity"`
	WindSpeed float64     `json:"wind_speed"`
	WindDeg   int         `json:"wind_deg"`
	Weather   []struct {
		ID          int    `json:"id"`
		Main        string `json:"main"`
		Description string `json:"description"`
		Icon        string `json:"icon"`
	} `json:"weather"`
}

OWForcast は、OpenWeatherMapからの天気予報データを格納する

func GetLocationWeather

func GetLocationWeather(weatherKey string, lat, lng float64, when int) (data OWForcast, err error)

GetLocationWeather は、指定された座標の天気をOpenWeatherMapで取得する。 when: -1は今、0は今日、1は明日、2は明後日

type OWForcasts

type OWForcasts struct {
	Current OWForcast   `json:"current"`
	Daily   []OWForcast `json:"daily"`
}

OWForcasts は、OpenWeatherMapからの天気予報データを格納する

type Persona

type Persona struct {
	Name            string
	Instance        string
	Client          *mastodon.Client
	AccessToken     string
	MyID            mastodon.ID
	Title           string
	Starter         string
	Assertion       string
	FirstFire       int
	Interval        int
	ItemPool        int
	Hashtags        []string
	Keywords        []string
	Comments        []string
	DBID            int
	WakeHour        int
	WakeMin         int
	SleepHour       int
	SleepMin        int
	LivesWithSun    bool
	Latitude        float64
	Longitude       float64
	PlaceName       string
	TimeZone        string
	RandomToots     []string
	RandomFrequency int
	Awake           time.Duration
	// contains filtered or unexported fields
}

Persona は、botの属性を格納する。

type SunInfo

type SunInfo struct {
	Results struct {
		Rise string `json:"civil_twilight_begin"`
		Set  string `json:"civil_twilight_end"`
		Noon string `json:"solar_noon"`
	} `json:"results"`
}

SunInfo は、日の入りと日の出時刻を格納する

type YahooContentsGeoCoderResults

type YahooContentsGeoCoderResults struct {
	ResultInfo struct {
		Count int `json:"Count"`
	} `json:"ResultInfo"`
	Feature []struct {
		Name     string `json:"Name"`
		Geometry struct {
			Coordinates string `json:"Coordinates"`
		} `json:"Geometry"`
		Property struct {
			Address string `json:"Address"`
		} `json:"Property"`
	}
}

YahooContentsGeoCoderResults は、YahooコンテンツジオコーダAPIからのデータを格納する

type YahooPlaceInfoResults

type YahooPlaceInfoResults struct {
	ResultSet struct {
		Result []struct {
			Name     string `json:"Name"`
			Where    string `json:"Where"`
			Combined string `json:"Combined"`
		} `json:"Result"`
	} `json:"ResultSet"`
}

YahooPlaceInfoResults は、Yahoo場所情報APIからのデータを格納する

Directories

Path Synopsis
cmd
mastobots command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址