core

package
v0.0.0-...-25f99af Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package core contains the bot's core functionalities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTargetFromEvent

func GetTargetFromEvent(event *irc.Event) string

GetTargetFromEvent If the message originated from a channel then return it, else return the nick that sent the message

func UpdateUserList

func UpdateUserList(event *irc.Event)

UpdateUserList Update the user list used for access control

Types

type Bot

type Bot struct {
	Admins *[]string
	// contains filtered or unexported fields
}

Bot structure that contains connection informations, IRC connection, command handlers and message handlers

func NewBot

func NewBot(nick, server, channel, channelKey string) *Bot

NewBot creates a new Bot, sets the required parameters and open the connection to the server.

func (*Bot) AddCmdHandler

func (bot *Bot) AddCmdHandler(cmdStruct *Command, replyCallback func(*ReplyCallbackData))

AddCmdHandler adds a command handler to bot. cmdStruct is a pointer to a Command structure. replyCallback is to be called by cmdProcessCallback (or not) to yield and process its result as a string message. Command handlers must return true if they found a command to process, false otherwise

func (*Bot) AddMsgHandler

func (bot *Bot) AddMsgHandler(msgProcessCallback func(*irc.Event, func(*ReplyCallbackData)), replyCallback func(*ReplyCallbackData))

AddMsgHandler adds a message handler to bot. msgProcessCallback will be called on every user message the bot reads (if a command was not found previously in the message). replyCallback is to be called by msgProcessCallback (or not) to yield and process its result as a string message.

func (*Bot) Reply

func (bot *Bot) Reply(data *ReplyCallbackData)

Reply sends a message to the user or channel specifed by "data.Target".

func (*Bot) ReplyToAll

func (bot *Bot) ReplyToAll(data *ReplyCallbackData)

ReplyToAll sends a message to the channel where the bot is connected

func (*Bot) Run

func (bot *Bot) Run()

Run starts the event loop

func (*Bot) Stop

func (bot *Bot) Stop()

Stop exits the event loop

type Command

type Command struct {
	Module      string
	HelpMessage string
	Triggers    []string
	Handler     func(event *irc.Event, callback func(*ReplyCallbackData)) bool
}

Command structure

type ReplyCallbackData

type ReplyCallbackData struct {
	Message string // Message to send
	Target  string // Destination target of the message (Channel or Nick)
}

ReplyCallbackData Structure used by the handlers to send data in a standardized format

Jump to

Keyboard shortcuts

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