bruxism

package module
v0.0.0-...-99912da Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2018 License: MIT Imports: 24 Imported by: 0

README

Bruxism

A chat bot for YouTube, Discord and IRC.

GoDoc Go report Build Status

Current plugin support:

Commands are prefixed with @BotName .

  • emoji <emoji> - Returns a big version of an emoji. Please read the README in emojiplugin for installation notes.
  • help [<topic>] - Returns generic help or help for a specific topic. Available topics: comic,remind
  • invite <id> - Provides invite URL for the bot.
  • numbertrivia [<number>] - Returns trivia for a random number or a specified number if provided.
  • playing - Set which game the bot is playing on Discord. Only enabled for bot owner.
  • reminder <time> | <reminder> - Sets a reminder.
  • stats - Lists bot statistics.
  • streamer <streamername|streamerid> - Grabs details about a YouTube streamer.
  • topstreamers - List the current top streamers on YouTube Gaming.

eg: @BotName help

Also supports direct invites on Discord and support for announcing streamers going live on YouTube Gaming.

Usage:

Installation:

go get github.com/iopred/bruxism/cmd/bruxism

go install github.com/iopred/bruxism/cmd/bruxism

cd $GOPATH/bin

Setup

You must first generate a YouTube Oauth token in the Google Developer Console.

Go to Credentials and download the JSON config file and save it in $GOPATH/bin as youtubeoauth2config.json

./bruxism -youtubeurl

You will then be given a URL (and copied to clipboard), visit that URL and copy the code, then run:

./bruxism -youtubeauth <AUTH CODE>

Now the bot can be run:

./bruxism -youtubechannelids <youtube channel id1,youtube channel id2>

Important!

The account you choose during the oauth flow is the account that the bot will use to send messages.

If you are trying to test the bot, make sure the account you are sending messages with is different from the bot account.

Bruxism ignores messages from the bot account, so if you are sharing accounts all commands will be ignored.

Run as a Discord bot

./bruxism -discordtoken "Bot <discord bot token>"

It is suggested that you set -discordapplicationclientid if you are running a bot account, this will make inviteplugin function correctly.

It is suggested that you set -discordowneruserid as this prevents anyone from calling playingplugin.

To invite your bot to a server, visit: https://discordapp.com/oauth2/authorize?client_id=<discord client id>&scope=bot

Run as an IRC bot

./bruxism -ircserver <irc server> -ircusername <irc username> -ircchannels <#channel1,#channel2>

Run as a Slack bot

./bruxism -slacktoken <slack token>

It is suggested that you set -slackowneruserid.

Image uploads

Some plugins upload images to imgur (such as chartplugin), it's suggested that you run your bot with -imgurid <imgurid> to enable this.

Arguments:

  • youtubeurl - Outputs a new OAuth URL for YouTube and then exits.
  • youtubeauth - Exchanges the provided auth code for an oauth2 token.
  • youtubeconfig - The filename for your YouTube OAuth client JSON. (Download JSON in Google Developers Console -> Credentials).
  • youtubetoken - The filename to store the oauth2 token.
  • youtubelivechannelids - Comma separated list of channel ids to poll.
  • discordtoken - Sets the Discord token.
  • discordemail - Sets the Discord account email.
  • discordpassword - Sets the Discord account password.
  • discordclientid - Sets the Discord client id.
  • ircserver - Sets the IRC server.
  • ircusername - Sets the IRC user name.
  • ircpassword - Sets the IRC password.
  • ircchannels - Comma separated list of IRC channels.
  • imgurid - Sets the Imgur client id, used for uploading images to imgur.
  • imguralbum - Sets an optional the Imgur album id, used for uploading images to imgur.
  • mashablekey - Sets the mashable oauth key.

Special Thanks

Bruce Marriner - For DiscordGo and the Music Plugin.

Documentation

Index

Constants

View Source
const (
	// MessageTypeCreate is the message type for message creation.
	MessageTypeCreate MessageType = "create"
	// MessageTypeUpdate is the message type for message updates.
	MessageTypeUpdate = "update"
	// MessageTypeDelete is the message type for message deletion.
	MessageTypeDelete = "delete"
)
View Source
const (
	LiveChatMessageSnippetTypeText       string = "textMessageEvent"
	LiveChatMessageSnippetTypeFanFunding string = "fanFundingEvent"
)

Enums for LiveMessageSnippet types.

View Source
const (
	LiveChatBanSnippetTypeTemporary string = "temporary"
	LiveChatBanSnippetTypePermanent        = "permanent"
)

Enums for LiveChatBanSnippet types.

View Source
const DiscordServiceName string = "Discord"

DiscordServiceName is the service name for the Discord service.

View Source
const IRCServiceName string = "IRC"

IRCServiceName is the service name for the IRC service.

View Source
const (
	LiveChatEndedEvent string = "chatEndedEvent"
)
View Source
const SlackServiceName string = "Slack"

