bot

package module
v0.0.0-...-7a3cad7 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2014 License: MIT Imports: 9 Imported by: 0

README

go-bot

Build Status GoDoc Coverage Status

Nice to meet you! I'm a IRC bot written in Go using go-ircevent for IRC connectivity.

I can be deployed to heroku and used in slack to overpower slackbot.

#go-bot @ irc.freenode.org

I'm always hanging out as go-bot in the channel #go-bot @ irc.freenode.org

To see what I can do, type !help in the channel or send me a private message.

My awesome commands

Active commands
  • !gif: Posts a random gif url from giphy.com. Try it with: !gif cat
  • !catgif: Posts a random cat gif url from thecatapi.com
  • !godoc: Searches packages in godoc.org. Try it with: !godoc net/http
Passive commands (triggers)

I also have some commands, which are triggered by keywords, urls, etc

  • url: Detects url and gets it's title (very naive implementation, works sometimes)
  • catfacts: Tells a random cat fact based on some cat keywords
  • jira: Detects jira issue numbers and posts the url (necessary to configure the JIRA URL)
  • chucknorris: Shows a random chuck norris quote every time the word "chuck" is mentioned
Brazilian commands (pt-br)

I also have some brazilian commands which only apply to Brazil:

  • megasena: Gera um número da megasena ou mostra o último resultado
  • cotacao: Informa a cotação atual do Dólar e Euro
Example commands

If you wish to write your own commands, start with the 2 example commands, they are in the example directory.

Joining and parting channels

If you want me to join your channel, send me a private message with:

!join #channel pass

If I'm boring you, just send a !part command in a channel I'm in.

Deploying to heroku

To see an example project on how to deploy it to heroku, please see my own configuration:

https://github.com/fabioxgn/go-bot-heroku

Deploying your own clone of me

To deploy your own go-bot, you need to:

  • Import the package bot
  • Import the commands you would like to use
  • Fill the Config struct
  • Call Bot.Run(config)

Here is a full example:

	import (
		"github.com/fabioxgn/go-bot"
		_ "github.com/fabioxgn/go-bot/commands/catfacts"
		_ "github.com/fabioxgn/go-bot/commands/catgif"
		_ "github.com/fabioxgn/go-bot/commands/chucknorris"
		// Import all the commands you wish to use
		"log"
		"strings"
	)

	func main() {
		bot.Run(&bot.Config{
			Server:   os.Getenv("IRC_SERVER"),
			Channels: strings.Split(os.Getenv("IRC_CHANNELS"), ","),
			User:     os.Getenv("IRC_USER"),
			Nick:     os.Getenv("IRC_NICK"),
			Password: os.Getenv("IRC_PASSWORD"),
			UseTLS:   true,
			Debug:    os.Getenv("DEBUG") != "",}
		)
	}

To join channels with passwords just put the password after the channel name separated by a space:

Channels: []string{"#mychannel mypassword", "#go-bot"}

Documentation

Overview

Package bot provides a simple to use IRC bot

Index

Constants

View Source
const (
	// CmdPrefix is the prefix used to identify a command.
	// !hello whould be identified as a command
	CmdPrefix = "!"
)

Variables

This section is empty.

Functions

func RegisterCommand

func RegisterCommand(command, description, exampleArgs string, cmdFunc func(cmd *Cmd) (string, error))

RegisterCommand adds a new command to the bot. The command(s) should be registered in the Ini() func of your package command: String which the user will use to execute the command, example: reverse decription: Description of the command to use in !help, example: Reverses a string exampleArgs: Example args to be displayed in !help <command>, example: string to be reversed cmdFunc: Function which will be executed. It will received a parsed command as a Cmd value

func RegisterPassiveCommand

func RegisterPassiveCommand(command string, cmdFunc func(cmd *PassiveCmd) (string, error))

RegisterPassiveCommand adds a new passive command to the bot. The command(s) should be registered in the Ini() func of your package Passive commands receives all the text posted to a channel without any parsing command: String used to identify the command, for internal use only (ex: logs) cmdFunc: Function which will be executed. It will received the raw message, channel and nick

func Run

func Run(c *Config)

Run reads the Config, connect to the specified IRC server and starts the bot. The bot will automatically join all the channels specified in the configuration

Types

type Cmd

type Cmd struct {
	Raw     string   // Raw is full string passed to the command
	Channel string   // Channel where the command was called
	Nick    string   // User who sent the message
	Message string   // Full string without the prefix
	Command string   // Command is the first argument passed to the bot
	FullArg string   // Full argument as a single string
	Args    []string // Arguments as array
}

Cmd holds the parsed user's input for easier handling of commands

type Config

type Config struct {
	Server        string   // IRC server:port. Ex: irc.freenode.org:7000
	Channels      []string // Channels to connect. Ex: []string{"#go-bot", "#channel mypassword"}
	User          string   // The IRC username the bot will use
	Nick          string   // The nick the bot will use
	Password      string   // Server password
	UseTLS        bool     // Should connect using TLS?
	TLSServerName string   // Must supply if UseTLS is true
	Debug         bool     // This will log all IRC communication to standad output
}

Config must contain the necessary data to connect to an IRC server

type PassiveCmd

type PassiveCmd struct {
	Raw     string // Raw message sent to the channel
	Channel string // Channel which the message was sent to
	Nick    string // Nick of the user which sent the message
}

PassiveCmd holds the information which will be passed to passive commands when receiving a message on the channel

Directories

Path Synopsis
commands
gif
url

Jump to

Keyboard shortcuts

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