bbs

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: Apache-2.0 Imports: 10 Imported by: 1

README

BBS Library

GoDoc

這個專案是提供 Golang 開發者存取現有在台灣的 BBS 資料結構的函式庫。

目前主要支援的 BBS 結構以 pttbbs(CurrentPTT/OpenPTT) 為主

未來可能會支援 FormosaBBS

目前支援的檔案

目前 pttbbs 支援的檔案請見此處

給開發者的資訊

請點此

測試方式

go test

這樣。

專有名詞部分

有些名詞因為太常出現,可能會考慮直接在程式碼裡面以縮寫表示而不寫出全名:

  • BM: Board Moderator 版主的意思

授權

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotUserComment          = fmt.Errorf("data is not a user comment")
	ErrUserCommentEmptyUserID  = fmt.Errorf("user comment has empty name")
	ErrUserCommentEmptyComment = fmt.Errorf("user comment detail has empty")
)

Functions

func Big5ToUtf8

func Big5ToUtf8(input []byte) string

func CstrToBytes

func CstrToBytes(cstr Cstr) []byte

CstrToBytes

Only the bytes until \0. See tests for more examples.

Params

cstr

Return

[]byte: bytes

func CstrToString

func CstrToString(cstr Cstr) string

CstrToString

Only the bytes until \0 when converting to string. See tests for more examples.

Params

cstr

Return

string: string

func FilterStringANSI added in v0.5.0

func FilterStringANSI(src string) string

func Register

func Register(drivername string, connector Connector)

func Utf8ToBig5

func Utf8ToBig5(input string) []byte

Types

type ArticleRecord

type ArticleRecord interface {
	Filename() string
	Modified() time.Time
	SetModified(newModified time.Time)
	Recommend() int
	Date() string
	Title() string
	Money() int
	Owner() string
}

type BadPostUserRecord added in v0.3.0

type BadPostUserRecord interface {
	// NumBadPosts return how many bad post this use have
	NumBadPosts() int
}

BadPostUserRecord return UserRecord interface which support NumBadPosts

type BoardRecord

type BoardRecord interface {
	BoardID() string

	Title() string

	IsClass() bool
	// ClassID should return the class id to which this board/class belongs.
	ClassID() string

	BM() []string
}

type BoardRecordInfo added in v0.5.0

type BoardRecordInfo interface {
	GetPostLimitPosts() uint8
	GetPostLimitLogins() uint8
	GetPostLimitBadPost() uint8
}

type BoardRecordSettings added in v0.5.0

type BoardRecordSettings interface {
	IsHide() bool
	IsPostMask() bool
	IsAnonymous() bool
	IsDefaultAnonymous() bool
	IsNoCredit() bool
	IsVoteBoard() bool
	IsWarnEL() bool
	IsTop() bool
	IsNoRecommend() bool
	IsAngelAnonymous() bool
	IsBMCount() bool
	IsNoBoo() bool
	IsRestrictedPost() bool
	IsGuestPost() bool
	IsCooldown() bool
	IsCPLog() bool
	IsNoFastRecommend() bool
	IsIPLogRecommend() bool
	IsOver18() bool
	IsNoReply() bool
	IsAlignedComment() bool
	IsNoSelfDeletePost() bool
	IsBMMaskContent() bool
}

type Connector

type Connector interface {
	// Open provides the driver parameter settings, such as BBSHome parameter and SHM parameters.
	Open(dataSourceName string) error
	// GetUserRecordsPath should return user records file path, eg: BBSHome/.PASSWDS
	GetUserRecordsPath() (string, error)
	// ReadUserRecordsFile should return UserRecord list in the file called name
	ReadUserRecordsFile(name string) ([]UserRecord, error)
	// GetUserFavoriteRecordsPath should return the user favorite records file path
	// for specific user, eg: BBSHOME/home/{{u}}/{{userID}}/.fav
	GetUserFavoriteRecordsPath(userID string) (string, error)
	// ReadUserFavoriteRecordsFile should return FavoriteRecord list in the file called name
	ReadUserFavoriteRecordsFile(name string) ([]FavoriteRecord, error)
	// GetBoardRecordsPath should return the board headers file path, eg: BBSHome/.BRD
	GetBoardRecordsPath() (string, error)
	// ReadBoardRecordsFile shoule return BoardRecord list in file, name is the file name
	ReadBoardRecordsFile(name string) ([]BoardRecord, error)
	// GetBoardArticleRecordsPath should return the article records file path, boardID is the board id,
	// eg: BBSHome/boards/{{b}}/{{boardID}}/.DIR
	GetBoardArticleRecordsPath(boardID string) (string, error)
	// GetBoardArticleRecordsPath should return the treasure records file path, boardID is the board id,
	// eg: BBSHome/man/boards/{{b}}/{{boardID}}/{{treasureID}}/.DIR
	GetBoardTreasureRecordsPath(boardID string, treasureID []string) (string, error)
	// ReadArticleRecordsFile returns ArticleRecord list in file, name is the file name
	ReadArticleRecordsFile(name string) ([]ArticleRecord, error)
	// GetBoardArticleFilePath return file path for specific boardID and filename
	GetBoardArticleFilePath(boardID string, filename string) (string, error)
	// GetBoardTreasureFilePath return file path for specific boardID, treasureID and filename
	GetBoardTreasureFilePath(boardID string, treasureID []string, name string) (string, error)
	// ReadBoardArticleFile should returns raw file of specific file name
	ReadBoardArticleFile(name string) ([]byte, error)
}

