Skip to content

Commit

Permalink
Allow to edit standup notes (#13)
Browse files Browse the repository at this point in the history
* initial commit

* adding uuid and editing working

* fix linting

* some more linting fixing

* some more cleaning

* update sql request
  • Loading branch information
matthieudolci authored Jul 14, 2018
1 parent 584bcf4 commit c6e2ab8
Show file tree
Hide file tree
Showing 59 changed files with 2,024 additions and 441 deletions.
14 changes: 10 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
name = "github.com/lib/pq"

[[constraint]]
branch = "master"
name = "github.com/nlopes/slack"
version = "0.2.0"

[prune]
go-tests = true
Expand Down
58 changes: 58 additions & 0 deletions bot/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package bot

import (
"database/sql"
"fmt"

log "github.com/Sirupsen/logrus"
"github.com/matthieudolci/hatcher/database"
uuid "github.com/satori/go.uuid"
)

func (s *Slack) rowExists(query string, args ...interface{}) bool {

var exists bool

err := database.DB.QueryRow(query, args...).Scan(&exists)
if err != nil && err != sql.ErrNoRows {
log.WithFields(log.Fields{
"arg": args,
}).WithError(err).Error("error checking if row exists")
}
return exists
}

func (s *Slack) queryRow(query string, args ...interface{}) error {

var id int

err := database.DB.QueryRow(query, args...).Scan(&id)
if err != nil && err != sql.ErrNoRows {
log.WithFields(log.Fields{
"arg": args,
}).WithError(err).Error("error querying the row")
}
return nil
}

func (s *Slack) queryUUID(query string, args ...interface{}) (string, error) {

var uuid string

err := database.DB.QueryRow(query, args...).Scan(&uuid)
if err != nil && err != sql.ErrNoRows {
log.WithFields(log.Fields{
"arg": args,
}).WithError(err).Error("error querying the row")
}

u := fmt.Sprint(uuid)

return u, err
}

func (s *Slack) createsUUID() string {
u := uuid.NewV4()
uuid := fmt.Sprint(u)
return uuid
}
2 changes: 1 addition & 1 deletion bot/handler_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/nlopes/slack"
)

// Listen on /slack for answer from the questions asked in bot_setup.go
// Listen on /slack for answer from the questions asked in setup.go
// and dispatch to the good functions
func (s *Slack) slackPostHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {

Expand Down
23 changes: 23 additions & 0 deletions bot/listen_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ func (s *Slack) run(ctx context.Context) {
log.Info("Now listening for incoming messages...")

for msg := range rtm.IncomingEvents {
switch x := msg.Data.(type) {
case *slack.MessageEvent:
if x.SubType == "message_changed" {
err := s.checkIfYesterdayMessageEdited(x)
if err != nil {
log.WithFields(log.Fields{
"userid": x.User,
}).WithError(err).Error("Checking if yesterday standup was edited")
}
err = s.checkIfTodayMessageEdited(x)
if err != nil {
log.WithFields(log.Fields{
"userid": x.User,
}).WithError(err).Error("Checking if yesterday standup was edited")
}
err = s.checkIfBlockerMessageEdited(x)
if err != nil {
log.WithFields(log.Fields{
"userid": x.User,
}).WithError(err).Error("Checking if yesterday standup was edited")
}
}
}
switch ev := msg.Data.(type) {
case *slack.MessageEvent:
if len(ev.User) == 0 {
Expand Down
Loading

0 comments on commit c6e2ab8

Please sign in to comment.