SlackServiceName is the service name for the Slack service.

View Source
const VersionString string = "0.11"

VersionString is the current version of the bot

View Source
const YouTubeServiceName string = "YouTube"

YouTubeServiceName is the service name for the YouTube service.

Variables

View Source
var ErrAlreadyJoined = errors.New("Already joined.")

ErrAlreadyJoined is an error dispatched on Join if the bot is already joined to the request.

Functions

func CommandHelp

func CommandHelp(service Service, command, arguments, help string) []string

CommandHelp is a helper message that creates help text for a command. eg. CommandHelp(service, "foo", "<bar>", "Foo bar baz") will return:

!foo <bar> - Foo bar baz

The string is automatatically styled in Discord.

func MatchesCommand

func MatchesCommand(service Service, commandString string, message Message) bool

MatchesCommand returns true if a message matches a command.

func MatchesCommandString

func MatchesCommandString(service Service, commandString string, private bool, message string) bool

MatchesCommandString returns true if a message matches a command. Commands will be matched ignoring case with a prefix if they are not private messages.

func MessageRecover

func MessageRecover()

MessageRecover is the default panic handler for bruxism.

func ParseCommand

func ParseCommand(service Service, message Message) (string, []string)

ParseCommand parses a message.

func ParseCommandString

func ParseCommandString(service Service, message string) (string, []string)

ParseCommandString will strip all prefixes from a message string, and return that string, and a space separated tokenized version of that string.

Types

type Bot

type Bot struct {
	Services    map[string]*serviceEntry
	ImgurID     string
	ImgurAlbum  string
	MashableKey string
}

Bot enables registering of Services and Plugins.

func NewBot

func NewBot() *Bot

NewBot will create a new bot.

func (*Bot) Open

func (b *Bot) Open()

Open will open all the current services and begins listening.

func (*Bot) RegisterPlugin

func (b *Bot) RegisterPlugin(service Service, plugin Plugin)

RegisterPlugin registers a plugin on a service.

func (*Bot) RegisterService

func (b *Bot) RegisterService(service Service)

RegisterService registers a service with the bot.

func (*Bot) Save

func (b *Bot) Save()

Save will save the current plugin state for all plugins on all services.

func (*Bot) UploadToImgur

func (b *Bot) UploadToImgur(re io.Reader, filename string) (string, error)

UploadToImgur uploads image data to Imgur and returns the url to it.

type CommandHelpFunc

type CommandHelpFunc func(bot *Bot, service Service, message Message) (string, string)

CommandHelpFunc is the function signature for command help methods.

func NewCommandHelp

func NewCommandHelp(args, help string) CommandHelpFunc

NewCommandHelp creates a new Command Help function.

type CommandMessageFunc

type CommandMessageFunc func(bot *Bot, service Service, message Message, args string, parts []string)

CommandMessageFunc is the function signature for bot message commands.

type CommandPlugin

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

CommandPlugin is a plugin that can have commands registered and will handle messages matching that command by calling functions.

func NewCommandPlugin

func NewCommandPlugin() *CommandPlugin

NewCommandPlugin will create a new command plugin.

func (*CommandPlugin) AddCommand

func (p *CommandPlugin) AddCommand(commandString string, message CommandMessageFunc, help CommandHelpFunc)

AddCommand adds a command.

func (*CommandPlugin) Help

func (p *CommandPlugin) Help(bot *Bot, service Service, message Message, detailed bool) []string

Help returns a list of help strings that are printed when the user requests them.

func (*CommandPlugin) Load

func (p *CommandPlugin) Load(bot *Bot, service Service, data []byte) error

Load will load plugin state from a byte array.

func (*CommandPlugin) Message

func (p *CommandPlugin) Message(bot *Bot, service Service, message Message)

Message handler. Iterates over the registered commands and executes them if the message matches.

func (*CommandPlugin) Name

func (p *CommandPlugin) Name() string

Name returns the name of the plugin.

func (*CommandPlugin) Save

func (p *CommandPlugin) Save() ([]byte, error)

Save will save plugin state to a byte array.

func (*CommandPlugin) Stats

func (p *CommandPlugin) Stats(bot *Bot, service Service, message Message) []string

Stats will return the stats for a plugin.

type Discord

type Discord struct {
	Shards int

	// The first session, used to send messages (and maintain backwards compatibility).
	Session             *discordgo.Session
	Sessions            []*discordgo.Session
	OwnerUserID         string
	ApplicationClientID string
	// contains filtered or unexported fields
}

Discord is a Service provider for Discord.

func NewDiscord

func NewDiscord(args ...interface{}) *Discord

NewDiscord creates a new discord service.

func (*Discord) BanUser

func (d *Discord) BanUser(channel, userID string, duration int) error

BanUser bans a user.

func (*Discord) Channel

func (d *Discord) Channel(channelID string) (channel *discordgo.Channel, err error)

func (*Discord) ChannelCount

func (d *Discord) ChannelCount() int

