bot

package module
v0.0.0-...-5f3cdcf Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: MIT Imports: 15 Imported by: 0

README

Porygon2

An IRC Bot written in Go

Install
# Dependencies
go get -u github.com/thoj/go-ircevent github.com/steveyen/gkvlite github.com/PuerkitoBio/goquery github.com/dustin/go-humanize github.com/kennygrant/sanitize gopkg.in/xmlpath.v2 github.com/kurrik/oauth1a github.com/kurrik/twittergo

# Porygon2
go get -u github.com/0x263b/porygon2
Example
package main

import (
	"github.com/0x263b/porygon2"
	_ "github.com/0x263b/porygon2/commands/8ball"
	_ "github.com/0x263b/porygon2/commands/admin"
	_ "github.com/0x263b/porygon2/commands/bing"
	_ "github.com/0x263b/porygon2/commands/choose"
	_ "github.com/0x263b/porygon2/commands/lastfm"
	_ "github.com/0x263b/porygon2/commands/opengraph"
	_ "github.com/0x263b/porygon2/commands/translate"
	_ "github.com/0x263b/porygon2/commands/twitter"
	_ "github.com/0x263b/porygon2/commands/urbandictionary"
	_ "github.com/0x263b/porygon2/commands/weather"
	_ "github.com/0x263b/porygon2/commands/wolfram"
	_ "github.com/0x263b/porygon2/commands/youtube"
)

func main() {
	config := newConfig()
	bot.Run(config)
}

func newConfig() *bot.Configure {
	return &bot.Configure{
		Server:   "irc.rizon.net:6697", // "server:port"
		Channel:  "#Porygon2",          // "#channel" or "#channel key"
		User:     "Porygon2",           // "bot"
		Nick:     "Porygon2",           // "bot"
		Nickserv: "some password",      // leave as "" if none
		Modes:    "GRp",                // "GRp"
		UseTLS:   true,                 // true/false
		Debug:    false,                // true/false
		Prefix:   "!",                  // "!"
		Owner:    "joe",                // your nick
		API: bot.API{
			Bing:                  "",
			Geocode:               "",
			Giphy:                 "",
			Lastfm:                "",
			Translate:             "",
			TwitterConsumerKey:    "",
			TwitterConsumerSecret: "",
			Weather:               "",
			Wolfram:               "",
			Youtube:               "",
		},
	}
}
Ubuntu service

Save as /etc/init/porygon2.conf and run service porygon2 start

# Upstart Configuration

description     "Porygon2"
author          "Black Smiling Face"

start on (net-device-up
          and local-filesystems
          and runlevel [2345])

stop on runlevel [016]

respawn

exec /path/to/porygon2
APIs

Documentation

Overview

Package bot provides a simple to use IRC bot

Index

Constants

This section is empty.

Variables

View Source
var (
	Conn         *irc.Connection
	Config       *Configure
	ChannelNicks = make(map[string][]string)
)

Functions

func ConfigureEvents

func ConfigureEvents()

func DeleteUserKey

func DeleteUserKey(nick string, key string)

func GetChannelKey

func GetChannelKey(channel string, key string) bool

func GetNames

func GetNames(channel string) []string

func GetUserKey

func GetUserKey(nick string, key string) string

func IsAdmin

func IsAdmin(senderNick string) bool

func IsIgnored

func IsIgnored(senderNick string) bool

func IsPrivateMsg

func IsPrivateMsg(channel, currentNick string) bool

func RegisterCommand

func RegisterCommand(command string, cmdFunc activeCmdFunc)

func RegisterPassiveCommand

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

func Run

func Run(c *Configure)

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

func SetChannelKey

func SetChannelKey(channel string, key string, value bool)

func SetUserKey

func SetUserKey(nick string, key string, value string)

Types

type API

type API struct {
	Lastfm                string
	Giphy                 string
	Translate             string
	TwitterConsumerKey    string
	TwitterConsumerSecret string
	Weather               string
	Wolfram               string
	Youtube               string
	Geocode               string
	Bing                  string
}

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 Configure

type Configure struct {
	Server        string // IRC server:port. Ex: irc.rizon.net:6697
	Channel       string // Initial channel to connect. Ex: "#channel"
	User          string // The IRC username the bot will use
	Nick          string // The nick the bot will use
	Nickserv      string // Nickserv password
	Password      string // Server password
	Modes         string // User modes. Ex: GRp
	UseTLS        bool   // Should connect using TLS? (yes)
	TLSServerName string // Must supply if UseTLS is true
	Debug         bool   // This will log all IRC communication to standad output
	Prefix        string // Prefix used to identify a command. !hello whould be identified as a command
	Owner         string // Owner of the bot. Used for admin-only commands
	API
}

Configure 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

Jump to

Keyboard shortcuts

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