commit 008ea94b533988c58f14403fa4100f3893cf1f4b
Author: Wim <wim@42.be>
Date: Wed Oct 28 00:04:57 2015 +0000
diff --git a/README.md b/README.md
index 5946908..db9d47b 100644
--- a/README.md
+++ b/README.md
@@ -616 +6110 @@ showjoinpart=true #show irc users joining and parting
token=yourtokenfrommattermost
#disable certificate checking (selfsigned certificates)
#SkipTLSVerify=true
+
+[general]
+#request your API key on https://github.com/giphy/GiphyAPI. This is a public beta key
+GiphyApiKey="dc6zaTOxFJmzC"
```
### mattermost
diff --git a/config.go b/config.go
index e40b0e9..ecdf65f 100644
--- a/config.go
+++ b/config.go
@@ -236 +239 @@ type Config struct {
IconURL string
SkipTLSVerify bool
}
+ General struct {
+ GiphyAPIKey string
+ }
}
func NewConfig(cfgfile string) *Config {
diff --git a/matterbridge.conf.sample b/matterbridge.conf.sample
index bac921c..f910e01 100644
--- a/matterbridge.conf.sample
+++ b/matterbridge.conf.sample
@@ -133 +136 @@ showjoinpart=true
#token=yourtokenfrommattermost
IconURL="http://youricon.png"
#SkipTLSVerify=true
+
+[general]
+GiphyAPIKey=dc6zaTOxFJmzC
diff --git a/matterbridge.go b/matterbridge.go
index 734904c..b9f34c7 100644
--- a/matterbridge.go
+++ b/matterbridge.go
@@ -36 +37 @@ package main
import (
"crypto/tls"
"github.com/42wim/matterbridge/matterhook"
+ "github.com/peterhellberg/giphy"
"github.com/thoj/go-ircevent"
"log"
"strconv"
@@ -8010 +8114 @@ func (b *Bridge) Send(nick string, message string) error {
func (b *Bridge) handleMatter() {
for {
message := b.m.Receive()
- switch message.Text {
+ cmd := strings.Fields(message.Text)[0]
+ switch cmd {
case "!users":
log.Println("received !users from", message.UserName)
b.i.SendRaw("NAMES " + b.Config.IRC.Channel)
+ case "!gif":
+ message.Text = b.giphyRandom(strings.Fields(strings.Replace(message.Text, "!gif ", "", 1)))
+ b.Send(b.Config.IRC.Nick, "")
}
texts := strings.Split(message.Text, "\n")
for _, text := range texts {
@@ -926 +9718 @@ func (b *Bridge) handleMatter() {
}
}
+func (b *Bridge) giphyRandom(query []string) string {
+ g := giphy.DefaultClient
+ if b.Config.General.GiphyAPIKey != "" {
+ g.APIKey = b.Config.General.GiphyAPIKey
+ }
+ res, err := g.Random(query)
+ if err != nil {
+ return "error"
+ }
+ return res.Data.FixedHeightDownsampledURL
+}
+
func main() {
NewBridge("matterbot", NewConfig("matterbridge.conf"))
select {}