Documentation
¶
Index ¶
- Variables
- func Connect()
- func InitializeNewUser(userID string)
- func PopulateDatabase()
- type Daily
- type Debug
- type Farm
- func (f *Farm) BeforeCreate(tx *gorm.DB) error
- func (f *Farm) CalcFarmPlotPrice() int
- func (f *Farm) CanHarvest() bool
- func (f *Farm) CanWater() bool
- func (f *Farm) CanWaterAt() string
- func (f *Farm) CreateEmbedDescription() string
- func (f *Farm) CreateEmbedFields() []*discordgo.MessageEmbedField
- func (f *Farm) CreateFarmOverview(msg *discordgo.MessageSend, m *discordgo.MessageCreate, user *User)
- func (f *Farm) CropsPerishedCheck() []string
- func (f *Farm) DeletePlot(plot *FarmPlot)
- func (f *Farm) GetUnusedPlots() int
- func (f *Farm) HarvestPlots() []harvestResult
- func (f *Farm) HasFreePlot() bool
- func (f *Farm) HasMaxAmountOfPlots() bool
- func (f *Farm) HasPlantedPlots() bool
- func (f *Farm) HasUserUnlocked(fc *FarmCrop) bool
- func (f *Farm) MissedWaterDeadline() bool
- func (f *Farm) Peek() bool
- func (f *Farm) QueryFarmPlots()
- func (f *Farm) QueryUserFarmData(u *User)
- func (f *Farm) ResetLastWatered()
- func (f *Farm) Save()
- func (f *Farm) SuccessfulHarvest() bool
- func (Farm) TableName() string
- func (f *Farm) UpdateInteractionOverview(discordUser *discordgo.User, me *discordgo.MessageEdit)
- func (f *Farm) WaterPlots()
- type FarmCrop
- type FarmPlot
- func (fp *FarmPlot) AfterCreate(tx *gorm.DB) error
- func (fp *FarmPlot) BeforeCreate(tx *gorm.DB) error
- func (fp *FarmPlot) DeleteFromDB()
- func (fp *FarmPlot) HarvestableAt() string
- func (fp *FarmPlot) HasFullyGrown() bool
- func (fp *FarmPlot) HasPerished() bool
- func (fp *FarmPlot) Perish()
- func (fp *FarmPlot) QueryCropInfo()
- func (fp *FarmPlot) Save()
- func (FarmPlot) TableName() string
- func (fp *FarmPlot) Water()
- type Model
- type User
- func (u *User) AddMoney(amount uint64)
- func (u *User) AfterCreate(tx *gorm.DB) error
- func (u *User) CanAfford(number uint64) bool
- func (u *User) CreateProfileComponents(work *Work, daily *Daily) []discordgo.MessageComponent
- func (u *User) CreateProfileEmbeds(du *discordgo.User, work *Work, daily *Daily, ...)
- func (u *User) DeductMoney(amount uint64)
- func (u *User) DoesUserExist(discordID string) bool
- func (u *User) PrettyPrintLifetimeEarnings() string
- func (u *User) PrettyPrintMoney() string
- func (u *User) QueryUserByDiscordID(discordID string)
- func (u *User) Save()
- func (User) TableName() string
- type Work
- func (w *Work) AfterCreate(tx *gorm.DB) error
- func (w *Work) CalcBuyToolPrice() (int, string)
- func (w *Work) CanDoWork() bool
- func (w *Work) CanDoWorkAt() string
- func (w *Work) CreateMessageComponents() []discordgo.MessageComponent
- func (w *Work) GetWorkInfo(u *User)
- func (w *Work) HasHitMaxToolLimit() bool
- func (w *Work) Save()
- func (w *Work) StreakPostMsgAction()
- func (w *Work) StreakPreMsgAction()
- func (Work) TableName() string
- type YoutubeCache
- func (c *YoutubeCache) Cache(videoID, title, thumbnail, channelName string, duration time.Duration)
- func (c *YoutubeCache) Check(videoID string, title, thumbnail, channelName, streamURL *string, ...) bool
- func (c *YoutubeCache) Save()
- func (YoutubeCache) TableName() string
- func (c *YoutubeCache) UpdateStreamURL(videoID, streamURL string) error
Constants ¶
This section is empty.
Variables ¶
var DB *gorm.DB
Functions ¶
func InitializeNewUser ¶
func InitializeNewUser(userID string)
func PopulateDatabase ¶
func PopulateDatabase()
Types ¶
type Daily ¶
func (*Daily) CanDoDaily ¶
CanDoDaily - Checks if the user can do their daily again Returns true if the user can do their daily and false if they cant
func (*Daily) CanDoDailyAt ¶
Returns the time the user can do their daily next as a formatted discord string https://hammertime.cyou/
func (*Daily) DoDaily ¶
Does the daily Returns If the daily could be executed The money earned as a pretty string Streak reward value Percentage of streak completed Title for the message Footer for the message
func (*Daily) GetDailyInfo ¶
Queries the database for the daily data with the given user object.
type Farm ¶
type Farm struct { Model Plots []*FarmPlot OwnedPlots uint8 LastWateredAt time.Time // Last time the user watered the farm plots HighestPlantedCropIndex uint8 PlotsChanged bool `gorm:"-"` // Ignored by the database HarvestEarnings int `gorm:"-"` // If 0 then no earnings }
func (*Farm) BeforeCreate ¶
Only triggers on DB.Create(...)
func (*Farm) CalcFarmPlotPrice ¶
Returns the cost of what buying a new plot would cost for the user
func (*Farm) CanHarvest ¶
Returns true if the user can harvest any of their crops
func (*Farm) CanWaterAt ¶
Returns the time the user can water their crops as a formatted discord string https://hammertime.cyou/
func (*Farm) CreateEmbedDescription ¶
func (*Farm) CreateEmbedFields ¶
func (f *Farm) CreateEmbedFields() []*discordgo.MessageEmbedField
func (*Farm) CreateFarmOverview ¶
func (f *Farm) CreateFarmOverview(msg *discordgo.MessageSend, m *discordgo.MessageCreate, user *User)
CreateFarmOverview creates the message that will be sent to the user
func (*Farm) CropsPerishedCheck ¶
Will return the amount of crops that have perished from plots Will also remove perished crop plots from the database Remember to have call GetFarmPlots() before calling this function
func (*Farm) DeletePlot ¶
func (*Farm) GetUnusedPlots ¶
Rember to run GetFarmPlots() before running this function
func (*Farm) HarvestPlots ¶
func (f *Farm) HarvestPlots() []harvestResult
Returns an array containing the crop object that was harvested Money earned is saved in f.HarvestEarnings. Remember to add it to the user's balance Run QueryFarmPlots() before running this function
func (*Farm) HasFreePlot ¶
Returns true if the user has a free (unused) farm plot
func (*Farm) HasMaxAmountOfPlots ¶
func (*Farm) HasPlantedPlots ¶
Returns true if anything is planted on the farm Run QueryFarmPlots() first
func (*Farm) HasUserUnlocked ¶
func (*Farm) MissedWaterDeadline ¶
func (*Farm) Peek ¶
Peek looks at the farm and updates it to reflect the current state Always run before doing anything with the farm Checks if crops have perished Returns true if any crop perished
func (*Farm) QueryFarmPlots ¶
func (f *Farm) QueryFarmPlots()
Updates the object to contain all the farmplots
func (*Farm) QueryUserFarmData ¶
Queries the database for the farm data with the given user object. Needs to be called first
func (*Farm) ResetLastWatered ¶
func (f *Farm) ResetLastWatered()
ResetLastWatered updates last watered to so that the user can water their plats again
func (*Farm) SuccessfulHarvest ¶
func (*Farm) UpdateInteractionOverview ¶
func (f *Farm) UpdateInteractionOverview(discordUser *discordgo.User, me *discordgo.MessageEdit)
func (*Farm) WaterPlots ¶
func (f *Farm) WaterPlots()
Functions waters every single plot Meaning it will update the plantedAt time Run QueryFarmPlots() before running this function
type FarmCrop ¶
type FarmCrop struct { Model Name string Emoji string DurationToGrow time.Duration HarvestReward int }
func (*FarmCrop) GetAllCrops ¶
func (*FarmCrop) GetCropByName ¶
func (*FarmCrop) GetDuration ¶
Outputs the duration in a pretty format Example: 10 days; 1 day; 16 hours; 1 hour; 20 mins Does not handle days with hours, or hours with minutes Does not handle seconds
type FarmPlot ¶
type FarmPlot struct { Model FarmID uint `gorm:"index"` Farm Farm `gorm:"references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // The farm this plot belongs to CropID int Crop FarmCrop `gorm:"references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` // The planted crop PlantedAt time.Time // When the user planted the crop Perished bool // Perished crops wont yeild any money }
func (*FarmPlot) AfterCreate ¶
Only triggers on DB.Create(...)
func (*FarmPlot) BeforeCreate ¶
Only triggers on DB.Create(...)
func (*FarmPlot) DeleteFromDB ¶
func (fp *FarmPlot) DeleteFromDB()
Removes the entry from the database
func (*FarmPlot) HarvestableAt ¶
Returns a discord formatted string showing when the crop will be harvestable
func (*FarmPlot) HasFullyGrown ¶
Check if the crop has fully grown by comparing the duration to grow with the planted at time and the current time Call QueryCropInfo() first
func (*FarmPlot) HasPerished ¶
func (*FarmPlot) Perish ¶
func (fp *FarmPlot) Perish()
Will mark the crop as perished and save it to the database
func (*FarmPlot) QueryCropInfo ¶
func (fp *FarmPlot) QueryCropInfo()
type User ¶
type User struct { Model DiscordID string `gorm:"uniqueIndex"` Money uint64 LifetimeEarnings uint64 Work Work `gorm:"foreignKey:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` Daily Daily `gorm:"foreignKey:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` Farm Farm `gorm:"foreignKey:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` }
func (*User) CreateProfileComponents ¶
func (u *User) CreateProfileComponents(work *Work, daily *Daily) []discordgo.MessageComponent
func (*User) CreateProfileEmbeds ¶
func (*User) DeductMoney ¶
func (*User) DoesUserExist ¶
Returns true if a user with that discord ID exists in the database
func (*User) PrettyPrintLifetimeEarnings ¶
func (*User) PrettyPrintMoney ¶
func (*User) QueryUserByDiscordID ¶
Queries the database for the user with the given discord ID. The object which calls the method will be updated with the user's data
type Work ¶
type Work struct { Model LastWorkedAt time.Time ConsecutiveStreaks uint16 Streak uint16 Tools uint8 }
func (*Work) CalcBuyToolPrice ¶
Returns how much it would cost the user to buy a new tool Returns the amount as an int and formatted string
func (*Work) CanDoWork ¶
CanDoWork - Checks if the user can work again Returns true if the user can work and false if they cant
func (*Work) CanDoWorkAt ¶
Returns the time the user can work next as a formatted discord string https://hammertime.cyou/
func (*Work) CreateMessageComponents ¶
func (w *Work) CreateMessageComponents() []discordgo.MessageComponent
func (*Work) GetWorkInfo ¶
Queries the database for the work data with the given user object.
func (*Work) HasHitMaxToolLimit ¶
func (*Work) StreakPostMsgAction ¶
func (w *Work) StreakPostMsgAction()
Wrap around the streak if the streak length in the config got updated/changed
func (*Work) StreakPreMsgAction ¶
func (w *Work) StreakPreMsgAction()
StreakPreMsgAction - Checks the streak for the work object Resets it down to 0 if the user failed their streak. i.e. Waited too long since the last work If the user can work... Updates the streak for the user i.e. adding one to the counters and ensuring the streak is not over the max streak and updating the time of the last work
type YoutubeCache ¶
type YoutubeCache struct { Model VideoID string `gorm:"uniqueIndex"` Title string `gorm:"not null"` Thumbnail string `gorm:"not null"` ChannelName string `gorm:"not null"` Duration time.Duration `gorm:"not null"` URLCache string URLCacheExpiresAt time.Time }
func (*YoutubeCache) Cache ¶
func (c *YoutubeCache) Cache(videoID, title, thumbnail, channelName string, duration time.Duration)
func (*YoutubeCache) Check ¶
func (c *YoutubeCache) Check(videoID string, title, thumbnail, channelName, streamURL *string, duration *time.Duration) bool
Check checks if the videoID exists in the cache Populates the values if the video is found Returns true if it exists
func (YoutubeCache) TableName ¶
func (YoutubeCache) TableName() string
func (*YoutubeCache) UpdateStreamURL ¶
func (c *YoutubeCache) UpdateStreamURL(videoID, streamURL string) error