Skip to content

Commit

Permalink
core: Update Go to 1.22 and use new cmp.Or
Browse files Browse the repository at this point in the history
  • Loading branch information
Brawl345 committed May 28, 2024
1 parent 993bc87 commit c7c871c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 32 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/Brawl345/gobot

go 1.21

toolchain go1.21.5
go 1.22

require (
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.27
Expand Down
16 changes: 4 additions & 12 deletions model/sql/sql.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sql

import (
"cmp"
"database/sql"
"embed"
"fmt"
Expand All @@ -20,21 +21,12 @@ var log = logger.New("db")
var embeddedMigrations embed.FS

func New() (*sqlx.DB, error) {
host := strings.TrimSpace(os.Getenv("MYSQL_HOST"))
if host == "" {
host = "localhost"
}
port := strings.TrimSpace(os.Getenv("MYSQL_PORT"))
if port == "" {
port = "3306"
}
host := cmp.Or(strings.TrimSpace(os.Getenv("MYSQL_HOST")), "localhost")
port := cmp.Or(strings.TrimSpace(os.Getenv("MYSQL_PORT")), "3306")
user := strings.TrimSpace(os.Getenv("MYSQL_USER"))
password := strings.TrimSpace(os.Getenv("MYSQL_PASSWORD"))
dbname := strings.TrimSpace(os.Getenv("MYSQL_DB"))
tls := strings.TrimSpace(os.Getenv("MYSQL_TLS"))
if tls == "" {
tls = "false"
}
tls := cmp.Or(strings.TrimSpace(os.Getenv("MYSQL_TLS")), "false")

connectionString := fmt.Sprintf(
"%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local&tls=%s",
Expand Down
6 changes: 2 additions & 4 deletions plugin/gemini/gemini.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gemini

import (
"cmp"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -101,10 +102,7 @@ func (p *Plugin) onGemini(b *gotgbot.Bot, c plugin.GobotContext) error {
apiUrlGemini = proxyUrlGemini
}

systemInstruction := p.credentialService.GetKey("google_gemini_system_instruction")
if systemInstruction == "" {
systemInstruction = DefaultSystemInstruction
}
systemInstruction := cmp.Or(p.credentialService.GetKey("google_gemini_system_instruction"), DefaultSystemInstruction)

var contents []Content
geminiData, err := p.geminiService.GetHistory(c.EffectiveChat)
Expand Down
6 changes: 2 additions & 4 deletions plugin/getfile/getfile.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package getfile

import (
"cmp"
"io"
"os"
"path"
Expand Down Expand Up @@ -119,10 +120,7 @@ func (p *Plugin) OnMedia(b *gotgbot.Bot, c plugin.GobotContext) error {
return nil
}

dir := p.credentialService.GetKey("getfile_dir")
if dir == "" {
dir = "Files"
}
dir := cmp.Or(p.credentialService.GetKey("getfile_dir"), "Files")

savePath := filepath.Join(dir, subFolder)
err = os.MkdirAll(savePath, 0770)
Expand Down
12 changes: 3 additions & 9 deletions utils/tgUtils/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tgUtils

import (
"cmp"
"errors"
"os"
"strconv"
Expand Down Expand Up @@ -101,15 +102,8 @@ func AddRectionWithFallback(b *gotgbot.Bot, message *gotgbot.Message, emoji stri

var telegramErr *gotgbot.TelegramError
if err != nil && errors.As(err, &telegramErr) && telegramErr.Description == ErrReactionInvalid {
fallback := opts.Fallback
if fallback == "" {
fallback = emoji
}

sendMessageOpts := opts.SendMessageOpts
if sendMessageOpts == nil {
sendMessageOpts = utils.DefaultSendOptions()
}
fallback := cmp.Or(opts.Fallback, emoji)
sendMessageOpts := cmp.Or(opts.SendMessageOpts, utils.DefaultSendOptions())

_, err = message.Reply(b, fallback, sendMessageOpts)
}
Expand Down

0 comments on commit c7c871c

Please sign in to comment.