Driver should implement Connector interface

type Cstr

type Cstr []byte

Cstr

[]byte with C String property in that \0 is considered as the end of the bytes/string. It is used to convert from fixed-length bytes to string or []byte with no \0.

Naming Cstr instead of CString is to avoid confusion with C.CString (C.CString is from string, and should be compatible with string, not with []byte) (We also have str(len/cpy/cmp) functions in C)

See tests for more examples of how to use fixed-bytes with Cstr to get no-\0 string / []byte

type DB

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

DB is whole bbs filesystem, including where file store, how to connect to local cache ( system V shared memory or etc.) how to parse or store it's data to bianry

func Open

func Open(drivername string, dataSourceName string) (*DB, error)

Open opan a

func (*DB) AddArticleRecordFileRecord added in v0.5.0

func (db *DB) AddArticleRecordFileRecord(boardID string, article ArticleRecord) error

AddArticleRecordFileRecord append article ArticleRecord to boardID

func (*DB) AddBoardRecord added in v0.3.0

func (db *DB) AddBoardRecord(brd BoardRecord) error

func (*DB) AppendBoardArticleFile added in v0.8.1

func (db *DB) AppendBoardArticleFile(boardID string, filename string, content []byte) error

func (*DB) CreateArticleRecord added in v0.8.1

func (db *DB) CreateArticleRecord(boardID, owner, date, title string) (ArticleRecord, error)

CreateArticleRecord returns new ArticleRecord with new filename in boardID and owner, date and title. This method will find a usable filename in board and occupy it.

func (*DB) DeleteUserDraft added in v0.5.0

func (db *DB) DeleteUserDraft(userID, draftID string) error

func (*DB) GetBoardArticleCommentRecords added in v0.5.0

func (db *DB) GetBoardArticleCommentRecords(boardID string, ar ArticleRecord) (crs []UserCommentRecord, err error)

GetBoardArticleCommentRecords returns the comment records of the specific article.

func (*DB) GetBoardUserCommentRecord added in v0.5.0

func (db *DB) GetBoardUserCommentRecord(boardID, userID string) (recs []UserCommentRecord, err error)

GetBoardUserCommentRecord returns the comment records of the user from the specific board.

func (*DB) GetUserArticleRecordFile added in v0.4.0

func (db *DB) GetUserArticleRecordFile(userID string) ([]UserArticleRecord, error)

GetUserArticleRecordFile returns aritcle file which user posted.

func (*DB) GetUserCommentRecordFile added in v0.5.0

func (db *DB) GetUserCommentRecordFile(userID string) ([]UserCommentRecord, error)

GetUserCommentRecordFile returns the comment records of the specific user from all boards and all articles.

func (*DB) GetUserDrafts added in v0.6.0

func (db *DB) GetUserDrafts(userID, draftID string) (UserDraft, error)

func (*DB) NewBoardRecord added in v0.3.0

func (db *DB) NewBoardRecord(args map[string]interface{}) (BoardRecord, error)

func (*DB) ReadBoardArticleFile

func (db *DB) ReadBoardArticleFile(boardID string, filename string) ([]byte, error)

func (*DB) ReadBoardArticleRecordsFile

func (db *DB) ReadBoardArticleRecordsFile(boardID string) ([]ArticleRecord, error)

func (*DB) ReadBoardRecord added in v0.3.0

