models

package
v0.0.0-...-09d31aa Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeTagArray

func EncodeTagArray(arr []Tag) []string

Types

type Change

type Change struct {
	ID     string      `bson:"_id"`
	Model  ChangeModel `bson:"model"`
	Op     string      `bson:"op"`
	Author string      `bson:"author"`
	Listed bool        `bson:"listed"`
	Keys   []ChangeKey `bson:"keys"`
	Date   time.Time   `bson:"date"`

	ChangeObjectSet
}

Change represents a change in the rpdata history through the API.

func (*Change) Objects

func (change *Change) Objects() []interface{}

Objects makes a combined, mixed array of all the models stored in this change.

func (*Change) PassesFilter

func (change *Change) PassesFilter(filter ChangeFilter) bool

type ChangeFilter

type ChangeFilter struct {
	Keys         []ChangeKey
	EarliestDate *time.Time
	LatestDate   *time.Time
	Author       *string
	Limit        *int
}

ChangeFilter is a filter for listing changes.

type ChangeKey

type ChangeKey struct {
	Model ChangeModel `bson:"model"`
	ID    string      `bson:"id"`
}

ChangeKey is a key for a change that can be used when subscribing to them.

func (*ChangeKey) Decode

func (ck *ChangeKey) Decode(str string) error

func (*ChangeKey) String

func (ck *ChangeKey) String() string

type ChangeModel

type ChangeModel string

ChangeModel describes a model related to the change.

const (
	// ChangeModelCharacter is a value of ChangeModel
	ChangeModelCharacter ChangeModel = "Character"
	// ChangeModelChannel is a value of ChangeModel
	ChangeModelChannel ChangeModel = "Channel"
	// ChangeModelLog is a value of ChangeModel
	ChangeModelLog ChangeModel = "Log"
	// ChangeModelPost is a value of ChangeModel
	ChangeModelPost ChangeModel = "Post"
	// ChangeModelStory is a value of ChangeModel
	ChangeModelStory ChangeModel = "Story"
	// ChangeModelTag is a value of ChangeModel
	ChangeModelTag ChangeModel = "Tag"
	// ChangeModelChapter is a value of ChangeModel
	ChangeModelChapter ChangeModel = "Chapter"
	// ChangeModelComment is a value of ChangeModel
	ChangeModelComment ChangeModel = "Comment"
	// ChangeModelFile is a value of ChangeModel
	ChangeModelFile ChangeModel = "File"
)

func (ChangeModel) IsValid

func (e ChangeModel) IsValid() bool

IsValid returns true if the underlying string is one of the correct values.

func (ChangeModel) MarshalGQL

func (e ChangeModel) MarshalGQL(w io.Writer)

MarshalGQL marshals the underlying graphql value.

func (ChangeModel) String

func (e ChangeModel) String() string

func (*ChangeModel) UnmarshalGQL

func (e *ChangeModel) UnmarshalGQL(v interface{}) error

UnmarshalGQL unmarshals the underlying graphql value.

type ChangeObjectSet

type ChangeObjectSet struct {
	Logs       []*Log       `bson:"logs" json:"logs,omitempty"`
	Characters []*Character `bson:"characters" json:"characters,omitempty"`
	Channels   []*Channel   `bson:"channels" json:"channels,omitempty"`
	Posts      []*Post      `bson:"posts" json:"posts,omitempty"`
	Stories    []*Story     `bson:"stories" json:"stories,omitempty"`
	Tags       []*Tag       `bson:"tags" json:"tags,omitempty"`
	Chapters   []*Chapter   `bson:"chapters" json:"chapters,omitempty"`
	Comments   []*Comment   `bson:"comments" json:"comments,omitempty"`
	Files      []*File      `bson:"files" json:"files,omitempty"`
}

func (*ChangeObjectSet) AddObject

func (change *ChangeObjectSet) AddObject(object interface{}) bool

AddObject adds the model into the appropriate array.

type Channel

type Channel struct {
	Name         string `bson:"_id"`
	Logged       bool   `bson:"logged"`
	Hub          bool   `bson:"hub"`
	EventName    string `bson:"eventName,omitempty"`
	LocationName string `bson:"locationName,omitempty"`
}

