tusk

package module
v0.0.0-...-2c00c83 Latest Latest
Warning

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

Go to latest
Published: May 27, 2021 License: Apache-2.0 Imports: 19 Imported by: 1

README

Tusk

Tusk is the core functionality of the Narwhal IRC bot.

Any use of Tusk outside of its intended purpose of serving Narwhal is not supported.

Hex.pm Hex.pm Hex.pm

Why

See our description at Narwhal.

License

Tusk is licensed under the Apache-2.0 license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigFoundPath string

ConfigFoundPath is the directory we found the config in

View Source
var (
	MessageBreaker = strings.Repeat("-", 80)
)
View Source
var Paths []string

Consistent paths

Functions

func AnnounceLibera

func AnnounceLibera(c *girc.Client)

func BanUser

func BanUser(c *girc.Client, channel string, user string)

BanUser will ban the specified user from a channel

func BanUsers

func BanUsers(c *girc.Client, channel string, users []string)

BanUsers will ban multiple users from a channel

func DeduplicateList

func DeduplicateList(list []string) []string

DeduplicateList will eliminate duplicates from a list

func GetNowAsISO8601

func GetNowAsISO8601() (now string)

GetNowAsISO8601 will return the current date / time as ISO 8601

func GetRandomString

func GetRandomString(list []string) (item string)

GetRandomString will get a random string from our array

func Ghost

func Ghost(c *girc.Client)

Ghost will attempt to GHOST the client

func IsAdmin

func IsAdmin(issuer, fullIssuer, host string) (userIsAdmin bool)

IsAdmin will check our issuer, fullIssuer (includes ident), and host if they match our admin list

func IsInStringArr

func IsInStringArr(list []string, item string) bool

IsInStringArr will check if this item is in the specified string array

func KickUser

func KickUser(c *girc.Client, e girc.Event, m NarwhalMessage, user string)

KickUser will kick the specified user from a channel

func KickUsers

func KickUsers(c *girc.Client, e girc.Event, m NarwhalMessage)

KickUsers will kick multiple users from a channel

func Matches

func Matches(requirement string, checking string) bool

Matches is our string match function that checks our provided string against a requirement Such requirement can be basic globbing, regex, or exact match.

func NewTusk

func NewTusk()

NewTusk will create a new tusk for our Narwhal, but only one tusk is allowed at a time.

func OnConnected

func OnConnected(c *girc.Client, e girc.Event)

OnConnected will handle connection to an IRC network

func OnInvite

func OnInvite(c *girc.Client, e girc.Event)

OnInvite will handle a request to invite an IRC channel

func OnJoin

func OnJoin(c *girc.Client, e girc.Event)

OnJoin will handle when a user joins a channel

func OnKick

func OnKick(c *girc.Client, e girc.Event)

OnKick will handle when the bot gets kicked

func OnLeave

func OnLeave(c *girc.Client, e girc.Event)

OnLeave will handle when a user leaves a channel

func Parser

func Parser(c *girc.Client, e girc.Event)

Parser will handle the majority of incoming messages, user joins, etc.

func PrintPrettyMessage

func PrintPrettyMessage(m NarwhalMessage)

PrintPrettyMessage will print to out output a slightly prettier version of this Message

func RemoveFromStringArr

func RemoveFromStringArr(list []string, items []string) []string

RemoveFromStringArr will remove items from the string array

func SaveConfig

func SaveConfig()

SaveConfig will save the config in our previously recognized location

func Shutdown

func Shutdown(c *girc.Client)

Shutdown will PART from all channels and shut down the client

func UnbanUser

func UnbanUser(c *girc.Client, channel string, user string)

UnbanUser will unban the specified user from a channel

func UnbanUsers

func UnbanUsers(c *girc.Client, channel string, users []string)

UnbanUsers will unban multiple users from a channel

Types

type NarwhalAdminConfig

type NarwhalAdminConfig struct {
	// DisabledCommands is a list of admin commands to disable
	DisabledCommands []string
}

NarwhalAdminConfig is our configuration for the Narwhal admin plugin

type NarwhalAdminPlugin

type NarwhalAdminPlugin struct{}

NarwhalAdminPlugin is our Admin plugin

var NarwhalAdminManager NarwhalAdminPlugin

NarwhalAdminManager is our admin management plugin

func (*NarwhalAdminPlugin) AddAdmin

func (adminmanager *NarwhalAdminPlugin) AddAdmin(c *girc.Client, user string)

AddAdmin will add a user to the admin list This will add them based on the provided nick. If they are currently on the network, we will add them based on their ident as well.

func (*NarwhalAdminPlugin) Blacklist

func (adminmanager *NarwhalAdminPlugin) Blacklist(users []string)

Blacklist will add users to the blacklist

func (*NarwhalAdminPlugin) CommandIssuer

func (adminmanager *NarwhalAdminPlugin) CommandIssuer(c *girc.Client, e girc.Event, m NarwhalMessage)

