google

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CalendarCommand = command.BasicCommandTemplate{
	Help:           "Get Events from Google Calendar",
	MentionCommand: "calendar",
	GenerateFn: func(d command.CommandData) command.Command {
		c := command.Command{}

		calendarCli, err := getGoogleCalendarClient()
		if err != nil {
			errMessage := fmt.Sprintf("[ERROR]\t[getGoogleCalendarClient]\t`%s`", err.Error())
			task := command.NewReplyEngineTask(d.Engine, d.Channel, errMessage)
			c.Add(task)
			return c
		}

		email, err := getEmailAddress(d)
		if err != nil {
			errMessage := fmt.Sprintf("[ERROR]\t[getEmailAddress]\t`%s`", err.Error())
			task := command.NewReplyEngineTask(d.Engine, d.Channel, errMessage)
			c.Add(task)
			return c
		}

		command.NewReplyEngineTask(d.Engine, d.Channel, i18n.Message("Getting events of [%s] ...", email)).Run()
		list, err := calendarCli.EventList(email, 10)
		if err != nil {
			errMessage := fmt.Sprintf("[ERROR]\t[EventList]\t`%s`", err.Error())
			task := command.NewReplyEngineTask(d.Engine, d.Channel, errMessage)
			c.Add(task)
			return c
		}

		msg := formatCalendarAsSlackMessage(list.List)
		task := command.NewReplyEngineTask(d.Engine, d.Channel, msg)
		c.Add(task)
		return c
	},
}

To use Calendar Command, you should setup, (1) Credentials for Google API (2) OAuth Token for Calendar. (1): https://cloud.google.com/docs/authentication/ (2): https://developers.google.com/calendar/quickstart/go

View Source
var WhereCommand = command.BasicCommandTemplate{
	Help:           "Get current location from Google Calendar",
	MentionCommand: "where",
	GenerateFn: func(d command.CommandData) command.Command {
		c := command.Command{}

		calendarCli, err := getGoogleCalendarClient()
		if err != nil {
			errMessage := fmt.Sprintf("[ERROR]\t[getGoogleCalendarClient]\t`%s`", err.Error())
			task := command.NewReplyEngineTask(d.Engine, d.Channel, errMessage)
			c.Add(task)
			return c
		}

		email, err := getEmailAddress(d)
		if err != nil {
			errMessage := fmt.Sprintf("[ERROR]\t[getEmailAddress]\t`%s`", err.Error())
			task := command.NewReplyEngineTask(d.Engine, d.Channel, errMessage)
			c.Add(task)
			return c
		}

		command.NewReplyEngineTask(d.Engine, d.Channel, i18n.Message("Getting location of [%s] ...", email)).Run()
		list, err := calendarCli.EventListWithOption(email, calendar.EventListOption{
			TimeMin:      time.Now().Add(-1 * time.Hour),
			SingleEvents: true,
			OrderBy:      calendar.OrderByStartTime,
			MaxResults:   10,
		})
		if err != nil {
			errMessage := fmt.Sprintf("[ERROR]\t[EventList]\t`%s`", err.Error())
			task := command.NewReplyEngineTask(d.Engine, d.Channel, errMessage)
			c.Add(task)
			return c
		}

		res := getCalendarEvent(list.List)
		if !res.hasTimeEvent && !res.hasAllDayEvent {
			task := command.NewReplyEngineTask(d.Engine, d.Channel, i18n.Message("Somewhere around there"))
			c.Add(task)
			return c
		}

		msg := makeMessage(res)
		task := command.NewReplyEngineTask(d.Engine, d.Channel, msg)
		c.Add(task)
		return c
	},
}

Functions

This section is empty.

Types

type RoomCommand added in v0.0.5

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

func (*RoomCommand) Exec added in v0.0.5

func (a *RoomCommand) Exec(d command.CommandData)

func (RoomCommand) GetHelp added in v0.0.5

func (RoomCommand) GetHelp() string

func (RoomCommand) GetMentionCommand added in v0.0.5

func (RoomCommand) GetMentionCommand() string

func (RoomCommand) GetRegexp added in v0.0.5

func (RoomCommand) GetRegexp() *regexp.Regexp

func (RoomCommand) HasHelp added in v0.0.5

func (RoomCommand) HasHelp() bool

type RoomEvent added in v0.0.5

type RoomEvent struct {
	Room      string
	Event     string
	StartTime time.Time
	EndTime   time.Time
	IsEmpty   bool
}

type RoomEvents added in v0.0.5

type RoomEvents []RoomEvent

func (RoomEvents) Len added in v0.0.5

func (l RoomEvents) Len() int

func (RoomEvents) Less added in v0.0.5

func (l RoomEvents) Less(i, j int) bool

func (RoomEvents) Swap added in v0.0.5

func (l RoomEvents) Swap(i, j int)

Jump to

Keyboard shortcuts

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