gcalbot

package
v0.0.0-...-3abce5f Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: BSD-3-Clause, MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const AllDayDateFormat = "2006-01-02"
View Source
const MySQLTimeFormat = "15:04:05"

Variables

This section is empty.

Functions

func FormatEvent

func FormatEvent(
	event *calendar.Event,
	calendarSummary string,
	timezone *time.Location,
	format24HourTime bool,
) (string, error)

func FormatEventSchedule

func FormatEventSchedule(
	events []*calendar.Event,
	timezone *time.Location,
	format24HourTime bool,
) (schedule string, err error)

func FormatTime

func FormatTime(dateTime time.Time, format24HourTime, trailingZeroes bool) string

func FormatTimeRange

func FormatTimeRange(
	startDateTime, endDateTime *calendar.EventDateTime,
	timezone *time.Location,
	format24HourTime bool,
) (timeRange string, err error)

func GetCalendarService

func GetCalendarService(account *Account, config *oauth2.Config, db *DB) (srv *calendar.Service, err error)

func GetConvHelpText

func GetConvHelpText(channel chat1.ChatChannel, convIsPrivateMsg, isKeybaseMessage bool) string

func GetDurationFromMinutes

func GetDurationFromMinutes(minutes int) time.Duration

func GetDurationFromTimeString

func GetDurationFromTimeString(timeString string) (time.Duration, error)

func GetMinutesFromDuration

func GetMinutesFromDuration(duration time.Duration) int

func GetTimeStringFromDuration

func GetTimeStringFromDuration(duration time.Duration) string

func GetUserFormat24HourTime

func GetUserFormat24HourTime(srv *calendar.Service) (format24HourTime bool, err error)

func GetUserTimezone

func GetUserTimezone(srv *calendar.Service) (timezone *time.Location, err error)

func MinutesBeforeString

func MinutesBeforeString(minutesBefore int) string

func ParseTime

func ParseTime(startDateTime, endDateTime *calendar.EventDateTime) (start, end time.Time, isAllDay bool, err error)

Types

type Account

type Account struct {
	KeybaseUsername string
	AccountNickname string
	Token           oauth2.Token
}

type AccountHelpPage

type AccountHelpPage struct {
	Title string
}

type AggregatedDailyScheduleSubscription

type AggregatedDailyScheduleSubscription struct {
	CalendarIDs      []string
	KeybaseConvID    chat1.ConvIDStr
	Timezone         *time.Location
	DaysToSend       DaysToSendType
	ScheduleToSend   ScheduleToSendType
	NotificationTime time.Duration
	Account          Account
}

type Channel

type Channel struct {
	ChannelID     string
	CalendarID    string
	ResourceID    string
	Expiry        time.Time
	NextSyncToken string
}

type ChannelAndAccount

type ChannelAndAccount struct {
	Channel Channel
	Account Account
}

type ConfigPage

type ConfigPage struct {
	Title    string
	CaretSVG template.HTML

	ConvID        chat1.ConvIDStr
	ConvHelpText  string
	ConvIsPrivate bool

	Account  string
	Accounts []*Account

	CalendarID string
	Calendars  []*calendar.CalendarListEntry

	Reminder        string
	ReminderOptions []ReminderType
	Invite          bool

	DSEnabled         bool
	DSDays            DaysToSendType
	DSDaysOptions     []DSDaysOption
	DSSchedule        ScheduleToSendType
	DSScheduleOptions []DSScheduleOption
	DSTime            string
	DSTimeOptions     [48]DSTimeOption

	Updated        bool
	PushNotAllowed bool
}

type DB

type DB struct {
	*base.DB
	*base.DebugOutput
}

func NewDB

func NewDB(
	db *sql.DB,
	debugConfig *base.ChatDebugOutputConfig,
) *DB

func (*DB) CompleteState

func (d *DB) CompleteState(state string) error

func (*DB) CountSubscriptionsByAccountAndCalender

func (d *DB) CountSubscriptionsByAccountAndCalender(account *Account, calendarID string) (count int, err error)

func (*DB) DeleteAccount

func (d *DB) DeleteAccount(keybaseUsername, accountNickname string) error

func (*DB) DeleteChannelByChannelID

func (d *DB) DeleteChannelByChannelID(channelID string) error

func (*DB) DeleteDailyScheduleSubscription

func (d *DB) DeleteDailyScheduleSubscription(account *Account, calendarID string, keybaseConvID chat1.ConvIDStr) error

func (*DB) DeleteSubscription

