bbs

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: GPL-3.0 Imports: 11 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParams     = errors.New("invalid params")
	ErrInvalidBBoardID   = errors.New("invalid bboardID")
	ErrInvalidUUserID    = errors.New("invalid uuserID")
	ErrInvalidArticleID  = errors.New("invalid articleID")
	ErrInvalidPermission = errors.New("invalid permission")
)

Functions

func ChangeEmail added in v0.7.0

func ChangeEmail(uuserID UUserID, email string) (err error)

func ChangePasswd added in v0.6.0

func ChangePasswd(userID UUserID, origPasswd string, passwd string, ip string) (err error)

func CheckPasswd added in v0.7.0

func CheckPasswd(uuserID UUserID, passwd string, ip string) (err error)

func CreateComment added in v0.14.0

func CreateComment(userID UUserID, boardID BBoardID, articleID ArticleID, commentType ptttype.CommentType, content []byte, ip string) (comment []byte, mtime types.Time4, err error)

func DeserializeBoardIdxByClassStr added in v0.20.2

func DeserializeBoardIdxByClassStr(idxStr string) (boardClass []byte, brdname string, err error)

func DeserializeBoardIdxByNameStr added in v0.20.2

func DeserializeBoardIdxByNameStr(idxStr string) (brdname string, err error)

func EditArticle added in v0.18.0

func EditArticle(
	uuserID UUserID,
	bboardID BBoardID,
	articleID ArticleID,
	posttype []byte,
	title []byte,
	content [][]byte,
	oldSZ int,
	oldsum cmsys.Fnv64_t,
	ip string) (newContent []byte, mtime types.Time4, newTitle []byte, newClass []byte, newFullTitle []byte, err error)

func GetArticle added in v0.4.0

func GetArticle(uuserID UUserID, bboardID BBoardID, articleID ArticleID, retrieveTS types.Time4, isHash bool) (content []byte, mtime types.Time4, sum cmsys.Fnv64_t, err error)

func GetFavorites added in v0.9.0

func GetFavorites(uuserID UUserID, retrieveTS types.Time4) (content []byte, mtime types.Time4, err error)

func GetPostTemplate added in v0.23.3

func GetPostTemplate(uuserID UUserID, bboardID BBoardID, templateID ptttype.SortIdx, retrieveTS types.Time4, isHash bool) (content []byte, mtime types.Time4, sum cmsys.Fnv64_t, err error)

func GetUserVisitCount added in v0.19.2

func GetUserVisitCount() int32

func IsBoardValidUser added in v0.9.5

func IsBoardValidUser(uuserID UUserID, boardID BBoardID) (isValid bool, err error)

func IsBoardsValidUser added in v0.17.0

func IsBoardsValidUser(uuserID UUserID, boardIDs []BBoardID) (isValid map[BBoardID]bool, err error)

func IsSysop added in v0.7.1

func IsSysop(uuserID UUserID, perm ptttype.PERM) (isValid bool)

func IsValidIDEmail added in v0.8.1

func IsValidIDEmail(email string) (err error)

func ReloadUHash added in v0.13.0

func ReloadUHash(uuserID UUserID) (err error)

func SerializeArticleIdxStr added in v0.14.3

func SerializeArticleIdxStr(summary *ArticleSummary) (idxStr string)

func SerializeBoardIdxByClassStr added in v0.20.2

func SerializeBoardIdxByClassStr(boardClass []byte, brdname string) (idxStr string)

func SerializeBoardIdxByNameStr added in v0.20.2

func SerializeBoardIdxByNameStr(brdname string) (idxStr string)

func SetIDEmail added in v0.7.1

func SetIDEmail(uuserID UUserID, isSet bool) (userLevel2 ptttype.PERM2, err error)

func SetUserPerm added in v0.13.1

func SetUserPerm(userID UUserID, setUserID UUserID, perm ptttype.PERM) (newPerm ptttype.PERM, err error)

func WriteFavorites added in v0.23.6

func WriteFavorites(uuserID UUserID, content []byte) (mtime types.Time4, err error)

Types

type ArticleID added in v0.3.0

type ArticleID string

func DeleteArticles added in v0.19.0

func DeleteArticles(uuserID UUserID, bboardID BBoardID, articleIDs []ArticleID, ip string) ([]ArticleID, error)

func DeserializeArticleIdxStr added in v0.14.3

func DeserializeArticleIdxStr(idxStr string) (createTime types.Time4, articleID ArticleID, err error)

func ToArticleID added in v0.3.0

func ToArticleID(filename *ptttype.Filename_t) ArticleID

ToArticleID

aidc is with fixed-size (8 bytes), no need the separator to do the separation.

func (*ArticleID) ToFilename added in v0.4.0

