Skip to content

Commit

Permalink
Merge branch 'release/3.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
j4rv committed Apr 12, 2024
2 parents ea4f489 + de46408 commit 4883b2b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/jarvbot/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func onMessageCreated(ctx context.Context) func(ds *discordgo.Session, mc *disco
// the command key must be lowercased
var commands = map[string]command{
// public
"!version": simpleTextResponse("v3.5.0"),
"!version": simpleTextResponse("v3.5.1"),
"!source": simpleTextResponse("Source code: https://github.com/j4rv/discord-bot"),
"!genshindailycheckin": answerGenshinDailyCheckIn,
"!genshindailycheckinstop": answerGenshinDailyCheckInStop,
Expand Down
4 changes: 3 additions & 1 deletion cmd/jarvbot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var warnMessageMinLength = 1
var warnMessageMaxLength = 320

const avatarTargetSize = "1024"
const maxMessageCount = 25
const maxMessageCount = 40

// https://discord.com/branding
const colorYellow = 0xFEE75C
Expand All @@ -31,6 +31,8 @@ const timeoutDurationWhenMisfire = 8 * time.Minute
const timeoutDurationWhenNuclearCatastrophe = 2 * time.Minute

const backupCRON = "0 0 * * 1"
const cleanStateMessagesCRON = "*/10 * * * *"
const stateMessageMaxLifetime = 1 * time.Hour
const dailyCheckInReminderCRON = "CRON_TZ=Asia/Shanghai 0 0 * * *"
const dailyCheckInReminderMessage = `Remember to do the Daily Check-In!
- Genshin: https://webstatic-sea.mihoyo.com/ys/event/signin-sea/index.html?act_id=e202102251931481
Expand Down
24 changes: 24 additions & 0 deletions cmd/jarvbot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/signal"
"strings"
"syscall"
"time"

"github.com/bwmarrin/discordgo"
"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -112,6 +113,7 @@ func initCRONs(ds *discordgo.Session) {

initCron("backupCRON", backupCRON, backupCRONFunc(ds))
initCron("dailyCheckInCRON", dailyCheckInReminderCRON, dailyCheckInCRONFunc(ds))
initCron("cleanStateMessagesCRON", cleanStateMessagesCRON, cleanStateMessagesCRONFunc(ds))
initCron("parametricCRON", parametricReminderCRON, parametricCRONFunc(ds))
initCron("playStoreCRON", playStoreReminderCRON, playStoreCRONFunc(ds))
initCron("react4RolesCRON", react4RolesCRON, react4RolesCRONFunc(ds))
Expand Down Expand Up @@ -150,6 +152,28 @@ func initSlashCommands(ds *discordgo.Session) func() {
}
}

func cleanStateMessagesCRONFunc(ds *discordgo.Session) func() {
return func() {
log.Println("Doing state message cleanup")
for _, pc := range ds.State.PrivateChannels {
cleanStateMessagesInChannel(ds, pc)
}
for _, gc := range ds.State.Guilds {
for _, gc := range gc.Channels {
cleanStateMessagesInChannel(ds, gc)
}
}
}
}

func cleanStateMessagesInChannel(ds *discordgo.Session, channel *discordgo.Channel) {
for _, msg := range channel.Messages {
if msg.Timestamp.Before(time.Now().Add(-stateMessageMaxLifetime)) {
ds.State.MessageRemove(msg)
}
}
}

func diff(body, prefix string) string {
lines := strings.Split(body, "\n")
var formattedBody string
Expand Down

0 comments on commit 4883b2b

Please sign in to comment.