core

package
v0.0.0-...-984de81 Latest Latest
Warning

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

Go to latest
Published: May 2, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package core contains bot functionality for iris. Currently following Pomodoro technique.

Index

Constants

This section is empty.

Variables

View Source
var (
	ClientID, _      = configparser.Register("iris.clientid", "ClientID of the bot", nil)
	ClientSecrets, _ = configparser.Register("iris.clientsecret", "ClientSecret of the bot", nil)
	BotToken, _      = configparser.Register("iris.authtoken", "authentication token of the bot", nil)
	CmdPrefix, _     = configparser.Register("iris.cmdprefix", "prefix for iris", "/i ")
	Loaded           = false

	// VERSION is defined via git.
	VERSION     = "unknown"
	IrisSession *discordgo.Session
	IrisUser    *discordgo.User
)

TODO: add options to check for valid configuration name.

Functions

func GetBotToken

func GetBotToken() string

GetBotToken will handles authToken.

func LoadIrisConfig

func LoadIrisConfig() error

LoadIrisConfig loads required configs.

Types

type Iris

type Iris struct {
	// contains filtered or unexported fields
}

Iris defines the structure for the bot's functionality.

func New

func New() *Iris

New creates a new instance of Iris that can deploy over Heroku.

func (*Iris) Start

func (ir *Iris) Start() error

Start will start the bot, blocking til completed.

type NotifyInfo

type NotifyInfo struct {
	TitleID string
	User    *datastore.User
}

NotifyInfo defines notification message for users.

type Pomodoro

type Pomodoro struct {
	// contains filtered or unexported fields
}

Pomodoro defines a single state of a pomodoro sessions. Usage of channel to handle cancel signal.

func NewPom

func NewPom(workDuration time.Duration, onWorkEnd TaskCallback, notify NotifyInfo) *Pomodoro

NewPom create a new pomodoro and start it using time.NewTimer. onWorkEnd will be called after the goroutine.

func (*Pomodoro) Cancel

func (pom *Pomodoro) Cancel()

Cancel is used to cancel the current state of the goroutine. sync.Once to prevent panic.

type TaskCallback

type TaskCallback func(info NotifyInfo, finished bool)

TaskCallback receives NotifyInfo and a boolean to define whether the task is completed or not.

type UserPomodoroMap

type UserPomodoroMap struct {
	// contains filtered or unexported fields
}

UserPomodoroMap is a map-like structure to init a single pomodoro in a channel. It has goroutine safe ops.

func NewUserPomodoroMap

func NewUserPomodoroMap() UserPomodoroMap

NewUserPomodoroMap creates a ChannelPomMap and prepares it to be used.

func (*UserPomodoroMap) Count

func (u *UserPomodoroMap) Count() int

Count counts the number of current Pomodoro being tracked.

func (*UserPomodoroMap) CreateIfEmpty

func (u *UserPomodoroMap) CreateIfEmpty(duration time.Duration, onWorkEnd TaskCallback, notify NotifyInfo) bool

CreateIfEmpty will create a new Pomodoro for given user according to their discordID if user has none. The pomodoro will then be removed from the mapping once completed or canceled.

func (*UserPomodoroMap) RemoveIfExists

func (u *UserPomodoroMap) RemoveIfExists(discordID string) bool

RemoveIfExists will remove a Pomodoro from given channel i one already exists.

Jump to

Keyboard shortcuts

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