tankabot

package module
v0.0.0-...-062e87e Latest Latest
Warning

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

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

README

tankabot

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

依存ソフトウェア

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

機能

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

使い方

  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 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 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
	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

Jump to

Keyboard shortcuts

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