mastobots

package module
v0.0.0-...-6d9f25d Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 27 Imported by: 0

README

mastobots

お好みの単語が含まれるRSSアイテムを探し、コメントをつけて定期的にトゥートするbotです。メンションに反応するなどの機能もあります。

MySQLデータベースに保存された日本語のRSSアイテムをJuman++で形態素解析し、好みの単語をその結果と照合します。

データベースには別途、feedAggregatorなどを使ってRSSアイテムを読み込んでおく必要があります。

設定ファイル(config.yml)にbotごとの情報を記入すれば、何匹でもbotを駆動することができます。

依存ソフトウェア

以下があらかじめインストールされていないと起動しません。

機能

  • トゥートの間隔、コメント、好みの単語などをカスタマイズ可能。
  • 「いい(+bot固有の語尾)」とメンションすると、背中を押したり押さなかったりしてくれる。
  • botに「フォロー」を含んだメンションをすると、botがフォローしてくる。
  • botに場所と時間(今、今日、明日、明後日)を指定して天気を尋ねると、OpenWeatherMapからの情報を教えてくれる。「体感」という言葉を含めて尋ねると体感気温を返してくる。
  • 寝る。寝ている間はトゥートも反応もしない。寝ている間に通知が来ていたら、起きた時に対応する。就寝時刻と起床時刻は自由に設定可。二つを同時刻に設定すれば、寝ない。
  • 設定ファイルでLivesWithSunをtrueに設定すると、LatitudeとLongitudeで指定した地点での太陽の出入り時刻に応じて寝起きする。ジオコーディングデータはYahoo! YOLP APIから、時刻はSunrise Sunsetからそれぞれ取得。
  • 設定ファイルでRandomFrequencyをゼロ以上にし、かつRandomTootsに1つ以上の文字列を指定すると、不定期に指定文字列のいずれかを呟く。(この機能を使わない場合は、RandomFrequencyはゼロに設定し、かつRandomTootsには空の配列要素を1つ設定してください)
  • -p <整数> オプション付きで起動すると、<整数>分限定で起動する。

使い方

  1. 下準備:database_tables.sql の記載に従って、MySQLデータベースにテーブルを作成する。定期的にfeedAggregatorなどを使ってRSSアイテムを収集しておく。
  2. cmd/mastobots フォルダで go get、go build すると、フォルダに mastobots コマンドができる。
  3. config.yml.example を config.yml にリネームまたはコピーし、自分の環境に応じて書き換えるあるいは追記する。
  4. ./mastobots で起動。screenなどと併用するか、systemdでサービス化してください。

クレジット

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 MastoApp

type MastoApp struct {
	Server       string
	ClientID     string
	ClientSecret string
}

MastoApp は、Mastodonクライアントの情報を格納する。

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
	MyApp           *MastoApp
	Email           string
	Password        string
	Client          *mastodon.Client
	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

Jump to

Keyboard shortcuts

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