func (a *ArticleID) ToFilename() (filename *ptttype.Filename_t)

func (ArticleID) ToRaw added in v0.4.2

func (a ArticleID) ToRaw() (filename *ptttype.Filename_t)

ToRaw

1st 8 bytes are aidc. bytes starting 8th are ownerID

type ArticleSummary added in v0.3.0

type ArticleSummary struct {
	BBoardID   BBoardID         `json:"bid"`
	ArticleID  ArticleID        `json:"aid"`
	IsDeleted  bool             `json:"deleted"`
	Filename   string           `json:"filename"`
	CreateTime types.Time4      `json:"create_time"`
	MTime      types.Time4      `json:"modified"`
	Recommend  int8             `json:"recommend"`
	Owner      UUserID          `json:"owner"`
	FullTitle  []byte           `json:"full_title"`
	Money      int32            `json:"money"`
	Filemode   ptttype.FileMode `json:"mode"`
	Class      []byte           `json:"class"`
	Read       bool             `json:"read"`
	Idx        string           `json:"idx"`

	RealTitle   []byte              `json:"title"`
	SubjectType ptttype.SubjectType `json:"subject_type"`
}

func CreateArticle added in v0.12.0

func CreateArticle(
	uuserID UUserID,
	bboardID BBoardID,
	posttype []byte,
	title []byte,
	content [][]byte,
	ip string) (

	summary *ArticleSummary,
	err error)

func CrossPost added in v0.16.0

func CrossPost(
	uuserID UUserID,
	bboardID BBoardID,
	articleID ArticleID,
	xboardID BBoardID,
	ip string,
) (articleSummary *ArticleSummary, comment []byte, commentMTime types.Time4, err error)

func LoadBottomArticles added in v0.15.0

func LoadBottomArticles(uuserID UUserID, bboardID BBoardID) (summaries []*ArticleSummary, err error)

func LoadGeneralArticles added in v0.3.0

func LoadGeneralArticles(
	uuserID UUserID,
	bboardID BBoardID,
	startIdxStr string,
	nArticles int,
	isDesc bool) (

	summaries []*ArticleSummary,
	nextIdxStr string,
	nextCreateTime types.Time4,
	isNewest bool,
	startNumIdx ptttype.SortIdx,
	err error)

LoadGeneralArticles in descending mode.

func NewArticleSummaryFromRaw added in v0.3.0

func NewArticleSummaryFromRaw(bboardID BBoardID, articleSummaryRaw *ptttype.ArticleSummaryRaw) *ArticleSummary

type BBoardID added in v0.3.0

type BBoardID string // The integrated bid-boardID, concat with _, safe because bid is number >= 1.

func ToBBoardID added in v0.3.0

func ToBBoardID(bid ptttype.Bid, boardIDRaw *ptttype.BoardID_t) BBoardID

ToBBoardID

concat bid and boardID as BBoardID, concat with _ because bid and boardIDRaw are from ptt, no need to check the validity

func (BBoardID) ToBrdname added in v0.4.0

func (b BBoardID) ToBrdname() string

func (BBoardID) ToRaw added in v0.3.0

func (b BBoardID) ToRaw() (bid ptttype.Bid, boardIDRaw *ptttype.BoardID_t, err error)

ToRaw

BBoardID is possible coming from outside, requiring validation.

type BoardDetail added in v0.18.0

type BoardDetail struct {
	Brdname            string            `json:"brdname"`
	RealTitle          []byte            `json:"title"` // Require to separate RealTitle, BoardClass, BoardType, because it's hard to parse in utf8
	BoardClass         []byte            `json:"class"`
	BoardType          []byte            `json:"type"` //□, ◎, Σ
	BM                 []UUserID         `json:"moderators"`
	BrdAttr            ptttype.BrdAttr   `json:"attr"`
	Gid                ptttype.Bid       `json:"pttgid"`
	Bid                ptttype.Bid       `json:"pttbid"`
	BBoardID           BBoardID          `json:"bid"`
	ChessCountry       ptttype.ChessCode `json:"chesscountry"`
	VoteLimitLogins    uint8             `json:"votelimitlogins"`
	BUpdate            types.Time4       `json:"bupdate"`
	PostLimitLogins    uint8             `json:"postlimitlogins"`
	BVote              uint8             `json:"bvote"`
	VTime              types.Time4       `json:"vtime"`
	Level              ptttype.PERM      `json:"level"`
	PermReload         types.Time4       `json:"permreload"`
	NUser              int32             `json:"nuser"`
	PostExpire         ptttype.Bid       `json:"postexpire"`
	EndGamble          types.Time4       `json:"endgamble"`
	PostType           [][]byte          `json:"posttype"`
	PostTypeTemplate   []bool            `json:"posttype_tmpl"`
	FastRecommendPause uint8             `json:"fastrecommendpause"`
	VoteLimitBadpost   uint8             `json:"votelimitbadpost"`
	PostLimitBadPost   uint8             `json:"postlimitbadpost"`

	LastPostTime types.Time4 `json:"last_post_time"`
	Total        int32       `json:"total"`

	IdxByName  string `json:"idx_name"`
	IdxByClass string `json:"idx_class"`

	Reason ptttype.RestrictReason `json:"reason"`
}

