Skip to content

Commit

Permalink
Fixes #83 : Adds Discord Integration Example
Browse files Browse the repository at this point in the history
  • Loading branch information
saniales committed Dec 24, 2018
1 parent 130d742 commit 9de78e2
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions examples/interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"time"

"github.com/bwmarrin/discordgo"
"github.com/nlopes/slack"
"github.com/saniales/golang-crypto-trading-bot/environment"
"github.com/saniales/golang-crypto-trading-bot/exchanges"
Expand Down Expand Up @@ -135,3 +136,52 @@ var TelegramIntegrationExample = strategies.IntervalStrategy{
},
},
}

var discordBot *discordgo.Session

// DiscordIntegrationExample sends messages to a specified discord channel.
var DiscordIntegrationExample = strategies.IntervalStrategy{
Model: strategies.StrategyModel{
Name: "DiscordIntegrationExample",
Setup: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
// Create a new Discord session using the provided bot token.
discordBot, err := discordgo.New("Bot " + "YOUR-DISCORD-TOKEN")
if err != nil {
return err
}

go func() {
err = discordBot.Open()
if err != nil {
return
}
}()

//sleep some time
time.Sleep(time.Second * 5)
if err != nil {
return err
}

return nil
},
OnUpdate: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
_, err := discordBot.ChannelMessageSend("CHANNEL-ID", "OMG SOMETHING HAPPENING!!!!!")
if err != nil {
return err
}
return nil
},
OnError: func(err error) {
logrus.Errorf("I Got an error %s", err)
telegramBot.Stop()
},
TearDown: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
err := discordBot.Close()
if err != nil {
return err
}
return nil
},
},
}

0 comments on commit 9de78e2

Please sign in to comment.