chat

package
v0.0.0-...-d1826b6 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: AGPL-3.0, MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Global = New()

Global represents a global chat. Players will write in this chat by default when they send any message in the chat.

Functions

This section is empty.

Types

type Chat

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

Chat represents the in-game chat. Messages may be written to it to send a message to all subscribers. The zero value of Chat is a chat ready to use. Methods on Chat may be called from multiple goroutines concurrently. Chat implements the io.Writer and io.StringWriter interfaces. fmt.Fprintf and fmt.Fprint may be used to write formatted messages to the chat.

func New

func New() *Chat

New returns a new chat.

func (*Chat) Close

func (chat *Chat) Close() error

Close closes the chat, removing all subscribers from it.

func (*Chat) Subscribe

func (chat *Chat) Subscribe(s Subscriber)

Subscribe adds a subscriber to the chat, sending it every message written to the chat. In order to remove it again, use Chat.Unsubscribe().

func (*Chat) Subscribed

func (chat *Chat) Subscribed(s Subscriber) bool

Subscribed checks if a subscriber is currently subscribed to the chat.

func (*Chat) Unsubscribe

func (chat *Chat) Unsubscribe(s Subscriber)

Unsubscribe removes a subscriber from the chat, so that messages written to the chat will no longer be sent to it.

func (*Chat) Write

func (chat *Chat) Write(p []byte) (n int, err error)

Write writes the byte slice p as a string to the chat. It is equivalent to calling Chat.WriteString(string(p)).

func (*Chat) WriteString

func (chat *Chat) WriteString(s string) (n int, err error)

WriteString writes a string s to the chat.

type StdoutSubscriber

type StdoutSubscriber struct{}

StdoutSubscriber is an implementation of Subscriber that forwards messages sent to the chat to the stdout.

func (StdoutSubscriber) Message

func (c StdoutSubscriber) Message(a ...interface{})

Message ...

type Subscriber

type Subscriber interface {
	// Message sends a formatted message to the subscriber. The message is formatted as it would when using
	// fmt.Println.
	Message(a ...interface{})
}

Subscriber represents an entity that may subscribe to a Chat. In order to do so, the Subscriber must implement methods to send messages to it.

Jump to

Keyboard shortcuts

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