func LoadBoardDetail added in v0.18.0

func LoadBoardDetail(uuserID UUserID, bboardID BBoardID) (detail *BoardDetail, err error)

func LoadGeneralBoardDetails added in v0.23.0

func LoadGeneralBoardDetails(uuserID UUserID, startIdxStr string, nBoards int, isAsc bool, bsortBy ptttype.BSortBy) (details []*BoardDetail, nextIdxStr string, err error)

func NewBoardDetailFromRaw added in v0.18.0

func NewBoardDetailFromRaw(boardDetailRaw *ptttype.BoardDetailRaw, bid ptttype.Bid) *BoardDetail

type BoardSummary

type BoardSummary struct {
	Gid          ptttype.Bid            `json:"pttgid"`
	Bid          ptttype.Bid            `json:"pttbid"`
	BBoardID     BBoardID               `json:"bid"`
	BrdAttr      ptttype.BrdAttr        `json:"attr"`
	StatAttr     ptttype.BoardStatAttr  `json:"user_attr"`
	Brdname      string                 `json:"brdname"`
	RealTitle    []byte                 `json:"title"` // Require to separate RealTitle, BoardClass, BoardType, because it's hard to parse in utf8
	BoardClass   []byte                 `json:"class"`
	BoardType    []byte                 `json:"type"` //□, ◎, Σ
	BM           []UUserID              `json:"moderators"`
	Reason       ptttype.RestrictReason `json:"reason"`
	LastPostTime types.Time4            `json:"last_post_time"`
	NUser        int32                  `json:"number_of_user"`
	Total        int32                  `json:"total"`
	Read         bool                   `json:"read"`

	IdxByName  string `json:"idx_name"`
	IdxByClass string `json:"idx_class"`
}

func CreateBoard added in v0.11.1

func CreateBoard(
	userID UUserID,
	clsBid ptttype.Bid,
	brdname string,
	brdClass []byte,
	brdTitle []byte,
	BMs []UUserID,
	brdAttr ptttype.BrdAttr,
	level ptttype.PERM,
	chessCountry ptttype.ChessCode,
	isGroup bool,
) (summary *BoardSummary, err error)

func LoadAutoCompleteBoards added in v0.10.0

func LoadAutoCompleteBoards(uuserID UUserID, startIdxStr string, nBoards int, keyword string, isAsc bool) (summaries []*BoardSummary, nextIdxStr string, err error)

func LoadBoardSummary added in v0.8.0

func LoadBoardSummary(uuserID UUserID, bboardID BBoardID) (summary *BoardSummary, err error)

func LoadBoardsByBids added in v0.9.2

func LoadBoardsByBids(uuserID UUserID, bids []ptttype.Bid) (summaries []*BoardSummary, err error)

func LoadClassBoards added in v0.17.0

func LoadClassBoards(uuserID UUserID, clsBid ptttype.Bid, bsortBy ptttype.BSortBy) (summaries []*BoardSummary, err error)

func LoadFullClassBoards added in v0.17.0

func LoadFullClassBoards(uuserID UUserID, startBid ptttype.Bid, nBoards int) (summaries []*BoardSummary, nextBid ptttype.Bid, err error)

func LoadGeneralBoards

func LoadGeneralBoards(uuserID UUserID, startIdxStr string, nBoards int, title []byte, keyword []byte, isAsc bool, bsortBy ptttype.BSortBy) (summaries []*BoardSummary, nextIdxStr string, err error)

func LoadHotBoards added in v0.9.0

func LoadHotBoards(uuserID UUserID) (summary []*BoardSummary, err error)

func NewBoardSummaryFromRaw

func NewBoardSummaryFromRaw(boardSummaryRaw *ptttype.BoardSummaryRaw) *BoardSummary

type UUserID added in v0.3.3

type UUserID string // The integrated bid-userid, concat with _, safe because bid is number >= 1.

func CheckExistsUser added in v0.9.4

func CheckExistsUser(username string) (uuserID UUserID, err error)

func Login

func Login(username string, passwd string, ip string) (uuserID UUserID, err error)

Login

XXX need to check for the permission

func Register