ChannelCount returns the number of channels the bot is in.

func (*Discord) CommandPrefix

func (d *Discord) CommandPrefix() string

CommandPrefix returns the command prefix for the service.

func (*Discord) DeleteMessage

func (d *Discord) DeleteMessage(channel, messageID string) error

DeleteMessage deletes a message.

func (*Discord) Guild

func (d *Discord) Guild(guildID string) (guild *discordgo.Guild, err error)

func (*Discord) Guilds

func (d *Discord) Guilds() []*discordgo.Guild

func (*Discord) IsBotOwner

func (d *Discord) IsBotOwner(message Message) bool

IsBotOwner returns whether or not a message sender was the owner of the bot.

func (*Discord) IsChannelOwner

func (d *Discord) IsChannelOwner(message Message) bool

IsChannelOwner returns whether or not the sender of a message is a moderator.

func (*Discord) IsMe

func (d *Discord) IsMe(message Message) bool

IsMe returns whether or not a message was sent by the bot.

func (*Discord) IsModerator

func (d *Discord) IsModerator(message Message) bool

IsModerator returns whether or not the sender of a message is a moderator.

func (*Discord) IsPrivate

func (d *Discord) IsPrivate(message Message) bool

IsPrivate returns whether or not a message was private.

func (*Discord) Join

func (d *Discord) Join(join string) error

Join accept an invite or return an error. If AlreadyJoinedError is return, @me has already accepted that invite.

func (*Discord) MessageHistory

func (d *Discord) MessageHistory(channel string) []Message

MessageHistory returns the message history for a channel.

func (*Discord) Name

func (d *Discord) Name() string

Name returns the name of the service.

func (*Discord) Nickname

func (d *Discord) Nickname(message Message) string

func (*Discord) NicknameForID

func (d *Discord) NicknameForID(userID, userName, channelID string) string

func (*Discord) Open

func (d *Discord) Open() (<-chan Message, error)

Open opens the service and returns a channel which all messages will be sent on.

func (*Discord) PrivateMessage

func (d *Discord) PrivateMessage(userID, message string) error

PrivateMessage will send a private message to a user.

func (*Discord) SendAction

func (d *Discord) SendAction(channel, message string) error

SendAction sends an action.

func (*Discord) SendFile

func (d *Discord) SendFile(channel, name string, r io.Reader) error

SendFile sends a file.

func (*Discord) SendMessage

func (d *Discord) SendMessage(channel, message string) error

SendMessage sends a message.

func (*Discord) SupportsMessageHistory

func (d *Discord) SupportsMessageHistory() bool

SupportsMessageHistory returns if the service supports message history.

func (*Discord) SupportsMultiline

func (d *Discord) SupportsMultiline() bool

SupportsMultiline returns whether the service supports multiline messages.

func (*Discord) SupportsPrivateMessages

func (d *Discord) SupportsPrivateMessages() bool

SupportsPrivateMessages returns whether the service supports private messages.

func (*Discord) Typing

func (d *Discord) Typing(channel string) error

Typing sets that the bot is typing.

func (*Discord) UnbanUser

func (d *Discord) UnbanUser(channel, userID string) error

UnbanUser unbans a user.

func (*Discord) UserChannelPermissions

func (d *Discord) UserChannelPermissions(userID, channelID string) (apermissions int, err error)

func (*Discord) UserColor

func (d *Discord) UserColor(userID, channelID string) int

func (*Discord) UserID

func (d *Discord) UserID() string

UserID returns the bots user id.

func (*Discord) UserName

func (d *Discord) UserName() string

UserName returns the bots name.

type DiscordMessage

type DiscordMessage struct {
	Discord          *Discord
	DiscordgoMessage *discordgo.Message
	MessageType      MessageType
	Nick             *string
	Content          *string
}

DiscordMessage is a Message wrapper around discordgo.Message.

func (*DiscordMessage) Channel

func (m *DiscordMessage) Channel() string

Channel returns the channel id for this message.

func (*DiscordMessage) Message

func (m *DiscordMessage) Message() string

Message returns the message content for this message.

func (*DiscordMessage) MessageID

func (m *DiscordMessage) MessageID() string

MessageID returns the message ID for this message.

func (*DiscordMessage) RawMessage

func (m *DiscordMessage) RawMessage() string

RawMessage returns the raw message content for this message.

func (*DiscordMessage) Type

func (m *DiscordMessage) Type() MessageType

Type returns the type of message.

func (*DiscordMessage) UserAvatar

func (m *DiscordMessage) UserAvatar() string

UserAvatar returns the avatar url for this message.

func (*DiscordMessage) UserID

func (m *DiscordMessage) UserID() string

UserID returns the user id for this message.

func (*DiscordMessage) UserName

func (m *DiscordMessage) UserName() string

UserName returns the user name for this message.

type HelpFunc

type HelpFunc func(*Bot, Service, Message, bool) []string

