ipc

package
v0.0.0-...-9648343 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package ipc describes an IPC request/response protocol for communicating chat commands and chat response messages.

Index

Constants

View Source
const (
	// CooldownUser mode cools down the channel as well as the user and is the
	// default mode.
	CooldownUser int = 0

	// CooldownChannel mode cools down the channel only.
	CooldownChannel = 1

	// CooldownNone mode does not have a user/channel cooldown. Rather, the
	// command has its own cooldown implementation or uses a cooldown key that
	// can ignore channel cooldown.
	CooldownNone = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Commands []string `json:"commands"`
	// A verbatim command never has a prefix adjustment
	Verbatim     bool   `json:"verbatim,omitempty"`
	Strict       bool   `json:"strict,omitempty"`        // Does not accept arguments
	ArgValidator string `json:"arg_validator,omitempty"` // Regex to apply to argument string

	Endpoint string `json:"endpoint"`

	Async bool `json:"async,omitempty"`

	Admin        bool   `json:"admin,omitempty"`
	Owner        bool   `json:"owner,omitempty"`
	Privileged   bool   `json:"privileged,omitempty"`
	AlwaysOn     bool   `json:"online,omitempty"`
	CooldownMode int    `json:"cooldown_mode,omitempty"`
	Cooldown     string `json:"cooldown,omitempty"`
	CooldownTime int    `json:"cooldown_int,omitempty"`
}

A Command is a complete description of a command and its keywords.

type Fragment

type Fragment struct {
	// M is the token
	M string `json:"m"`
	// If X is set, banphrase checking needs to be performed
	X bool `json:"x,omitempty"`
}

A Fragment is a partial message. Individual elements of the message can be banphrase-checked.

func M

func M(s string) Fragment

M is used to create a fragment that does not need to be banphrase-checked.

func X

func X(s string) Fragment

X is used to create a fragment that should be banphrase-checked.

type Host

type Host struct {
	BaseURL string            `json:"base_url"`
	Headers map[string]string `json:"headers"`
	MsgPack bool              `json:"msgpack,omitempty"`
}

A Host implements commands.

type HostCommandSet

type HostCommandSet struct {
	ID       string            `json:"id"`
	BaseURL  string            `json:"base_url"`
	Headers  map[string]string `json:"headers,omitempty"`
	MsgPack  bool              `json:"msgpack,omitempty"`
	Commands []Command         `json:"commands"`

	// TODO: perhaps this is per command
	SetTag  string `json:"set_tag"`
	Whisper bool   `json:"whisper,omitempty"`
}

A HostCommandSet is used to communicate the commands offered by a service.

func (HostCommandSet) Host

func (hcs HostCommandSet) Host() Host

Host extracts a Host structure from a HostCommandSet.

type Response

type Response = TwitchMessageResponse

func Direct

func Direct(display, msg string) Response

Direct returns a direct response to a user. Intended for system messages.

func Reply

func Reply(display string, frags ...Fragment) Response

func Respond

func Respond(args ...Fragment) Response

type TwitchMessageContext

type TwitchMessageContext struct {
	Timestamp         int64             `json:"ts"`
	User              string            `json:"user"`
	UserID            string            `json:"uid"`
	DisplayName       string            `json:"display"`
	TargetUser        string            `json:"target"` // For whispers, equal to User
	Tags              map[string]string `json:"tags,omitempty"`
	NormalizedMessage string            `json:"msg"`
	Prefix            string            `json:"prefix,omitempty"`
	Command           string            `json:"cmd"`
	Args              []string          `json:"args"`
}

A TwitchMessageContext is a message context for Twitch-based command triggers.

type TwitchMessageResponse

type TwitchMessageResponse struct {
	Fragments []Fragment `json:"fragmsg,omitempty"`

	Command  bool   `json:"cmd,omitempty"` // Execute as command
	Response string `json:"response,omitempty"`

	Inline  bool `json:"inline,omitempty"`  // Can be inlined
	Whisper bool `json:"whisper,omitempty"` // Should reply as whisper

	CooldownKey  string `json:"cooldown_key,omitempty"`
	CooldownTime int    `json:"cooldown_time,omitempty"`

	// Output should be discarded if it was recently sent
	IsCooldownReaction bool `json:"is_cooldown_reaction,omitempty"`
}

A TwitchMessageResponse is a response to a command. If Response is empty, the cooldown associated with the command is not processed.

TODO: support high-rate commands like Pajbot does to merge command output using templated/combined message responses.

Jump to

Keyboard shortcuts

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