libs

package
v0.0.0-...-7f00f21 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ISTEST           = false
	ISSAVETODATABASE = true

	ISHEADLESSMODE = true
)
View Source
const LIMITXPOSTCHAR = 141

Variables

View Source
var (
	PASSWORDCONTROLLER []byte
)
View Source
var (
	// TOMORROW 起動時の次の日
	// why: 起動時明日の予約投稿を取得する
	TOMORROW = time.Now().AddDate(0, 0, 1)
)

Functions

func DownloadGCSFile

func DownloadGCSFile(url string) (string, error)

DownloadGCSFile はGCS URLからファイルをダウンロードし、一時ファイルを作成してパスを返す

func FluctuationPostTime

func FluctuationPostTime(t time.Time) time.Time

FluctuationPostTime 投稿時間の変更 設定投稿時間に分単位の前後ゆらぎを持たせる Ruleが即時投稿の場合は、即時投稿

func GetAccounts

func GetAccounts(ctx context.Context, store *firestore.Client) ([]models.Account, error)

GetAccounts 購読設定なしを除いたアカウント情報を取得

func GetGroups

func GetGroups(ctx context.Context, store *firestore.Client, account models.Account) ([]models.Group, error)

func GetInfoForAccount

func GetInfoForAccount(ctx context.Context, store *firestore.Client, account models.Account) (*models.Rule, []models.Schedule, error)

GetInfoForAccount 購読設定なしを除いたアカウント情報(Rule, Schedules)を取得 Scheduleは起動日の次の日予定された投稿を取得(owner_id) 日時指定取得は行わない

func GetPost

func GetPost(ctx context.Context, store *firestore.Client, postId string) (*models.Post, error)

GetPost 投稿情報を取得 本日の予定された投稿を取得 if checked, is_deleted, post_id is not match, return error

func GetPosts

func GetPosts(ctx context.Context, store *firestore.Client, account models.Account) ([]models.Post, error)

func GetPostsIsSchedule

func GetPostsIsSchedule(ctx context.Context, store *firestore.Client, account models.Account, rule models.Rule) ([]models.Post, error)

GetPostsIsSchedule 投稿情報を取得

func GetRule

func GetRule(ctx context.Context, store *firestore.Client, accountId string) (*models.Rule, error)

GetRule ユーザルールを取得 ユーザルールのIsEnableを確認する

func IsBlue

func IsBlue(s string) bool

文字数での判定

func IsLastCheck

func IsLastCheck(post models.Post) bool

func IsPosting

func IsPosting(termhours int, post models.Post) bool

func IsTime

func IsTime(now time.Time, timings []string) bool

IsTime 予約投稿の時間かどうか

func NewError

func NewError(fn string, err any) error

func NewGotwiClient

func NewGotwiClient(accesstoken, accesssecret string) (*gotwi.Client, error)

func SelectPosts

func SelectPosts() (int, error)

SelectPosts 明日の投稿を選別し、Tasksに登録 Taskはユーザーごとに登録される、そのユーザーの当日の予約投稿を登録 Taskには当日の予約投稿のPostIDsを登録、当日の予約投稿のタイミングを登録し、当日PostIDによってデータベース参照、Postを実行

func TimeToKey

func TimeToKey(t time.Time) string

TimeToKey 時間をキーに変換 UTC時間でキーを作成 (15:04UTC)

func UploadImage

func UploadImage(api *anaconda.TwitterApi, filename string) (string, error)

func UploadMedias

func UploadMedias(accessToken, accessSecret string, filenames ...string) ([]string, error)

func UploadVideo

func UploadVideo(api *anaconda.TwitterApi, filename string) (string, error)

Types

type Client

type Client struct {
	Firestore *models.ClientForFirestore

	PasswordController []byte
}

func NewClient

func NewClient() *Client

func (*Client) GetAccounts

func (p *Client) GetAccounts(hour int) ([]models.Account, error)

func (*Client) GetPosts

func (p *Client) GetPosts(account models.Account) ([]Post, error)

func (*Client) ToDecrypto

func (p *Client) ToDecrypto(account models.Account, post *Post) error

type Post

type Post struct {
	AccessToken  string
	AccessSecret string
	Password     string

	*models.Post
}

func (*Post) Do

func (p *Post) Do() error

func (*Post) DoAPI

