Documentation
¶
Index ¶
- Constants
- type Entry
- type EntryDB
- type EntryService
- type Event
- type EventData
- type EventService
- type Offers
- type QueueUser
- type Rep
- type RepDB
- type RepService
- type Services
- type ServicesConfig
- type Trade
- type TradeData
- type TradeOfferer
- type TradeService
- type Trades
- type User
- type UserData
- type UserService
Constants ¶
const ( // MaxQueue limits the amount of queues a user can join MaxQueue int = 3 // MaxEvent limits the amount of events a user can create MaxEvent int = 1 // MaxTrade limits the amount of trades a user can create MaxTrade int = 5 )
const ( // ErrDiscordIDRequired is an internal error raised when // no discord ID was given (primary key) ErrDiscordIDRequired string = "need discord user ID" )
const (
// ErrNotFound is returned when a record isn't found in the Entry database
ErrNotFound = "models: entry not found"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct { Name string `gorm:"not null"` SellPrice int `gorm:"column:sell_price"` NorthSt string `gorm:"type:varchar(255);column:north_start"` NorthEnd string `gorm:"type:varchar(255);column:north_end"` NorthMonths string `gorm:"type:varchar(255);column:north_hemi_months"` SouthSt string `gorm:"type:varchar(255);column:south_start"` SouthEnd string `gorm:"type:varchar(255);column:south_end"` SouthMonths string `gorm:"type:varchar(255);column:south_hemi_months"` Time string `gorm:"type:varchar(255);column:time_of_day"` Location string `gorm:"type:varchar(255);column:location"` Image string `gorm:"type:varchar(255);column:image"` Type string `gorm:"type:varchar(255);column:type"` }
Entry represents a database entry of either an insect or fish in the postgres database
type EntryDB ¶
type EntryDB interface { ByName(name, tableName string) (*Entry, error) ByMonth(colName, month, entryType string) []Entry FindLike(name, tableName string) []Entry }
EntryDB is used to interact with data entry database
If the entry is found, we will return the entry and nil error ¶
If the entry is not found, we will return ErrNotFound ¶
Lastly, we will return any other errors not generated by this package
type EntryService ¶
type EntryService interface { EntryDB }
EntryService handles interactions with the bug and fish (Entry) database
func NewEntryService ¶
func NewEntryService(db *gorm.DB) EntryService
NewEntryService creates a new service to data entry database
type Event ¶
type Event interface { // AddEvent creates a new event on the server AddEvent(User *discordgo.User, MsgID string, limit int) // EventExists will check if a requested event exists currently EventExists(msgID string) bool // AddToQueue will add another user to the queue who registers as long as the // queue is not full AddToQueue(UserID *discordgo.User, eventID string) (*discordgo.User, error) // GetQueue will return the current queue line GetQueue(eventID string) *[]QueueUser // Close will remove a event listing from the map Close(eventID, role string, user *discordgo.User, roles []string) error // Clean will remove event listings from the map that have exceeded time limit // // DO NOT CALL THIS RANDOMLY!! // // This should only be called in the goroutine in main (ticker to check expiration) Clean() // Remove will remove a queue individual from event based on Event ID Remove(eventID string, user *discordgo.User) // GetHost returns the original host of the event GetHost(eventID string) *discordgo.User // GetExpiration returns the expiration time of a particular event GetExpiration(eventID string) time.Time }
Event represents all methods we can use to interact with Event type data
type EventData ¶
type EventData struct { DiscordUser *discordgo.User Limit int Queue []QueueUser Expiration time.Time }
EventData represents an event a user has created
type EventService ¶
type EventService interface { Event }
EventService is a layer of abstraction leading to the Event interface
func NewEventService ¶
func NewEventService() EventService
NewEventService creates a new Event service
type Offers ¶
type Offers struct {
// contains filtered or unexported fields
}
Offers defines offer tracking to a trade
type Rep ¶
type Rep struct { gorm.Model // Unique Discord ID DiscordID string `gorm:"not_null;unique_index"` // Number of reps stored in database RepNum int `gorm:"not_null"` }
Rep defines the postgres SQL table model using GORM
type RepDB ¶
type RepDB interface { // AddRep adds a repID linked with a user ID to be repped // into a temp map AddRep(userID, repID string) // Clean will delete a repID event from the tmp map Clean(repID string) // Create inserts a new rep value into the database Create(rep *Rep) error // Exists will check if an user is in the database Exists(userID string) bool // GetRep returns the rep number of an individual GetRep(userID string) int // RepIDExists returns true if a given RepID event exists in // tmp map RepIDExists(repID string) bool // GetUser will return the userID behind the repID event // saved in tmp map GetUser(repID string) string // Increase will increase the rep number in the database for a given // user by one Increase(userID string) error }
RepDB contains all methods we can use to interact with rep database
type RepService ¶
type RepService interface { RepDB }
RepService wraps to RepDB
func NewRepService ¶
func NewRepService(db *gorm.DB) RepService
NewRepService creates the rep service object
type Services ¶
type Services struct { // Gateway to EntryService methods Entry EntryService // Gateway to EventService methods Event EventService // Gateway to UserService methods User UserService // Gateway to RepService methods Rep RepService // Gateway to TradeService methods Trade TradeService // contains filtered or unexported fields }
Services handles services for bot
func NewServices ¶
func NewServices(cfgs ...ServicesConfig) (*Services, error)
NewServices initializes the configuration for every service
func (Services) AutoMigrate ¶
AutoMigrate attempts to automigrate sql tables
type ServicesConfig ¶
ServicesConfig represents functions that are meant to be running configurations for services
func WithEvents ¶
func WithEvents() ServicesConfig
WithEvents will initialize an events server 'database'
func WithGorm ¶
func WithGorm(dialect, connectionInfo string) ServicesConfig
WithGorm opens a database connection using the Gorm package and sets the database
func WithLogMode ¶
func WithLogMode(mode bool) ServicesConfig
WithLogMode makes sure that every database interaction in logged whether for debugging or other logging purposes
type Trade ¶
type Trade interface { // GetOffer retrieves a trade offer (string) by tradeID and userID GetOffer(tradeID, userID string) string // Clean will remove an expired item from the map Clean() // GetExpiration returns the expiration time of the trade event GetExpiration(tradeID string) time.Time // AddOffer will track an offer to a tradeID // // This func will return an err if the user is already in trade, else nil AddOffer(tradeID, offer string, user *discordgo.User) error // AddTrade will add a new trade event to tracking AddTrade(tradeID string, user *discordgo.User) // Exists returns true if an event with the trade ID exists Exists(tradeID string) bool // GetHost returns the creator of the trade GetHost(tradeID string) *discordgo.User // Close will close a trade event. If the user does not have permission to close the event, the func // will return an error Close(tradeID string, user *discordgo.User, userRoles []string, adminID string) error // Remove removes a user's offer from a tradeID Remove(tradeID string, user *discordgo.User) // GetAllOffers will return a slice of all trade offers associated with the tradeID GetAllOffers(tradeID string) []TradeOfferer }
Trade contains all the methods we can use to interact with trade data
type TradeData ¶
type TradeData struct { // User info of trade host DiscordUser *discordgo.User // time the trade event will expire Expiration time.Time // slice of offer related data associated with tradeID Offers []TradeOfferer }
TradeData represents all data needed to keep track of a trade event
type TradeOfferer ¶
type TradeOfferer struct { // User contains the discord user info of user offering to a trade User *discordgo.User // What the user is offering in string format Offer string }
TradeOfferer defines someone offering a response to a trade
type TradeService ¶
type TradeService interface { Trade }
TradeService wraps to the Trade interface
func NewTradeService ¶
func NewTradeService() TradeService
NewTradeService initializes a new Trade Service
type Trades ¶
type Trades struct {
// contains filtered or unexported fields
}
Trades defines a trade event
type User ¶
type User interface { // AddOffer adds an offer to user tracking when user offers can item to a trade event AddOffer(tradeID string, user *discordgo.User, expire time.Time) // RemoveOffer removes an offer from user tracking after user // unregisters from trade event RemoveOffer(tradeID string, user *discordgo.User) // AddTrade will add a trade event to user tracking AddTrade(user *discordgo.User, tradeID string, expire time.Time) // UserExists returns a bool indicating if the requested user is // already in server tracking or not UserExists(user *discordgo.User) bool // AddUser will add a new user to the map along with initialized slices // for events and queues tracking AddUser(user *discordgo.User) error // AddEvent adds a new event to the user tracking events AddEvent(user *discordgo.User, eventID string, expire time.Time) // LimitEvent returns true if the user has an event list equal to the max event // // In otherwords, if this is true, the user should not be able to // make more events LimitEvent(user *discordgo.User) bool // RemoveEvent removes an event from a user's tracking state RemoveEvent(user *discordgo.User, eventID string) // Clean will remove event listings from tracking that have exceeded time limit // // DO NOT CALL THIS RANDOMLY!! // // This should only be called in the goroutine in main (ticker to check expiration) Clean() // AddQueue adds an item to the queue AddQueue(eventID string, user *discordgo.User, expire time.Time) // LimitQueue returns true when user hit max queue amount // // Otherwise, it return false LimitQueue(user *discordgo.User) bool // RemoveQueue will remove an item from the queue slice RemoveQueue(eventID string, user *discordgo.User) // RemoveAllQueue will remove all events with a certain eventID from all users RemoveAllQueue(eventID string) // LimitTrade returns true when the user has reached // the max amount of trade creation LimitTrade(userID string) bool // RemoveTrade removes a trade event from tracking RemoveTrade(tradeID string, user *discordgo.User) }
User defines all the methods we can use to interact with the User Service
type UserData ¶
type UserData struct {
// contains filtered or unexported fields
}
UserData represents user data bot needs to keep track of in order to perform event and queue services
type UserService ¶
type UserService interface { User }
UserService wraps to the User interface
func NewUserService ¶
func NewUserService() UserService
NewUserService initializes a new user service