A Channel represents information abount an IRC RP channel, and whether it should be logged

func (*Channel) ApplyUpdate

func (channel *Channel) ApplyUpdate(update ChannelUpdate)

func (*Channel) IsChangeObject

func (*Channel) IsChangeObject()

IsChangeObject is an interface implementation to identify it as a valid ChangeObject in GQL.

type ChannelFilter

type ChannelFilter struct {
	Names        []string `json:"names"`
	Logged       *bool    `json:"logged"`
	EventName    *string  `json:"eventName"`
	LocationName *string  `json:"locationName"`
	Limit        int      `json:"limit"`
}

ChannelFilter is a filter for channel listing.

type ChannelUpdate

type ChannelUpdate struct {
	Logged       *bool   `json:"logged"`
	Hub          *bool   `json:"hub"`
	EventName    *string `json:"eventName"`
	LocationName *string `json:"locationName"`
}

ChannelUpdate is a filter for channel listing.

type Chapter

type Chapter struct {
	ID             string             `bson:"_id"`
	StoryID        string             `bson:"storyId"`
	Title          string             `bson:"title"`
	Author         string             `bson:"author"`
	Source         string             `bson:"source"`
	CreatedDate    time.Time          `bson:"createdDate"`
	FictionalDate  time.Time          `bson:"fictionalDate,omitempty"`
	EditedDate     time.Time          `bson:"editedDate"`
	CommentMode    ChapterCommentMode `bson:"commentMode"`
	CommentsLocked bool               `bson:"commentsLocked"`
}

A Chapter is a part of a story.

func (*Chapter) ApplyUpdate

func (chapter *Chapter) ApplyUpdate(update ChapterUpdate)

func (*Chapter) CanComment

func (chapter *Chapter) CanComment() bool

CanComment returns true if the chapter can be commented to.

func (*Chapter) IsChangeObject

func (*Chapter) IsChangeObject()

IsChangeObject is an interface implementation to identify it as a valid ChangeObject in GQL.

type ChapterCommentMode

type ChapterCommentMode string

ChapterCommentMode represents the kind of tags.

const (
	// ChapterCommentModeDisabled is a chapter comment mode, see GraphQL documentation.
	ChapterCommentModeDisabled ChapterCommentMode = "Disabled"

	// ChapterCommentModeArticle is a chapter comment mode, see GraphQL documentation.
	ChapterCommentModeArticle ChapterCommentMode = "Article"

	// ChapterCommentModeChat is a chapter comment mode, see GraphQL documentation.
	ChapterCommentModeChat ChapterCommentMode = "Chat"

	// ChapterCommentModeMessage is a chapter comment mode, see GraphQL documentation.
	ChapterCommentModeMessage ChapterCommentMode = "Message"
)

func (ChapterCommentMode) IsEnabled

func (e ChapterCommentMode) IsEnabled() bool

IsEnabled returns true if comments are enabled.

func (ChapterCommentMode) MarshalGQL

func (e ChapterCommentMode) MarshalGQL(w io.Writer)

MarshalGQL turns it into a JSON string

func (*ChapterCommentMode) UnmarshalGQL

func (e *ChapterCommentMode) UnmarshalGQL(v interface{}) error

UnmarshalGQL unmarshals

type ChapterFilter

type ChapterFilter struct {
	StoryID *string
	Limit   int
}

type ChapterUpdate

type ChapterUpdate struct {
	Title          *string
	Source         *string
	FictionalDate  *time.Time
	CommentMode    *ChapterCommentMode
	CommentsLocked *bool
}

type Character

type Character struct {
	ID          string   `json:"id" bson:"_id" db:"id"`
	Nicks       []string `json:"nicks" bson:"nicks" db:"nicks"`
	Name        string   `json:"name" bson:"name" db:"name"`
	ShortName   string   `json:"shortName" bson:"shortName" db:"short_name"`
	Author      string   `json:"author" bson:"author" db:"author"`
	Description string   `json:"description" bson:"description" db:"description"`
}

Character is a common data model representing an RP character or NPC.

func (*Character) ApplyUpdate

func (character *Character) ApplyUpdate(update CharacterUpdate)

func (*Character) HasNick

func (character *Character) HasNick(nick string) bool