func (d *DB) DeleteSubscription(account *Account, subscription Subscription) error

func (*DB) ExistsAccount

func (d *DB) ExistsAccount(keybaseUsername string, accountNickname string) (exists bool, err error)

func (*DB) ExistsChannelByAccountAndCalendar

func (d *DB) ExistsChannelByAccountAndCalendar(account *Account, calendarID string) (exists bool, err error)

func (*DB) ExistsInvite

func (d *DB) ExistsInvite(account *Account, calendarID, eventID string) (exists bool, err error)

func (*DB) ExistsSubscription

func (d *DB) ExistsSubscription(account *Account, subscription Subscription) (exists bool, err error)

func (*DB) GetAccount

func (d *DB) GetAccount(keybaseUsername, accountNickname string) (account *Account, err error)

func (*DB) GetAccountListForUsername

func (d *DB) GetAccountListForUsername(keybaseUsername string) (accounts []*Account, err error)

func (*DB) GetAggregatedDailyScheduleSubscription

func (d *DB) GetAggregatedDailyScheduleSubscription(scheduleToSend ScheduleToSendType) (subscriptions []*AggregatedDailyScheduleSubscription, err error)

func (*DB) GetChannel

func (d *DB) GetChannel(account *Account, calendarID string) (channel *Channel, err error)

func (*DB) GetChannelAndAccountByID

func (d *DB) GetChannelAndAccountByID(channelID string) (channel *Channel, account *Account, err error)

func (*DB) GetChannelListByAccount

func (d *DB) GetChannelListByAccount(account *Account) (channels []*Channel, err error)

func (*DB) GetDailyScheduleSubscription

func (d *DB) GetDailyScheduleSubscription(
	account *Account,
	calendarID string,
	keybaseConvID chat1.ConvIDStr,
) (subscription *DailyScheduleSubscription, exists bool, err error)

func (*DB) GetExpiringChannelAndAccountList

func (d *DB) GetExpiringChannelAndAccountList() (pairs []*ChannelAndAccount, err error)

func (*DB) GetInviteAndAccountByUserMessage

func (d *DB) GetInviteAndAccountByUserMessage(keybaseUsername string, messageID chat1.MessageID) (invite *Invite, account *Account, err error)

func (*DB) GetReminderSubscriptionAndAccountPairs

func (d *DB) GetReminderSubscriptionAndAccountPairs() (pairs []*SubscriptionAndAccount, err error)

func (*DB) GetReminderSubscriptionsByAccountAndCalendar

func (d *DB) GetReminderSubscriptionsByAccountAndCalendar(
	account *Account,
	calendarID string,
	subscriptionType SubscriptionType,
) (subscriptions []*Subscription, err error)

func (*DB) GetState

func (d *DB) GetState(state string) (*OAuthRequest, error)

OAuth state

func (*DB) GetSubscriptions

func (d *DB) GetSubscriptions(account *Account, calendarID string, keybaseConvID chat1.ConvIDStr) (subscriptions []*Subscription, err error)

func (*DB) InsertAccount

func (d *DB) InsertAccount(account Account) error

Account

func (*DB) InsertChannel

func (d *DB) InsertChannel(account *Account, channel Channel) error

Channel

func (*DB) InsertDailyScheduleSubscription

func (d *DB) InsertDailyScheduleSubscription(account *Account, subscription DailyScheduleSubscription) error

Daily Schedule Subscription

func (*DB) InsertInvite

func (d *DB) InsertInvite(account *Account, invite Invite) error

Invite

func (*DB) InsertSubscription

func (d *DB) InsertSubscription(account *Account, subscription Subscription) error

Subscription

func (*DB) PutState

func (d *DB) PutState(state string, oauthState OAuthRequest) error

func (*DB) UpdateChannel

func (d *DB) UpdateChannel(oldChannelID, newChannelID string, expiry time.Time) error

func (*DB) UpdateChannelNextSyncToken

func (d *DB) UpdateChannelNextSyncToken(channelID, nextSyncToken string) error

type DSDaysOption

type DSDaysOption struct {
	Title string
	Days  DaysToSendType
}

type DSScheduleOption

type DSScheduleOption struct {
	Title    string
	Schedule ScheduleToSendType
}

type DSTimeOption

type DSTimeOption struct {
	Title  string
	Minute string
}

type DailyScheduleSubscription

