common

package
v0.0.0-...-75854ce Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CommandNameSeparator = ","
View Source
const InvalidNameError string = `` /* 201-byte string literal not displayed */

Variables

View Source
var Colors = []string{}/* 109 elements not displayed */

Colors holds all the valid html color names for MovieNight the values in colors must be lowercase so it matches with the color input this saves from having to call strings.ToLower(color) every time to check

View Source
var Emotes = make(EmotesMap)
View Source
var WrappedEmotesOnly bool = false

Functions

func EmoteToHtml

func EmoteToHtml(file, title string) string

func ExecuteServerTemplate

func ExecuteServerTemplate(w http.ResponseWriter, key string, data interface{}) error

func ExtractForwarded

func ExtractForwarded(r *http.Request) string

Return the value of "Forwarded" or "X-Forwarded-For", if "Forwarded" & "X-Forwarded-For" are present then "Forwarded" value is returned. Return "" if "Forwarded" and "X-Forwarded-For" are absent.

func GetFullChatCommand

func GetFullChatCommand(c string) string

func InitTemplates

func InitTemplates(filesystem fs.FS) error

Called from the server

func IsValidColor

func IsValidColor(s string) bool

IsValidColor takes a string s and compares it against a list of css color names. It also accepts hex codes in the form of #RGB and #RRGGBB

func IsValidName

func IsValidName(name string) bool

IsValidName checks that name is within the correct ranges, follows the regex defined and is not a valid color name

func LogChatf

func LogChatf(format string, v ...interface{})

func LogChatln

func LogChatln(v ...interface{})

func LogDebugf

func LogDebugf(format string, v ...interface{})

func LogDebugln

func LogDebugln(v ...interface{})

func LogErrorf

func LogErrorf(format string, v ...interface{})

func LogErrorln

func LogErrorln(v ...interface{})

func LogInfof

func LogInfof(format string, v ...interface{})

func LogInfoln

func LogInfoln(v ...interface{})

func ParseEmotes

func ParseEmotes(msg string) string

func ParseEmotesArray

func ParseEmotesArray(words []string) []string

func RandomColor

func RandomColor() string

RandomColor returns a hex color code

func SetupLogging

func SetupLogging(level LogLevel, file string) error

Types

type ChatCommandNames

type ChatCommandNames []string
var (
	// User Commands
	CNMe     ChatCommandNames = []string{"me"}
	CNHelp   ChatCommandNames = []string{"help"}
	CNCount  ChatCommandNames = []string{"count"}
	CNColor  ChatCommandNames = []string{"color", "colour"}
	CNWhoAmI ChatCommandNames = []string{"w", "whoami"}
	CNAuth   ChatCommandNames = []string{"auth"}
	CNUsers  ChatCommandNames = []string{"users"}
	CNNick   ChatCommandNames = []string{"nick", "name"}
	CNStats  ChatCommandNames = []string{"stats"}
	CNPin    ChatCommandNames = []string{"pin", "password"}
	CNEmotes ChatCommandNames = []string{"emotes"}
	// Mod Commands
	CNSv      ChatCommandNames = []string{"sv"}
	CNPlaying ChatCommandNames = []string{"playing"}
	CNUnmod   ChatCommandNames = []string{"unmod"}
	CNKick    ChatCommandNames = []string{"kick"}
	CNBan     ChatCommandNames = []string{"ban"}
	CNUnban   ChatCommandNames = []string{"unban"}
	CNPurge   ChatCommandNames = []string{"purge"}
	// Admin Commands
	CNMod          ChatCommandNames = []string{"mod"}
	CNReloadPlayer ChatCommandNames = []string{"reloadplayer"}
	CNReloadEmotes ChatCommandNames = []string{"reloademotes"}
	CNModpass      ChatCommandNames = []string{"modpass"}
	CNIP           ChatCommandNames = []string{"iplist"}
	CNRoomAccess   ChatCommandNames = []string{"changeaccess", "hodor"}
)

Names for commands

func (ChatCommandNames) String

func (c ChatCommandNames) String() string

type ChatData

type ChatData struct {
	Type DataType
	Data DataInterface
}

func NewChatCommand

func NewChatCommand(command CommandType, args []string) ChatData