HasNick gets whether the character has the nick.

func (*Character) IsChangeObject

func (*Character) IsChangeObject()

IsChangeObject is an interface implementation to identify it as a valid ChangeObject in GQL.

func (*Character) Nick

func (character *Character) Nick() *string

Nick gets the character's nick.

type CharacterFilter

type CharacterFilter struct {
	IDs    []string
	Nicks  []string
	Names  []string
	Author *string
	Search *string
	Limit  int
}

CharacterFilter is a filter for character listing.

type CharacterUpdate

type CharacterUpdate struct {
	Name        *string
	ShortName   *string
	Description *string
}

CharacterUpdate is an update for characters.

type Comment

type Comment struct {
	ID            string    `bson:"_id"`
	ChapterID     string    `bson:"chapterId"`
	Subject       string    `bson:"subject"`
	Author        string    `bson:"author"`
	CharacterName string    `bson:"characterName"`
	CharacterID   string    `bson:"characterId"`
	FictionalDate time.Time `bson:"fictionalDate"`
	CreatedDate   time.Time `bson:"createdDate"`
	EditedDate    time.Time `bson:"editedDate"`
	Source        string    `bson:"source"`
}

A Comment is a comment on a chapter.

func (*Comment) ApplyUpdate

func (comment *Comment) ApplyUpdate(update CommentUpdate)

func (*Comment) IsChangeObject

func (*Comment) IsChangeObject()

IsChangeObject is an interface implementation to identify it as a valid ChangeObject in GQL.

type CommentFilter

type CommentFilter struct {
	ChapterID *string
	Limit     int
}

type CommentUpdate

type CommentUpdate struct {
	Source        *string
	CharacterName *string
	CharacterID   *string
	Subject       *string
	FictionalDate *time.Time
}

type File

type File struct {
	ID       string    `bson:"_id" json:"id"`
	Time     time.Time `bson:"time" json:"time"`
	Kind     string    `bson:"kind" json:"kind"`
	Public   bool      `bson:"public" json:"public"`
	Name     string    `bson:"name" json:"name"`
	MimeType string    `bson:"mimeType" json:"mimeType"`
	Size     int64     `bson:"size" json:"size"`
	Author   string    `bson:"author" json:"author"`
	URL      string    `bson:"url,omitempty" json:"url,omitempty"`
}

A File is a record of a file stored in the Space.

func (*File) IsChangeObject

func (*File) IsChangeObject()

IsChangeObject is an interface implementation to identify it as a valid ChangeObject in GQL.

type FileFilter

type FileFilter struct {
	Author    *string
	Public    *bool
	MimeTypes []string
}

A FileFilter is a filter that can be used to filter files.

type FileUpdate

type FileUpdate struct {
	Public *bool
	Name   *string
}

A FileUpdate is a set of changes possible to do on file metadata.

type Key

type Key struct {
	ID     string `bson:"_id"`
	Name   string `bson:"name"`
	User   string `bson:"user"`
	Secret string `bson:"secret"`
}

A Key contains a JWT secret and the limitations of it. There are two types of keys, single-user keys and wildcard keys. The former is used to authenticate a single user (e.g. the logbot) through an API while the latter is only for services that can be trusted to perform its own authentication (a frontend).

func (*Key) ValidForUser

func (key *Key) ValidForUser(user string) bool

ValidForUser returns true if the key's user is the same as the user, or it's a wildcard key.

type KeyFilter

type KeyFilter struct {
	UserID *string
}

type Log

type Log struct {
	ID           string    `bson:"_id"`
	ShortID      string    `bson:"shortId"`
	Date         time.Time `bson:"date"`
	ChannelName  string    `bson:"channel"`
	EventName    string    `bson:"event,omitempty"`
	Title        string    `bson:"title,omitempty"`
	Description  string    `bson:"description,omitempty"`
	Open         bool      `bson:"open"`
	CharacterIDs []string  `bson:"characterIds"`
}

Log is the header/session for a log file.

func (*Log) ApplyUpdate

func (log *Log) ApplyUpdate(update LogUpdate)

func (*Log) IsChangeObject

func (*Log) IsChangeObject()

IsChangeObject is an interface implementation to identify it as a valid ChangeObject in GQL.