HelpFunc is the function signature for a help handler.

type IRC

type IRC struct {
	Conn *client.Conn
	// contains filtered or unexported fields
}

IRC is a Service provider for IRC.

func NewIRC

func NewIRC(host, nick, password string, channels []string) *IRC

NewIRC creates a new IRC service.

func (*IRC) BanUser

func (i *IRC) BanUser(channel, userID string, duration int) error

BanUser bans a user.

func (*IRC) ChannelCount

func (i *IRC) ChannelCount() int

ChannelCount returns the number of channels the bot is in.

func (*IRC) CommandPrefix

func (i *IRC) CommandPrefix() string

CommandPrefix returns the command prefix for the service.

func (*IRC) DeleteMessage

func (i *IRC) DeleteMessage(channel, messageID string) error

DeleteMessage deletes a message.

func (*IRC) IsBotOwner

func (i *IRC) IsBotOwner(message Message) bool

IsBotOwner returns whether or not a message sender was the owner of the bot.

func (*IRC) IsChannelOwner

func (i *IRC) IsChannelOwner(message Message) bool

IsChannelOwner returns whether or not the sender of a message is the owner.

func (*IRC) IsMe

func (i *IRC) IsMe(message Message) bool

IsMe returns whether or not a message was sent by the bot.

func (*IRC) IsModerator

func (i *IRC) IsModerator(message Message) bool

IsModerator returns whether or not the sender of a message is a moderator.

func (*IRC) IsPrivate

func (i *IRC) IsPrivate(message Message) bool

IsPrivate returns whether or not a message was private.

func (*IRC) Join

func (i *IRC) Join(join string) error

Join will join a channel.

func (*IRC) MessageHistory

func (i *IRC) MessageHistory(channel string) []Message

MessageHistory returns the message history for a channel.

func (*IRC) Name

func (i *IRC) Name() string

Name returns the name of the service.

func (*IRC) Open

func (i *IRC) Open() (<-chan Message, error)

Open opens the service and returns a channel which all messages will be sent on.

func (*IRC) PrivateMessage

func (i *IRC) PrivateMessage(userID, message string) error

PrivateMessage will send a private message to a user.

func (*IRC) SendAction

func (i *IRC) SendAction(channel, message string) error

SendAction sends an action.

func (*IRC) SendFile

func (i *IRC) SendFile(channel, name string, r io.Reader) error

SendFile sends a file.

func (*IRC) SendMessage

func (i *IRC) SendMessage(channel, message string) error

SendMessage sends a message.

func (*IRC) SupportsMessageHistory

func (i *IRC) SupportsMessageHistory() bool

SupportsMessageHistory returns if the service supports message history.

func (*IRC) SupportsMultiline

func (i *IRC) SupportsMultiline() bool

SupportsMultiline returns whether the service supports multiline messages.

func (*IRC) SupportsPrivateMessages

func (i *IRC) SupportsPrivateMessages() bool

SupportsPrivateMessages returns whether the service supports private messages.

func (*IRC) Typing

func (i *IRC) Typing(channel string) error

Typing sets that the bot is typing.

func (*IRC) UnbanUser

func (i *IRC) UnbanUser(channel, userID string) error

UnbanUser unbans a user.

func (*IRC) UserID

func (i *IRC) UserID() string

UserID returns the bots user id.

func (*IRC) UserName

func (i *IRC) UserName() string

UserName returns the bots name.

type IRCMessage

type IRCMessage client.Line

IRCMessage is a Message wrapper around client.Line.

func (*IRCMessage) Channel

func (m *IRCMessage) Channel() string

Channel returns the channel id for this message.

func (*IRCMessage) Message

func (m *IRCMessage) Message() string

Message returns the message content for this message.

func (*IRCMessage) MessageID

func (m *IRCMessage) MessageID() string

MessageID returns the message ID for this message.

func (*IRCMessage) RawMessage

func (m *IRCMessage) RawMessage() string

RawMessage returns the raw message content for this message.

func (*IRCMessage) Type

func (m *IRCMessage) Type() MessageType

Type returns the type of message.

func (*IRCMessage) UserAvatar

func (m *IRCMessage) UserAvatar() string

UserAvatar returns the avatar url for this message.

func (*IRCMessage) UserID

func (m *IRCMessage) UserID() string

UserID returns the user id for this message.

func (*IRCMessage) UserName

func (m *IRCMessage) UserName() string

UserName returns the user name for this message.

type LiveChatMessage

type LiveChatMessage youtube.LiveChatMessage

LiveChatMessage is a Message wrapper around youtube.LiveChatMessage.

func (*LiveChatMessage) Channel

func (m *LiveChatMessage) Channel() string

Channel returns the channel id for this message.

func (*LiveChatMessage) Message

func (m *LiveChatMessage) Message() string

Message returns the message content for this message.

func (*LiveChatMessage) MessageID

func (m *LiveChatMessage) MessageID() string

MessageID returns the message ID for this message.

