ipc

package
v0.0.0-...-e2e6f4c Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: BSD-3-Clause Imports: 1 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

View Source
var Direct = Reply

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

View Source
var NoResponse = Response{}

Functions

func M

func M(s string) string

func X

func X(s string) string

Types

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.

type IRC

type IRC struct {
	Tags    map[string]string `json:"tags,omitempty"`
	Channel string            `json:"channel,omitempty"`
}

type MessageContext

type MessageContext struct {
	Timestamp         int64  `json:"ts"`
	Platform          string `json:"platform"`
	NormalizedMessage string `json:"msg"`

	Command string   `json:"cmd"`
	Args    []string `json:"args"`
	Prefix  string   `json:"prefix,omitempty"`

	User        string `json:"user"`    // Unique, but not permanent
	UserID      string `json:"uid"`     // Unique
	DisplayName string `json:"display"` // Friendly, sometimes unique
	TargetUser  string `json:"target"`  // For whispers, equal to User

	Tags map[string]string `json:"tags,omitempty"`
}

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

func (MessageContext) Arg

func (mctx MessageContext) Arg(i int) string

func (MessageContext) Trailer

func (mctx MessageContext) Trailer(i int) string

type Response

type Response struct {
	Fragmsg   []Fragment `json:"fragmsg,omitempty"`
	Fragments []string   `json:"frags,omitempty"`

	Command            bool   `json:"cmd,omitempty"`         // Execute as command
	SkipsBanphrase     bool   `json:"no_bancheck,omitempty"` // Explicitly for commands or specialized messages
	DeprecatedResponse string `json:"response,omitempty"`
	NotIfBanphrased    bool   `json:"not_if_bp,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 Response 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.

func Reply

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

func Respond

func Respond(args ...string) Response

type Twitch

type Twitch struct {
	Tags        map[string]string `json:"tags,omitempty"`
	User        string            `json:"user"`
	UserID      string            `json:"uid"`
	DisplayName string            `json:"display"`
	TargetUser  string            `json:"target"`
	Whisper     bool              `json:"whisper,omitempty"`
}

Jump to

Keyboard shortcuts

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