func (db *DB) ReadBoardRecord(index uint) (*BoardRecord, error)

ReadBoardRecordFileRecord return boardRecord brd on index in record file.

func (*DB) ReadBoardRecords

func (db *DB) ReadBoardRecords() ([]BoardRecord, error)

ReadBoardRecords returns the UserRecords

func (*DB) ReadBoardTreasureFile

func (db *DB) ReadBoardTreasureFile(boardID string, treasuresID []string, filename string) ([]byte, error)

func (*DB) ReadBoardTreasureRecordsFile

func (db *DB) ReadBoardTreasureRecordsFile(boardID string, treasureID []string) ([]ArticleRecord, error)

func (*DB) ReadUserFavoriteRecords

func (db *DB) ReadUserFavoriteRecords(userID string) ([]FavoriteRecord, error)

ReadUserFavoriteRecords returns the FavoriteRecord for specific userID

func (*DB) ReadUserRecords

func (db *DB) ReadUserRecords() ([]UserRecord, error)

ReadUserRecords returns the UserRecords

func (*DB) RemoveBoardRecord added in v0.3.0

func (db *DB) RemoveBoardRecord(index uint) error

RemoveBoardRecordFileRecord remove boardRecord brd on index in record file.

func (*DB) UpdateBoardRecord added in v0.3.0

func (db *DB) UpdateBoardRecord(index uint, brd *BoardRecord) error

UpdateBoardRecordFileRecord update boardRecord brd on index in record file, index is start with 0

func (*DB) WriteBoardArticleFile added in v0.8.1

func (db *DB) WriteBoardArticleFile(boardID, filename string, content []byte) error

WriteBoardArticleFile writes content into filename in boardID

func (*DB) WriteUserDraft added in v0.7.0

func (db *DB) WriteUserDraft(userID, draftID string, draftContent UserDraft) error

type FavoriteRecord

type FavoriteRecord interface {
	Title() string
	Type() FavoriteType
	BoardID() string

	// Records is FavoriteTypeFolder only.
	Records() []FavoriteRecord
}

type FavoriteType

type FavoriteType int
const (
	FavoriteTypeBoard  FavoriteType = iota // 0
	FavoriteTypeFolder                     // 1
	FavoriteTypeLine                       // 2

)

type LastCountryUserRecord added in v0.3.0

type LastCountryUserRecord interface {
	// LastLoginCountry will return the country with this user's last login IP
	LastLoginCountry() string
}

LastCountryUserRecord return UserRecord interface which support LastCountry

type MailboxUserRecord added in v0.3.0

type MailboxUserRecord interface {
	// MailboxDescription will return the mailbox description with this user
	MailboxDescription() string
}

MailboxUserRecord return UserRecord interface which support MailboxDescription

type UserArticleConnector added in v0.4.0

type UserArticleConnector interface {

	// GetUserArticleRecordsPath should return the file path which user article record stores.
	GetUserArticleRecordsPath(userID string) (string, error)

	// ReadUserArticleRecordFile should return the article record in file.
	ReadUserArticleRecordFile(name string) ([]UserArticleRecord, error)

	// WriteUserArticleRecordFile write user article records into file.
	WriteUserArticleRecordFile(name string, records []UserArticleRecord) error

	// AppendUserArticleRecordFile append user article records into file.
	AppendUserArticleRecordFile(name string, record UserArticleRecord) error
}

UserArticleConnector is a connector for bbs who support cached user article records

type UserArticleRecord added in v0.4.0

type UserArticleRecord interface {
	BoardID() string
	Title() string
	Owner() string
	ArticleID() string
}

type UserCommentConnector added in v0.5.0

type UserCommentConnector interface {

	// GetUserCommentRecordsPath should return the file path where storing the
	//  user comment records.
	GetUserCommentRecordsPath(userID string) (string, error)

	// ReadUserCommentRecordFile should return the use comment records from the
	//  file.
	ReadUserCommentRecordFile(name string) ([]UserCommentRecord, error)
}

UserCommentConnector is a connector for bbs to access the cached user comment records.

type UserCommentRecord added in v0.5.0

type UserCommentRecord interface {
	CommentOrder() uint32
	CommentTime() time.Time
	Owner() string
	IP() string
	Comment() string
	String() string
	BoardID() string
	Filename() string
}

func NewUserCommentRecord added in v0.5.0

func NewUserCommentRecord(order uint32, data string, boardID string, ar ArticleRecord) (UserCommentRecord, error)