func (*LiveChatMessage) RawMessage

func (m *LiveChatMessage) RawMessage() string

RawMessage returns the message content for this message.

func (*LiveChatMessage) Type

func (m *LiveChatMessage) Type() MessageType

Type returns the type of message.

func (*LiveChatMessage) UserAvatar

func (m *LiveChatMessage) UserAvatar() string

UserAvatar returns the avatar url for this message.

func (*LiveChatMessage) UserID

func (m *LiveChatMessage) UserID() string

UserID returns the user id for this message.

func (*LiveChatMessage) UserName

func (m *LiveChatMessage) UserName() string

UserName returns the user name for this message.

type LoadFunc

type LoadFunc func(*Bot, Service, []byte) error

LoadFunc is the function signature for a load handler.

type Message

type Message interface {
	Channel() string
	UserName() string
	UserID() string
	UserAvatar() string
	Message() string
	RawMessage() string
	MessageID() string
	Type() MessageType
}

Message is a message interface, wraps a single message from a service.

type MessageFunc

type MessageFunc func(*Bot, Service, Message)

MessageFunc is the function signature for a message handler.

type MessageType

type MessageType string

MessageType is a type used to determine the CRUD state of a message.

type MockMessage

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

func NewMockMessage

func NewMockMessage() *MockMessage

func (*MockMessage) Channel

func (m *MockMessage) Channel() string

Satisfy Message interface below

func (*MockMessage) Message

func (m *MockMessage) Message() string

func (*MockMessage) MessageID

func (m *MockMessage) MessageID() string

func (*MockMessage) RawMessage

func (m *MockMessage) RawMessage() string

func (*MockMessage) SetAvatar

func (m *MockMessage) SetAvatar(avatar string) *MockMessage

func (*MockMessage) SetChannel

func (m *MockMessage) SetChannel(channel string) *MockMessage

Functional options to set various properties

func (*MockMessage) SetMessage

func (m *MockMessage) SetMessage(message string) *MockMessage

func (*MockMessage) SetMessageID

func (m *MockMessage) SetMessageID(messageID string) *MockMessage

func (*MockMessage) SetRawMessage

func (m *MockMessage) SetRawMessage(message string) *MockMessage

func (*MockMessage) SetUserID

func (m *MockMessage) SetUserID(userid string) *MockMessage

func (*MockMessage) SetUserName

func (m *MockMessage) SetUserName(username string) *MockMessage

func (*MockMessage) Type

func (m *MockMessage) Type() MessageType

func (*MockMessage) UserAvatar

func (m *MockMessage) UserAvatar() string

func (*MockMessage) UserID

func (m *MockMessage) UserID() string

func (*MockMessage) UserName

func (m *MockMessage) UserName() string

type MockService

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

Service is a service interface, wraps a single service such as YouTube or Discord.

func NewMockService

func NewMockService() *MockService

func (*MockService) BanUser

func (s *MockService) BanUser(channel, userID string, duration int) error

func (*MockService) ChannelCount

func (s *MockService) ChannelCount() int

func (*MockService) CommandPrefix

func (s *MockService) CommandPrefix() string

func (*MockService) DeleteMessage

func (s *MockService) DeleteMessage(channel, messageID string) error

func (*MockService) IsBotOwner

func (s *MockService) IsBotOwner(message Message) bool

func (*MockService) IsChannelOwner

func (s *MockService) IsChannelOwner(message Message) bool

func (*MockService) IsMe

func (s *MockService) IsMe(message Message) bool

func (*MockService) IsModerator

func (s *MockService) IsModerator(message Message) bool

func (*MockService) IsPrivate

func (s *MockService) IsPrivate(message Message) bool

func (*MockService) Join

func (s *MockService) Join(join string) error

func (*MockService) MessageHistory

func (s *MockService) MessageHistory(chanel string) []Message

func (*MockService) Name

func (s *MockService) Name() string

func (*MockService) NewMessage

func (s *MockService) NewMessage(message Message)

func (*MockService) Open

func (s *MockService) Open() (<-chan Message, error)

func (*MockService) PrivateMessage

func (s *MockService) PrivateMessage(userID, messageID string) error

func (*MockService) SendAction

func (s *MockService) SendAction(channel, message string) error

func (*MockService) SendFile

func (s *MockService) SendFile(channel, name string, r io.Reader) error

func (*MockService) SendMessage

func (s *MockService) SendMessage(channel, message string) error

func (*MockService) SetName

func (m *MockService) SetName(name string) *MockService

func (*MockService) SetUserID

func (m *MockService) SetUserID(userid string) *MockService

func (*MockService) SetUserName

func (m *MockService) SetUserName(username string) *MockService

func (*MockService) SupportsMessageHistory

func (s *MockService) SupportsMessageHistory() bool

func (*MockService) SupportsMultiline

func (s *MockService) SupportsMultiline() bool

func (*MockService) SupportsPrivateMessages

