tankabot

package module
v0.0.0-...-9a2be23 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 25 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

tankabot

自分がフォローしているアカウントの投稿から短歌(五七五七七)になっている部分を見つけ出し、リプライでお知らせする Mastodon ボットです。俳句検出botの亜流です。

依存ソフトウェア

以下があらかじめ利用可能でないと起動・動作しません。

  • MySQL
  • Sudachi HTTP API(既定値 http://localhost:8080、分割モードB)

Sudachi APIの接続先とタイムアウトは、config.yml の SudachiAPIURL と SudachiAPITimeout で変更できます。接続先にはベースURLを指定し、botが /v1/analyze を付加します。

Sudachiの品詞階層は sudachidict_full v20260723 の全52種類を監査済みです。未監査の品詞階層が辞書更新やユーザー辞書によって返された場合は、誤判定を続けず解析エラーとして扱います。辞書更新後の実API互換性は次で確認できます。

TANKABOT_SUDACHI_API_URL=http://localhost:8080 go test -run TestLiveSudachiAPICompatibility

機能

  • ホームタイムラインにいるアカウントの投稿を見守って短歌を検出する。
  • フォローすると自動でフォローバックしてくる。
  • 「フォロー解除」とメンションするかDMすると、フォローを解除してくる。
  • 寝る。寝ている間はトゥートも反応もしない。寝ている間に通知が来ていたら、起きた時に対応する。就寝時刻と起床時刻は自由に設定可。二つを同時刻に設定すれば、寝ない。
  • 設定ファイルでLivesWithSunをtrueに設定すると、LatitudeとLongitudeで指定した地点での太陽の出入り時刻に応じて寝起きする。ジオコーディングデータはYahoo! YOLP APIから、時刻はSunrise Sunsetからそれぞれ取得。
  • 設定ファイルでRandomFrequencyをゼロ以上にすると、不定期にネットの記事から短歌を拾って呟く。(この機能を使わない場合は、RandomFrequencyはゼロに設定してください)
  • -p <整数> オプション付きで起動すると、<整数>分限定で起動する。

句切り確認コマンド

cmd/kugiri は、任意の文字列をbotと同じ規則で区切り、各単位の拍数と検出された短歌を表示します。

go build -o kugiri ./cmd/kugiri
./kugiri -api-url http://localhost:8080 '解析する文字列'

文字列は標準入力からも渡せます。接続先は TANKABOT_SUDACHI_API_URL 環境変数でも指定できます。

echo '解析する文字列' | TANKABOT_SUDACHI_API_URL=http://localhost:8080 ./kugiri

使い方

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

クレジット

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActivateBot

func ActivateBot(bot *Persona, db DB, p int) (err error)

ActivateBot は、botを活動させる。

func Initialize

func Initialize() (bot 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
	Songs   string
	Updated time.Time
}

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

type KugiriResult

type KugiriResult struct {
	Segments []KugiriSegment
	Tankas   string
}

KugiriResult contains tankabot's segmentation and any detected tankas.

func AnalyzeKugiri

func AnalyzeKugiri(ctx context.Context, text, apiURL string, timeout time.Duration) (KugiriResult, error)

AnalyzeKugiri runs the same Sudachi mode-B analysis and boundary rules used by the bot. The API URL is a base URL; /v1/analyze is appended automatically.

type KugiriSegment

type KugiriSegment struct {
	Surface     string
	MoraCount   int
	CanStart    bool
	SentenceTop bool
	NounOnly    bool
}

KugiriSegment is one unit at whose beginning tankabot may place a ku boundary.

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 Persona

type Persona struct {
	Name            string
	Instance        string
	Client          *mastodon.Client
	AccessToken     string
	MyID            mastodon.ID
	Title           string
	Starter         string
	Assertion       string
	ItemPool        int
	MorningComments []string
	EveningComments []string
	Hashtags        []string
	DBID            int
	WakeHour        int
	WakeMin         int
	SleepHour       int
	SleepMin        int
	LivesWithSun    bool
	Latitude        float64
	Longitude       float64
	PlaceName       string
	TimeZone        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
kugiri command
tankabot command

Jump to

Keyboard shortcuts

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