func Register(
	username string,
	passwd string,
	ip string,
	email string,

	nickname []byte,
	realname []byte,
	career []byte,
	address []byte,
	over18 bool,
) (uuserID UUserID, err error)

func ToUUserID added in v0.3.3

func ToUUserID(userIDRaw *ptttype.UserID_t) UUserID

func (UUserID) ToRaw added in v0.3.3

func (u UUserID) ToRaw() (userIDRaw *ptttype.UserID_t, err error)

func (UUserID) ToUsername added in v0.4.0

func (u UUserID) ToUsername() string

type Userec

type Userec struct {
	Version  uint32  `json:"version"`
	UUserID  UUserID `json:"user_id"`
	Username string  `json:"username"`
	Realname []byte  `json:"realname"`
	Nickname []byte  `json:"nickname"`

	Uflag ptttype.UFlag `json:"flag"`
	// Unused1      uint32      /* 從前放習慣2, 使用前請先清0 */
	Userlevel    ptttype.PERM `json:"perm"`
	Numlogindays uint32       `json:"login_days"`
	Numposts     uint32       `json:"posts"`
	Firstlogin   types.Time4  `json:"first_login"`
	Lastlogin    types.Time4  `json:"last_login"`
	Lasthost     string       `json:"last_ip"` // last IPv4.
	Money        int32        `json:"money"`

	Email string `json:"email"`
	// Address []byte
	Justify []byte `json:"justify"`
	// UnusedBirth [3]uint8  /* 生日 月日年 */
	Over18      bool              `json:"over18"`
	PagerUIType uint8             `json:"pager_ui"` /* 呼叫器界面類別 (was: WATER_*) */
	Pager       ptttype.PagerMode `json:"pager"`    /* 呼叫器狀態 */
	Invisible   bool              `json:"invisible"`
	// Unused4     [2]byte
	Exmailbox uint32 `json:"exmail"`

	// r3968 移出 sizeof(chicken_t)=128 bytes
	// Unused5       [4]byte
	Career []byte `json:"career"`
	// UnusedPhone   Phone_t  /* 電話 */
	// Unused6       uint32   /* 從前放轉換前的 numlogins, 使用前請先清0 */
	// Chkpad1       [44]byte
	Role          uint32      `json:"role"`
	LastSeen      types.Time4 `json:"last_seen"`
	TimeSetAngel  types.Time4 `json:"time_set_angel"`
	TimePlayAngel types.Time4 `json:"time_play_angel"`

	LastSong  types.Time4 `json:"last_song"`
	LoginView uint32      `json:"login_view"`

	Vlcount   uint16 `json:"violation"`
	FiveWin   uint16 `json:"five_win"`
	FiveLose  uint16 `json:"five_lose"`
	FiveTie   uint16 `json:"five_tie"`
	ChcWin    uint16 `json:"chc_win"`
	ChcLose   uint16 `json:"chc_lose"`
	ChcTie    uint16 `json:"chc_tie"`
	Conn6Win  uint16 `json:"conn6_win"`
	Conn6Lose uint16 `json:"conn6_lose"`
	Conn6Tie  uint16 `json:"conn6_tie"`
	// UnusedMind [2]byte /* 舊心情 */
	GoWin     uint16 `json:"go_win"`
	GoLose    uint16 `json:"go_lose"`
	GoTie     uint16 `json:"go_tie"`
	DarkWin   uint16 `json:"dark_win"`
	DarkLose  uint16 `json:"dark_lose"`
	DarkTie   uint16 `json:"dark_tie"` /* 暗棋戰績 和 */
	UaVersion uint8  `json:"ua_version"`

	Signature uint8 `json:"signature"` /* 慣用簽名檔 */
	// Unused10  uint8    /* 從前放好文章數, 使用前請先清0 */
	BadPost uint8   `json:"bad_post"` /* 評價為壞文章數 */
	MyAngel UUserID `json:"angel"`    /* 我的小天使 */

	ChessEloRating    uint16           `json:"check_rank"`
	WithMe            ptttype.WithMe_t `json:"withme"`
	TimeRemoveBadPost types.Time4      `json:"time_remove_bad_post"`
	TimeViolateLaw    types.Time4      `json:"time_violate_law"`

	UserLevel2 ptttype.PERM2 `json:"user_level2"`
	UpdateTS2  types.Time4   `json:"update_ts2"`
}

https://github.com/ptt/pttbbs/blob/master/include/pttstruct.h

func GetUser added in v0.5.0

func GetUser(uuserID UUserID) (user *Userec, err error)

func NewUserecFromRaw

func NewUserecFromRaw(userecRaw *ptttype.UserecRaw, userec2Raw *ptttype.Userec2Raw) (user *Userec)

Jump to

Keyboard shortcuts

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