papaBot

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: MIT Imports: 31 Imported by: 0

README

papa-bot

Bot written in Go. Comprehensive in design, easily extensible. Initially designed for IRC, now supports multiple transports.

Full documentation @ GoDoc.org

⚠ IRC transport is not being maintained anymore.
How good is it?

Bot is actively developed and constantly used by me and my friends, so there's that.

Features
  • Multiple transports support.
  • Easy to write extensions (just take a look at the example)
  • Event based operation.
  • Configuration through a TOML file and persistent run time variables.
  • All text messages are in TOML files, for easy editing and l18n.
  • Flood protection.
  • Abuse protection.
  • Ignore list.
  • Stores all the links posted on the channel.
  • Allows full text search through the links.
  • Logs all channel activity.
  • User accounts and permissions handling.
Supported transports
Bundled extensions
  • Custom reminders.
  • Custom counters/countdowns.
  • Link title and description.
  • Link duplicates announce.
  • Link info from Reddit and pinned Reddit live announcements.
  • GitHub repository information.
  • BTC price check and rapid change announce (Bitstamp).
  • Air quality data search (acqicn.org).
  • Movie information (OMDb).
  • Wikipedia article lookup.
  • Wolfram Alpha lookup.
  • YouTube video info.
  • Link to thread version of Twitter status.
  • Last seen speaking check.
TODO
  • Figure out the bot-transports-events package entanglement so that transport can be passed in event.
  • Unify extension panic and error handling.
  • IRC split handling.
  • Alt nicks handling
  • Cross-transport people identification.
  • Write some tests!

Documentation

Overview

Package papaBot provides an IRC bot with focus on easy extension and customization.

Index

Constants

View Source
const (
	Version   = "1.0.7"
	Debug     = false // Set to true to crash on runtime errors.
	BuildDate = ""
)

Use: go build -ldflags "-X github.com/pawelszydlo/papa-bot/papaBot.BuildDate=`date -u +.%Y%m%d.%H%M%S`"

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {

	// Database connection.
	Db *sql.DB
	// HTTP client.
	HTTPClient *http.Client
	// Logger.
	Log *logrus.Logger
	// Event dispatcher instance.
	EventDispatcher *events.EventDispatcher

	// Bot's configuration.
	Config *Configuration
	// Bot texts struct.
	Texts *botTexts
	// Values humanizer.
	Humanizer *humanize.Humanizer

	// Enabled transports.
	Transports map[string]transports.Transport
	// contains filtered or unexported fields
}

Bot itself.

func New

func New(configFile, textsFile string) (error, *Bot)

New creates a new bot.

func (*Bot) AddMoreInfo

func (bot *Bot) AddMoreInfo(transport, channel, info string) error

AddMoreInfo will set more information to be viewed for the channel.

func (*Bot) AddToIgnoreList

func (bot *Bot) AddToIgnoreList(userId string)

AddToIgnoreList will add a user to the ignore list.

func (*Bot) AreSamePeople

func (bot *Bot) AreSamePeople(nick1, nick2 string) bool

areSamePeople checks if two nicks belong to the same person.

func (*Bot) GetAuthenticatedNick

func (bot *Bot) GetAuthenticatedNick(userId string) string

GetAuthenticatedNick will get authenticated user's nick by his full name.

func (*Bot) GetPageBody

func (bot *Bot) GetPageBody(URL string, customHeaders map[string]string) (error, string, []byte)

GetPageBody gets and returns a body of a page. Return format is error, final url, body.

func (*Bot) GetVar

func (bot *Bot) GetVar(name string) string

GetVar returns the value of a custom variable.

func (*Bot) LoadTexts

func (bot *Bot) LoadTexts(section string, data interface{}) error

LoadTexts loads texts from a section of a config file into a struct, auto handling templates and lists. The name of the field in the data struct defines the name in the config file. The type of the field determines the expected config value.

func (*Bot) NextDailyTick

func (bot *Bot) NextDailyTick() time.Time

NextDailyTick will get the time for bot's next daily tick.

func (*Bot) NickIsMe

func (bot *Bot) NickIsMe(transportName, nick string) bool

NickIsMe checks if the sender is the bot.

func (*Bot) RegisterCommand

func (bot *Bot) RegisterCommand(cmd *BotCommand)

RegisterCommand will register a new command with the bot.

func (*Bot) RegisterExtension

func (bot *Bot) RegisterExtension(ext extension)

RegisterExtension will register a new extension with the bot.

func (*Bot) RegisterTransport

func (bot *Bot) RegisterTransport(transport transports.Transport)

RegisterTransport will register a new transport with the bot.

func (*Bot) RemoveFromIgnoreList

func (bot *Bot) RemoveFromIgnoreList(userId string)

RemoveFromIgnoreList will remove user from the ignore list.

func (*Bot) Run

func (bot *Bot) Run()

Run starts the bot's main loop.

func (*Bot) SendMassNotice

func (bot *Bot) SendMassNotice(message string)

SendMassNotice sends a notice to all the channels bot is on, on all transports.

func (*Bot) SendMessage

func (bot *Bot) SendMessage(sourceEvent *events.EventMessage, message string)

SendMessage sends a message to the channel.

func (*Bot) SendNotice

func (bot *Bot) SendNotice(sourceEvent *events.EventMessage, message string)

SendNotice sends a notice to the channel.

func (*Bot) SendPrivateMessage

func (bot *Bot) SendPrivateMessage(sourceEvent *events.EventMessage, nick, message string)

SendPrivateMessage sends a message directly to the user.

func (*Bot) SetVar

func (bot *Bot) SetVar(name, value string)

SetVar will set a custom variable. Set to empty string to delete.

func (*Bot) UserIsAdmin

func (bot *Bot) UserIsAdmin(userId string) bool

userIsOwner checks if the user is an authenticated admin.

func (*Bot) UserIsAuthenticated

func (bot *Bot) UserIsAuthenticated(userId string) bool

userIsAuthenticated checks if the user is authenticated with the bot.

func (*Bot) UserIsOwner

func (bot *Bot) UserIsOwner(userId string) bool

userIsOwner checks if the user is an authenticated owner.

func (*Bot) UserIsOwnerOrAdmin

func (bot *Bot) UserIsOwnerOrAdmin(userId string) bool

isOwnerOrAdmin will check whether user has privileges.

type BotCommand

type BotCommand struct {
	// Names of the command (main and aliases).
	CommandNames []string
	// Does this command require private query?
	Private bool
	// This command can only be run by the owner?
	Owner bool
	// This command can only be run by an admin?
	Admin bool
	// Help string showing possible parameters.
	HelpParams string
	// Help string with the description.
	HelpDescription string
	// Function to be executed.
	CommandFunc func(bot *Bot, sourceEvent *events.EventMessage, params []string)
}

Bot's commands.

type Configuration

type Configuration struct {
	Name                       string
	Language                   string
	ChatLogging                bool
	CommandsPer5               int
	UrlAnnounceIntervalMinutes time.Duration
	UrlAnnounceIntervalLines   int
	PageBodyMaxSize            uint
	HttpDefaultUserAgent       string
	DailyTickHour              int
	DailyTickMinute            int
	LogLevel                   logrus.Level
}

Bot's configuration. It will be loaded from the provided file on New(), overwriting any defaults.

Directories

Path Synopsis
Example usage of papaBot.
Example usage of papaBot.
Extensions for papaBot.
Extensions for papaBot.
irc
Helpful utility functions.
Helpful utility functions.

Jump to

Keyboard shortcuts

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