Compare commits
No commits in common. "bbfaaaf04b69bf74143cf6974e626ce97296edbc" and "bda9a5fa8f4af9218bd59364ad6dda2ca26ffc58" have entirely different histories.
bbfaaaf04b
...
bda9a5fa8f
5 changed files with 40 additions and 30 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -26,4 +26,3 @@ go.work
|
||||||
tmp
|
tmp
|
||||||
config/**.toml
|
config/**.toml
|
||||||
data
|
data
|
||||||
docker-compose.yml
|
|
||||||
|
|
22
docker-compose.yml
Normal file
22
docker-compose.yml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
services:
|
||||||
|
bot:
|
||||||
|
build: .
|
||||||
|
restart: always
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
volumes:
|
||||||
|
- ./config:/app/config
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
postgres:
|
||||||
|
image: postgres:alpine
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
volumes:
|
||||||
|
- ./data:/var/lib/postgresql/data
|
||||||
|
adminer:
|
||||||
|
image: docker.io/adminer
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
|
@ -2,13 +2,12 @@ package exp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/anhgelus/gokord"
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anhgelus/gokord"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func MessageXP(length uint, diversity uint) uint {
|
func MessageXP(length uint, diversity uint) uint {
|
||||||
|
@ -51,14 +50,14 @@ func LevelXP(level uint) uint {
|
||||||
|
|
||||||
// TimeStampNDaysBefore returns the timestamp (year-month-day) n days before today
|
// TimeStampNDaysBefore returns the timestamp (year-month-day) n days before today
|
||||||
func TimeStampNDaysBefore(n uint) string {
|
func TimeStampNDaysBefore(n uint) string {
|
||||||
var unix time.Time
|
var y, d int
|
||||||
|
var m time.Month
|
||||||
if gokord.Debug {
|
if gokord.Debug {
|
||||||
unix = time.Unix(time.Now().Unix()-int64(n), 0) // reduce time for debug
|
y, m, d = time.Unix(time.Now().Unix()-int64(24*60*60), 0).Date() // reduce time for debug
|
||||||
} else {
|
} else {
|
||||||
unix = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0)
|
y, m, d = time.Unix(time.Now().Unix()-int64(n*24*60*60), 0).Date()
|
||||||
}
|
}
|
||||||
unix = unix.UTC()
|
return fmt.Sprintf("%d-%d-%d", y, m, d)
|
||||||
return fmt.Sprintf("%d-%d-%d %d:%d:%d UTC", unix.Year(), unix.Month(), unix.Day(), unix.Hour(), unix.Minute(), unix.Second())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TrimMessage(s string) string {
|
func TrimMessage(s string) string {
|
||||||
|
|
17
main.go
17
main.go
|
@ -4,17 +4,16 @@ import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/anhgelus/gokord"
|
"github.com/anhgelus/gokord"
|
||||||
"github.com/anhgelus/gokord/cmd"
|
cmd "github.com/anhgelus/gokord/cmd"
|
||||||
"github.com/anhgelus/gokord/logger"
|
"github.com/anhgelus/gokord/logger"
|
||||||
"github.com/anhgelus/les-copaings-bot/commands"
|
"github.com/anhgelus/les-copaings-bot/commands"
|
||||||
"github.com/anhgelus/les-copaings-bot/config"
|
"github.com/anhgelus/les-copaings-bot/config"
|
||||||
"github.com/anhgelus/les-copaings-bot/user"
|
"github.com/anhgelus/les-copaings-bot/user"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -118,15 +117,7 @@ func main() {
|
||||||
creditsCmd,
|
creditsCmd,
|
||||||
},
|
},
|
||||||
AfterInit: func(dg *discordgo.Session) {
|
AfterInit: func(dg *discordgo.Session) {
|
||||||
d := 24 * time.Hour
|
stopPeriodicReducer = gokord.NewTimer(24*time.Hour, func(stop chan<- interface{}) {
|
||||||
if gokord.Debug {
|
|
||||||
d = 24 * time.Second
|
|
||||||
}
|
|
||||||
|
|
||||||
user.PeriodicReducer(dg)
|
|
||||||
|
|
||||||
stopPeriodicReducer = gokord.NewTimer(d, func(stop chan<- interface{}) {
|
|
||||||
logger.Debug("Periodic reducer")
|
|
||||||
user.PeriodicReducer(dg)
|
user.PeriodicReducer(dg)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"slices"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/anhgelus/gokord"
|
"github.com/anhgelus/gokord"
|
||||||
"github.com/anhgelus/gokord/logger"
|
"github.com/anhgelus/gokord/logger"
|
||||||
"github.com/anhgelus/les-copaings-bot/config"
|
"github.com/anhgelus/les-copaings-bot/config"
|
||||||
"github.com/anhgelus/les-copaings-bot/exp"
|
"github.com/anhgelus/les-copaings-bot/exp"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"slices"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func onNewLevel(dg *discordgo.Session, m *discordgo.Member, level uint) {
|
func onNewLevel(dg *discordgo.Session, m *discordgo.Member, level uint) {
|
||||||
|
@ -87,14 +86,14 @@ func PeriodicReducer(dg *discordgo.Session) {
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
cfg := config.GetGuildConfig(g.ID)
|
cfg := config.GetGuildConfig(g.ID)
|
||||||
res := gokord.DB.
|
err := gokord.DB.
|
||||||
Model(&CopaingXP{}).
|
Model(&CopaingXP{}).
|
||||||
Where("guild_id = ? and created_at < ?", g.ID, exp.TimeStampNDaysBefore(cfg.DaysXPRemains)).
|
Where("guild_id = ? and created_at < ?", g.ID, exp.TimeStampNDaysBefore(cfg.DaysXPRemains)).
|
||||||
Delete(&CopaingXP{})
|
Delete(&CopaingXP{}).
|
||||||
if res.Error != nil {
|
Error
|
||||||
logger.Alert("user/level.go - Removing old XP", res.Error.Error(), "guild_id", g.ID)
|
if err != nil {
|
||||||
|
logger.Alert("user/level.go - Removing old XP", err.Error(), "guild_id", g.ID)
|
||||||
}
|
}
|
||||||
logger.Debug("Guild cleaned", "guild", g.Name, "rows affected", res.RowsAffected)
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue