Skip to content

Commit

Permalink
Merge branch 'release/3.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
j4rv committed Apr 11, 2024
2 parents 6ab0197 + 069c497 commit d7b2932
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/jarvbot/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"math/rand"
"os"
"regexp"
"runtime/debug"
"sort"
Expand Down Expand Up @@ -45,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.4.0"),
"!version": simpleTextResponse("v3.4.1"),
"!source": simpleTextResponse("Source code: https://github.com/j4rv/discord-bot"),
"!genshindailycheckin": answerGenshinDailyCheckIn,
"!genshindailycheckinstop": answerGenshinDailyCheckInStop,
Expand Down Expand Up @@ -81,6 +82,7 @@ var commands = map[string]command{
"!addglobalcommand": adminOnly(answerAddGlobalCommand),
"!removeglobalcommand": adminOnly(answerRemoveGlobalCommand),
"!announce": adminOnly(answerAnnounce),
"!dbbackup": adminOnly(answerDbBackup),
"!reboot": adminOnly(answerReboot),
"!shutdown": adminOnly(answerShutdown),
"!abortshutdown": adminOnly(answerAbortShutdown),
Expand Down Expand Up @@ -313,6 +315,16 @@ func answerAnnounce(ds *discordgo.Session, mc *discordgo.MessageCreate, ctx cont
return errors == ""
}

func answerDbBackup(ds *discordgo.Session, mc *discordgo.MessageCreate, ctx context.Context) bool {
reader, err := os.Open(dbFilename)
if err != nil {
ds.ChannelMessageSend(mc.ChannelID, "Could not open database: "+err.Error())
return false
}
_, err = ds.ChannelFileSend(mc.ChannelID, dbFilename, reader)
return err == nil
}

func answerListCommands(ds *discordgo.Session, mc *discordgo.MessageCreate, ctx context.Context) bool {
keys, err := commandDS.allSimpleCommandKeys(mc.GuildID)
notifyIfErr("answerListCommands::allSimpleCommandKeys", err, ds)
Expand Down
5 changes: 5 additions & 0 deletions cmd/jarvbot/modding.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func onMessageUpdated(ctx context.Context) func(ds *discordgo.Session, mc *disco
if err != nil {
return
}
if mc.BeforeUpdate.Content == mc.Message.Content {
return
}
ds.ChannelMessageSendEmbed(
logsChannelID,
&discordgo.MessageEmbed{
Expand Down Expand Up @@ -165,5 +168,7 @@ func messageUpdatedToString(from, to *discordgo.Message) string {
}
str += diff(from.Content, "- ")
str += diff(to.Content, "+ ")
str += fmt.Sprintf("\n[Link to message](https://discord.com/channels/%s/%s/%s)",
from.GuildID, from.ChannelID, from.ID)
return str
}

0 comments on commit d7b2932

Please sign in to comment.