CommandIssuer is our primary function for command and param handling

func (*NarwhalAdminPlugin) Parse

func (adminmanager *NarwhalAdminPlugin) Parse(c *girc.Client, e girc.Event, m NarwhalMessage)

func (*NarwhalAdminPlugin) RemoveAdmin

func (adminmanager *NarwhalAdminPlugin) RemoveAdmin(c *girc.Client, user string)

RemoveAdmin will remove a user from the admin list This will remove them based on the provided nick. If they are currently on the network, we will remove them based on their ident as well.

func (*NarwhalAdminPlugin) RemoveFromBlacklist

func (adminmanager *NarwhalAdminPlugin) RemoveFromBlacklist(users []string)

RemoveFromBlacklist will remove users from the blacklist

type NarwhalAutoKickerConfig

type NarwhalAutoKickerConfig struct {
	// EnabledAutoban determines whether to enable the automatic banning of users which exceed our MinimumKickToBanCount
	EnabledAutoban bool `json:",omitempty"`

	// Hosts to kick. Matches from end.
	Hosts []string

	// MessageMatches is a list of messages that will result in kicks
	MessageMatches []string

	// MinimumKickToBanCount is a minimum amount of times a user should be kicked before being automatically banned. Only enforced when EnabledAutoban is set
	MinimumKickToBanCount int `json:",omitempty"`

	// Users to kick. Matches from beginning.
	Users []string
}

NarwhallAutoKickerConfig is our configuration for the Narwhal autokicker

type NarwhalAutoKickerPlugin

type NarwhalAutoKickerPlugin struct {
	// Tracker is a map of usernames to the amount of times they've been kicked
	Tracker map[string]int
}

NarwhalAutoKickerPlugin is our Autokick plugin

var NarwhalAutoKicker NarwhalAutoKickerPlugin

NarwhalAutoKicker is our autokicker plugin

func (*NarwhalAutoKickerPlugin) AddHost

func (autokicker *NarwhalAutoKickerPlugin) AddHost(host string)

AddHost will add the specified host to the AutoKick Hosts list, if they aren't already added

func (*NarwhalAutoKickerPlugin) AddMessage

func (autokicker *NarwhalAutoKickerPlugin) AddMessage(message string)

AddMessage will add the specified message to the AutoKick MessageMatches list, if they aren't already added

func (*NarwhalAutoKickerPlugin) AddUsers

func (autokicker *NarwhalAutoKickerPlugin) AddUsers(users []string)

AddUsers will add the specified users to the AutoKick Users list, if they aren't already added

func (*NarwhalAutoKickerPlugin) Parse

func (autokicker *NarwhalAutoKickerPlugin) Parse(c *girc.Client, e girc.Event, m NarwhalMessage)

func (*NarwhalAutoKickerPlugin) RemoveHost

func (autokicker *NarwhalAutoKickerPlugin) RemoveHost(host string)

RemoveHost will remove the specified host from the AutoKick Hosts list, if they are added

func (*NarwhalAutoKickerPlugin) RemoveMessage

func (autokicker *NarwhalAutoKickerPlugin) RemoveMessage(message string)

RemoveMessage will remove the specified message from the AutoKick MessageMatches list, if they are added

func (*NarwhalAutoKickerPlugin) RemoveUsers

func (autokicker *NarwhalAutoKickerPlugin) RemoveUsers(users []string)

RemoveUsers will remove the specified users from the AutoKick Users list, if they are added

type NarwhalConfig

type NarwhalConfig struct {
	// Network is the IRC network to connection to.
	Network string `toml:"Network"`

	// Port is the port on the network we're connecting to. Likely 6667.
	Port int `toml:"Port,omitempty"`

	// LiberaAnnounceMigration enables the option to passively announce a move from a different IRC network to Libera
	LiberaAnnounceMigration bool

	// User is the IRC Bot username
	User string

	// Name is the IRC Bot name
	Name string

	// FallbackNick is the IRC bot fallback nickname if first nick is registered to someone else
	FallbackNick string `toml:"FallbackNick,omitempty"`

	// Password is the IRC bot password for authentication
	Password string

	// Plugins is a list of plugin configurations
	Plugins NarwhalPluginsConfig `toml:"Plugins,omitempty"`

	// Channels is a list of channels to join
	Channels []string

	// Users is our users configuration
	Users NarwhalUsersConfig `toml:"Users,omitempty"`
}

NarwhalConfig is our primary Narwhal configuration

var Config NarwhalConfig

Config is our Narwhal Config

func ReadConfig

func ReadConfig() (NarwhalConfig, error)

ReadConfig will read our narwhal configuration, if it exists, and return it

func SetDefaults

func SetDefaults(config NarwhalConfig) NarwhalConfig

SetDefaults will set the defaults for the provided NarwhalConfig

type NarwhalMessage

