models

package
v0.0.0-...-a9e5fbf Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Everyone can call the command
	PermissionEveryone int = 1 << 0
	// Follower only
	// PermissionFollower int = 1 << 1
	// Subscriber only
	PermissionSubscriber int = 1 << 2
	// Vip only
	// PermissionVip int = 1 << 3
	// Moderator only
	PermissionModerator int = 1 << 4
	// Streamer only. Streamer always has permission by default.
	// Is this flag really needed?
	PermissionStreamer int = 1 << 5
)

User levels for command. Externally, only Everyone, Moderator, Streamer will be available.

View Source
const (
	// TextTokenType pure text token in parsed response
	TextTokenType = 1
	// VariableTokenType variable token, in form of $(name [args0, args1, ...])
	// For example, $(channel_id), $(countup OOO), etc. are of variable token type
	VariableTokenType = 2
)

Variables

View Source
var (
	// Default response keys in response map
	DefaultResponseKey        = "DEFAULT"
	DefaultFailureResponseKey = "FAILURE"
)

Functions

This section is empty.

Types

type Bot

type Bot struct {
	// Bot's Twitch ID
	TwitchID int64 `dynamo:"ID,hash"`
	// Bot's Twitch username
	Username string `index:"Username-index,hash"`
	// Twitch Oauth token
	OauthToken string
}

Bot contains info about Twitch chatbots.

type Channel

type Channel struct {
	// Channel's Twitch ID
	TwitchID int64 `dynamo:"ID,hash"`
	// Channel's Twitch Username
	Username string `index:"Username-index,hash"`
	// Channel's Twitch display name
	DisplayName string
	// Bots which join this channel
	BotIDs []int64 `dynamo:",set"`
	// Commands of the channel
	Commands map[string]Command // `dynamo:",set"`
	// Channel's preferred locale. Default to en-us if empty
	LocaleID string
}

Channel describes Twitch channel

type Command

type Command struct {
	// Generated (not by DB) unique ID for command
	// UUID string `dynamo:"ID,hash"`
	// Bot's Twitch ID
	BotID int64
	// Channel's Twitch ID
	ChannelID int64
	// Command name
	Name string
	// Chat plugin type: response, add_command, edit_command, delete_command, etc
	PluginType string
	// Bot's Response, in parsed form
	Responses map[string]ParsedResponse // `dynamo:",set"`
	// Cooldown in seconds
	CooldownSecond int
	// Permission bitset as integer
	Permission int
	// True if enabled
	Enabled bool
	// Group of commands. Commands can be active/inactive per group.
	Group string
	// Locale ID (BCP 47 Code) for default localized message. Fallback to the streamer's if empty
	LocaleID string
}

Command chatbot commands

func NewCommand

func NewCommand(botID int64, channelID int64, name string, plugintype string, defaultResponse *ParsedResponse,
	failureReaponse *ParsedResponse, localeID string) *Command

Create a new Command object with inputs.

type ParsedResponse

type ParsedResponse struct {
	RawText string // RawText is simply concated RawText of tokens. Is it really needed?
	Tokens  []Token
}

ParsedResponse response raw text is parsed into tokens TODO: Any better name than "parsed reponse"?

type PluginData

type PluginData struct {
	// Partition key. Composite of (PluginType, ChannelID, Key)
	// TODO: Find out how to configure composite partition key in the library
	PrimaryKey string `dynamo:"ID,hash"`
	// Plugin Type
	PluginType string `index:"PluginType-index,hash"`
	// Channel's integer Twitch ID. Don't use username which can change
	ChannelID int64 `index:"ChannelID-index,hash"`
	// Key. Plugin-dependent. Chat ID, Viewer ID, etc
	Key string
	// Value the actualy type is plugin-dependent
	Value interface{}
}

PluginData struct of data to be used by plugins

func NewPluginData

func NewPluginData(pluginType string, channelID int64, key string, value interface{}) *PluginData

NewPluginData creates a new PluginData object

type Token

type Token struct {
	RawText      string  // raw text of the token, including arguments and nested variables.
	TokenType    int     // string or variable.
	VariableName string  // needed to find Variable struct with this name.
	Arguments    []Token // for function variables like $(time [arg1]), $(rand [arg1], [arg2]), etc.
}

Token a response is parsed into a sequence of tokens, which is either a text or a variable. Each token is then passed into converter, which resolves variables and completes the response text

For example, "Welcome, $(user) to the stream. Stream is up for $(uptime)" is parsed to three tokens {"Welcome, ", "$(user)", " to the stream. Stream is up for ", "$(uptime)"} Note that

Tokens "Welcome, " and " to the stream. Stream is up for " are of TextToken type Tokens "$(user)" and "$(uptime)" are of VariableToken type

For TextToken objects, token.RawText is the value. For VariableToken objects, the value should be somehow retrieved from somewhere.

The type of arguments is Token, not string, because of nested variables

Jump to

Keyboard shortcuts

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