func (p *Post) DoAPI() error

func (*Post) DoGUI

func (p *Post) DoGUI() error

DoGUI: GUI for blue

func (*Post) DoTestAPI

func (p *Post) DoTestAPI() error

func (*Post) DoTestGUI

func (p *Post) DoTestGUI() error

DoTestGUI GUI for blue

type Selector

type Selector struct {
	Account models.Account
	Rule    models.Rule

	// アカウントが保持する情報を全部取得
	Schedules []models.Schedule
	Group     []models.Group
	Posts     []models.Post
}

Selector 本日の投稿を選別するための構造体 まずは全ての情報を取得する

func GetSelectors

func GetSelectors(ctx context.Context, store *firestore.Client) ([]Selector, error)

# database - GetSelectors: アカウントと付帯情報を取得 - GetAccounts: アカウント情報を取得 - GetInfoForAccount: アカウント情報(Rule, Schedules)を取得 - GetPostsIsSchedule: 投稿情報を取得 - GetPosts: 投稿情報を取得 - GetGroups: グループ情報を取得 - GetPost: 投稿情報を取得

func (*Selector) ToTask

func (s *Selector) ToTask() (*TaskForSchedule, error)

ToTask 明日の予約投稿の準備を行う Selectorには、ユーザーごとの情報が格納されている TODO: Rule指定の当日ランダム投稿はどうするか 指定ルール、指定スケジュール、指定投稿を選別し、TaskForScheduleに格納

type TaskForSchedule

type TaskForSchedule struct {
	IsSchedule bool           `firestore:"is_schedule,omitempty" json:"is_schedule,omitempty"`
	Account    models.Account `firestore:"account,omitempty" json:"account,omitempty"`
	Rule       models.Rule    `firestore:"rule,omitempty" json:"rule,omitempty"`

	// 当日予定された投稿
	Schedules []models.Schedule `firestore:"schedules,omitempty" json:"schedules,omitempty"`
	Group     []models.Group    `firestore:"group,omitempty" json:"group,omitempty"`
	Posts     []models.Post     `firestore:"posts,omitempty" json:"posts,omitempty"`

	TimingForSchedules []string `firestore:"timing_for_schedules,omitempty" json:"timing_for_schedules,omitempty"`
	TimingForRules     []string `firestore:"timing_for_rules,omitempty" json:"timing_for_rules,omitempty"`

	TimingForSearch []string `firestore:"timing_for_search,omitempty" json:"timing_for_search,omitempty"`
}

firestore collection, document nameをどう定義するか 当データをどう定義するか、どのようなデータを取得するか 希望としては、ユーザーごとの処理を記述し、 そのユーザーのスケジュール、ルール、投稿を取得する ユーザが与薬した投稿があるかどうかに絞る Keyはユーザー名とする 投稿時は、当コレクションを取得すれば、全ユーザーの情報が手に入る where: account.id == account.id, in_array(timing_for_schedules, timing_for_rules)

func GetTasks

func GetTasks(ctx context.Context, store *firestore.Client, t time.Time) ([]TaskForSchedule, error)

GetTasks 前日に整理取得した本日の予約投稿を取得 ユーザ情報とRule, Schedule, Postが含まれる

func (*TaskForSchedule) DoForRule

func (task *TaskForSchedule) DoForRule() error

DoForRule Ruleの投稿処理 当該時刻の投稿は1つのみ IsSchedule == falseの投稿のみ抽出し、その中から一つ選択する

func (*TaskForSchedule) DoForSchedule

func (task *TaskForSchedule) DoForSchedule(t time.Time) error

DoForSchedule 予約投稿の処理 複数個ある場合を含むSchedulesに対する投稿を行う

func (*TaskForSchedule) Done

func (task *TaskForSchedule) Done(post *models.Post) error

Done 投稿完了後の処理 投稿完了後、taskのPostを除外し、task及びpost.Count/LastPostedAtを更新する

func (*TaskForSchedule) Post

func (task *TaskForSchedule) Post(post *models.Post) error

Post 共通の投稿処理 To Blue GUI, To APIの分岐を行う

func (*TaskForSchedule) Update

func (task *TaskForSchedule) Update(ctx context.Context, store *firestore.Client, post *models.Post) error

Update task及びpostの更新

Jump to

Keyboard shortcuts

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