-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.go
61 lines (51 loc) · 1.17 KB
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package app
import (
"github.com/herwonowr/slackhell/internal/bot"
"github.com/herwonowr/slackhell/internal/config"
"github.com/herwonowr/slackhell/internal/repository"
"github.com/herwonowr/slackhell/internal/service"
"github.com/spf13/cobra"
)
var (
runCmd = &cobra.Command{
Use: "run",
Short: "Run Slackhell C2",
RunE: func(cmd *cobra.Command, args []string) error {
return run(cmd)
},
}
)
func run(cmd *cobra.Command) error {
debug := false
config, err := config.NewConfig(cmd)
if err != nil {
return err
}
if config.Log.Debug {
debug = true
}
repo, err := repository.NewService(config.Database.Path)
if err != nil {
return err
}
err = repo.Init()
if err != nil {
return err
}
defer repo.Close()
srv := service.NewService(repo)
botClient := bot.NewService(srv, config.Slack.Token, debug)
err = botClient.InitBot(databaseVersion, config.Account.ID, config.Account.RealName)
if err != nil {
return err
}
err = botClient.Listen()
if err != nil {
return err
}
return nil
}
func init() {
rootCmd.AddCommand(runCmd)
runCmd.PersistentFlags().StringP("config", "c", "./data/config/slackhell.toml", "slackhell configuration file")
}