shige

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2015 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package shige implements Shigebot, a twitch irc bot.

Index

Constants

View Source
const BotName = "Shigebot 1.1.6"

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	// If not nil, this function will be called when a PRIVMSG is received.
	// The function must return true if the handling of this message should
	// continue (the message will be forwarded to all the internal command
	// handlers) or false otherwise.
	OnPrivmsg func(*irc.Event) bool

	// The documentation for all the built-in commands. This is already set
	// by default, but it can be modified when there is a need to customize the
	// built-in commands or how they show up in the gist.
	BuiltinCommandsInfo string
	// contains filtered or unexported fields
}

A Bot is an instance of Shigebot connected to multiple channels on twitch on a single twitch account.

func Init

func Init(twitchUser, twitchOauth, gistOAuth string, channelList []string,
	isMod, caseSensitive bool) (b *Bot, err error)

Init initializes a new instance of Bot and connects to twitch irc servers using twitchUser and twitchOauth as credentials. Each channel in channelList is joined (channel names must include the # prefix). The isMod flag specifies whether the bot's account is a moderator in the channels it will join. Running in non-moderator mode will result in a lower message rate limit as well as randomization of each message by appending a random number to bypass twitch spam prevention. caseSensitive makes text commands case sensitive if true. gistOAuth is the github oauth token that will be used to upload the command list. Returns a pointer to the Bot instance and an error if anything goes wrong.

func (Bot) AddCommand

func (b Bot) AddCommand(name string, handler func(*CommandData))

AddCommand adds a command and binds it to handler.

func (Bot) Channel

func (b Bot) Channel(channel string) *Channel

Channel returns a pointer to channel.

func (Bot) CommandExists

func (b Bot) CommandExists(name string) bool

CommandExists returns whether the command exists.

func (Bot) Ignore

func (b Bot) Ignore(nicknames ...string)

Ignore ignores text commands for a list of nicks. Note: the bot ignores itself by default.

func (Bot) Ignored

func (b Bot) Ignored(nick string) bool

Ignored returns whether text commands are ignored for the nickname.

func (Bot) Irc

func (b Bot) Irc() *irc.Connection

Irc returns a pointer to the irc connection object used by the bot.

func (*Bot) Join

func (b *Bot) Join(channel string)

Join makes the bot join channel and load any commands that might have been previously saved for that channel.

func (Bot) Part

func (b Bot) Part(channel string)

Part makes the bot leave channel.

func (Bot) Privmsgf

func (b Bot) Privmsgf(channel, format string, args ...interface{})

Privmsgf formats and sends a rate-limited message to channel.

func (Bot) RemoveCommand

func (b Bot) RemoveCommand(name string)

RemoveCommand removes a command.

func (Bot) Run

func (b Bot) Run()

Run starts the bot, allowing it to start handling commands.

func (Bot) Unignore

func (b Bot) Unignore(nicknames ...string)

Unignore restores text commands for a list of nicks.

type Channel

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

A Channel is a single irc channel to which the bot is connected.

func (Channel) AddCommand

func (c Channel) AddCommand(name, text string) error

AddCommand adds a simple text command.

func (*Channel) AddMod

func (c *Channel) AddMod(nick string)

AddMod allows nick to use mod commands.

func (Channel) Command

func (c Channel) Command(name string) *TextCommand

Command returns a pointer to a command.

func (Channel) CommandExists

func (c Channel) CommandExists(name string) bool

CommandExists returns whether a command exists.

func (Channel) CommandList

func (c Channel) CommandList() string

CommandList returns a comma-separated list of the commands, prefixing moderator commands with a +. The list is alphabetically sorted.

func (Channel) EditCommand

func (c Channel) EditCommand(name, text string) error

EditCommand replaces the text of an existing simple text command.

func (Channel) FullCommandList

func (c Channel) FullCommandList(separator, modPrefix string,
	noDescription bool) (res string)

FullCommandList retrieves a list of the commands and their description (or text if they are simple text commands) separated by the string separator. Mod commands will be prefixed by the modPrefix string. If noDescription is true, description or text will be omitted. The list is alphabetically sorted.

func (Channel) IsMod

func (c Channel) IsMod(nick string) bool

IsMod returns whether nick is allowed to use mod commands.

func (Channel) Printf

func (c Channel) Printf(format string, args ...interface{})

Printf calls fmt.Printf with the channel name as a prefix to the text.

func (Channel) Println

func (c Channel) Println(args ...interface{})

Println calls fmt.Println with the channel name as a prefix to the text.

func (Channel) Privmsgf

func (c Channel) Privmsgf(format string, args ...interface{})

Privmsgf formats and sends a rate-limited message.

func (Channel) RemoveCommand

func (c Channel) RemoveCommand(name string) error

RemoveCommand removes a simple text command.

func (*Channel) RemoveMod

func (c *Channel) RemoveMod(nick string)

RemoveMod revokes the use of mod commands for nick.

func (Channel) SetCommandMod

func (c Channel) SetCommandMod(name string, modOnly bool) error

SetCommandMod sets whether a command is for mods only or not.

type CommandData

type CommandData struct {
	// Channel is a pointer to the channel where this message originated.
	Channel *Channel
	// Args contains every parameter after the command name. It is built using
	// strings.Fields, so repeated whitespace is ignored.
	Args []string
	// Nick is the nickname of the user that sent the command.
	Nick string
}

CommandData holds information about a chat message that contains a recognized command.

type TextCommand

type TextCommand struct {
	// Text is the reply that the command will trigger.
	Text string
	// ModOnly is true when the command is reserved for mods.
	ModOnly bool
	// LastUsage is the time the command was last used
	LastUsage time.Time
}

A TextCommand is a simple text command in a irc channel.

Directories

Path Synopsis
Package gist implements utilities to communicate with the github gist API.
Package gist implements utilities to communicate with the github gist API.

Jump to

Keyboard shortcuts

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