|
|
|
@ -2,12 +2,33 @@ package level
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
|
|
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/db"
|
|
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/util"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var ShouldListen = true
|
|
|
|
|
|
|
|
|
|
func Event(dg *discordgo.Session, m *discordgo.MessageCreate) {
|
|
|
|
|
if m.Author.Bot || ShouldListen {
|
|
|
|
|
if m.Author.Bot || !ShouldListen {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prevTime := db.GetLastActive(m.Author.ID)
|
|
|
|
|
nextTime, err := discordgo.SnowflakeTimestamp(m.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
util.ReportError(dg, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
xp := int64(nextTime.Sub(prevTime).Seconds())
|
|
|
|
|
if xp > int64(len(m.Content)-3)/3 {
|
|
|
|
|
xp = int64(len(m.Content)-3) / 3
|
|
|
|
|
}
|
|
|
|
|
if xp > 10 {
|
|
|
|
|
xp = 10
|
|
|
|
|
}
|
|
|
|
|
if xp < 0 {
|
|
|
|
|
xp = 0
|
|
|
|
|
}
|
|
|
|
|
db.IncrementXP(m.Author.ID, xp, nextTime)
|
|
|
|
|
}
|
|
|
|
|