2020-05-12 12:57:42 +07:00
|
|
|
package level
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/bwmarrin/discordgo"
|
2020-05-30 12:48:22 +07:00
|
|
|
|
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/db"
|
|
|
|
"gitea.teamortix.com/chanbakjsd/Milen/util"
|
2020-05-12 12:57:42 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
var ShouldListen = true
|
|
|
|
|
|
|
|
func Event(dg *discordgo.Session, m *discordgo.MessageCreate) {
|
2020-05-31 03:05:56 +07:00
|
|
|
if !ShouldListen {
|
2020-05-30 12:48:22 +07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
prevTime := db.GetLastActive(m.Author.ID)
|
|
|
|
nextTime, err := discordgo.SnowflakeTimestamp(m.ID)
|
|
|
|
if err != nil {
|
|
|
|
util.ReportError(dg, err)
|
2020-05-12 12:57:42 +07:00
|
|
|
return
|
|
|
|
}
|
2020-05-30 12:48:22 +07:00
|
|
|
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)
|
2020-05-30 14:50:26 +07:00
|
|
|
|
|
|
|
if _, ok := ShouldCheck[m.GuildID]; !ok {
|
|
|
|
ShouldCheck[m.GuildID] = make(map[string]bool)
|
|
|
|
}
|
|
|
|
ShouldCheck[m.GuildID][m.Author.ID] = true
|
2020-05-12 12:57:42 +07:00
|
|
|
}
|