Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding !score command #81

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions pkg/chatbot/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,54 @@ func uptimeCmd(user *users.User) {
Say(msg)
}

func scoreCmd(user *users.User, params []string) {
log.Println(user.Username, "ran !score")
var username string
var lifetimeScore, monthlyScore float32

// check to see if an arg was provided
if len(params) == 0 {
username = user.Username
lifetimeScore = user.CurrentScore()
monthlyScore = user.CurrentMonthlyScore()
} else {
username = helpers.StripAtSign(params[0])
u := users.Find(username)

// check to see if they are in our DB
if u.ID == 0 {
Say("I don't know them, sorry!")
return
}

lifetimeScore = u.CurrentScore()
monthlyScore = u.CurrentMonthlyScore()
}

msg := "@%s has %.2f points this month"
msg = fmt.Sprintf(msg, username, monthlyScore)

// add total miles if they have been around for more than one month
if lifetimeScore > monthlyScore {
msg += " (%vmi total)."
msg = fmt.Sprintf(msg, math.Round(float64(lifetimeScore)))
} else {
msg += "."

// add helpful messages for new folks
if len(params) == 0 {
if monthlyScore < 0.2 {
msg += " You'll earn more miles the longer you watch the stream."
}
if monthlyScore == 0.0 {
msg += " (Sometimes it takes a bit for me to notice you. You should be good now!)"
}
}
}

Say(msg)
}

func milesCmd(user *users.User, params []string) {
log.Println(user.Username, "ran !miles")
var username string
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/tripbot/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ var IgnoredUsers = []string{
"casinothanks",
"clearyourbrowserhistory",
"commanderroot",
"community4smallstreamers",
"communityshowcase",
"cristianepre",
"cyclemotion",
"discord_for_streamers",
"droopdoggg",
"electricallongboard",
"eubyt",
Expand Down Expand Up @@ -91,6 +93,7 @@ var IgnoredUsers = []string{
"nightbot",
"nuclearpigeons",
"p0lizei_",
"playacted",
"prankcher",
"rladmsdb88",
"rubberslayer",
Expand All @@ -100,13 +103,15 @@ var IgnoredUsers = []string{
"slocool",
"stickypigs",
"streamlabs",
"stygian_styx",
"talkingrobble",
"taormina2600",
"teresedirty",
"teyyd",
"tripbot4000",
"twitchdetails",
"unixchat",
"utensilzinc",
"v_and_k",
"violets_tv",
"virgoproz",
Expand Down
10 changes: 10 additions & 0 deletions pkg/users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ func (u User) CurrentMonthlyMiles() float32 {
return u.GetScore(scoreboards.CurrentMilesScoreboard()) + u.sessionMiles()
}

func (u User) CurrentScore() float32 {
//TODO: update to Score (not miles)
return u.Miles + u.sessionMiles()
}

func (u User) CurrentMonthlyScore() float32 {
//TODO: update to Score (not miles)
return u.GetScore(scoreboards.CurrentMilesScoreboard()) + u.sessionMiles()
}

// User.save() will take the given user and store it in the DB
func (u User) save() {
if c.Conf.Verbose {
Expand Down