bot

package
v0.0.0-...-d677359 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Commands that the user will use to interact with the bot
	ENTRYPOINT = "./watchlist"

	ADD_COMMAND     = "add"     // Add entry to watchlist
	DELETE_COMMAND  = "delete"  // Delete item from watchlist
	VIEW_COMMAND    = "view"    // View watchlist
	UPDATE_COMMAND  = "update"  // Update the link for an entry
	DONE_COMMAND    = "done"    // Mark entry as complete
	RATE_COMMAND    = "rate"    // Rate an entry
	RANDOM_COMMAND  = "random"  // Get a random movie from watchlist
	CONTACT_COMMAND = "contact" // Get contact info for the developer
	HELP_COMMAND    = "help"    // Display help message

)

Variables

View Source
var REGEX_PATTERN = regexp.MustCompile(`("[^"]+"|\S+)`)

Matches words and quoted strings (ex. Godfather, "The Godfather")

"[^"]+"     matches 1+ substrings inside quotes
\S+         matches 1+ substrings separated by whitespaces

Functions

func DeleteEntry

func DeleteEntry(db *sql.DB, userID string, title string, category Category) error

Delete an entry from the database

Params:

db:		ptr to sqlite3 database connection
userID:	user ID of the entry

func DoneEntry

func DoneEntry(db *sql.DB, userID string, title string, category Category) error

Mark an entry as completed in the database

Params:

db:			ptr to sqlite3 database connection
userID:		user ID of the entry
title:		title of the entry
category:	category of the entry

Returns:

error:	error object

func MasterHandler

func MasterHandler(db *sql.DB, s *discordgo.Session, m *discordgo.MessageCreate)

Main handler for the bot that will delegate to private handlers based on user input

All handler functions require use the following parameters:

  • db: ptr to database connection (not required for help and contact handlers)
  • s: ptr to discord session (contains methods for websocket communication)
  • m: ptr to discord message (contains info about author, channel, etc.)

func RateEntry

func RateEntry(db *sql.DB, userID string, title string, category Category, rating int) error

Rate an entry in the database

Params:

db:			ptr to sqlite3 database connection
userID:		user ID of the entry
title:		title of the entry
category:	category of the entry
rating:		rating to update the entry with

Returns:

error:	error object

func UpdateEntry

func UpdateEntry(db *sql.DB, userID string, title string, category Category, newLink string) error

Updates the link for an entry in the database

Params:

db:			ptr to sqlite3 database connection
userID:		user ID of the entry
title:		title of the entry
category:	category of the entry
newLink:	new link to update the entry with

Returns:

error:	error object

Types

type Category

type Category string

Category represents the type of item in the watchlist

const (
	Movie Category = "movie"
	Show  Category = "show"
	Anime Category = "anime"
)

func (*Category) IsValid

func (c *Category) IsValid() error

Validator for category struct

type Entry

type Entry struct {
	UserID   string    `json:"user_id"`
	Date     time.Time `json:"date"`
	Title    string    `json:"title"`
	Category Category  `json:"category"`
	Done     bool      `json:"done"`
	Rating   int       `json:"rating"`
	Link     string    `json:"link"`
}

Entry represents a single entry in the watchlist

func (*Entry) Add

func (e *Entry) Add(db *sql.DB) error

Adds an entry to the database

func (*Entry) IsValid

func (e *Entry) IsValid() error

Validator for entry struct

func (*Entry) String

func (e *Entry) String() string

Stringer for entry struct

type EntryNotFoundError

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

func (*EntryNotFoundError) Error

func (e *EntryNotFoundError) Error() string

type InvalidCategoryError

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

func (*InvalidCategoryError) Error

func (e *InvalidCategoryError) Error() string

type InvalidSortByError

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

func (*InvalidSortByError) Error

func (e *InvalidSortByError) Error() string

type InvalidTimestampError

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

func (*InvalidTimestampError) Error

func (e *InvalidTimestampError) Error() string

type InvalidTitleError

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

func (*InvalidTitleError) Error

func (e *InvalidTitleError) Error() string

type InvalidUserIDError

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

func (*InvalidUserIDError) Error

func (e *InvalidUserIDError) Error() string

type NotEnoughArgumentsError

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

func (*NotEnoughArgumentsError) Error

func (e *NotEnoughArgumentsError) Error() string

type SortBy

type SortBy string
const (
	// Enumerations for sorting the watchlist with the view command
	SORT_TITLE    SortBy = "title"
	SORT_DATE     SortBy = "date"
	SORT_CATEGORY SortBy = "category"
)

func (*SortBy) IsValid

func (s *SortBy) IsValid() error

enum validation

type Watchlist

type Watchlist struct {
	UserID  string   `json:"user_id"`
	Entries []*Entry `json:"entries"`
}

func FetchWatchlist

func FetchWatchlist(db *sql.DB, userID string, watched bool) (*Watchlist, error)

Fetch watchlist from the database if it exists

Params:

db: 		ptr to sqlite3 database connection
userID: 	user ID we are searching for entries for
watched:	true if we want all entries, false if we want only unwatched entries

Returns:

*Watchlist: 	ptr to watchlist object
error:			error object

func (*Watchlist) Sort

func (w *Watchlist) Sort(sort_by SortBy)

Sort the watchlist by the provided sort_by option

Params:

sort_by: 	sort_by option (one of SORT_TITLE, SORT_DATE, SORT_CATEGORY)

func (*Watchlist) String

func (w *Watchlist) String() string

stringer method

Jump to

Keyboard shortcuts

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