From bc486670d70a0c649cd3c3b11a5191424878c6df Mon Sep 17 00:00:00 2001 From: dd84ai Date: Wed, 22 Nov 2023 19:50:53 +0100 Subject: [PATCH] refactor: add management command to clear up channels --- app/management/anounce.go | 3 --- app/management/channels.go | 53 ++++++++++++++++++++++++++++++++++++++ app/management/migrate.go | 11 -------- 3 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 app/management/channels.go diff --git a/app/management/anounce.go b/app/management/anounce.go index 46a1a12c..5c499927 100644 --- a/app/management/anounce.go +++ b/app/management/anounce.go @@ -22,9 +22,6 @@ var amounceCmd = &cobra.Command{ logus.Info("Anounce is called with args=", logus.Args(args)) dg := discorder.NewClient() - // go listener.Run() - // time.Sleep(5 * time.Second) - channels := configurator.NewConfiguratorChannel(configurator.NewConfigurator(settings.Dbpath)) channelIDs, _ := channels.List() diff --git a/app/management/channels.go b/app/management/channels.go new file mode 100644 index 00000000..c1afcb56 --- /dev/null +++ b/app/management/channels.go @@ -0,0 +1,53 @@ +/* +Copyright © 2023 NAME HERE +*/ +package management + +import ( + "darkbot/app/configurator" + "darkbot/app/settings" + "darkbot/app/settings/logus" + "darkbot/app/settings/types" + "fmt" + + "github.com/spf13/cobra" +) + +var channelDeleteCMD = &cobra.Command{ + Use: "channel_delete", + Short: "Delete channelID", + Run: func(cmd *cobra.Command, args []string) { + logus.Info("Cmd is called with args=", logus.Args(args)) + channels := configurator.NewConfiguratorChannel(configurator.NewConfigurator(settings.Dbpath)) + + for _, channeID := range args { + channels.Remove(types.DiscordChannelID(channeID)) + } + }, +} +var channelListCMD = &cobra.Command{ + Use: "channel_list", + Short: "List channelIDs", + Run: func(cmd *cobra.Command, args []string) { + logus.Info("Cmd is called with args=", logus.Args(args)) + channels := configurator.NewConfiguratorChannel(configurator.NewConfigurator(settings.Dbpath)) + + channelIDs, _ := channels.List() + fmt.Println("channelIDs=", channelIDs) + }, +} + +func init() { + rootCmd.AddCommand(channelDeleteCMD) + rootCmd.AddCommand(channelListCMD) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // migrateCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // migrateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/app/management/migrate.go b/app/management/migrate.go index b09a5e97..96815db3 100644 --- a/app/management/migrate.go +++ b/app/management/migrate.go @@ -11,7 +11,6 @@ import ( "github.com/spf13/cobra" ) -// migrateCmd represents the migrate command var migrateCmd = &cobra.Command{ Use: "migrate", Short: "Migrate db", @@ -23,14 +22,4 @@ var migrateCmd = &cobra.Command{ func init() { rootCmd.AddCommand(migrateCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // migrateCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // migrateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") }