model

package
v0.0.0-...-067838b Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package model contains the structure and functions used to pass information between the computations of the bot and the driver code, in bot.go

Index

Constants

View Source
const COMMAND_MAX_LENGTH = 32

Variables

View Source
var (
	Autoreplies     []AutoReply
	Actions         []Action
	Degrees         map[string]Degree
	MemeList        []Meme
	Settings        SettingsStruct
	Teachings       map[string]Teaching
	Groups          GroupsStruct
	Timetables      map[string]Timetable
	Mantainers      []Mantainer
	Representatives map[string]Representative
)

Functions

func InitGlobals

func InitGlobals()

func ParseDegrees

func ParseDegrees() (degrees map[string]Degree, err error)

func ParseRepresentatives

func ParseRepresentatives() (map[string]Representative, error)

func ParseTeachings

func ParseTeachings() (teachings map[string]Teaching, err error)

func ParseTimetables

func ParseTimetables() (timetables map[string]Timetable, err error)

func SaveGroups

func SaveGroups(groups GroupsStruct) error

Types

type Action

type Action struct {
	Name string
	Type string        `json:"type"`
	Data DataInterface `json:"data"`
}

func GetActionFromType

func GetActionFromType(name string, commandType string) Action

GetActionFromType returns an Action struct with the right DataInterface, inferred from the commandType string

func ParseActions

func ParseActions() (actions []Action, err error)

func ParseActionsBytes

func ParseActionsBytes(reader io.Reader) (actions []Action, err error)

type AutoReply

type AutoReply struct {
	Text     string `json:"text"`
	IsStrict bool   `json:"strict"`
	Reply    string `json:"reply"`
}

func ParseAutoReplies

func ParseAutoReplies() (autoReplies []AutoReply, err error)

type CommandResponse

type CommandResponse struct {
	Text        string
	NextCommand string
	Rows        tgbotapi.InlineKeyboardMarkup
}

CommandResponse is returned by the command handler, it contains information about the command computation.

func (CommandResponse) HasNextCommand

func (r CommandResponse) HasNextCommand() bool

HasNextCommand returns true if the CommandResponse has some nextCommand

func (CommandResponse) HasRows

func (r CommandResponse) HasRows() bool

HasButtonRows returns true if the CommandResponse has some rows

func (CommandResponse) HasText

func (r CommandResponse) HasText() bool

HasText returns true if the CommandResponse has some text

func (CommandResponse) IsEmpty

func (r CommandResponse) IsEmpty() bool

IsEmpty returns true if the CommandResponse has no text and no nextCommand

type Curriculum

type Curriculum struct {
	Name     string `json:"name"`
	Callback string `json:"callback"`
}

type DataInterface

type DataInterface interface {
	HandleBotCommand(bot *tgbotapi.BotAPI, message *tgbotapi.Message) CommandResponse
	HandleBotCallback(bot *tgbotapi.BotAPI, update *tgbotapi.Update, callback_text string)
	GetDescription() string
}

type Degree

type Degree struct {
	Id    string `json:"id"`
	Name  string `json:"name"`
	Icon  string `json:"icon"`
	Years []Year `json:"years"`
	Chat  string `json:"chat"`
}

type GroupsStruct

type GroupsStruct = map[int64][]int64

SECTION GLOBAL JSON STRUCTS

func ParseOrCreateGroups

func ParseOrCreateGroups() (GroupsStruct, error)

type HelpData

type HelpData struct {
	Description string `json:"description"`
	Slashes     bool   `json:"slashes"`
}

func (HelpData) GetDescription

func (d HelpData) GetDescription() string

func (HelpData) HandleBotCallback

func (_ HelpData) HandleBotCallback(_bot *tgbotapi.BotAPI, _update *tgbotapi.Update, _callback_text string)

func (HelpData) HandleBotCommand

func (data HelpData) HandleBotCommand(*tgbotapi.BotAPI, *tgbotapi.Message) CommandResponse

