Documentation ¶
Index ¶
- Constants
- func ProcessArgs(server string, command *Command, channel string, isChan bool, msgArgs []string, ...) (err error)
- type Command
- func New(ext, cmd, desc string, handler Handler, kind Kind, scope Scope, args ...string) *Command
- func NewAuthed(ext, cmd, desc string, handler Handler, kind Kind, scope Scope, reqLevel uint8, ...) *Command
- func NewAuthedErr(ext, cmd, desc string, handler Handler, kind Kind, scope Scope, reqLevel uint8, ...) (*Command, error)
- func NewErr(ext, cmd, desc string, handler Handler, kind Kind, scope Scope, args ...string) (*Command, error)
- type Event
- type Handler
- type HandlerFunc
- type Kind
- type Scope
Constants ¶
const ( // KindPrivmsg only listens to irc.PRIVMSG events. Privmsg Kind = 0x1 // KindNotice only listens to irc.NOTICE events. Notice Kind = 0x2 // AnyKind listens to both irc.PRIVMSG and irc.NOTICE events. AnyKind Kind = 0x3 // Private only listens to PRIVMSG or NOTICE sent directly to the bot. Private Scope = 0x1 // PUBLIC only listens to PRIVMSG or NOTICE sent to a channel. Public Scope = 0x2 // AnyScope listens to events sent to a channel or directly to the bot. AnyScope Scope = 0x3 )
Constants used for defining the targets/scope of a command.
Variables ¶
This section is empty.
Functions ¶
func ProcessArgs ¶
func ProcessArgs(server string, command *Command, channel string, isChan bool, msgArgs []string, ev *Event, ircEvent *irc.Event, state *data.State, store *data.Store) (err error)
ProcessArgs parses all the arguments. It looks up channel and user arguments using the state and store, and generally populates the Event struct with argument information.
Types ¶
type Command ¶
type Command struct { // The name of the command. Name string // Extension is the name of the extension registering this command. Extension string // Description is a description of the command's function. Description string // Kind is the kind of messages this command reacts to, may be // any of the constants: Privmsg, Notice or AllKinds. Kind Kind // Scope is the scope of the messages this command reacts to, may be // any of the constants: Private, Public or Allscopes. Scope Scope // Args is the arguments for the command. Each argument must be in it's own // element, be named with flags optionally prefixing the name, and have the // form of one of the following: // #channel: This form is for requiring a target channel for the command. // If this parameter is present and a message directly to the bot is // received this parameter is required and if it's missing an error // will be returned. // If this parameter is present and a message to a channel is received // the there is two cases: 1) The first parameter given is a channel, // this then becomes the TargetChannel. 2) The first parameter given // is non existent or not a channel, the current channel then becomes // the TargetChannel. // required: This form marks a required attribute and it must be present // or an error will be returned. It must come after #channel but before // [optional] and varargs... arguments. // [optional]: This form is an optional argument. It must come before after // required but before varargs... arguments. // varargs...: This form is a variadic argument, there may be 0 or more // arguments to satisfy this parameter and they will all be parsed // together as one string by the commander. This must come at the end. // There are two types of flags available: // ~: This flag is a nickname flag. If this flag is present the bot // will look up the nickname given in the state database, if it does // not exist an error will occur. // *: This flag is a user flag. It looks up a user based on nick OR // username. If any old nickname is given, it first looks up the user // in the state database, and then checks his authentication record // to get his username (and therefore access). If the name is prefixed // by a *, then it looks up the user based on username directly. If // the user is not found (via nickname), not authed (via username) // the command will fail. Args []string // RequireAuth is whether or not this command requires authentication. RequireAuth bool // ReqLevel is the required level for use. ReqLevel uint8 // ReqFlags is the required flags for use. ReqFlags string // Handler the handler structure that will handle events for this command. Handler Handler // contains filtered or unexported fields }
Command holds all the information about a command.
func New ¶
New is a helper method to easily create a Command. See the documentation for Command on what each parameter is. Panics if the args are invalid.
func NewAuthed ¶
func NewAuthed( ext, cmd, desc string, handler Handler, kind Kind, scope Scope, reqLevel uint8, reqFlags string, args ...string) *Command
NewAuthed is a helper method to easily create an authenticated Command. See the documentation on Command for what each parameter is. Panics if the args are invalid.
type Event ¶
type Event struct { *irc.Event // User can be nil if the bot's State is disabled. User *data.User // StoredUser will be nil when there is no required access. StoredUser *data.StoredUser // UserChannelModes will be nil when the message was not sent to a channel. UserChannelModes *data.UserModes // Channel will be nil when the message was not sent to a channel. Channel *data.Channel // TargetChannel will not be nil when the command has the #channel // parameter. The parameter can still be nil when the channel is not known // to the bot. TargetChannel *data.Channel // TargetUsers is populated when the arguments contain a ~nick argument, and // as a byproduct of looking up authentication, when the arguments contain // a *user argument, and a nickname is passed instead of a *username. TargetUsers map[string]*data.User // TargetStoredUser is populated when the arguments contain a *user // argument. TargetStoredUsers map[string]*data.StoredUser // TargetVarUsers is populated when the arguments contain a ~nick... // argument. When a *user... parameter is used, it will be sparsely filled // whenever a user is requested by nickname not *username. TargetVarUsers []*data.User // TargetVarUsers is populated when the arguments contain a *user... // argument. TargetVarStoredUsers []*data.StoredUser Args map[string]string }
Event represents the data about the event that occurred. The commander fills the Event structure with information about the user and channel involved. It also embeds the State and Store for easy access.
Some parts of Event will be nil under certain circumstances so elements within must be checked for nil, see each element's documentation for further information.
type HandlerFunc ¶
HandlerFunc implements Handler