config

package
v0.0.0-...-105f304 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2016 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigFile = "config.json"

ConfigFile is the configuration file to use.

Variables

View Source
var Autosave = flag.BoolP("config-autosave", "s", true, "Don't save config when something is changed.")

Autosave determines if the config should be automatically saved when something is changed.

View Source
var IndentConfig = false

IndentConfig determines if the config should be pretty-printed

View Source
var NilUser = User{}

NilUser is an empty user type.

Functions

func ASave

func ASave()

ASave calls Save if Autosave is true

func AddUser

func AddUser(user User) bool

AddUser adds the given user to the whitelist.

func GetUsersWithSettingAndRun

func GetUsersWithSettingAndRun(run func(u User), setting string, values ...string)

GetUsersWithSettingAndRun gets the users with the given setting and runs a function for them.

func Load

func Load()

Load loads the whitelist from file.

func RemoveUser

func RemoveUser(identifier string) bool

RemoveUser removes the given user from the whitelist.

func Save

func Save()

Save saves the whitelist data to file.

Types

type Configuration

type Configuration struct {
	Whitelist    []User `json:"whitelist"`
	LastReadPost int    `json:"last-read-post"`
}

Configuration is the container for a config.

func GetConfig

func GetConfig() *Configuration

GetConfig gets the configuration

type User

type User struct {
	UID         int               `json:"uid"`
	Name        string            `json:"name"`
	Year        int               `json:"year"`
	Permissions []string          `json:"permissions"`
	Settings    map[string]string `json:"settings"`
}

User struct that is used for whitelisted user entries

func CreateUser

func CreateUser(uid int, name string, year int) User

CreateUser creates an user.

func GetAllUsers

func GetAllUsers() []User

GetAllUsers returns all the whitelisted users.

func GetUser

func GetUser(identifier string) User

GetUser gets the User struct that has the given value as name or UID.

func GetUserWithName

func GetUserWithName(name string) User

GetUserWithName gets the User struct that has the given name.

func GetUserWithUID

func GetUserWithUID(uid int) User

GetUserWithUID gets the User struct that has the given UID.

func GetUsersWithSetting

func GetUsersWithSetting(setting string, values ...string) []User

GetUsersWithSetting get all the users that have the given setting.

func (User) AddPermission

func (u User) AddPermission(permission string) bool

AddPermission adds the given permission to the user.

func (User) Destination

func (u User) Destination() string

Destination returns the UID for Telebot.

func (User) GetLanguage

func (u User) GetLanguage() string

GetLanguage gets the user display language

func (User) GetSetting

func (u User) GetSetting(key string) (string, bool)

GetSetting gets the given setting from the user.

func (User) HasPermission

func (u User) HasPermission(permission string) bool

HasPermission checks if the user has the given permission.

func (User) HasSetting

func (u User) HasSetting(key string) bool

HasSetting checks if the user has the given setting.

func (User) RemovePermission

func (u User) RemovePermission(permission string) bool

RemovePermission removes the given permission from the user.

func (User) RemoveSetting

func (u User) RemoveSetting(key string)

RemoveSetting removes a setting

func (User) SetSetting

func (u User) SetSetting(key string, value string)

SetSetting sets a setting

Jump to

Keyboard shortcuts

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