improved log messages
This commit is contained in:
14
handlers.go
14
handlers.go
@@ -24,7 +24,7 @@ type Command struct {
|
|||||||
var commands []Command = []Command{cmd_form, cmd_tag, cmd_tag_short, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish}
|
var commands []Command = []Command{cmd_form, cmd_tag, cmd_tag_short, cmd_dadjoke, cmd_ping, cmd_ask, cmd_sticky, cmd_cat, cmd_autojoinroles, cmd_autopublish}
|
||||||
|
|
||||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||||
logrus.Info("\nStarting up...")
|
logrus.Info("Starting up...")
|
||||||
findAndDeleteUnusedMessages()
|
findAndDeleteUnusedMessages()
|
||||||
removeOldCommandFromAllGuilds(s)
|
removeOldCommandFromAllGuilds(s)
|
||||||
var existingCommandNames []string
|
var existingCommandNames []string
|
||||||
@@ -34,13 +34,13 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
|
|||||||
existingCommandNames = append(existingCommandNames, existingCommand.Name)
|
existingCommandNames = append(existingCommandNames, existingCommand.Name)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error fetching existing commands for guild %s: %v\n", guild.Name, err)
|
logrus.Errorf("error fetching existing commands for guild %s: %v", guild.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
if !slices.Contains(existingCommandNames, command.Definition.Name) || slices.Contains(os.Args, "--update="+command.Definition.Name) {
|
if !slices.Contains(existingCommandNames, command.Definition.Name) || slices.Contains(os.Args, "--update="+command.Definition.Name) {
|
||||||
cmd, err := s.ApplicationCommandCreate(s.State.User.ID, guild.ID, &command.Definition)
|
cmd, err := s.ApplicationCommandCreate(s.State.User.ID, guild.ID, &command.Definition)
|
||||||
logrus.Infof("\nAdded command \"%s\"", cmd.Name)
|
logrus.Infof("Added command '%s'", cmd.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error("error creating command,", err)
|
logrus.Error("error creating command,", err)
|
||||||
continue
|
continue
|
||||||
@@ -48,14 +48,14 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logrus.Info("\nSuccessfully started the Bot!")
|
logrus.Info("Successfully started the Bot!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
|
func guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
_, err := s.ApplicationCommandCreate(s.State.User.ID, event.Guild.ID, &command.Definition)
|
_, err := s.ApplicationCommandCreate(s.State.User.ID, event.Guild.ID, &command.Definition)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error creating command for guild %s: %v\n", event.Guild.Name, err)
|
logrus.Errorf("error creating command for guild %s: %v", event.Guild.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,10 +115,10 @@ func removeOldCommandFromAllGuilds(s *discordgo.Session) {
|
|||||||
}
|
}
|
||||||
for _, existingCommand := range existingCommands {
|
for _, existingCommand := range existingCommands {
|
||||||
if !slices.Contains(commandIDs, existingCommand.Name) {
|
if !slices.Contains(commandIDs, existingCommand.Name) {
|
||||||
logrus.Infof("\nDeleting command \"%s\"", existingCommand.Name)
|
logrus.Infof("Deleting command '%s'", existingCommand.Name)
|
||||||
err := s.ApplicationCommandDelete(s.State.User.ID, guild.ID, existingCommand.ID)
|
err := s.ApplicationCommandDelete(s.State.User.ID, guild.ID, existingCommand.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error deleting command %s for guild %s: %v\n", existingCommand.Name, guild.Name, err)
|
logrus.Errorf("error deleting command %s for guild %s: %v", existingCommand.Name, guild.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@@ -51,11 +51,11 @@ func main() {
|
|||||||
logrus.Error("error opening connection,", err)
|
logrus.Error("error opening connection,", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.Infof("\nBot is now running as \"%s\"!", bot.State.User.Username)
|
logrus.Infof("Bot is now running as '%s'!", bot.State.User.Username)
|
||||||
sc := make(chan os.Signal, 1)
|
sc := make(chan os.Signal, 1)
|
||||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||||
<-sc
|
<-sc
|
||||||
logrus.Info("\nShutting down...")
|
logrus.Info("Shutting down...")
|
||||||
bot.Close()
|
bot.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user