type LogFilter

type LogFilter struct {
	Open       *bool
	Characters []string
	Channels   []string
	Events     []string
	MinDate    *time.Time
	MaxDate    *time.Time
	Search     *string
	Limit      int
}

A LogFilter is a filter that can be used to list logs.

type LogImporter

type LogImporter string

LogImporter describes a model related log importing.

const (
	// LogImporterMircLike is a value of LogImporter
	LogImporterMircLike LogImporter = "MircLike"
	// LogImporterForumLog is a value of LogImporter
	LogImporterForumLog LogImporter = "ForumLog"
	// LogImporterForumLog is a value of LogImporter
	LogImporterIrcCloud LogImporter = "IrcCloud"
)

func (LogImporter) IsValid

func (e LogImporter) IsValid() bool

IsValid returns true if the underlying string is one of the correct values.

func (LogImporter) MarshalGQL

func (e LogImporter) MarshalGQL(w io.Writer)

MarshalGQL marshals the underlying graphql value.

func (LogImporter) String

func (e LogImporter) String() string

func (*LogImporter) UnmarshalGQL

func (e *LogImporter) UnmarshalGQL(v interface{}) error

UnmarshalGQL unmarshals the underlying graphql value.

type LogSuggestion

type LogSuggestion struct {
	Log        *Log
	Characters []*Character
	HasChannel bool
	HasEvent   bool
}

A LogSuggestion is a suggestion for a log.

type LogUpdate

type LogUpdate struct {
	Title        *string
	EventName    *string
	Description  *string
	Open         *bool
	CharacterIDs []string
}

type Post

type Post struct {
	ID       string    `bson:"_id"`
	LogID    string    `bson:"logId"`
	Time     time.Time `bson:"time"`
	Kind     string    `bson:"kind"`
	Nick     string    `bson:"nick"`
	Text     string    `bson:"text"`
	Position int       `bson:"position"`
}

A Post is a part of a log file.

func (*Post) ApplyUpdate

func (post *Post) ApplyUpdate(update PostUpdate)

func (*Post) IsChangeObject

func (*Post) IsChangeObject()

IsChangeObject is an interface implementation to identify it as a valid ChangeObject in GQL.

type PostFilter

type PostFilter struct {
	IDs    []string
	Kinds  []string
	LogID  *string
	Search *string
	Limit  int
}

PostFilter is used to generate a query to the database.

type PostUpdate

type PostUpdate struct {
	Time *time.Time
	Kind *string
	Nick *string
	Text *string
}

type Story

type Story struct {
	ID                  string        `bson:"_id"`
	Author              string        `bson:"author"`
	Name                string        `bson:"name"`
	Category            StoryCategory `bson:"category"`
	Open                bool          `bson:"open"`
	Listed              bool          `bson:"listed"`
	Tags                []Tag         `bson:"tags"`
	CreatedDate         time.Time     `bson:"createdDate"`
	FictionalDate       time.Time     `bson:"fictionalDate,omitempty"`
	UpdatedDate         time.Time     `bson:"updatedDate"`
	SortByFictionalDate bool          `bson:"sortByFictionalDate"`
}

A Story is user content that does not have a wiki-suitable format. Documents, new stories, short stories, and so on. The story model is a container for multiple chapters this time, in contrast to the previous version.

func (*Story) ApplyUpdate

func (story *Story) ApplyUpdate(update StoryUpdate)

func (*Story) IsChangeObject

func (_ *Story) IsChangeObject()

IsChangeObject is an interface implementation to identify it as a valid ChangeObject in GQL.

type StoryCategory

type StoryCategory string

StoryCategory represents the category of a story.

const (
	// StoryCategoryInfo is a story category, see GraphQL documentation.
	StoryCategoryInfo StoryCategory = "Info"
	// StoryCategoryNews is a story category, see GraphQL documentation.
	StoryCategoryNews StoryCategory = "News"
	// StoryCategoryDocument is a story category, see GraphQL documentation.
	StoryCategoryDocument StoryCategory = "Document"
	// StoryCategoryBackground is a story category, see GraphQL documentation.
	StoryCategoryBackground StoryCategory = "Background"
	// StoryCategoryStory is a story category, see GraphQL documentation.
	StoryCategoryStory StoryCategory = "Story"
)

