authorization

package
v0.0.0-...-bdea560 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2017 License: MIT Imports: 8 Imported by: 0

README

Authorization

Expects a file userfile.json to be present in your bot's working directory. See userfile_dist.json for a skeleton file. The general idea is that you define users, which have host masks, and channels, which have roles, which map to usernames.

You can define any role you want, and hook up some usernames to it. In a plugin you can then authorize an action like so:

if authorization.Authorize(command.User, command.Channel, "author") == true {
	// Yep, this user is allowed to do that.
}

Documentation

Overview

Package authorization provides user matchting and channel / role authorization. It allows you to dictate who can (and can't) do what.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authorize

func Authorize(c *bot.ChannelData, r string, b *bot.User) (uname string, err error)

Authorize tries to match a channel, role and bot User. It'll return a username if a match is found, or the original nick if a match was made to the special "*" user.

func Fullhost

func Fullhost(b *bot.User) string

Fullhost constructs a full (IRC-style) host for a Bot user.

func Load

func Load()

Load (re)loads userfile.json into our Userfile struct.

func MatchHost

func MatchHost(host string) (username string, err error)

MatchHost tries to find a hostname, returning a username if found

Types

type Channel

type Channel struct {
	Roles map[string][]string `json:"roles"`
}

Channel holds a singular Channel with Roles

type User

type User struct {
	Username string
	Rawmasks []string `json:"masks"`
	Masks    []*regexp.Regexp
}

User holds a singular User with Masks.

func (*User) Match

func (user *User) Match(host string) bool

Match tries to match a host against known Users.

type Userfile

type Userfile struct {
	Channels map[string]*Channel `json:"channels"`
	Users    map[string]*User    `json:"users"`
}

Userfile holds our Users and Channels.

Jump to

Keyboard shortcuts

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