type InlineKeyboardRows

type InlineKeyboardRows [][]tgbotapi.InlineKeyboardButton

func ChooseTimetableDay

func ChooseTimetableDay(callback_text string) InlineKeyboardRows

Returns buttons which permits to choose the day for the timetable

func GetLectureYears

func GetLectureYears(callback_text string, course string) InlineKeyboardRows

Returns a group of buttons rows for the available years of a `course`

func GetTimetableCoursesRows

func GetTimetableCoursesRows(timetables *map[string]Timetable) InlineKeyboardRows

Returns a group of button rows for a selected groups on `timetables`

type InvalidData

type InvalidData struct{}

func (InvalidData) GetDescription

func (d InvalidData) GetDescription() string

func (InvalidData) HandleBotCallback

func (_ InvalidData) HandleBotCallback(_bot *tgbotapi.BotAPI, _update *tgbotapi.Update, _callback_text string)

func (InvalidData) HandleBotCommand

func (data InvalidData) HandleBotCommand(*tgbotapi.BotAPI, *tgbotapi.Message) CommandResponse

type IssueData

type IssueData struct {
	Description string `json:"description"`
	Response    string `json:"response"`
	Fallback    string `json:"fallback"`
}

func (IssueData) GetDescription

func (d IssueData) GetDescription() string

func (IssueData) HandleBotCallback

func (_ IssueData) HandleBotCallback(_bot *tgbotapi.BotAPI, _update *tgbotapi.Update, _callback_text string)

func (IssueData) HandleBotCommand

func (data IssueData) HandleBotCommand(bot *tgbotapi.BotAPI, message *tgbotapi.Message) CommandResponse

type Lectures

type Lectures struct {
	Description  string `json:"description"`
	Title        string `json:"title"`
	FallbackText string `json:"fallbackText"`
}

func (Lectures) GetDescription

func (d Lectures) GetDescription() string

func (Lectures) HandleBotCallback

func (data Lectures) HandleBotCallback(bot *tgbotapi.BotAPI, update *tgbotapi.Update, callback_text string)

Handle the callback for the lectures command (`/lezioni`) Parse the `callback_text` to check which operation it must to do: - If the string ends with "_today" or "_tomorrow" it returns the timetable - If the string just contains a "_y_<number>" it asks for today or tomorrow - Otherwise prints the course year of what timetable the user wants to see

func (Lectures) HandleBotCommand

func (data Lectures) HandleBotCommand(_ *tgbotapi.BotAPI, message *tgbotapi.Message) CommandResponse

type ListData

type ListData struct {
	Description string     `json:"description"`
	Header      string     `json:"header"`
	Template    string     `json:"template"`
	Items       [][]string `json:"items"`
}

func (ListData) GetDescription

func (d ListData) GetDescription() string

func (ListData) HandleBotCallback

func (_ ListData) HandleBotCallback(_bot *tgbotapi.BotAPI, _update *tgbotapi.Update, _callback_text string)

func (ListData) HandleBotCommand

func (data ListData) HandleBotCommand(*tgbotapi.BotAPI, *tgbotapi.Message) CommandResponse

type LookingForData

type LookingForData struct {
	Description  string `json:"description"`
	SingularText string `json:"singularText"`
	PluralText   string `json:"pluralText"`
	ChatError    string `json:"chatError"`
}

func (LookingForData) GetDescription

func (d LookingForData) GetDescription() string

func (LookingForData) HandleBotCallback

func (_ LookingForData) HandleBotCallback(_bot *tgbotapi.BotAPI, _update *tgbotapi.Update, _callback_text string)

func (LookingForData) HandleBotCommand

func (data LookingForData) HandleBotCommand(bot *tgbotapi.BotAPI, message *tgbotapi.Message) CommandResponse

type LuckData

type LuckData struct {
	Description     string `json:"description"`
	NoLuckGroupText string `json:"noLuckGroupText"`
}

func (LuckData) GetDescription

