aboutsummaryrefslogtreecommitdiff
path: root/exp
diff options
context:
space:
mode:
authorWilliam Hergès <anhgelus.morhtuuzh@proton.me>2025-05-13 21:13:59 +0200
committerGitHub <noreply@github.com>2025-05-13 21:13:59 +0200
commit8d6af4b6aa8f4902316c7f30c5229c97b0ec1a81 (patch)
treed19607355cfa0a180d3269d78e7e2249aa3d2277 /exp
parent9e826eee980634b82d6981a868b045f3d4b48852 (diff)
parent75ca960199b85f3f4b491652c837d297827e40ce (diff)
Merge pull request #8 from anhgelus/v3
V3
Diffstat (limited to 'exp')
-rw-r--r--exp/functions.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/exp/functions.go b/exp/functions.go
new file mode 100644
index 0000000..720a755
--- /dev/null
+++ b/exp/functions.go
@@ -0,0 +1,59 @@
+package exp
+
+import (
+ "fmt"
+ "github.com/anhgelus/gokord"
+ "math"
+ "slices"
+ "time"
+)
+
+func MessageXP(length uint, diversity uint) uint {
+ return uint(math.Floor(
+ 0.025*math.Pow(float64(length), 1.25)*math.Sqrt(float64(diversity)) + 1,
+ ))
+}
+
+func CalcDiversity(msg string) uint {
+ var chars []rune
+ for _, c := range []rune(msg) {
+ if !slices.Contains(chars, c) {
+ chars = append(chars, c)
+ }
+ }
+ return uint(len(chars))
+}
+
+func VocalXP(time uint) uint {
+ return uint(math.Floor(
+ 0.01*math.Pow(float64(time), 1.3) + 1,
+ ))
+}
+
+// Level gives the level with the given XP.
+// See LevelXP to get the XP required to get a level.
+func Level(xp uint) uint {
+ return uint(math.Floor(
+ 0.2 * math.Sqrt(float64(xp)),
+ ))
+}
+
+// LevelXP gives the XP required to get this level.
+// See Level to get the level with the given XP.
+func LevelXP(level uint) uint {
+ return uint(math.Floor(
+ math.Pow(float64(5*level), 2),
+ ))
+}
+
+// TimeStampNDaysBefore returns the timestamp (year-month-day) n days before today
+func TimeStampNDaysBefore(n uint) string {
+ var y, d int
+ var m time.Month
+ if gokord.Debug {
+ y, m, d = time.Unix(time.Now().Unix()-int64(24*60*60), 0).Date() // reduce time for debug
+ } else {
+ y, m, d = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0).Date()
+ }
+ return fmt.Sprintf("%d-%d-%d", y, m, d)
+}