func (s *MockService) SupportsPrivateMessages() bool

func (*MockService) Typing

func (s *MockService) Typing(channel string) error

func (*MockService) UnbanUser

func (s *MockService) UnbanUser(channel, userID string) error

func (*MockService) UserID

func (s *MockService) UserID() string

func (*MockService) UserName

func (s *MockService) UserName() string

type Plugin

type Plugin interface {
	Name() string
	Load(*Bot, Service, []byte) error
	Save() ([]byte, error)
	Help(*Bot, Service, Message, bool) []string
	Message(*Bot, Service, Message)
	Stats(*Bot, Service, Message) []string
}

Plugin is a plugin interface, supports loading and saving to a byte array and has help and message handlers.

func NewHelpPlugin

func NewHelpPlugin() Plugin

NeHelpPlugin will create a new help plugin.

type SaveFunc

type SaveFunc func() ([]byte, error)

SaveFunc is the function signature for a save handler.

type Service

type Service interface {
	Name() string
	UserName() string
	UserID() string
	Open() (<-chan Message, error)
	IsMe(message Message) bool
	SendMessage(channel, message string) error
	SendAction(channel, message string) error
	DeleteMessage(channel, messageID string) error
	SendFile(channel, name string, r io.Reader) error
	BanUser(channel, userID string, duration int) error
	UnbanUser(channel, userID string) error
	Join(join string) error
	Typing(channel string) error
	PrivateMessage(userID, messageID string) error
	IsBotOwner(message Message) bool
	IsPrivate(message Message) bool
	IsChannelOwner(message Message) bool
	IsModerator(message Message) bool
	SupportsPrivateMessages() bool
	SupportsMultiline() bool
	CommandPrefix() string
	ChannelCount() int
	SupportsMessageHistory() bool
	MessageHistory(chanel string) []Message
}

Service is a service interface, wraps a single service such as YouTube or Discord.

type SimplePlugin

type SimplePlugin struct {
	LoadFunc    LoadFunc    `json:"-"`
	SaveFunc    SaveFunc    `json:"-"`
	MessageFunc MessageFunc `json:"-"`
	HelpFunc    HelpFunc    `json:"-"`
	StatsFunc   StatsFunc   `json:"-"`
	// contains filtered or unexported fields
}

SimplePlugin is a simple wrapper around a Plugin that can implement handlers by function reference.

func NewSimplePlugin

func NewSimplePlugin(name string) *SimplePlugin

NewSimplePlugin creates a new simple plugin.

func (*SimplePlugin) Help

func (p *SimplePlugin) Help(bot *Bot, service Service, message Message, detailed bool) []string

Help returns a list of help strings that are printed when the user requests them.

func (*SimplePlugin) Load

func (p *SimplePlugin) Load(bot *Bot, service Service, data []byte) error

Load will load plugin state from a byte array.

func (*SimplePlugin) Message

func (p *SimplePlugin) Message(bot *Bot, service Service, message Message)

Message handler.

func (*SimplePlugin) Name

func (p *SimplePlugin) Name() string

Name returns the name of the plugin.

func (*SimplePlugin) Save

func (p *SimplePlugin) Save() ([]byte, error)

Save will save plugin state to a byte array.

func (*SimplePlugin) Stats

func (p *SimplePlugin) Stats(bot *Bot, service Service, message Message) []string

type Slack

type Slack struct {
	Client *slack.Client
	RTM    *slack.RTM
	Me     *slack.AuthTestResponse

	OwnerUserID string
	// contains filtered or unexported fields
}

Slack is a Service provider for Slack.

func NewSlack

func NewSlack(token string) *Slack

NewSlack creates a new Slack service.

func (*Slack) BanUser

func (s *Slack) BanUser(channel, userID string, duration int) error

BanUser bans a user.

func (*Slack) ChannelCount

func (s *Slack) ChannelCount() int

ChannelCount returns the number of channels the bot is in.

func (*Slack) CommandPrefix

func (s *Slack) CommandPrefix() string

CommandPrefix returns the command prefix for the service.

func (*Slack) DeleteMessage

func (s *Slack) DeleteMessage(channel, messageID string) error

DeleteMessage deletes a message.

func (*Slack) IsBotOwner

func (s *Slack) IsBotOwner(message Message) bool

IsBotOwner returns whether or not a message sender was the owner of the bot.

func (*Slack) IsChannelOwner

func (s *Slack) IsChannelOwner(message Message) bool

IsChannelOwner returns whether or not the sender of a message is the owner.

func (*Slack) IsMe

func (s *Slack) IsMe(message Message) bool

IsMe returns whether or not a message was sent by the bot.

func (*Slack) IsModerator

func (s *Slack) IsModerator(message Message) bool

IsModerator returns whether or not the sender of a message is a moderator.

func (*Slack) IsPrivate

func (s *Slack) IsPrivate(message Message) bool

IsPrivate returns whether or not a message was private.

func (*Slack) Join