func (d LuckData) GetDescription() string

func (LuckData) HandleBotCallback

func (_ LuckData) HandleBotCallback(_bot *tgbotapi.BotAPI, _update *tgbotapi.Update, _callback_text string)

func (LuckData) HandleBotCommand

func (data LuckData) HandleBotCommand(_ *tgbotapi.BotAPI, message *tgbotapi.Message) CommandResponse

type Mantainer

type Mantainer struct {
	Id       int64  `json:"id"`
	Username string `json:"username"`
}

func ParseMantainers

func ParseMantainers() (mantainer []Mantainer, err error)

type Meme

type Meme struct {
	Name string
	Text string
}

func ParseMemeList

func ParseMemeList() (memes []Meme, err error)

type MessageData

type MessageData struct {
	Text        string `json:"text"`
	Description string `json:"description"`
}

SECTION ACTION STRUCTS DATA

func (MessageData) GetDescription

func (d MessageData) GetDescription() string

func (MessageData) HandleBotCallback

func (_ MessageData) HandleBotCallback(_bot *tgbotapi.BotAPI, _update *tgbotapi.Update, _callback_text string)

func (MessageData) HandleBotCommand

func (data MessageData) HandleBotCommand(*tgbotapi.BotAPI, *tgbotapi.Message) CommandResponse

type NotLookingForData

type NotLookingForData struct {
	Description   string `json:"description"`
	Text          string `json:"text"`
	ChatError     string `json:"chatError"`
	NotFoundError string `json:"notFoundError"`
}

func (NotLookingForData) GetDescription

func (d NotLookingForData) GetDescription() string

func (NotLookingForData) HandleBotCallback

func (_ NotLookingForData) HandleBotCallback(_bot *tgbotapi.BotAPI, _update *tgbotapi.Update, _callback_text string)

func (NotLookingForData) HandleBotCommand

func (data NotLookingForData) HandleBotCommand(_ *tgbotapi.BotAPI, message *tgbotapi.Message) CommandResponse

type Representative

type Representative struct {
	Course          string   `json:"course"`
	Representatives []string `json:"representatives"`
}

type RepresentativesData

type RepresentativesData struct {
	Description  string `json:"description"`
	Title        string `json:"title"`
	FallbackText string `json:"fallbackText"`
}

func (RepresentativesData) GetDescription

func (d RepresentativesData) GetDescription() string

func (RepresentativesData) HandleBotCallback

func (data RepresentativesData) HandleBotCallback(bot *tgbotapi.BotAPI, update *tgbotapi.Update, callback_text string)

func (RepresentativesData) HandleBotCommand

func (data RepresentativesData) HandleBotCommand(_ *tgbotapi.BotAPI,
	message *tgbotapi.Message) CommandResponse

type SettingsStruct

type SettingsStruct struct {
	MainGroupsIdentifiers []string `json:"mainGroupsIdentifiers"`
}

func ParseSettings

func ParseSettings() (settings SettingsStruct, err error)

type Teaching

type Teaching struct {
	Name       string   `json:"name"`
	Url        string   `json:"url"`
	Chat       string   `json:"chat"`
	Website    string   `json:"website"`
	Professors []string `json:"professors"`
}

type Timetable

type Timetable struct {
	Course       string `json:"course"`    // Course title
	Name         string `json:"name"`      // Course name
	Type         string `json:"type"`      // Type (laurea|magistrale|2cycle)
	Curriculum   string `json:"curricula"` // Curriculum
	Title        string `json:"title"`
	FallbackText string `json:"fallbackText"`
}

Recognized by a callback string

type Year

type Year struct {
	Year      int64            `json:"year"`
	Chat      string           `json:"chat"`
	Teachings YearStudyDiagram `json:"teachings"`
}

type YearStudyDiagram

type YearStudyDiagram struct {
	Mandatory []string `json:"mandatory"`
	Electives []string `json:"electives"`
}

Jump to

Keyboard shortcuts

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