summaryrefslogtreecommitdiffstats
path: root/matterbridge.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2015-10-28 00:04:57 +0100
committerWim <wim@42.be>2015-10-28 00:04:57 +0100
commit008ea94b533988c58f14403fa4100f3893cf1f4b (patch)
tree5ed780ff34bec0664bee81fcbcc3e65a61cd73c1 /matterbridge.go
parent693f1946b7ef34b430466d1de7dc9a0d445c3894 (diff)
downloadmatterbridge-msglm-008ea94b533988c58f14403fa4100f3893cf1f4b.tar.gz
matterbridge-msglm-008ea94b533988c58f14403fa4100f3893cf1f4b.tar.bz2
matterbridge-msglm-008ea94b533988c58f14403fa4100f3893cf1f4b.zip
Add giphy support. !gif <query>
Diffstat (limited to 'matterbridge.go')
-rw-r--r--matterbridge.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/matterbridge.go b/matterbridge.go
index 734904cf..b9f34c7c 100644
--- a/matterbridge.go
+++ b/matterbridge.go
@@ -3,6 +3,7 @@ package main
import (
"crypto/tls"
"github.com/42wim/matterbridge/matterhook"
+ "github.com/peterhellberg/giphy"
"github.com/thoj/go-ircevent"
"log"
"strconv"
@@ -80,10 +81,14 @@ 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, "![img]("+message.Text+")")
}
texts := strings.Split(message.Text, "\n")
for _, text := range texts {
@@ -92,6 +97,18 @@ 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 {}