func (s *Slack) Join(join string) error

Join accept an invite or return an error.

func (*Slack) MessageHistory

func (s *Slack) MessageHistory(channel string) []Message

MessageHistory returns the message history for a channel.

func (*Slack) Name

func (s *Slack) Name() string

Name returns the name of the service.

func (*Slack) Open

func (s *Slack) Open() (<-chan Message, error)

Open opens the service and returns a channel which all messages will be sent on.

func (*Slack) PrivateMessage

func (s *Slack) PrivateMessage(userID, message string) error

PrivateMessage will send a private message to a user.

func (*Slack) SendAction

func (s *Slack) SendAction(channel, message string) error

SendAction sends an action.

func (*Slack) SendFile

func (s *Slack) SendFile(channel, name string, r io.Reader) error

SendFile sends a file.

func (*Slack) SendMessage

func (s *Slack) SendMessage(channel, message string) error

SendMessage sends a message.

func (*Slack) SupportsMessageHistory

func (s *Slack) SupportsMessageHistory() bool

SupportsMessageHistory returns if the service supports message history.

func (*Slack) SupportsMultiline

func (s *Slack) SupportsMultiline() bool

SupportsMultiline returns whether the service supports multiline messages.

func (*Slack) SupportsPrivateMessages

func (s *Slack) SupportsPrivateMessages() bool

SupportsPrivateMessages returns whether the service supports private messages.

func (*Slack) Typing

func (s *Slack) Typing(channel string) error

Typing sets that the bot is typing.

func (*Slack) UnbanUser

func (s *Slack) UnbanUser(channel, userID string) error

UnbanUser unbans a user.

func (*Slack) UserID

func (s *Slack) UserID() string

UserID returns the bots user id.

func (*Slack) UserName

func (s *Slack) UserName() string

UserName returns the bots name.

type SlackMessage

type SlackMessage struct {
	SlackMessage *slack.Msg
	MessageType  MessageType
}

SlackMessage is a Message wrapper around slack.MessageEvent.

func (*SlackMessage) Channel

func (m *SlackMessage) Channel() string

Channel returns the channel id for this message.

func (*SlackMessage) Message

func (m *SlackMessage) Message() string

Message returns the message content for this message.

func (*SlackMessage) MessageID

func (m *SlackMessage) MessageID() string

MessageID returns the message ID for this message.

func (*SlackMessage) RawMessage

func (m *SlackMessage) RawMessage() string

RawMessage returns the raw message content for this message.

func (*SlackMessage) Type

func (m *SlackMessage) Type() MessageType

Type returns the type of message.

func (*SlackMessage) UserAvatar

func (m *SlackMessage) UserAvatar() string

UserAvatar returns the avatar url for this message.

func (*SlackMessage) UserID

func (m *SlackMessage) UserID() string

UserID returns the user id for this message.

func (*SlackMessage) UserName

func (m *SlackMessage) UserName() string

UserName returns the user name for this message.

type StatsFunc

type StatsFunc func(*Bot, Service, Message) []string

StatsFunc is the function signature for a stats handler.

type YTLiveChannel

type YTLiveChannel struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

YTLiveChannel is a monitor that will send new live videos to a provided channel.

func NewYTLiveChannel

func NewYTLiveChannel(service *youtube.Service) *YTLiveChannel

func (*YTLiveChannel) ChannelName

func (y *YTLiveChannel) ChannelName(channel string) string

func (*YTLiveChannel) Monitor

func (y *YTLiveChannel) Monitor(channel string, liveVideoChan chan *youtube.Video) error

Monitor monitors a channel for new live videos and sends them down liveVideoChan. If the channel is live when this is called, it will not send the video down the channel.

func (*YTLiveChannel) Unmonitor

func (y *YTLiveChannel) Unmonitor(channel string, liveVideoChan chan *youtube.Video) error

UnmonitorAll unmonitors a channel for live videos.

type YouTube

type YouTube struct {
	Client  *http.Client
	Service *youtube.Service

	InsertChan chan interface{}
	DeleteChan chan interface{}
	// contains filtered or unexported fields
}

YouTube is a Service provider for YouTube.

func NewYouTube

func NewYouTube(url bool, auth, configFilename, tokenFilename string) *YouTube

NewYouTube creates a new YouTube service.

func (*YouTube) BanUser

func (yt *YouTube) BanUser(channel, userID string, duration int) error

BanUser bans a user.

func (*YouTube) ChannelCount

func (yt *YouTube) ChannelCount() int

ChannelCount returns the number of channels the bot is in.

func (*YouTube) ChannelIDForVideoID

func (yt *YouTube) ChannelIDForVideoID(videoID string) (channelID string, ok bool)

ChannelIDForVideoID gets a channelID for a video id.

func (*YouTube) ChannelNameForVideoID

func (yt *YouTube) ChannelNameForVideoID(videoID string) string

ChannelName gets a channel name for a channel id.

