Documentation ¶
Index ¶
- Constants
- Variables
- func EmoteToHtml(file, title string) string
- func ExecuteServerTemplate(w http.ResponseWriter, key string, data interface{}) error
- func ExtractForwarded(r *http.Request) string
- func GetFullChatCommand(c string) string
- func InitTemplates(filesystem fs.FS) error
- func IsValidColor(s string) bool
- func IsValidName(name string) bool
- func LogChatf(format string, v ...interface{})
- func LogChatln(v ...interface{})
- func LogDebugf(format string, v ...interface{})
- func LogDebugln(v ...interface{})
- func LogErrorf(format string, v ...interface{})
- func LogErrorln(v ...interface{})
- func LogInfof(format string, v ...interface{})
- func LogInfoln(v ...interface{})
- func ParseEmotes(msg string) string
- func ParseEmotesArray(words []string) []string
- func RandomColor() string
- func SetupLogging(level LogLevel, file string) error
- type ChatCommandNames
- type ChatData
- func NewChatCommand(command CommandType, args []string) ChatData
- func NewChatEvent(event EventType, name, color string) ChatData
- func NewChatHiddenMessage(clientType ClientDataType, data interface{}) ChatData
- func NewChatMessage(name, color, msg string, lvl CommandLevel, msgtype MessageType) ChatData
- type ChatDataJSON
- type ClientData
- type ClientDataType
- type CommandLevel
- type CommandType
- type DataCommand
- type DataEvent
- type DataInterface
- type DataMessage
- type DataType
- type EmotesMap
- type EventType
- type HiddenMessage
- type JoinData
- type LogLevel
- type MessageType
Constants ¶
const CommandNameSeparator = ","
const InvalidNameError string = `` /* 201-byte string literal not displayed */
Variables ¶
var ChatCommands = []ChatCommandNames{ CNMe, CNHelp, CNCount, CNColor, CNWhoAmI, CNAuth, CNUsers, CNNick, CNStats, CNPin, CNEmotes, CNSv, CNPlaying, CNUnmod, CNKick, CNBan, CNUnban, CNPurge, CNMod, CNReloadPlayer, CNReloadEmotes, CNModpass, CNIP, CNRoomAccess, }
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
var Emotes = make(EmotesMap)
var WrappedEmotesOnly bool = false
Functions ¶
func EmoteToHtml ¶
func ExecuteServerTemplate ¶
func ExecuteServerTemplate(w http.ResponseWriter, key string, data interface{}) error
func ExtractForwarded ¶
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 IsValidColor ¶
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 ¶
IsValidName checks that name is within the correct ranges, follows the regex defined and is not a valid color name
func LogDebugln ¶
func LogDebugln(v ...interface{})
func LogErrorln ¶
func LogErrorln(v ...interface{})
func ParseEmotes ¶
func ParseEmotesArray ¶
func SetupLogging ¶
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 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 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 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 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