core

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResponseTypeEither   ResponseTypeEnum = iota
	ResponseTypeFull                      = iota
	ResponseTypeFragment                  = iota
)

Variables

This section is empty.

Functions

func AddCommand

func AddCommand(from, channel string, command CommandEnum, args ...string)

AddCommand adds an IncomingCommand to the command queue.

func AddScheduledCommand

func AddScheduledCommand(trigger time.Time, from, channel string, command CommandEnum, args ...string)

AddScheduledCommand adds a Job to the main Scheduler.

func DeliverAnalysis

func DeliverAnalysis(channel, format string, a ...interface{})

DeliverAnalysis adds an echo command to the queue.

func GetOffsetForOrdinal added in v0.1.0

func GetOffsetForOrdinal(ordinal string) string

GetOffsetForOrdinal gets the offset for a given ordinal number string.

func GetTriggerFromParserResult

func GetTriggerFromParserResult(result *ParserResult) (bool, time.Time)

GetTriggerFromParserResult does what it says.

func OnResponse

func OnResponse(callback func(channel, response string))

OnResponse sets a response callback.

func ShouldParse added in v0.0.3

func ShouldParse(message string) bool

ShouldParse returns whether the message should be NLP parsed.

func Shutdown

func Shutdown()

Shutdown ends the main execution and scheduler loops.

func StartLoop

func StartLoop(context ContextEnum, identifier string)

StartLoop starts the main execution loop.

Types

type ArgsList

type ArgsList []string

ArgsList is a list of arguments.

func (ArgsList) Get

func (a ArgsList) Get(index int) string

Get returns a string value for the argument at the given postiion.

type Article added in v0.2.1

type Article struct {
	ID             int    `json:"id"`
	URL            string `json:"url"`
	RelatedURL     string `json:"relatedUrl,omitempty"`
	SourceURL      string `json:"sourceUrl,omitempty"`
	SourceTitle    string `json:"sourceTitle,omitempty"`
	SourceImageURL string `json:"sourceImageUrl,omitempty"`
	Title          string `json:"title"`
	Description    string `json:"description,omitempty"`
	Published      int64  `json:"published"`
	Updated        int64  `json:"updated,omitempty"`
	Created        int64  `json:"created"`
	Feed           *Feed  `json:"feed"`
}

type ArticleAPIResponse added in v0.3.0

type ArticleAPIResponse struct {
	Items []*Article `json:"items"`
}

ArticleAPIResponse represents an article API response.

type CommandEnum

type CommandEnum int

CommandEnum represents a Command type.

const (
	CommandHelp CommandEnum = iota
	CommandUptime
	CommandAbout
	CommandSocial
	CommandTrack
	CommandLatestPost
	CommandLatestArticle
	CommandWeather
	CommandRain
	CommandSnow
	CommandRandomNumber
	CommandCoinFlip
	CommandWinner
	CommandGif
	CommandTime
	CommandDate
	CommandEcho
	CommandChangeMood
	CommandIgnoreUser
	CommandTrustUser
	CommandForgetUser
	CommandToggleAnalysis
	CommandSchedule
)

type CommandMap

type CommandMap map[string][]*IncomingCommand

CommandMap is a map of string to list of IncomingCommand structs.

func (CommandMap) Add

func (m CommandMap) Add(key string, command *IncomingCommand)

Add adds a IncomingCommand to the list found at the given key.

type CommandQueue

type CommandQueue struct {
	// contains filtered or unexported fields
}

CommandQueue is an array of IncomingCommand structs and a Mutex.

func (*CommandQueue) Add

func (q *CommandQueue) Add(command *IncomingCommand)

Add adds an IncomingCommand to the queue.

func (*CommandQueue) Execute

func (q *CommandQueue) Execute() []*Sequence

Execute returns a list of Sequences from the command queue and clears it.

type ContextEnum

type ContextEnum int

ContextEnum represents the execution context (IRC, Twitch)

const (
	ContextIRC ContextEnum = iota
	ContextTwitch
	ContextWeb
)

func (ContextEnum) String

func (c ContextEnum) String() string

type Feed added in v0.3.0

type Feed struct {
	ID          int    `json:"id"`
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	About       string `json:"about,omitempty"`
	FeedURL     string `json:"feedUrl,omitempty"`
	SiteURL     string `json:"siteUrl"`
	ImageURL    string `json:"imageUrl,omitempty"`
}

type IncomingCommand

type IncomingCommand struct {
	Command CommandEnum
	Args    ArgsList
	From    string
	Channel string
}

IncomingCommand represents a command from a user.

func (*IncomingCommand) Hash

func (c *IncomingCommand) Hash() string

Hash returns a hash value for the command and arguments.

type Job

type Job struct {
	Command CommandEnum
	Args    []string
	Channel string
	From    string
	Trigger time.Time
}

Job represents a scheduled command.

type MoodEnum

type MoodEnum int

MoodEnum represents a bot mood.

const (
	MoodNone MoodEnum = iota
	MoodDefault
	MoodQuiet
	MoodAngry
)

func (MoodEnum) String

func (m MoodEnum) String() string

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser represents a map of Commands to PhraseDefinition objects.

func (*Parser) LoadPhrase

func (p *Parser) LoadPhrase(phrase string, command CommandEnum, args ...string)

LoadPhrase adds a phrase as a PhraseDefinition object to memory.

