ifunny

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: AGPL-3.0 Imports: 9 Imported by: 2

README

TODO

  • move over the chat library code from discovery-bot
  • move over the feed scouring code from psyduck-etl/ifunny
  • basic crawling stuff: getting content ( from feeds, explore, timelines ), observe users, comments
  • channels for streaming crawl-able content ( think iterators from the node library ), using golang-set Iterators might make sense here

Not TODO

  • auth - supply your own basic / bearer token
  • writable api - might accept patches, but this intends to be primarily a read-only package
  • extra features - this library only aims to support core iFunny features

Documentation

Index

Constants

View Source
const (
	UNK_0 messageType = iota
	TEXT_MESSAGE
	UNK_2
	JOIN_CHANNEL
	EXIT_CHANNEL
)
View Source
const (
	CONTENT_PIC        = "pic"
	CONTENT_VIDEO_CLIP = "video_clip"
	CONTENT_COMICS     = "comics" // created from the in-app comic maker
)

TODO types of content, missing a bunch of content types an enum type when we have all of them ( will we ever? )

View Source
const (
	EVENT_UNKNOWN = -1
	EVENT_JOIN    = 100
	EVENT_EXIT    = 101
	EVENT_MESSAGE = 200
	EVENT_INVITED = 300
)
View Source
const (
	LogLevel = logrus.InfoLevel
)

Variables

This section is empty.

Functions

func JSONDecode

func JSONDecode(data, output interface{}) error

Types

type APIError added in v0.0.4

type APIError struct {
	Kind        string `json:"error"`
	Description string `json:"error_description"`
	Status      int    `json:"status"`
}

func (APIError) Error added in v0.0.4

func (e APIError) Error() string

type Chat

type Chat struct {
	// contains filtered or unexported fields
}

func (*Chat) Call

func (chat *Chat) Call(desc turnpike.Call, output interface{}) error

func (*Chat) GetChannel

func (chat *Chat) GetChannel(call turnpike.Call) (*ChatChannel, error)

func (*Chat) GetUsers

func (chat *Chat) GetUsers(desc turnpike.Call) ([]*User, error)

func (*Chat) IterMessages

func (chat *Chat) IterMessages(desc turnpike.Call) <-chan Result[*ChatEvent]

func (*Chat) ListMessages

func (chat *Chat) ListMessages(desc turnpike.Call) ([]*ChatEvent, int64, int64, error)

func (*Chat) OnChanneEvent

func (chat *Chat) OnChanneEvent(channel string, handle func(event *ChatEvent) error) (func(), error)

func (*Chat) OnChannelInvite

func (chat *Chat) OnChannelInvite(handle func(eventType int, channel *ChatChannel) error) (func(), error)

func (*Chat) OnChannelUpdate

func (chat *Chat) OnChannelUpdate(handle func(eventType int, channel *ChatChannel) error) (func(), error)

func (*Chat) Publish

func (chat *Chat) Publish(desc turnpike.Publish) error

func (*Chat) Subscribe

func (chat *Chat) Subscribe(desc turnpike.Subscribe, handle EventHandler) (func(), error)

type ChatChannel

type ChatChannel struct {
	Name          string `json:"name"`
	Title         string `json:"title"`
	MembersOnline int    `json:"members_online"`
	MembersTotal  int    `json:"members_total"`

	Type      compose.ChannelType      `json:"type"`
	JoinState compose.ChannelJoinState `json:"join_state"`
	Role      compose.ChannelRole      `json:"role"`
	TouchDT   int64                    `json:"touch_dt"` // maybe when we last were online ??

	User struct {
		ID         string `json:"id"`
		Nick       string `json:"nick"`
		LastSeenAt int64  `json:"last_seen_at"`

		IsVerified bool `json:"is_verified"`
	} `json:"user"`
}

type ChatChannelPage

type ChatChannelPage struct {
	Channels struct {
		Items  []*ChatChannel `json:"items"`
		Paging Cursor         `json:"paging"`
	} `json:"channels"`
	Num int `json:"num"`
}

type ChatEvent

