update versions and change to std logger

This commit is contained in:
Seraphim Strub 2023-04-23 00:33:20 +02:00
parent aa20d59a0f
commit df441014ed
17 changed files with 212 additions and 147 deletions

View file

@ -2,8 +2,8 @@ package config
import (
"encoding/json"
"github.com/disgoorg/log"
"io"
"log"
"net/http"
)
@ -35,6 +35,6 @@ func LoadAppleList() error {
return err
}
AppleList = data.Body
log.Debug("loaded apple list of lenght: ", len(AppleList))
log.Printf("DEBUG: loaded apple list of lenght: %v", len(AppleList))
return nil
}

View file

@ -4,10 +4,11 @@ import (
"fmt"
"github.com/disgoorg/disgo/events"
"grow.rievo.dev/discordBots/cmd/vcbot/helper"
"log"
)
func JoinEvent(event *events.GuildVoiceJoin) {
event.Client().Logger().Debug("JoinEvent")
log.Printf("DEBUG: JoinEvent")
channelId := *event.VoiceState.ChannelID
channel, _ := event.Client().Rest().GetChannel(channelId)
channelName := channel.Name()
@ -26,7 +27,7 @@ func MoveEvent(event *events.GuildVoiceMove) {
// no that's not a move event
return
}
event.Client().Logger().Debug("MoveEvent")
log.Printf("DEBUG: MoveEvent")
channelOldId := *event.OldVoiceState.ChannelID
channelOld, _ := event.Client().Rest().GetChannel(channelOldId)
channelOldName := channelOld.Name()
@ -44,9 +45,9 @@ func MoveEvent(event *events.GuildVoiceMove) {
}
func LeaveEvent(event *events.GuildVoiceLeave) {
event.Client().Logger().Debug("LeaveEvent")
log.Printf("DEBUG: LeaveEvent")
if event.OldVoiceState.ChannelID == nil {
event.Client().Logger().Error("OldVoiceState.ChannelID missing")
log.Printf("ERROR: OldVoiceState.ChannelID missing")
return
}
channelOldId := *event.OldVoiceState.ChannelID

View file

@ -7,6 +7,7 @@ import (
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/snowflake/v2"
"grow.rievo.dev/discordBots/cmd/vcbot/config"
"log"
"math/rand"
)
@ -14,14 +15,14 @@ func SendNoMention(client bot.Client, msg, msgEdit string) {
message, err := client.Rest().CreateMessage(config.ChannelVoiceLogID, discord.NewMessageCreateBuilder().
SetContent(msg).Build())
if err != nil {
client.Logger().Error("unable to send channel message: ", err)
log.Printf("ERROR: unable to send channel message: %v", err)
return
}
_, err = client.Rest().UpdateMessage(config.ChannelVoiceLogID,
message.ID,
discord.NewMessageUpdateBuilder().ClearContent().SetContent(msgEdit).Build())
if err != nil {
client.Logger().Error("unable to update channel message: ", err)
log.Printf("ERROR: unable to update channel message: %v", err)
return
}
}
@ -70,7 +71,7 @@ func UpdateVoiceChannels(client bot.Client, deleteChannels bool) {
voiceChannels, err := GetVoiceChannels(client)
if err != nil {
client.Logger().Error("error in getVoiceChannels: ", err)
log.Printf("ERROR: error in getVoiceChannels: %v", err)
}
voiceChannelsWithState := make(map[snowflake.ID]string)
voiceChannelsEmpty := make(map[snowflake.ID]string)
@ -93,16 +94,16 @@ func UpdateVoiceChannels(client bot.Client, deleteChannels bool) {
})
if len(voiceChannels) == 2 && len(voiceChannelsWithState) == 0 {
client.Logger().Debug("all channels are empty")
log.Printf("DEBUG: all channels are empty")
return
}
if len(voiceChannelsWithState) >= len(voiceChannels) {
// if there are no empty voiceChannels create one
client.Logger().Debug("new channel has to be created")
log.Printf("DEBUG: new channel has to be created")
name, err := GetName(voiceChannels)
if err != nil {
client.Logger().Error("no empty channels")
log.Printf("ERROR: no empty channels")
return
}
_, err = client.Rest().CreateGuildChannel(config.RegisterGuildID, discord.GuildVoiceChannelCreate{
@ -118,15 +119,15 @@ func UpdateVoiceChannels(client bot.Client, deleteChannels bool) {
if len(voiceChannels)-len(voiceChannelsWithState) > 1 && deleteChannels {
// if there are more than one empty voiceChannels delete all but 1
client.Logger().Debug("channel has to be deleted")
client.Logger().Debug("empty channels: ", voiceChannelsEmpty)
log.Printf("DEBUG: channel has to be deleted")
log.Printf("DEBUG: empty channels: %v", voiceChannelsEmpty)
for id, s := range voiceChannelsEmpty {
// get the oldest channel and delete it
client.Logger().Debug("deleting: ", s)
log.Printf("DEBUG: deleting: %v", s)
err := client.Rest().DeleteChannel(id)
if err != nil {
client.Logger().Error("not able to delete: ", err)
log.Printf("ERROR: not able to delete: %v", err)
return
}
break

View file

@ -6,18 +6,17 @@ import (
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/log"
"grow.rievo.dev/discordBots/cmd/vcbot/config"
"grow.rievo.dev/discordBots/cmd/vcbot/event"
"log"
"os"
"os/signal"
"syscall"
)
func main() {
log.SetLevel(log.LevelInfo)
log.Info("starting vcbot...")
log.Info("disgo version: ", disgo.Version)
log.Printf("INFO: starting vcbot...")
log.Printf("INFO: disgo version: %v", disgo.Version)
err := config.LoadAppleList()
if err != nil {
@ -66,7 +65,7 @@ func main() {
log.Fatal("couldn't find needed channel")
}
log.Infof("vcbot is now running. Press CTRL-C to exit.")
log.Printf("ERROR: vcbot is now running. Press CTRL-C to exit.")
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-s