Skip to content

Commit

Permalink
refactor: add management command to clear up channels
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Nov 22, 2023
1 parent eb227e0 commit bc48667
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
3 changes: 0 additions & 3 deletions app/management/anounce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
53 changes: 53 additions & 0 deletions app/management/channels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
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")
}
11 changes: 0 additions & 11 deletions app/management/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/spf13/cobra"
)

// migrateCmd represents the migrate command
var migrateCmd = &cobra.Command{
Use: "migrate",
Short: "Migrate db",
Expand All @@ -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")
}

0 comments on commit bc48667

Please sign in to comment.