xp: Buff general messages and nerf command messages

master
Luther Wen Xu 2019-11-18 23:23:40 +07:00
parent 31af8e915d
commit a11d9c94d2
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
2 changed files with 11 additions and 4 deletions

@ -6,11 +6,13 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
) )
const generalChannelID = "645550570001924098"
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.Bot { if m.Author.Bot {
return return
} }
go incrementXP(s, m.Author.ID) go incrementXP(s, m.Author.ID, m.ChannelID == generalChannelID)
if m.Content == "pgqlevel" { if m.Content == "pgqlevel" {
handleXPRequest(s, m) handleXPRequest(s, m)

11
xp.go

@ -8,6 +8,8 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
) )
const notInGeneralNerf = 10
var lastMessage = make(map[string]time.Time) var lastMessage = make(map[string]time.Time)
var incrementMutex = sync.Mutex{} var incrementMutex = sync.Mutex{}
var levelUpRequirementCache [30]int var levelUpRequirementCache [30]int
@ -21,8 +23,11 @@ func init() {
} }
} }
func incrementXP(dg *discordgo.Session, discordID string) { func incrementXP(dg *discordgo.Session, discordID string, inGeneral bool) {
amountToIncrement := calculateIncrement(discordID) amountToIncrement := calculateIncrement(discordID)
if !inGeneral {
amountToIncrement /= notInGeneralNerf
}
tx, err := db.Begin() tx, err := db.Begin()
if err != nil { if err != nil {
@ -71,8 +76,8 @@ func calculateIncrement(discordID string) int {
} }
//Constructed on Desmos: //Constructed on Desmos:
//y=\frac{100}{\left(1+e^{-\left(\frac{x-15}{3}\right)}\right)} //y=\frac{100}{\left(1+e^{-\left(x-5\right)}\right)}
return int(100 / (1 + math.Pow(math.E, -((delta.Seconds()-15)/3)))) return int(100 / (1 + math.Pow(math.E, -(delta.Seconds()-5))))
} }
func convertXPIntoLevel(xp int) (int, int) { func convertXPIntoLevel(xp int) (int, int) {