type NarwhalMessage struct {
	Admin         bool
	Authenticated bool
	Channel       string
	Command       string
	Host          string
	FullIssuer    string
	Issuer        string
	Message       string
	MessageNoCmd  string
	Params        []string
}

NarwhalMessage is a custom message

func ParseMessage

func ParseMessage(c *girc.Client, e girc.Event) NarwhalMessage

ParseMessage will parse an event and return a NarwhalMessage

type NarwhalPlugin

type NarwhalPlugin interface {
	Parse(c *girc.Client, e girc.Event, m NarwhalMessage)
}

NarwhalPlugin is a plugin interface

type NarwhalPluginManager

type NarwhalPluginManager struct {
	Modules map[string]plugin.Symbol
}

NarwhalPluginManager is our plugin manager

var PluginManager NarwhalPluginManager

PluginManager is our Plugin Manager

func (*NarwhalPluginManager) IsEnabled

func (pm *NarwhalPluginManager) IsEnabled(pluginName string) bool

IsEnabled will return if the plugin specified is enabled

func (*NarwhalPluginManager) LoadPlugins

func (pm *NarwhalPluginManager) LoadPlugins() error

LoadPlugins is responsible for loading any plugins from our modules directory

type NarwhalPluginsConfig

type NarwhalPluginsConfig struct {
	Enabled []string

	Admin    NarwhalAdminConfig      `toml:"Admin,omitempty"`
	AutoKick NarwhalAutoKickerConfig `toml:"AutoKick,omitempty"`
	Replacer NarwhalReplacerConfig   `toml:"Replacer,omitempty"`
	Slap     NarwhalSlapConfig       `toml:"Slap,omitempty"`
}

NarwhalPluginsConfig is a list of command configurations

type NarwhalReplacerConfig

type NarwhalReplacerConfig struct {
	// CachedMessageLimit is our limit of how many messages to cache
	CachedMessageLimit int
}

NarwhalReplacerConfig is our configuration for the Narwhal replacer plugin

type NarwhalReplacerPlugin

type NarwhalReplacerPlugin struct{}

NarwhalReplacerPlugin is our Replacer plugin

var NarwhalReplacer NarwhalReplacerPlugin

NarwhalReplacer is our string replacer plugin

func (*NarwhalReplacerPlugin) AddToCache

func (replacer *NarwhalReplacerPlugin) AddToCache(m NarwhalMessage)

AddToCache will add the provided messaged to our cached list and remove the first entry if we get above our limit

func (*NarwhalReplacerPlugin) Parse

func (replacer *NarwhalReplacerPlugin) Parse(c *girc.Client, e girc.Event, m NarwhalMessage)

type NarwhalSlapConfig

type NarwhalSlapConfig struct {
	// CustomActions is a list of custom actions on how to slap a user
	CustomActions []string
}

NarwhalSlapConfig is our configuration for the Narwhal autokicker

type NarwhalSlapPlugin

type NarwhalSlapPlugin struct {
	Messages []string
}

NarwhalSlapPlugin is our slap plugin

var NarwhalSlap NarwhalSlapPlugin

NarwhalSlap is our slap plugin

func (*NarwhalSlapPlugin) Parse

func (slap *NarwhalSlapPlugin) Parse(c *girc.Client, e girc.Event, m NarwhalMessage)

type NarwhalSongPlugin

type NarwhalSongPlugin struct{}

NarwhalSong is our Song plugin

var NarwhalSong NarwhalSongPlugin

NarwhalSong is our song plugin

func (*NarwhalSongPlugin) Parse

func (song *NarwhalSongPlugin) Parse(c *girc.Client, e girc.Event, m NarwhalMessage)

type NarwhalThankMePlugin

type NarwhalThankMePlugin struct {
	Messages []string
}

NarwhalThankMePlugin is our Thank Me plugin The goal is just to reply with something random like "No problem" when thanked

var NarwhalThank NarwhalThankMePlugin

NarwhalThank is our thank me plugin

func (*NarwhalThankMePlugin) Parse

func (thank *NarwhalThankMePlugin) Parse(c *girc.Client, e girc.Event, m NarwhalMessage)

type NarwhalUrlParserPlugin

type NarwhalUrlParserPlugin struct{}

NarwhalUrlParserPlugin is our URL plugin

var NarwhalUrlParser NarwhalUrlParserPlugin

NarwhalUrlParser is our url parser

func (*NarwhalUrlParserPlugin) Parse

func (parser *NarwhalUrlParserPlugin) Parse(c *girc.Client, e girc.Event, m NarwhalMessage)

type NarwhalUsersConfig

type NarwhalUsersConfig struct {
	// Admins is an array of users authorized to perform admin actions
	Admins []string

	// Blacklist is an array of users blacklisted from performing Plugins
	Blacklist []string
}

NarwhalUsersConfig is our configuration for blacklisting users, administrative users, and autokicking

Jump to

Keyboard shortcuts

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