type DailyScheduleSubscription struct {
	CalendarID       string
	KeybaseConvID    chat1.ConvIDStr
	Timezone         *time.Location
	DaysToSend       DaysToSendType
	ScheduleToSend   ScheduleToSendType
	NotificationTime time.Duration
}

type DaysToSendType

type DaysToSendType string
const (
	DaysToSendEveryday DaysToSendType = "everyday"
	DaysToSendMonToFri DaysToSendType = "monday through friday"
	DaysToSendSunToThu DaysToSendType = "sunday through thursday"
)

type ErrorPage

type ErrorPage struct {
	Title string
}

type EventStatus

type EventStatus string
const (
	EventStatusConfirmed EventStatus = "confirmed"
	EventStatusTentative EventStatus = "tentative"
	EventStatusCancelled EventStatus = "cancelled"
)

type HTTPSrv

type HTTPSrv struct {
	*base.HTTPSrv
	// contains filtered or unexported fields
}

func NewHTTPSrv

func NewHTTPSrv(
	stats *base.StatsRegistry,
	kbc *kbchat.API,
	debugConfig *base.ChatDebugOutputConfig,
	db *DB,
	oauthConfig *oauth2.Config,
	reminderScheduler ReminderScheduler,
	handler *Handler,
) *HTTPSrv

type Handler

type Handler struct {
	*base.DebugOutput
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(
	stats *base.StatsRegistry,
	kbc *kbchat.API,
	debugConfig *base.ChatDebugOutputConfig,
	db *DB,
	oauth *oauth2.Config,
	reminderScheduler ReminderScheduler,
	tokenSecret string,
	httpPrefix string,
) *Handler

func (*Handler) HandleCommand

func (h *Handler) HandleCommand(msg chat1.MsgSummary) error

func (*Handler) HandleNewConv

func (h *Handler) HandleNewConv(conv chat1.ConvSummary) error

func (*Handler) LoginToken

func (h *Handler) LoginToken(username string) string

type Invite

type Invite struct {
	CalendarID string
	EventID    string
	MessageID  chat1.MessageID
}

type InviteReaction

type InviteReaction string
const (
	InviteReactionYes   InviteReaction = "Yes 👍"
	InviteReactionNo    InviteReaction = "No 👎"
	InviteReactionMaybe InviteReaction = "Maybe 🤷"
)

type LoginPage

type LoginPage struct {
	Title string
}

type OAuthRequest

type OAuthRequest struct {
	KeybaseUsername string
	AccountNickname string
	KeybaseConvID   chat1.ConvIDStr
	IsComplete      bool
}

type ReminderScheduler

type ReminderScheduler interface {
	UpdateOrCreateReminderEvent(
		account *Account,
		subscription *Subscription,
		event *calendar.Event,
	) error
	AddSubscription(account *Account, subscription Subscription)
	RemoveSubscription(account *Account, subscription Subscription)
}

type ReminderType

type ReminderType struct {
	Title  string
	Minute string
}

type RenewChannelScheduler

type RenewChannelScheduler struct {
	*base.DebugOutput
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRenewChannelScheduler

func NewRenewChannelScheduler(
	stats *base.StatsRegistry,
	debugConfig *base.ChatDebugOutputConfig,
	db *DB,
	config *oauth2.Config,
	httpPrefix string,
) *RenewChannelScheduler

func (*RenewChannelScheduler) Run

func (r *RenewChannelScheduler) Run() (err error)

func (*RenewChannelScheduler) Shutdown

func (r *RenewChannelScheduler) Shutdown() (err error)

type ResponseStatus

type ResponseStatus string
const (
	ResponseStatusNeedsAction ResponseStatus = "needsAction"
	ResponseStatusDeclined    ResponseStatus = "declined"
	ResponseStatusTentative   ResponseStatus = "tentative"
	ResponseStatusAccepted    ResponseStatus = "accepted"
)

type ScheduleToSendType

type ScheduleToSendType string
const (
	ScheduleToSendToday    ScheduleToSendType = "today"
	ScheduleToSendTomorrow ScheduleToSendType = "tomorrow"
)

type Subscription

type Subscription struct {
	CalendarID     string
	KeybaseConvID  chat1.ConvIDStr
	DurationBefore time.Duration
	Type           SubscriptionType
}

type SubscriptionAndAccount

type SubscriptionAndAccount struct {
	Subscription Subscription
	Account      Account
}

type SubscriptionType

type SubscriptionType string
const (
	SubscriptionTypeInvite   SubscriptionType = "invite"
	SubscriptionTypeReminder SubscriptionType = "reminder"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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