Documentation
¶
Index ¶
- Constants
- func EventBetweenDays(start, end time.Time) func(Event) bool
- func FormatDate(t time.Time) string
- func FormatTime(t time.Time) string
- func FormatTimeDate(t time.Time) string
- func ParseDDMMYYDate(date string) (time.Time, error)
- func ParseJSONDate(date string) time.Time
- func SpaceName(facilityID int) string
- type AreaMetadata
- type BusStop
- type BusStopHeap
- type BusTimes
- type ByStartDate
- type Cinnabot
- func (cb *Cinnabot) About(msg *message)
- func (cb *Cinnabot) AddFunction(command string, resp ResponseFunc) error
- func (cb *Cinnabot) Broadcast(msg *message)
- func (cb *Cinnabot) BusTimings(msg *message)
- func (cb *Cinnabot) CBS(msg *message)
- func (cb *Cinnabot) Cancel(msg *message)
- func (cb *Cinnabot) Capitalize(msg *message)
- func (cb *Cinnabot) CheckArgCmdPair(cmd string, args []string) bool
- func (cb *Cinnabot) CinnabotFeedback(msg *message)
- func (cb *Cinnabot) DHSurvey(msg *message)
- func (cb *Cinnabot) DHSurveyFeedback(msg *message)
- func (cb *Cinnabot) DiningFeedback(msg *message)
- func (cb *Cinnabot) Echo(msg *message)
- func (cb *Cinnabot) Feedback(msg *message)
- func (cb *Cinnabot) GetStats(msg *message)
- func (cb *Cinnabot) GoSafely(fn func())
- func (cb *Cinnabot) Help(msg *message)
- func (cb *Cinnabot) Listen(timeout int) tgbotapi.UpdatesChannel
- func (cb *Cinnabot) NUSBus(msg *message)
- func (cb *Cinnabot) ResidentialFeedback(msg *message)
- func (cb *Cinnabot) Resources(msg *message)
- func (cb *Cinnabot) Router(msg tgbotapi.Message)
- func (cb *Cinnabot) SayHello(msg *message)
- func (cb *Cinnabot) SendMessage(chattable tgbotapi.Chattable)
- func (cb *Cinnabot) SendTextMessage(recipient int, text string) error
- func (cb *Cinnabot) Spaces(msg *message)
- func (cb *Cinnabot) Start(msg *message)
- func (cb *Cinnabot) Subscribe(msg *message)
- func (cb *Cinnabot) USCFeedback(msg *message)
- func (cb *Cinnabot) Unsubscribe(msg *message)
- func (cb *Cinnabot) Weather(msg *message)
- type Event
- type EventPredicate
- type ForecastData
- type ForecastMetadata
- type FuncMap
- type NextBus
- type Response
- type ResponseFunc
- type Service
- type ServiceResult
- type Shuttle
- type Space
- type Spaces
- type WeatherForecast
Constants ¶
const ( TR1 = "THEME ROOM 1" TR2 = "THEME ROOM 2" CTPH = "CHUA THIAN POH HALL" AMPH = "AMPHITHEATRE" CHATTER = "CHATTERBOX" )
String constants
Variables ¶
This section is empty.
Functions ¶
func EventBetweenDays ¶
EventBetweenDays returns an EventPredicate testing if an event falls between the start and end date, inclusive. It is meant to be called with start, end time.Time obtained from ParseDDMMYYDate, which by default has time = 12MN.
func FormatDate ¶
FormatDate formats a time.Time into date in a standardised format
func FormatTime ¶
FormatTime formats a time.Time into a time in a standardised format
func FormatTimeDate ¶
FormatTimeDate formats a time.Time into a full time and date, in a standardised format
func ParseDDMMYYDate ¶
ParseDDMMYYDate parses user-inputted dd/mm/yy date into time.Time
func ParseJSONDate ¶
ParseJSONDate parses date from format used in nususc.com's API into a time.Time object
Types ¶
type AreaMetadata ¶
type AreaMetadata struct {
Name string `json:"name"`
Loc tgbotapi.Location `json:"label_location"`
}
type BusStop ¶
type BusStop struct {
BusStopNumber string `json:"no"`
Latitude string `json:"lat"`
Longitude string `json:"lng"`
BusStopName string `json:"name"`
}
Bus stop structs
type BusStopHeap ¶
type BusStopHeap struct {
// contains filtered or unexported fields
}
func (BusStopHeap) Len ¶
func (h BusStopHeap) Len() int
func (BusStopHeap) Less ¶
func (h BusStopHeap) Less(i, j int) bool
func (*BusStopHeap) Pop ¶
func (h *BusStopHeap) Pop() interface{}
func (*BusStopHeap) Push ¶
func (h *BusStopHeap) Push(x interface{})
func (BusStopHeap) Swap ¶
func (h BusStopHeap) Swap(i, j int)
type ByStartDate ¶
type ByStartDate Space
ByStartDate implements sort.Interface for Space based on the space[i].Start field
func (ByStartDate) Len ¶
func (space ByStartDate) Len() int
func (ByStartDate) Less ¶
func (space ByStartDate) Less(i, j int) bool
func (ByStartDate) Swap ¶
func (space ByStartDate) Swap(i, j int)
type Cinnabot ¶
type Cinnabot struct {
Name string // The name of the bot registered with Botfather
// contains filtered or unexported fields
}
Cinnabot is main struct that processes user requests.
func InitCinnabot ¶
InitCinnabot initializes an instance of Cinnabot.
func (*Cinnabot) About ¶
func (cb *Cinnabot) About(msg *message)
About returns a link to Cinnabot's source code.
func (*Cinnabot) AddFunction ¶
func (cb *Cinnabot) AddFunction(command string, resp ResponseFunc) error
AddFunction binds a response function to a command string in Cinnabot's FuncMap
func (*Cinnabot) Broadcast ¶
func (cb *Cinnabot) Broadcast(msg *message)
Broadcast broadcasts a message after checking for admin status [trial] Admins are to first send a message with tags before sending actual message
func (*Cinnabot) BusTimings ¶
func (cb *Cinnabot) BusTimings(msg *message)
BusTimings checks the bus timings based on given location
func (*Cinnabot) Capitalize ¶
func (cb *Cinnabot) Capitalize(msg *message)
Capitalize returns a capitalized form of the input string.
func (*Cinnabot) CheckArgCmdPair ¶
Checks if arg can be used with command Used to supplement cache as cache only records functions as states
func (*Cinnabot) CinnabotFeedback ¶
func (cb *Cinnabot) CinnabotFeedback(msg *message)
func (*Cinnabot) DHSurvey ¶
func (cb *Cinnabot) DHSurvey(msg *message)
function to send message when someone enters dhsurvey tag
func (*Cinnabot) DHSurveyFeedback ¶
func (cb *Cinnabot) DHSurveyFeedback(msg *message)
function to add DH survey entry to database
func (*Cinnabot) DiningFeedback ¶
func (cb *Cinnabot) DiningFeedback(msg *message)
func (*Cinnabot) Echo ¶
func (cb *Cinnabot) Echo(msg *message)
Echo parrots back the argument given by the user.
func (*Cinnabot) Feedback ¶
func (cb *Cinnabot) Feedback(msg *message)
Feedback allows users an avenue to give feedback. Admins can retrieve by searching the /feedback handler in the db
func (*Cinnabot) GetStats ¶
func (cb *Cinnabot) GetStats(msg *message)
function to count number of users and messages
func (*Cinnabot) GoSafely ¶
func (cb *Cinnabot) GoSafely(fn func())
GoSafely is a utility wrapper to recover and log panics in goroutines. If we use naked goroutines, a panic in any one of them crashes the whole program. Using GoSafely prevents this.
func (*Cinnabot) Help ¶
func (cb *Cinnabot) Help(msg *message)
Help gives a list of handles that the user may call along with a description of them
func (*Cinnabot) NUSBus ¶
func (cb *Cinnabot) NUSBus(msg *message)
NUSBus retrieves the next timing for NUS Shuttle buses
func (*Cinnabot) ResidentialFeedback ¶
func (cb *Cinnabot) ResidentialFeedback(msg *message)
func (*Cinnabot) Resources ¶
func (cb *Cinnabot) Resources(msg *message)
Link returns useful resources
func (*Cinnabot) Router ¶
func (cb *Cinnabot) Router(msg tgbotapi.Message)
Router routes Telegram messages to the appropriate response functions. Hack: Cache to store previous function information
func (*Cinnabot) SayHello ¶
func (cb *Cinnabot) SayHello(msg *message)
Test functions [Not meant to be used in bot] SayHello says hi.
func (*Cinnabot) SendMessage ¶
func (cb *Cinnabot) SendMessage(chattable tgbotapi.Chattable)
SendMessage sends messages which require non-default options such as reply markups.
func (*Cinnabot) SendTextMessage ¶
SendTextMessage sends a basic text message back to the specified user.
func (*Cinnabot) Spaces ¶
func (cb *Cinnabot) Spaces(msg *message)
Spaces is the primary Cinnabot Spaces method that the end user interacts with.
"/spaces" displays bookings for today. "/spaces now" displays bookings right this moment. "/spaces week" displays bookings in the next 7 days. "/spaces dd/mm/yy" displays bookings on the given date. "/spaces dd/mm/yy dd/mm/yy" displays bookings in the given interval (limited to one month++). "/spaces help" informs the user of available commands. Extra arguments are ignored. Unparseable commands return the help menu.
func (*Cinnabot) Subscribe ¶
func (cb *Cinnabot) Subscribe(msg *message)
Subscribe subscribes the user to a broadcast channel [trial]
func (*Cinnabot) USCFeedback ¶
func (cb *Cinnabot) USCFeedback(msg *message)
func (*Cinnabot) Unsubscribe ¶
func (cb *Cinnabot) Unsubscribe(msg *message)
Unsubscribe unsubscribes the user from a broadcast channel [trial]
type Event ¶
type Event struct {
Type string `json:"__type"`
ID float64 `json:"id"`
Title string `json:"title"`
Start string `json:"start"`
End string `json:"end"`
AllDay bool `json:"allDay"`
Color string `json:"colour"`
}
An Event is a single booking of a location.
type EventPredicate ¶
EventPredicate is a predicate function for use with Restrict.
type ForecastData ¶
type ForecastData struct {
FMD []ForecastMetadata `json:"forecasts"`
}
type ForecastMetadata ¶
type FuncMap ¶
type FuncMap map[string]ResponseFunc
A FuncMap is a map of command strings to response functions. It is used for routing commands to responses.
type Response ¶
type Response struct {
Result ServiceResult `json:"ShuttleServiceResult"`
}
NUSBusTimes structs for unmarshalling
type ServiceResult ¶
type ServiceResult struct {
Shuttles []Shuttle `json:"shuttles"`
}
type Space ¶
type Space []Event
Space stores a set of Events, all belonging to the same location ("Space"), such as TR1 or CTPH.
type Spaces ¶
type Spaces []Space
func (Spaces) Restrict ¶
func (spaces Spaces) Restrict(predicate EventPredicate) Spaces
Restrict returns a new Spaces object containing all events in the original Spaces for which predicate returns true.
type WeatherForecast ¶
type WeatherForecast struct {
AM []AreaMetadata `json:"area_metadata"`
FD []ForecastData `json:"items"`
}
Structs for weather forecast function