func (*StoryCategory) IsValid

func (e *StoryCategory) IsValid() bool

IsValid returns whether the category is one of the valid values.

func (StoryCategory) MarshalGQL

func (e StoryCategory) MarshalGQL(w io.Writer)

MarshalGQL turns it into a JSON string

func (*StoryCategory) UnmarshalGQL

func (e *StoryCategory) UnmarshalGQL(v interface{}) error

UnmarshalGQL unmarshals

type StoryFilter

type StoryFilter struct {
	Author                *string
	Tags                  []Tag
	EarliestFictionalDate time.Time
	LatestFictionalDate   time.Time
	Category              *StoryCategory
	Open                  *bool
	Unlisted              *bool
	Limit                 int
}

type StoryUpdate

type StoryUpdate struct {
	Name                *string
	Category            *StoryCategory
	Author              *string
	Open                *bool
	Listed              *bool
	FictionalDate       *time.Time
	UpdatedDate         *time.Time
	SortByFictionalDate *bool
}

type Tag

type Tag struct {
	Kind TagKind `bson:"kind"`
	Name string  `bson:"name"`
}

A Tag associates a story with other content, like other stories, logs and more.

func DecodeTagArray

func DecodeTagArray(arr []string) ([]*Tag, error)

func (*Tag) Decode

func (tag *Tag) Decode(v string) error

func (*Tag) Equal

func (tag *Tag) Equal(other Tag) bool

Equal returns true if the tags match one another.

func (*Tag) IsChangeObject

func (*Tag) IsChangeObject()

IsChangeObject is an interface implementation to identify it as a valid ChangeObject in GQL.

func (*Tag) String

func (tag *Tag) String() string

type TagFilter

type TagFilter struct {
	Kind *TagKind `bson:"kind,omitempty"`
}

TagFilter is a filter for tag listing.

type TagKind

type TagKind string

TagKind represents the kind of tags.

const (
	// TagKindOrganization is a tag kind, see GraphQL documentation.
	TagKindOrganization TagKind = "Organization"

	// TagKindCharacter is a tag kind, see GraphQL documentation.
	TagKindCharacter TagKind = "Character"

	// TagKindLocation is a tag kind, see GraphQL documentation.
	TagKindLocation TagKind = "Location"

	// TagKindEvent is a tag kind, see GraphQL documentation.
	TagKindEvent TagKind = "Event"

	// TagKindSeries is a tag kind, see GraphQL documentation.
	TagKindSeries TagKind = "Series"
)

func (TagKind) MarshalGQL

func (e TagKind) MarshalGQL(w io.Writer)

MarshalGQL turns it into a JSON string

func (*TagKind) UnmarshalGQL

func (e *TagKind) UnmarshalGQL(v interface{}) error

UnmarshalGQL unmarshals

type Token

type Token struct {
	UserID      string
	Permissions []string
}

A Token contains the parsed results from an bearer token. Its methods are safe to use with a nil receiver, but the userID should be checked.

func (*Token) Authenticated

func (token *Token) Authenticated() bool

Authenticated returns true if the token is non-nil and parsed

func (*Token) Permitted

func (token *Token) Permitted(permissions ...string) bool

Permitted returns true if the token is non-nil and has the given permission or the "admin" permission

func (*Token) PermittedUser

func (token *Token) PermittedUser(userID, permissionIfUser, permissionOtherwise string) bool

PermittedUser checks the first permission if the user matches, the second otherwise. This is a common pattern.

type UnknownNick

type UnknownNick struct {
	Nick  string `bson:"_id"`
	Score int    `bson:"score"`
}

UnknownNick represents an unknown nick name.

type User

type User struct {
	ID          string   `bson:"_id" json:"id"`
	Nick        string   `bson:"nick,omitempty" json:"nick,omitempty"`
	Permissions []string `bson:"permissions" json:"permissions"`
}

A User represents user information about a user that has logged in.

func (*User) Permitted

func (user *User) Permitted(permissions ...string) bool

Permitted returns true if either of the permissions can be found

`token.UserID == page.Author || token.Permitted("story.edit")`

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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