NewUserCommentRecord parses the data and returns the user comment record.

Return error when input data is not matched the user comment pattern.

type UserDraft added in v0.6.0

type UserDraft interface {
	Raw() []byte
}

func NewUserDraft added in v0.6.0

func NewUserDraft(raw []byte) UserDraft

type UserDraftConnector added in v0.5.0

type UserDraftConnector interface {

	// GetUserDraftPath should return the user's draft file path
	// eg: BBSHome/home/{{u}}/{{userID}}/buf.{{draftID}}
	GetUserDraftPath(userID, draftID string) (string, error)

	// ReadUserDraft return the user draft from the named file.
	ReadUserDraft(name string) ([]byte, error)

	// DeleteUserDraft should remove the named file.
	DeleteUserDraft(name string) error

	// WriteUserDraft should replace user draft from named file and user draft data
	WriteUserDraft(name string, draft []byte) error
}

UserDraftConnector is a connector for bbs which supports modify user draft file.

type UserRecord

type UserRecord interface {
	// UserID return user's identification string, and it is userid in
	// mostly bbs system
	UserID() string
	// HashedPassword return user hashed password, it only for debug,
	// If you want to check is user password correct, please use
	// VerifyPassword insteaded.
	HashedPassword() string
	// VerifyPassword will check user's password is OK. it will return null
	// when OK and error when there are something wrong
	VerifyPassword(password string) error
	// Nickname return a string for user's nickname, this string may change
	// depend on user's mood, return empty string if this bbs system do not support
	Nickname() string
	// RealName return a string for user's real name, this string may not be changed
	// return empty string if this bbs system do not support
	RealName() string
	// NumLoginDays return how many days this have been login since account created.
	NumLoginDays() int
	// NumPosts return how many posts this user has posted.
	NumPosts() int
	// Money return the money this user have.
	Money() int
	// LastLogin return last login time of user
	LastLogin() time.Time
	// LastHost return last login host of user, it is IPv4 address usually, but it
	// could be domain name or IPv6 address.
	LastHost() string
	// UserFlag return user setting.
	// uint32, see https://github.com/ptt/pttbbs/blob/master/include/uflags.h
	UserFlag() uint32
}

UserRecord mapping to `userec` in most system, it records uesr's basical data

type WriteArticleConnector added in v0.5.0

type WriteArticleConnector interface {

	// CreateBoardArticleFilename returns available filename for board with boardID
	CreateBoardArticleFilename(boardID string) (filename string, err error)

	// NewArticleRecord return ArticleRecord object in this driver with arguments
	NewArticleRecord(filename, owner, date, title string) (ArticleRecord, error)

	// AddArticleRecordFileRecord given record file name and new record, should append
	// file record in that file.
	AddArticleRecordFileRecord(name string, article ArticleRecord) error

	// UpdateArticleRecordFileRecord will write article in position index of name file
	// position is start with 0.
	UpdateArticleRecordFileRecord(name string, index uint, article ArticleRecord) error

	// WriteBoardArticleFile will turncate name file and write content into that file.
	WriteBoardArticleFile(name string, content []byte) error

	// AppendNewLine append content into file
	AppendBoardArticleFile(name string, content []byte) error
}

WriteArticleConnector is a connector for writing a article

type WriteBoardConnector

type WriteBoardConnector interface {

	// NewBoardRecord return BoardRecord object in this driver with arguments
	NewBoardRecord(args map[string]interface{}) (BoardRecord, error)

	// AddBoardRecordFileRecord given record file name and new record, should append
	// file record in that file.
	AddBoardRecordFileRecord(name string, brd BoardRecord) error

	// UpdateBoardRecordFileRecord update boardRecord brd on index in record file,
	// index is start with 0
	UpdateBoardRecordFileRecord(name string, index uint, brd BoardRecord) error

	// ReadBoardRecordFileRecord return boardRecord brd on index in record file.
	ReadBoardRecordFileRecord(name string, index uint) (BoardRecord, error)

	// RemoveBoardRecordFileRecord remove boardRecord brd on index in record file.
	RemoveBoardRecordFileRecord(name string, index uint) error
}

Driver which implement WriteBoardConnector supports modify board record file.

Directories

Path Synopsis
cmd
bbstool
bbstool command provides a command line interface for developer or operators control their bbstool database.
bbstool command provides a command line interface for developer or operators control their bbstool database.
cmd

Jump to

Keyboard shortcuts

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