type ChatEvent struct {
	ID   string `json:"id"`
	Text string `json:"text"`

	Type   messageType `json:"type"`
	Status int         `json:"status"`
	PubAt  float64     `json:"pub_at"`

	User struct {
		ID         string `json:"user"`
		Nick       string `json:"nick"`
		IsVerified bool   `json:"is_verified"`
		LastSeenAt int64  `json:"last_seen_at"`
	} `json:"user"`

	Channel string
}

type Client

type Client struct {
	Self *User
	// contains filtered or unexported fields
}

func MakeClient

func MakeClient(bearer, userAgent string) (*Client, error)

func MakeClientLog

func MakeClientLog(bearer, userAgent string, log *logrus.Logger) (*Client, error)

func (*Client) Chat

func (client *Client) Chat() (*Chat, error)

func (*Client) DMChannelName

func (client *Client) DMChannelName(them ...string) string

func (*Client) ExploreChatChannelPage added in v0.0.9

func (client *Client) ExploreChatChannelPage(requet compose.Request) (*Page[ChatChannel], error)

func (*Client) ExploreContentPage added in v0.0.9

func (client *Client) ExploreContentPage(requet compose.Request) (*Page[Content], error)

func (*Client) ExploreUserPage added in v0.0.9

func (client *Client) ExploreUserPage(requet compose.Request) (*Page[User], error)

func (*Client) GetChannels

func (client *Client) GetChannels(desc compose.Request) ([]*ChatChannel, error)

func (*Client) GetChannelsPage

func (client *Client) GetChannelsPage(desc compose.Request) (*Page[ChatChannel], error)

func (*Client) GetCommentPage added in v0.0.7

func (client *Client) GetCommentPage(request compose.Request) (*Page[Comment], error)

func (*Client) GetContent

func (client *Client) GetContent(id string) (*Content, error)

func (*Client) GetFeedPage

func (client *Client) GetFeedPage(request compose.Request) (*Page[Content], error)

func (*Client) GetUser

func (client *Client) GetUser(desc compose.Request) (*User, error)

func (*Client) IterChannelsQuery added in v0.0.9

func (client *Client) IterChannelsQuery(query string) <-chan Result[*ChatChannel]

func (*Client) IterComments added in v0.0.7

func (client *Client) IterComments(id string) <-chan Result[*Comment]

func (*Client) IterExploreChatChannel added in v0.0.9

func (client *Client) IterExploreChatChannel(compilation string) <-chan Result[*ChatChannel]

func (*Client) IterExploreContent added in v0.0.9

func (client *Client) IterExploreContent(compilation string) <-chan Result[*Content]

func (*Client) IterExploreUser added in v0.0.9

func (client *Client) IterExploreUser(compilation string) <-chan Result[*User]

func (*Client) IterFeed

func (client *Client) IterFeed(feed string) <-chan Result[*Content]

func (*Client) IterTimeline added in v0.0.9

func (client *Client) IterTimeline(id string) <-chan Result[*Content]

func (*Client) RequestJSON

func (client *Client) RequestJSON(desc compose.Request, output interface{}) error

type Comment added in v0.0.7

type Comment struct {
	ID           string `json:"id"`
	CID          string `json:"cid"`
	State        string `json:"state"`
	Date         int    `json:"date"`
	Text         string `json:"text"`
	IsReply      bool   `json:"is_reply"`
	IsSmiled     bool   `json:"is_smiled"`
	IsUnsmiled   bool   `json:"is_unsmiled"`
	IsEdited     bool   `json:"is_edited"`
	RootCommID   string `json:"root_comm_id"`
	ParentCommID string `json:"parent_comm_id"`
	Depth        int    `json:"depth"`
	User         User   `json:"user"`
	Num          struct {
		Smiles   int `json:"smiles"`
		Unsmiles int `json:"unsmiles"`
		Replies  int `json:"replies"`
	} `json:"num"`
	Attachments struct {
		MentionUser []struct {
			ID           string `json:"id"`
			UserID       string `json:"user_id"`
			Nick         string `json:"nick"`
			Start        int    `json:"start_index"`
			Stop         int    `json:"stop_index"`
			OriginalNick string `json:"original_nick"`
		} `json:"mention_user"`
	} `json:"attachments"`
	ContentThumbs struct {
		URL                 string `json:"url"`
		LargeURL            string `json:"large_url"`
		X640URL             string `json:"x640_url"`
		WebpURL             string `json:"webp_url"`
		LargeWebpURL        string `json:"large_webp_url"`
		X640WebpURL         string `json:"x640_webp_url"`
		ProportionalURL     string `json:"proportional_url"`
		ProportionalWebpURL string `json:"proportional_webp_url"`
		ProportionalSize    struct {
			Width  int `json:"w"`
			Height int `json:"h"`
		} `json:"proportional_size"`
	} `json:"content_thumbs"`
}