func (*Parser) LoadPhraseWithPrepositions

func (p *Parser) LoadPhraseWithPrepositions(command CommandEnum, phrase string)

LoadPhraseWithPrepositions adds prepositional phrases for a given phrase.

func (*Parser) LoadPhrases

func (p *Parser) LoadPhrases(command CommandEnum, phrases ...string)

LoadPhrases adds a list of phrases as PhraseDefinition objects to memory.

func (*Parser) Parse

func (p *Parser) Parse(message string) ParserResults

Parse converts a string to a list of ParserResult objects.

type ParserResult

type ParserResult struct {
	Command    CommandEnum
	Args       ArgsList
	ParsedArgs map[string]string
	Index      int
}

ParserResult represents a discovered command and it's arguments.

func Parse

func Parse(text string) []*ParserResult

Parse extracts commands from a message.

func (*ParserResult) GetParsedArg added in v0.2.1

func (r *ParserResult) GetParsedArg(key string) string

GetParsedArg returns a trimmed parsed argument.

type ParserResults

type ParserResults []*ParserResult

ParserResults represents a list of ParserResult objects.

func (ParserResults) Len

func (r ParserResults) Len() int

func (ParserResults) Less

func (r ParserResults) Less(i, j int) bool

func (ParserResults) Swap

func (r ParserResults) Swap(i, j int)

type PhraseDefinition

type PhraseDefinition struct {
	Command    CommandEnum
	Args       ArgsList
	RE         *regexp.Regexp
	ParsedArgs ArgsList
}

PhraseDefinition represents a regular expression and a list of matches.

type Post added in v0.2.1

type Post struct {
	ID      string    `json:"id"`
	Title   string    `json:"title"`
	Created time.Time `json:"created"`
	Tags    []Tag     `json:"tags"`
}

func (*Post) GetTags added in v0.2.1

func (p *Post) GetTags() string

func (*Post) GetURL added in v0.2.1

func (p *Post) GetURL() string

type PreparedCommand

type PreparedCommand struct {
	Command CommandEnum
	Args    ArgsList
	Users   []string
	Mood    MoodEnum
	Context ContextEnum
}

PreparedCommand represents a command with execution state.

func (*PreparedCommand) Execute

func (c *PreparedCommand) Execute() *ResponseMap

Execute returns a ResponseMap from a command.

func (*PreparedCommand) UserString

func (c *PreparedCommand) UserString() string

UserString returns a concatenated list of users.

type Response

type Response struct {
	Text  string `json:"text"`
	Delay int    `json:"delay"`
}

Response represents one text Response and wait time before sending.

type ResponseMap

type ResponseMap struct {
	// contains filtered or unexported fields
}

ResponseMap represents a tree of responses.

func (*ResponseMap) Get

Get a ResponseSet.

func (*ResponseMap) Set

func (t *ResponseMap) Set(rt ResponseTypeEnum, responses ResponseSet)

Set a ResponseSet.

func (*ResponseMap) SetEither

func (t *ResponseMap) SetEither(text string, delay int)

SetEither sets a single Response.

func (*ResponseMap) SetFragment

func (t *ResponseMap) SetFragment(text string)

SetFragment sets a single Response.

func (*ResponseMap) SetSentence

func (t *ResponseMap) SetSentence(text string, delay int)

SetSentence sets a single Response.

type ResponseSet

type ResponseSet []*Response

ResponseSet is a list of Response objects.

func CombineResponseMaps

func CombineResponseMaps(user string, responses []*ResponseMap) ResponseSet

CombineResponseMaps combines an array of ResponseMaps into one ResponseSet

type ResponseTypeEnum

type ResponseTypeEnum int

ResponseTypeEnum respresents a the type of Response.

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler manages a list of Jobs.

func NewScheduler

func NewScheduler() *Scheduler

NewScheduler returns a new Scheduler object.

func (*Scheduler) Add

func (s *Scheduler) Add(job *Job)

Add adds a Job to the Scheduler.

func (*Scheduler) Execute

func (s *Scheduler) Execute()

Execute runs eligible Jobs.

func (*Scheduler) Len

func (s *Scheduler) Len() int

func (*Scheduler) Less

func (s *Scheduler) Less(i, j int) bool

func (*Scheduler) Swap

func (s *Scheduler) Swap(i, j int)

type Sequence

type Sequence struct {
	Channel   string
	Responses ResponseSet
}

Sequence represents a ResponseSet and the channel to send to.

func (*Sequence) Length

func (s *Sequence) Length() int

Length returns the number of Responses in the Sequence.

type SimpleParserResult

type SimpleParserResult struct {
	Command string
	Args    ArgsList
}

SimpleParserResult represents a discovered command and it's arguments.

func SimpleParse

func SimpleParse(text, d string) *SimpleParserResult

SimpleParse looks for a basic command in a message.

type Tag added in v0.2.1

type Tag struct {
	ID    string `json:"id"`
	About string `json:"about"`
}

type UserRecord

type UserRecord struct {
	ID      string    `json:"id"`
	Name    string    `json:"name"`
	Context string    `json:"context"`
	Opinion int       `json:"opinion"`
	Mood    MoodEnum  `json:"mood"`
	Created time.Time `json:"created"`
}

UserRecord represents a user the bot knows.

Jump to

Keyboard shortcuts

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