func (*YouTube) CommandPrefix

func (yt *YouTube) CommandPrefix() string

CommandPrefix returns the command prefix for the service.

func (*YouTube) DeleteMessage

func (yt *YouTube) DeleteMessage(channel, messageID string) error

DeleteMessage deletes a message.

func (*YouTube) GetLiveVideos

func (yt *YouTube) GetLiveVideos(channelID string) ([]*youtube.Video, error)

GetLiveVideos gets a list of live videos for a channel

func (*YouTube) GetMe

func (yt *YouTube) GetMe() (*youtube.Channel, error)

GetMe gets the channel for the bot.

func (*YouTube) GetTopLivestreamIDs

func (yt *YouTube) GetTopLivestreamIDs(count int) ([]string, error)

GetTopLivestreamIDs gets the video ids for the current top livestreams.

func (*YouTube) GetTopLivestreams

func (yt *YouTube) GetTopLivestreams(count int) ([]*youtube.Video, error)

GetTopLivestreams gets a list of videos for the current top livestreams.

func (*YouTube) GetVideosByIDList

func (yt *YouTube) GetVideosByIDList(ids []string) ([]*youtube.Video, error)

GetVideosByIDList gets all the videos for a list of video IDs.

func (*YouTube) Init

func (yt *YouTube) Init() error

func (*YouTube) IsBotOwner

func (yt *YouTube) IsBotOwner(message Message) bool

IsBotOwner returns whether or not a message sender was the owner of the bot.

func (*YouTube) IsChannelOwner

func (yt *YouTube) IsChannelOwner(message Message) bool

IsChannelOwner returns whether or not the sender of a message is the owner.

func (*YouTube) IsMe

func (yt *YouTube) IsMe(message Message) bool

IsMe returns whether or not a message was sent by the bot.

func (*YouTube) IsModerator

func (yt *YouTube) IsModerator(message Message) bool

IsModerator returns whether or not the sender of a message is a moderator.

func (*YouTube) IsPrivate

func (yt *YouTube) IsPrivate(message Message) bool

IsPrivate returns whether or not a message was private.

func (*YouTube) Join

func (yt *YouTube) Join(videoID string) error

Join will join a video channel.

func (*YouTube) JoinSilent

func (yt *YouTube) JoinSilent(videoID string) (chan Message, error)

JoinSilent will join a video channel and return a channel of messages. Messages will not be broadcast through the bot.

func (*YouTube) JoinVideo

func (yt *YouTube) JoinVideo(video *youtube.Video) error

JoinVideo joins a Video and monitors it for messages on the default message channel.

func (*YouTube) JoinVideoAnnounce

func (yt *YouTube) JoinVideoAnnounce(video *youtube.Video)

JoinVideoAnnounce will join a video like normal, but announce to chat when the bot joins.

func (*YouTube) Leave

func (yt *YouTube) Leave(videoID string) error

Leave will leave a video channel.

func (*YouTube) LeaveAll

func (yt *YouTube) LeaveAll(channelID string) error

LeaveAll will leave all the video channels for a channel.

func (*YouTube) MessageHistory

func (yt *YouTube) MessageHistory(channel string) []Message

MessageHistory returns the message history for a channel.

func (*YouTube) Name

func (yt *YouTube) Name() string

Name returns the name of the service.

func (*YouTube) Open

func (yt *YouTube) Open() (<-chan Message, error)

Open opens the service and returns a channel which all messages will be sent on.

func (*YouTube) PrivateMessage

func (yt *YouTube) PrivateMessage(userID, message string) error

PrivateMessage will send a private message to a user.

func (*YouTube) SendAction

func (yt *YouTube) SendAction(channel, message string) error

SendAction sends an action.

func (*YouTube) SendFile

func (yt *YouTube) SendFile(channel, name string, r io.Reader) error

SendFile sends a file.

func (*YouTube) SendMessage

func (yt *YouTube) SendMessage(channel, message string) error

SendMessage sends a message.

func (*YouTube) SupportsMessageHistory

func (yt *YouTube) SupportsMessageHistory() bool

SupportsMessageHistory returns if the service supports message history.

func (*YouTube) SupportsMultiline

func (yt *YouTube) SupportsMultiline() bool

SupportsMultiline returns whether the service supports multiline messages.

func (*YouTube) SupportsPrivateMessages

func (yt *YouTube) SupportsPrivateMessages() bool

SupportsPrivateMessages returns whether the service supports private messages.

func (*YouTube) Typing

func (yt *YouTube) Typing(channel string) error

Typing sets that the bot is typing.

func (*YouTube) UnbanUser

func (yt *YouTube) UnbanUser(channel, userID string) error

UnbanUser unbans a user.

func (*YouTube) UserID

func (yt *YouTube) UserID() string

UserID returns the bots user id.

func (*YouTube) UserName

func (yt *YouTube) UserName() string

UserName returns the bots name.

Jump to

Keyboard shortcuts

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