type Content

type Content struct {
	Type        string   `json:"type"`
	ID          string   `json:"id"`
	Link        string   `json:"link"`
	DateCreated int64    `json:"date_created"`
	PublushAt   int64    `json:"publish_at"`
	Tags        []string `json:"tags"`
	State       string   `json:"state"`
	ShotStatus  string   `json:"shot_status"`

	FastStart  bool `json:"fast_start"`
	IsFeatured bool `json:"is_featured"`
	IsPinned   bool `json:"is_pinned"`
	IsAbused   bool `json:"is_abused"`
	IsUnsafe   bool `json:"is_unsafe"`

	IsRepublished bool `json:"is_republished"`
	IsSmiled      bool `json:"is_smiled"`
	IsUnsmiled    bool `json:"is_unsmiled"`

	Size struct {
		Height int `json:"h"`
		Width  int `json:"w"`
	} `json:"size"`

	Num struct {
		Comments    int `json:"comments"`
		Republished int `json:"republished"`
		Smiles      int `json:"smiles"`
		Unsmiles    int `json:"unsmiles"`
		Views       int `json:"views"`
	} `json:"num"`

	Creator struct {
		ID   string `json:"id"`
		Nick string `json:"nick"`
	} `json:"creator"`

	// type = pic|comics
	Pic struct {
		WebpURL string `json:"webp_url"`
	} `json:"pic,omitempty"`

	// type = video_clip
	VideoClip struct {
		ScreenURL  string `json:"screen_url"`
		SourceType string `json:"source_type"`
		Bytes      int    `json:"bytes"`
		Duration   int    `json:"duration"`
	} `json:"video_clip,omitempty"`
}

type Cursor added in v0.0.7

type Cursor struct {
	Cursors struct {
		Next string `json:"next,omitempty"`
		Prev string `json:"prev,omitempty"`
	} `json:"cursors"`
	HasNext bool `json:"hasNext"`
	HasPrev bool `json:"hasPrev"`
}

type EventHandler

type EventHandler func(eventType int, kwargs map[string]interface{}) error

type Iterator added in v0.0.2

type Iterator[T any] struct {
	Iter func() <-chan Result[T]
	Stop func()
}

type Page added in v0.0.7

type Page[T Comment | Content | User | ChatChannel] struct {
	Items  []T    `json:"items"`
	Paging Cursor `json:"paging"`
}

type Result added in v0.0.2

type Result[T any] struct {
	V   T
	Err error
}

type User

type User struct {
	Email            string `json:"email"`
	SafeMode         bool   `json:"safe_mode"`
	OriginalNick     string `json:"original_nick"`
	MessagingPrivacy string `json:"messaging_privacy_status"`

	ID    string `json:"id"`
	Nick  string `json:"nick"`
	About string `json:"about"`

	IsAvailableForChat    bool `json:"is_available_for_chat"`
	IsBanned              bool `json:"is_banned"`
	IsDeleted             bool `json:"is_deleted"`
	IsModerator           bool `json:"is_moderator"`
	IsVerified            bool `json:"is_verified"`
	IsInSubscribers       bool `json:"is_in_subscribers"`
	IsInSubscriptions     bool `json:"is_in_subscriptions"`
	IsSubscribedToUpdates bool `json:"is_subscribed_to_updates"`
	IsPrivate             bool `json:"is_private"`

	Num struct {
		Subscriptions int `json:"subscriptions"`
		Subscribers   int `json:"subscribers"`
		TotalPosts    int `json:"total_posts"`
		Created       int `json:"created"`
		Featured      int `json:"featured"`
		TotalSmiles   int `json:"total_smiles"`
		Achievements  int `json:"achievements"`
	} `json:"num"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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