func NewChatEvent

func NewChatEvent(event EventType, name, color string) ChatData

func NewChatHiddenMessage

func NewChatHiddenMessage(clientType ClientDataType, data interface{}) ChatData

func NewChatMessage

func NewChatMessage(name, color, msg string, lvl CommandLevel, msgtype MessageType) ChatData

func (ChatData) ToJSON

func (c ChatData) ToJSON() (ChatDataJSON, error)

type ChatDataJSON

type ChatDataJSON struct {
	Type DataType
	Data json.RawMessage
}

func DecodeData

func DecodeData(rawjson string) (ChatDataJSON, error)

func (ChatDataJSON) GetData

func (c ChatDataJSON) GetData() (DataInterface, error)

func (ChatDataJSON) ToData

func (c ChatDataJSON) ToData() (ChatData, error)

type ClientData

type ClientData struct {
	Type    ClientDataType
	Message string
}

func (ClientData) HTML

func (c ClientData) HTML() string

type ClientDataType

type ClientDataType int
const (
	CdMessage ClientDataType = iota // a normal message from the client meant to be broadcast
	CdUsers                         // get a list of users
	CdPing                          // ping the server to keep the connection alive
	CdAuth                          // get the auth levels of the user
	CdColor                         // get the users color
	CdEmote                         // get a list of emotes
	CdJoin                          // a message saying the client wants to join
	CdNotify                        // a notify message for the client to show
)

Data types for communicating with the client

type CommandLevel

type CommandLevel int
const (
	CmdlUser CommandLevel = iota
	CmdlMod
	CmdlAdmin
)

Command access levels

type CommandType

type CommandType int
const (
	CmdPlaying CommandType = iota
	CmdRefreshPlayer
	CmdPurgeChat
	CmdHelp
	CmdEmotes
)

Command Types

type DataCommand

type DataCommand struct {
	Command   CommandType
	Arguments []string
}

func (DataCommand) HTML

func (de DataCommand) HTML() string

type DataEvent

type DataEvent struct {
	Event EventType
	User  string
	Color string
	Users []string
}

func (DataEvent) HTML

func (de DataEvent) HTML() string

type DataInterface

type DataInterface interface {
	HTML() string
}

type DataMessage

type DataMessage struct {
	From    string
	Color   string
	Message string
	Level   CommandLevel
	Type    MessageType
}

func (DataMessage) HTML

func (dc DataMessage) HTML() string

TODO: Read this HTML from a template somewhere

type DataType

type DataType int
const (
	DTInvalid DataType = iota
	DTChat             // chat message
	DTCommand          // non-chat function
	DTEvent            // join/leave/kick/ban events
	DTClient           // a message coming from the client
	DTHidden           // a message that is purely instruction and data, not shown to user
)

Data types for command messages

type EmotesMap

type EmotesMap map[string]string

func (EmotesMap) Add

func (em EmotesMap) Add(fullpath string) EmotesMap

type EventType

type EventType int
const (
	EvJoin EventType = iota
	EvLeave
	EvKick
	EvBan
	EvServerMessage
	EvNameChange
	EvNameChangeForced
)

Event Types

type HiddenMessage

type HiddenMessage struct {
	Type ClientDataType
	Data interface{}
}

DataHidden is for the server to send instructions and data to the client without the purpose of outputting it on the chat

func (HiddenMessage) HTML

func (h HiddenMessage) HTML() string

type JoinData

type JoinData struct {
	Name  string
	Color string
}

type LogLevel

type LogLevel string
const (
	LLError LogLevel = "error" // only log errors
	LLChat  LogLevel = "chat"  // log chat and commands
	LLInfo  LogLevel = "info"  // log info messages (not quite debug, but not chat)
	LLDebug LogLevel = "debug" // log everything
)

type MessageType

type MessageType int
const (
	MsgChat            MessageType = iota // standard chat
	MsgAction                             // /me command
	MsgServer                             // server message
	MsgError                              // something went wrong
	MsgNotice                             // Like MsgServer, but for mods and admins only.
	MsgCommandResponse                    // The response from command
	MsgCommandError                       // The error response from command
)

Message Types

Jump to

Keyboard shortcuts

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