Skip to content

Commit b15b3c7

Browse files
committed
Add Slack integrations
Remove slack sub package and use github.com/nlopes/slack instead Add soft session refresh Add slackoverflow run which runs all tasks to sync questions Delete untracked questions and links
1 parent 1852b39 commit b15b3c7

17 files changed

+478
-138
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ dependencies: ## Install SlackOverflow build dependencies
8686
@govendor fetch github.com/jessevdk/go-flags@=v1.1.0
8787
$(call log_ok, github.com/jessevdk/go-flags@=v1.1.0)
8888

89+
$(call log_info, Install Slack API in Go.)
90+
@govendor fetch github.com/nlopes/slack
91+
$(call log_ok, github.com/nlopes/slack)
92+
8993
################################################################################
9094
# Contributors
9195
contributors: ## Update contributors list

slack/channels.go

-50
This file was deleted.

slack/slack.go

-31
This file was deleted.

slackoverflow/application.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
"strconv"
99
"time"
1010

11-
"github.com/aframevr/slackoverflow/slack"
1211
"github.com/aframevr/slackoverflow/sqlite3"
1312
"github.com/aframevr/slackoverflow/stackexchange"
1413
"github.com/aframevr/slackoverflow/std"
1514
flags "github.com/jessevdk/go-flags"
1615
"github.com/logrusorgru/aurora"
16+
"github.com/nlopes/slack"
1717
)
1818

1919
// User Session object
@@ -96,23 +96,24 @@ func (so *Application) Close(code int) {
9696
}
9797

9898
// SessionRefresh refresh session and makes sure that all deps are loaded
99-
func (so *Application) SessionRefresh() {
99+
func (so *Application) SessionRefresh(soft bool) {
100100

101101
// Check configuration
102102
if !so.config.IsConfigured() {
103103
Emergency("You must execute 'slackoverflow reconfigure' or correct errors in ~/.slackoverflow/slackoverflow.yaml")
104104
}
105105

106+
if soft && so.Slack != nil && so.SQLite3 != nil && so.StackExchange != nil {
107+
return
108+
}
106109
// Set Log Level from -v or -d flag default to config.Data.SlackOverflow.LogLevel
107110
UpdateLogLevel()
108111

109112
// Load Slack Client
110113
if so.Slack == nil {
111114
// Configure slack
112-
so.Slack = slack.Load()
113-
so.Slack.SetHost(so.config.Slack.APIHost)
114-
so.Slack.SetToken(so.config.Slack.Token)
115-
so.Slack.SetChannel(so.config.Slack.Channel)
115+
so.Slack = slack.New(so.config.Slack.Token)
116+
116117
Debug("Slack Client is loaded.")
117118
} else {
118119
Debug("Slack Client is already loaded.")

slackoverflow/cmd-config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type cmdConfig struct{}
1313
func (a *cmdConfig) Execute(args []string) error {
1414

1515
// Refresh the session before running this command and make sure that Slack Overflow is configured
16-
slackoverflow.SessionRefresh()
16+
slackoverflow.SessionRefresh(false)
1717

1818
selfConfig := std.NewTable("SlackOverflow Configuration", " ")
1919
selfConfig.AddRow("Log Level", slackoverflow.config.SlackOverflow.LogLevel)

slackoverflow/cmd-restart.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type cmdRestart struct{}
77
func (a *cmdRestart) Execute(args []string) error {
88

99
// Refresh the session before running this command and make sure that Slack Overflow is configured
10-
slackoverflow.SessionRefresh()
10+
slackoverflow.SessionRefresh(false)
1111

1212
return nil
1313
}

slackoverflow/cmd-run.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ type cmdRun struct{}
88
func (a *cmdRun) Execute(args []string) error {
99

1010
// Refresh the session before running this command
11-
slackoverflow.SessionRefresh()
11+
slackoverflow.SessionRefresh(true)
12+
stackechangeSync := cmdStackExchangeQuestions{}
13+
stackechangeSync.All = true
14+
stackechangeSync.Execute(args)
15+
16+
slackSync := cmdSlackQuestions{}
17+
slackSync.All = true
18+
slackSync.Execute(args)
1219

1320
return nil
1421
}

slackoverflow/cmd-slack-channels.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package slackoverflow
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/aframevr/slackoverflow/std"
7+
)
8+
9+
type cmdSlackChannels struct{}
10+
11+
// Execute
12+
func (slack *cmdSlackChannels) Execute(args []string) error {
13+
14+
// Refresh the session before running this command and make sure that Slack Overflow is configured
15+
slackoverflow.SessionRefresh(true)
16+
17+
channels, err := slackoverflow.Slack.GetChannels(true)
18+
if err != nil {
19+
std.Msg("Unable to fetch any channels")
20+
return nil
21+
}
22+
23+
if len(channels) > 0 {
24+
channelList := std.NewTable("ID", "Name", "Created")
25+
for _, channel := range channels {
26+
channelList.AddRow(
27+
channel.ID,
28+
channel.Name,
29+
fmt.Sprintf("%d", channel.Created),
30+
)
31+
}
32+
channelList.Print()
33+
}
34+
return nil
35+
}

0 commit comments

Comments
 (0)