update versions and change to std logger
This commit is contained in:
parent
aa20d59a0f
commit
df441014ed
17 changed files with 212 additions and 147 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue