remove sentry and move to slog

This commit is contained in:
Seraphim Strub 2023-11-05 16:03:52 +00:00
parent a20bc22ab1
commit 5d2b8f39d9
18 changed files with 134 additions and 232 deletions

View file

@ -4,10 +4,9 @@ import (
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/log"
"github.com/disgoorg/snowflake/v2"
"golang.org/x/exp/slog"
"io"
"log/slog"
"net/http"
"os"
"strings"
@ -18,21 +17,24 @@ var (
avatarCache map[snowflake.ID][]byte
)
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
func init() {
avatarCache = make(map[snowflake.ID][]byte)
}
func main() {
logger.Info("starting dealsbot...")
mux := http.NewServeMux()
client, err := disgo.New(token, bot.WithCacheConfigOpts(
cache.WithCaches(
cache.FlagsAll,
),
),
client, err := disgo.New(token,
bot.WithCacheConfigOpts(
cache.WithCaches(cache.FlagsAll)),
)
if err != nil {
slog.Error(err.Error())
logger.Error("error initializing disgo client", slog.Any("error", err))
return
}
rest := client.Rest()
@ -71,5 +73,6 @@ func main() {
return
})
log.Fatal(http.ListenAndServe(":8080", mux))
err = http.ListenAndServe(":8080", mux)
logger.Error("error from http listener", slog.Any("error", err))
}

View file

@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"log/slog"
"net/http"
"time"
)
@ -15,15 +15,17 @@ type EpicStruct struct {
idPrefix string
headers map[string]string
deals DealsMap
logger *slog.Logger
}
func NewEpicApi() EpicStruct {
func NewEpicApi(logger *slog.Logger) EpicStruct {
epic := EpicStruct{
url: "https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions",
baseUrl: "https://store.epicgames.com/p/",
idPrefix: "epic-",
headers: make(map[string]string),
deals: make(map[string]Deal),
logger: logger,
}
epic.headers["Accept-Language"] = "en"
epic.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"
@ -113,7 +115,7 @@ func (e EpicStruct) Load() error {
productSlug = element.OfferMappings[0].PageSlug
}
if productSlug == "" {
log.Printf("ERROR: product slug not found for: %v", element.Title)
e.logger.Error("product slug not found", slog.String("title", element.Title))
continue
}

View file

@ -3,6 +3,7 @@ package api
import (
"fmt"
"golang.org/x/net/html"
"log/slog"
"net/http"
"regexp"
)
@ -13,15 +14,17 @@ type GogStruct struct {
idPrefix string
headers map[string]string
deals DealsMap
logger *slog.Logger
}
func NewGogApi() GogStruct {
func NewGogApi(logger *slog.Logger) GogStruct {
gog := GogStruct{
url: "https://www.gog.com/en/games?priceRange=0,0&discounted=true",
baseUrl: "https://www.gog.com/game/",
idPrefix: "gog-",
headers: make(map[string]string),
deals: make(map[string]Deal),
logger: logger,
}
gog.headers["Accept-Language"] = "en"
gog.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"

View file

@ -3,6 +3,7 @@ package api
import (
"fmt"
"golang.org/x/net/html"
"log/slog"
"net/http"
"regexp"
)
@ -13,15 +14,17 @@ type GogFrontStruct struct {
idPrefix string
headers map[string]string
deals DealsMap
logger *slog.Logger
}
func NewGogFrontApi() GogFrontStruct {
func NewGogFrontApi(logger *slog.Logger) GogFrontStruct {
gog := GogFrontStruct{
url: "https://www.gog.com/",
baseUrl: "https://www.gog.com/game/",
idPrefix: "gog-",
headers: make(map[string]string),
deals: make(map[string]Deal),
logger: logger,
}
gog.headers["Accept-Language"] = "en"
gog.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"golang.org/x/net/html"
"log/slog"
"net/http"
"regexp"
)
@ -14,15 +15,17 @@ type HumbleBundleStruct struct {
idPrefix string
headers map[string]string
deals DealsMap
logger *slog.Logger
}
func NewHumbleBundleApi() HumbleBundleStruct {
func NewHumbleBundleApi(logger *slog.Logger) HumbleBundleStruct {
humbleBundle := HumbleBundleStruct{
url: "https://www.humblebundle.com/",
baseUrl: "https://www.humblebundle.com/store/",
idPrefix: "humblebundle-",
headers: make(map[string]string),
deals: make(map[string]Deal),
logger: logger,
}
humbleBundle.headers["Accept-Language"] = "en"
humbleBundle.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"

View file

@ -5,6 +5,7 @@ import (
"fmt"
"golang.org/x/net/html"
"io"
"log/slog"
"net/http"
"regexp"
)
@ -16,9 +17,10 @@ type SteamStruct struct {
idPrefix string
headers map[string]string
deals DealsMap
logger *slog.Logger
}
func NewSteamApi() SteamStruct {
func NewSteamApi(logger *slog.Logger) SteamStruct {
steam := SteamStruct{
url: "https://store.steampowered.com/search/results?force_infinite=1&maxprice=free&specials=1",
baseUrl: "https://store.steampowered.com/app/",
@ -26,6 +28,7 @@ func NewSteamApi() SteamStruct {
idPrefix: "steam-",
headers: make(map[string]string),
deals: make(map[string]Deal),
logger: logger,
}
steam.headers["Accept-Language"] = "en"
steam.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"

View file

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"regexp"
)
@ -14,14 +15,16 @@ type UbisoftStruct struct {
idPrefix string
headers map[string]string
deals DealsMap
logger *slog.Logger
}
func NewUbsioftApi() UbisoftStruct {
func NewUbsioftApi(logger *slog.Logger) UbisoftStruct {
ubisoft := UbisoftStruct{
url: "https://free.ubisoft.com/configuration.js",
idPrefix: "ubisoft-",
headers: make(map[string]string),
deals: make(map[string]Deal),
logger: logger,
}
ubisoft.headers["referer"] = "https://free.ubisoft.com/"
ubisoft.headers["origin"] = "https://free.ubisoft.com"

View file

@ -10,10 +10,9 @@ import (
"github.com/disgoorg/disgo/rest"
"github.com/disgoorg/disgo/webhook"
"github.com/disgoorg/snowflake/v2"
"github.com/getsentry/sentry-go"
"grow.rievo.dev/discordBots/cmd/dealsbot/api"
"grow.rievo.dev/discordBots/cmd/dealsbot/repository"
"log"
"log/slog"
"os"
"os/signal"
"reflect"
@ -26,7 +25,8 @@ var (
webhookToken = os.Getenv("webhook_token")
)
// sentry
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
var release string
func main() {
@ -40,28 +40,12 @@ func main() {
// - origin
// - check ubisoft works
err := sentry.Init(sentry.ClientOptions{
// Either set your DSN here or set the SENTRY_DSN environment variable.
//Dsn: "",
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
Release: release,
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}
// Flush buffered events before the program terminates.
defer sentry.Flush(2 * time.Second)
log.Printf("INFO: starting dealsbot...")
log.Printf("INFO: disgo version: %v", disgo.Version)
logger.Info("starting dealsbot...", slog.String("disgo version", disgo.Version))
client := webhook.New(webhookID, webhookToken)
defer client.Close(context.TODO())
repo := repository.InitDb()
repo := repository.InitDb(logger)
defer repo.Close()
ticker := time.NewTicker(10 * time.Minute)
@ -73,12 +57,17 @@ func main() {
select {
case <-ticker.C:
var apis []api.Api
apis = append(apis, api.NewUbsioftApi(), api.NewEpicApi(), api.NewSteamApi(), api.NewGogFrontApi(), api.NewGogApi(), api.NewHumbleBundleApi())
apis = append(apis,
api.NewUbsioftApi(logger),
api.NewEpicApi(logger),
api.NewSteamApi(logger),
api.NewGogFrontApi(logger),
api.NewGogApi(logger),
api.NewHumbleBundleApi(logger))
for _, a := range apis {
err := a.Load()
if err != nil {
sentry.CaptureException(fmt.Errorf("ERROR: loading from api: %w", err))
log.Printf("ERROR: %v", err)
logger.Error("failed loading api", slog.Any("error", err))
}
}
var deals []api.Deal
@ -91,15 +80,15 @@ func main() {
retrievedDeal, _ := repo.GetValue(deal.Id)
if deal.Id == retrievedDeal.Id {
log.Printf("DEBUG: %v is already published", deal.Id)
logger.Debug("deal is already published", slog.String("deal", deal.Id))
} else if reflect.DeepEqual(deal, retrievedDeal) {
log.Printf("ERROR: %v is published but not equal", deal.Id)
logger.Error("deal is published but not equal", slog.String("deal", deal.Id))
} else {
log.Printf("INFO: %v is new and will be published", deal.Id)
logger.Info("deal is new and will be published", slog.String("deal", deal.Id))
go sendWebhook(client, deal)
err := repo.SetValue(deal)
if err != nil {
log.Printf("ERROR: %v", err)
logger.Error("failed saving deal", slog.Any("error", err))
}
}
}
@ -107,9 +96,9 @@ func main() {
case <-tickerGC.C:
err := repo.RunGC()
if err != nil && !errors.Is(err, badger.ErrNoRewrite) {
log.Printf("ERROR: GC: %v", err)
logger.Error("GC failed", slog.Any("error", err))
} else {
log.Printf("DEBUG: GC successful")
logger.Debug("GC successful")
}
case <-quit:
ticker.Stop()
@ -119,11 +108,7 @@ func main() {
}
}()
log.Printf("INFO: dealsbot (%v) is now running. Press CTRL-C to exit.", release)
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelDebug)
sentry.CaptureMessage("DEBUG: dealsbot started")
})
logger.Info("dealsbot is now running. Press CTRL-C to exit.", slog.String("version", release))
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
@ -139,6 +124,6 @@ func sendWebhook(client webhook.Client, deal api.Deal) {
SetContent(status).Build(),
rest.WithDelay(2*time.Second),
); err != nil {
log.Printf("ERROR: sending message %v", err.Error())
logger.Error("sending message failed", slog.Any("error", err))
}
}

View file

@ -4,7 +4,7 @@ import (
"encoding/json"
"github.com/dgraph-io/badger/v4"
"grow.rievo.dev/discordBots/cmd/dealsbot/api"
"log"
"log/slog"
)
type Repository interface {
@ -17,16 +17,17 @@ type Repository interface {
type DealRepository struct {
db *badger.DB
logger *slog.Logger
}
func InitDb() *DealRepository {
func InitDb(logger *slog.Logger) *DealRepository {
opts := badger.DefaultOptions("./db")
opts.Logger = nil
db, err := badger.Open(opts)
if err != nil {
log.Fatal(err)
logger.Error("error opening DB", slog.Any("error", err))
}
return &DealRepository{db}
return &DealRepository{db, logger}
}
func (d *DealRepository) Close() error {

View file

@ -7,10 +7,12 @@ import (
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/gateway"
"log"
"log/slog"
"os"
)
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
var (
token = os.Getenv("disgo_token")
noCommands []discord.ApplicationCommandCreate
@ -18,8 +20,7 @@ var (
// this bot should in theory delete all registered commands for a certain bot
func main() {
log.Printf("INFO: starting delcombot...")
log.Printf("INFO: disgo version: %v", disgo.Version)
logger.Info("starting delcombot...", slog.String("disgo version", disgo.Version))
// permissions:
// intent:
@ -34,7 +35,7 @@ func main() {
),
)
if err != nil {
log.Fatal("error while building disgo instance: ", err)
logger.Error("error while building disgo instance", slog.Any("error", err))
return
}
@ -42,17 +43,18 @@ func main() {
client.Caches().GuildsForEach(func(guild discord.Guild) {
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), guild.ID, noCommands); err != nil {
log.Printf("INFO: error deleting guild commands from %v: %v", guild.Name, err)
logger.Info("error deleting guild commands", slog.String("guild name", guild.Name), slog.Any("error", err))
}
})
if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), noCommands); err != nil {
log.Printf("INFO: error deleting global commands %v", err)
logger.Info("error deleting global commands", slog.Any("error", err))
}
if err = client.OpenGateway(context.TODO()); err != nil {
log.Fatal("error while connecting to gateway: ", err)
logger.Error("error while connecting to gateway", slog.Any("error", err))
return
}
log.Printf("INFO: delcombot removed all guild and global commands")
logger.Info("delcombot removed all guild and global commands")
}

View file

@ -5,14 +5,16 @@ import (
"encoding/json"
"fmt"
"grow.rievo.dev/discordBots/cmd/domaincheckbot/config"
"log"
"log/slog"
"os"
"sort"
"strings"
)
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
func main() {
log.Println("add domains to domains.json")
logger.Info("add domains to domains.json")
scanner := bufio.NewScanner(os.Stdin)
@ -40,7 +42,7 @@ func main() {
newDomains = values
}
log.Printf("domains to add: %v\n", newDomains)
logger.Info("domains to add", slog.Any("domains", newDomains))
fmt.Print("add to domains.json? [y|N]: ")
if scanner.Scan() {
@ -48,7 +50,8 @@ func main() {
if input == "y" || input == "Y" {
err := storeDomains(newDomains)
if err != nil {
log.Fatal("failed storing domains.json")
logger.Error("failed storing domains.json", slog.Any("error", err))
return
}
fmt.Println("domains.json updated")
} else {

View file

@ -10,11 +10,10 @@ import (
"github.com/disgoorg/disgo/rest"
"github.com/disgoorg/disgo/webhook"
"github.com/disgoorg/snowflake/v2"
"github.com/getsentry/sentry-go"
"grow.rievo.dev/discordBots/cmd/domaincheckbot/config"
"grow.rievo.dev/discordBots/cmd/domaincheckbot/dns"
"grow.rievo.dev/discordBots/cmd/domaincheckbot/repository"
"log"
"log/slog"
"os"
"os/signal"
"reflect"
@ -27,30 +26,15 @@ var (
webhookToken = os.Getenv("webhook_token")
)
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
// TODO: clear db from domains removed from json
// sentry
var release string
func main() {
err := sentry.Init(sentry.ClientOptions{
// Either set your DSN here or set the SENTRY_DSN environment variable.
//Dsn: "",
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
Release: release,
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}
// Flush buffered events before the program terminates.
defer sentry.Flush(2 * time.Second)
log.Printf("INFO: starting domainCheck...")
log.Printf("INFO: disgo version: %v", disgo.Version)
logger.Info("starting domainCheck...", slog.String("disgo version", disgo.Version))
client := webhook.New(webhookID, webhookToken)
defer client.Close(context.TODO())
@ -73,9 +57,9 @@ func main() {
case <-tickerGC.C:
err := repo.RunGC()
if err != nil && !errors.Is(err, badger.ErrNoRewrite) {
log.Printf("ERROR: with GC: %v", err)
logger.Error("GC failed", slog.Any("error", err))
} else {
log.Printf("DEBUG: GC successful")
logger.Debug("GC successful")
}
case <-quit:
@ -86,11 +70,7 @@ func main() {
}
}()
log.Printf("INFO: domaincheckbot (%v) is now running. Press CTRL-C to exit.", release)
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelDebug)
sentry.CaptureMessage("DEBUG: domaincheckbot started")
})
logger.Info("domaincheckbot is now running. Press CTRL-C to exit.", slog.String("version", release))
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
@ -101,10 +81,10 @@ func checkDomain(counter int, d string, repo *repository.DomainRepository, clien
domain := dns.CheckDomain(d)
retrievedDomain, _ := repo.GetValue(d)
if reflect.DeepEqual(domain, retrievedDomain) {
log.Printf("DEBUG: %v: did not change", d)
logger.Debug("domain did not change", slog.String("domain", d))
return
}
log.Printf("INFO: !%v: changed", d)
logger.Info("domain changed changed", slog.String("domain", d))
counter += 1
if counter >= 2 {
go sendWebhook(client, domain, retrievedDomain)
@ -127,6 +107,6 @@ func sendWebhook(client webhook.Client, domain repository.Domain, oldDomain repo
SetContent(status).Build(),
rest.WithDelay(2*time.Second),
); err != nil {
log.Printf("ERROR: sending message %v", err.Error())
logger.Error("sending message failed", slog.Any("error", err))
}
}

View file

@ -6,39 +6,22 @@ import (
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/gateway"
"github.com/getsentry/sentry-go"
"grow.rievo.dev/discordBots/cmd/funbot/command"
"grow.rievo.dev/discordBots/cmd/funbot/config"
"log"
"log/slog"
"os"
"os/signal"
"strings"
"syscall"
"time"
)
// sentry
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
var release string
func main() {
err := sentry.Init(sentry.ClientOptions{
// Either set your DSN here or set the SENTRY_DSN environment variable.
//Dsn: "",
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
Release: release,
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}
// Flush buffered events before the program terminates.
defer sentry.Flush(2 * time.Second)
log.Printf("INFO: starting funbot...")
log.Printf("INFO: disgo version: %v", disgo.Version)
logger.Info("starting funbot...", slog.String("disgo version", disgo.Version))
// permissions:
// intent:
@ -55,7 +38,7 @@ func main() {
bot.WithEventListenerFunc(command.Listener),
)
if err != nil {
log.Fatal("error while building disgo instance: ", err)
logger.Error("error while building disgo instance", slog.Any("error", err))
return
}
@ -68,31 +51,30 @@ func main() {
if globalComands {
if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), config.Commands); err != nil {
log.Fatal("error while registering commands: ", err)
logger.Error("error while registering commands", slog.Any("error", err))
return
}
if config.RegisterGuildID != 0 {
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), config.RegisterGuildID, config.NoCommands); err != nil {
log.Printf("INFO: error deleting guild commands %v", err)
logger.Info("error deleting guild commands", slog.Any("error", err))
}
}
} else {
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), config.RegisterGuildID, config.Commands); err != nil {
log.Fatal("error while registering commands: ", err)
logger.Error("error while registering commands", slog.Any("error", err))
return
}
if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), config.NoCommands); err != nil {
log.Printf("INFO: error deleting global commands %v", err)
logger.Info("error deleting global commands", slog.Any("error", err))
}
}
if err = client.OpenGateway(context.TODO()); err != nil {
log.Fatal("error while connecting to gateway: ", err)
logger.Error("error while connecting to gateway", slog.Any("error", err))
return
}
log.Printf("INFO: funbot (%v) is now running. Press CTRL-C to exit.", release)
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelDebug)
sentry.CaptureMessage("DEBUG: funbot started")
})
logger.Info("funbot is now running. Press CTRL-C to exit.", slog.String("version", release))
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)

View file

@ -7,8 +7,7 @@ import (
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/snowflake/v2"
"github.com/getsentry/sentry-go"
"log"
"log/slog"
"os"
"os/signal"
"syscall"
@ -21,28 +20,13 @@ var (
channelTempID snowflake.ID
)
// sentry
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
var release string
func main() {
err := sentry.Init(sentry.ClientOptions{
// Either set your DSN here or set the SENTRY_DSN environment variable.
//Dsn: "",
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
Release: release,
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}
// Flush buffered events before the program terminates.
defer sentry.Flush(2 * time.Second)
log.Printf("INFO: starting tempbot...")
log.Printf("INFO: disgo version: %v", disgo.Version)
logger.Info("starting tempbot...", slog.String("disgo version", disgo.Version))
// permissions: Manage Messages
// intent:
@ -58,14 +42,14 @@ func main() {
),
)
if err != nil {
log.Fatal("error while building disgo instance: ", err)
logger.Error("error while building disgo instance", slog.Any("error", err))
return
}
defer client.Close(context.TODO())
if err = client.OpenGateway(context.TODO()); err != nil {
log.Fatal("error while connecting to gateway: ", err)
logger.Error("error while connecting to gateway", slog.Any("error", err))
}
channels, err := client.Rest().GetGuildChannels(registerGuildID)
@ -76,7 +60,7 @@ func main() {
}
}
if channelTempID == 0 {
log.Fatal("couldn't find needed channel")
logger.Error("couldn't find needed channel")
}
ticker := time.NewTicker(1 * time.Minute)
@ -87,7 +71,7 @@ func main() {
case <-ticker.C:
messages, err := client.Rest().GetMessages(channelTempID, 0, 0, 0, 100)
if err != nil {
log.Printf("ERROR: getting messages: %v", err)
logger.Error("getting messages", slog.Any("error", err))
}
var messageIDs []snowflake.ID
for _, message := range messages {
@ -95,17 +79,17 @@ func main() {
messageIDs = append(messageIDs, message.ID)
}
}
log.Printf("DEBUG: deleting messages: %v", len(messageIDs))
logger.Debug("deleting messages", slog.Int("number", len(messageIDs)))
if len(messageIDs) == 1 {
err = client.Rest().DeleteMessage(channelTempID, messageIDs[0])
if err != nil {
log.Printf("ERROR: deleting messages: %v", err)
logger.Error("failed deleting messages", slog.Any("error", err))
}
}
if len(messageIDs) > 1 {
err = client.Rest().BulkDeleteMessages(channelTempID, messageIDs)
if err != nil {
log.Printf("ERROR: deleting messages: %v", err)
logger.Error("failed deleting messages", slog.Any("error", err))
}
}
case <-quit:
@ -115,11 +99,7 @@ func main() {
}
}()
log.Printf("INFO: tempbot is now running. Press CTRL-C to exit.")
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelDebug)
sentry.CaptureMessage("DEBUG: tempbot started")
})
logger.Info("tempbot is now running. Press CTRL-C to exit.", slog.String("version", release))
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)

View file

@ -7,44 +7,25 @@ import (
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/gateway"
disgolog "github.com/disgoorg/log"
"github.com/getsentry/sentry-go"
"grow.rievo.dev/discordBots/cmd/vcbot/config"
"grow.rievo.dev/discordBots/cmd/vcbot/event"
"log"
"log/slog"
"os"
"os/signal"
"syscall"
"time"
)
// sentry
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
var release string
func main() {
disgolog.SetLevel(disgolog.LevelDebug)
err := sentry.Init(sentry.ClientOptions{
// Either set your DSN here or set the SENTRY_DSN environment variable.
//Dsn: "",
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
Release: release,
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}
// Flush buffered events before the program terminates.
defer sentry.Flush(2 * time.Second)
logger.Info("starting vcbot...", slog.String("disgo version", disgo.Version))
log.Printf("INFO: starting vcbot...")
log.Printf("INFO: disgo version: %v", disgo.Version)
err = config.LoadAppleList()
err := config.LoadAppleList()
if err != nil {
log.Fatal(err)
logger.Error("could not load apple list", slog.Any("error", err))
return
}
@ -66,21 +47,22 @@ func main() {
bot.WithEventListenerFunc(event.MoveEvent),
bot.WithEventListenerFunc(event.LeaveEvent),
bot.WithEventListenerFunc(func(event *events.Ready) {
log.Println("DEBUG: Connection Ready")
logger.Debug("Connection Ready")
}),
bot.WithEventListenerFunc(func(event *events.Resumed) {
log.Println("DEBUG: Connection Resumed")
logger.Debug("Connection Resumed")
}),
)
if err != nil {
log.Fatal("error while building vcbot instance: ", err)
logger.Error("error while building vcbot instance", slog.Any("error", err))
return
}
defer client.Close(context.TODO())
if err = client.OpenGateway(context.TODO()); err != nil {
log.Fatal("error while connecting to gateway: ", err)
logger.Error("error while connecting to gateway", slog.Any("error", err))
return
}
channels, err := client.Rest().GetGuildChannels(config.RegisterGuildID)
@ -93,14 +75,11 @@ func main() {
}
}
if config.ChannelVoiceGroupID == 0 {
log.Fatal("couldn't find needed channel")
logger.Error("couldn't find needed channel")
return
}
log.Printf("ERROR: vcbot is now running. Press CTRL-C to exit.")
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelDebug)
sentry.CaptureMessage("DEBUG: vcbot started")
})
logger.Info("INFO: vcbot is now running. Press CTRL-C to exit.", slog.String("version", release))
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)

View file

@ -6,36 +6,18 @@ import (
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/gateway"
"github.com/getsentry/sentry-go"
"grow.rievo.dev/discordBots/cmd/welcomebot/config"
"grow.rievo.dev/discordBots/cmd/welcomebot/event"
"log"
"os"
"os/signal"
"syscall"
"time"
)
// sentry
var release string
func main() {
err := sentry.Init(sentry.ClientOptions{
// Either set your DSN here or set the SENTRY_DSN environment variable.
//Dsn: "",
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production,
TracesSampleRate: 1.0,
Release: release,
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}
// Flush buffered events before the program terminates.
defer sentry.Flush(2 * time.Second)
log.Printf("INFO: starting welcomebot...")
log.Printf("INFO: disgo version: %v", disgo.Version)
@ -94,11 +76,7 @@ func main() {
log.Fatal("couldn't find needed role")
}
log.Printf("INFO: welcomebot is now running. Press CTRL-C to exit.")
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelDebug)
sentry.CaptureMessage("DEBUG: welcomebot started")
})
log.Printf("INFO: welcomebot (%v) is now running. Press CTRL-C to exit.", release)
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)

4
go.mod
View file

@ -7,7 +7,6 @@ require (
github.com/disgoorg/disgo v0.16.11
github.com/disgoorg/log v1.2.1
github.com/disgoorg/snowflake/v2 v2.0.1
github.com/getsentry/sentry-go v0.25.0
golang.org/x/net v0.17.0
)
@ -22,14 +21,15 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v23.5.26+incompatible // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/klauspost/compress v1.16.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b // indirect
github.com/stretchr/testify v1.8.2 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)

8
go.sum
View file

@ -30,10 +30,6 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/getsentry/sentry-go v0.25.0 h1:q6Eo+hS+yoJlTO3uu/azhQadsD8V+jQn2D8VvX1eOyI=
github.com/getsentry/sentry-go v0.25.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@ -75,8 +71,6 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk=
github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@ -136,8 +130,6 @@ golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=