Skip to content

Commit

Permalink
golint & gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
eraac committed Nov 26, 2017
1 parent e458a34 commit bd40dfd
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions api/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import "github.com/train-cat/client-train-go"

// CreateAlert -
func CreateAlert(stationID int, code string, typ string, userID string) error {
actionInput := traincat.ActionInput{
Type: typ,
Expand Down
5 changes: 4 additions & 1 deletion api/find.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package api

import (
"github.com/train-cat/bot/helper"
"github.com/train-cat/client-train-go"
"github.com/train-cat/client-train-go/filters"
"github.com/train-cat/bot/helper"
)

// FindStationNameByID return station name
func FindStationNameByID(stationID int) string {
s, err := traincat.GetStation(stationID)

Expand All @@ -17,7 +18,9 @@ func FindStationNameByID(stationID int) string {
return s.Name
}

// FindStopByOriginAndSchedule return one stop
func FindStopByOriginAndSchedule(originID int, schedule string) *traincat.Stop {
// TODO maybe add destination
f := &filters.Stop{
Pagination: filters.Pagination{
MaxPerPage: helper.Int(1),
Expand Down
1 change: 1 addition & 0 deletions api/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/train-cat/client-train-go"
)

// GetCodeTrainFromStop return code train
func GetCodeTrainFromStop(s *traincat.Stop) string {
ss := strings.Split(s.Links["train"].Href, "/")

Expand Down
3 changes: 2 additions & 1 deletion api/init.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package api

import (
"github.com/train-cat/client-train-go"
"github.com/spf13/viper"
"github.com/train-cat/client-train-go"
)

// Init function, should be call after log & config init
func Init() {
traincat.SetConfig(traincat.Config{
Host: viper.GetString("api-train.host"),
Expand Down
8 changes: 5 additions & 3 deletions api/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package api
import (
"time"

"github.com/train-cat/bot/helper"
"github.com/train-cat/client-train-go"
"github.com/train-cat/client-train-go/filters"
"github.com/train-cat/bot/helper"
)

const (
maxStops = 10
precisionSchedule = 20
)

// SearchStops return list of stops
func SearchStops(originID int, destinationID int, schedule string) ([]traincat.Stop, error) {
t, err := time.Parse("15:04:05", schedule)

Expand All @@ -27,8 +28,8 @@ func SearchStops(originID int, destinationID int, schedule string) ([]traincat.S
Pagination: filters.Pagination{
MaxPerPage: helper.Int(maxStops),
},
ScheduledBefore: helper.String(before),
ScheduledAfter: helper.String(after),
ScheduledBefore: helper.String(before),
ScheduledAfter: helper.String(after),
TrainThroughStationID: helper.Int(destinationID),
}

Expand All @@ -41,6 +42,7 @@ func SearchStops(originID int, destinationID int, schedule string) ([]traincat.S
return stops, nil
}

// SearchStations return list of stations (find by name)
func SearchStations(name string) ([]traincat.Station, error) {
f := &filters.Station{
Pagination: filters.Pagination{
Expand Down
2 changes: 2 additions & 0 deletions helper/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helper

import "github.com/Eraac/dialogflow"

// List of exit code available
const (
ExitCodeSuccess = iota
ExitCodeErrorInitConfig
Expand All @@ -11,5 +12,6 @@ const (
)

var (
// Platforms we have to interact with this bot
Platforms = []string{dialogflow.PlatformDialogflow, dialogflow.PlatformTelegram}
)
2 changes: 2 additions & 0 deletions helper/helper.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package helper

// Int return pointer to int
func Int(i int) *int {
return &i
}

// String return pointer to string
func String(s string) *string {
return &s
}
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/train-cat/bot/helper"
"github.com/train-cat/bot/api"
"github.com/train-cat/bot/helper"
"github.com/train-cat/bot/notify"
)

Expand Down
2 changes: 2 additions & 0 deletions intent/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"github.com/train-cat/bot/wording"
)

// ActionCancel -
const ActionCancel = "cancel"

// Cancel intent
func Cancel(req *dialogflow.Request) (*dialogflow.Response, error) {
res := dialogflow.NewResponse()

Expand Down
8 changes: 8 additions & 0 deletions intent/createAlert.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import (
"github.com/train-cat/bot/wording"
)

// List of actions receive by dialogflow
const (
ActionCreateAlertStart = "create_alert_start"
ActionCreateAlert = "create_alert"
ActionCreateAlertSelectStop = "create_alert_select_stop"
ActionCreateAlertConfirm = "create_alert_confirm"
ActionCreateAlertNo = "create_alert_no"
)

const (
keyOriginID = "origin_id"
keyOriginRaw = "origin_raw"
keyDestinationID = "destination_id"
Expand All @@ -29,6 +32,7 @@ const (
ctxCreateAlert = "createalert-followup"
)

// CreateAlertStart intent
func CreateAlertStart(_ *dialogflow.Request) (*dialogflow.Response, error) {
r := dialogflow.NewResponse()

Expand All @@ -39,6 +43,7 @@ func CreateAlertStart(_ *dialogflow.Request) (*dialogflow.Response, error) {
return r, nil
}

// CreateAlert intent
func CreateAlert(req *dialogflow.Request) (*dialogflow.Response, error) {
res := dialogflow.NewResponse()

Expand Down Expand Up @@ -91,6 +96,7 @@ func CreateAlert(req *dialogflow.Request) (*dialogflow.Response, error) {
return res, nil
}

// CreateAlertSelectStop intent
func CreateAlertSelectStop(req *dialogflow.Request) (*dialogflow.Response, error) {
res := dialogflow.NewResponse()

Expand Down Expand Up @@ -136,6 +142,7 @@ func CreateAlertSelectStop(req *dialogflow.Request) (*dialogflow.Response, error
return res, nil
}

// CreateAlertConfirm intent
func CreateAlertConfirm(req *dialogflow.Request) (*dialogflow.Response, error) {
res := dialogflow.NewResponse()

Expand Down Expand Up @@ -172,6 +179,7 @@ func CreateAlertConfirm(req *dialogflow.Request) (*dialogflow.Response, error) {
return res, nil
}

// CreateAlertNo intent
func CreateAlertNo(req *dialogflow.Request) (*dialogflow.Response, error) {
res := dialogflow.NewResponse()

Expand Down
2 changes: 2 additions & 0 deletions intent/welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"github.com/train-cat/bot/wording"
)

// ActionWelcome -
const ActionWelcome = "welcome"

// Welcome intent
func Welcome(req *dialogflow.Request) (*dialogflow.Response, error) {
res := dialogflow.NewResponse()

Expand Down
1 change: 1 addition & 0 deletions notify/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
stateDeleted = "deleted"
)

// Handler notify request asking for notification
func Handler(w http.ResponseWriter, req *http.Request) {
n := &notification{}

Expand Down
1 change: 1 addition & 0 deletions notify/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
telegram *tgbotapi.BotAPI
)

// Init should be call after log & config init
func Init() {
var err error

Expand Down
1 change: 1 addition & 0 deletions notify/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package notify

import "net/url"

// Telegram send message via telegram API
func Telegram(userID string, messages ...string) error {
for _, m := range messages {
params := url.Values{}
Expand Down
8 changes: 5 additions & 3 deletions wording/wording.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wording

import "fmt"

// List of keys available for wording
const (
HelloOne = "hello_one"
HelloTwo = "hello_two"
Expand Down Expand Up @@ -33,8 +34,8 @@ var (
AskListSchedule: {"J'ai une liste de train, lequel correspond à ton train ?"},
AskOrigin: {"Je vais avoir besoin de ta gare de départ, peux-tu me le dire ?"},
AskDestination: {"%s c'est noté ! Peux-tu me dire ta gare de destination ?"},
OriginNotFound: {"Je me pensais pourtant forte en géographie 🤓. Peux-tu me préciser ta gare ?"},
DestinationNotFound: {"Je me pensais pourtant forte en géographie 🤓. Peux-tu me préciser ta gare ?"},
OriginNotFound: {"Je me pensais pourtant forte en géographie 🤓. Peux-tu me préciser ta gare d'origine ?"},
DestinationNotFound: {"Je me pensais pourtant forte en géographie 🤓. Peux-tu me préciser ta gare de destination ?"},
SelectOrigin: {"J'ai plusieurs gares ! Peux-tu me préciser ta gare ?"},
SelectDestination: {"J'ai plusieurs gares ! Peux-tu me préciser ta gare ?"},
OriginOkAskSchedule: {"Destination %s ! A quelle heure pars-tu de la gare de %s?"},
Expand All @@ -44,10 +45,11 @@ var (
Cancel: {"Très bien, j'arrête !"},
CancelAlert: {"Ok ! J'oublie cette alerte, tu ne seras pas notifié"},
IssueOne: {"Hey, malheuresement ton train au départ de %s à %s est %s. ✊✊"},
IssueTwo: {"Je ne suis pas encore capable de t'aider 😢. Mais promis je travaille dure pour y arriver ! Bon courage 😊"},
IssueTwo: {"Je ne suis pas encore capable de t'aider 😢. Mais promis je travaille dur pour y arriver ! Bon courage 😊"},
}
)

// Get random message for the key
func Get(key string, a ...interface{}) string {
str, ok := wordings[key]

Expand Down

0 comments on commit bd40dfd

Please sign in to comment.