mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-23 19:22:03 -08:00
Add giphy support. !gif <query>
This commit is contained in:
parent
693f1946b7
commit
008ea94b53
@ -61,6 +61,10 @@ showjoinpart=true #show irc users joining and parting
|
|||||||
token=yourtokenfrommattermost
|
token=yourtokenfrommattermost
|
||||||
#disable certificate checking (selfsigned certificates)
|
#disable certificate checking (selfsigned certificates)
|
||||||
#SkipTLSVerify=true
|
#SkipTLSVerify=true
|
||||||
|
|
||||||
|
[general]
|
||||||
|
#request your API key on https://github.com/giphy/GiphyAPI. This is a public beta key
|
||||||
|
GiphyApiKey="dc6zaTOxFJmzC"
|
||||||
```
|
```
|
||||||
|
|
||||||
### mattermost
|
### mattermost
|
||||||
|
@ -23,6 +23,9 @@ type Config struct {
|
|||||||
IconURL string
|
IconURL string
|
||||||
SkipTLSVerify bool
|
SkipTLSVerify bool
|
||||||
}
|
}
|
||||||
|
General struct {
|
||||||
|
GiphyAPIKey string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(cfgfile string) *Config {
|
func NewConfig(cfgfile string) *Config {
|
||||||
|
@ -13,3 +13,6 @@ showjoinpart=true
|
|||||||
#token=yourtokenfrommattermost
|
#token=yourtokenfrommattermost
|
||||||
IconURL="http://youricon.png"
|
IconURL="http://youricon.png"
|
||||||
#SkipTLSVerify=true
|
#SkipTLSVerify=true
|
||||||
|
|
||||||
|
[general]
|
||||||
|
GiphyAPIKey=dc6zaTOxFJmzC
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"github.com/42wim/matterbridge/matterhook"
|
"github.com/42wim/matterbridge/matterhook"
|
||||||
|
"github.com/peterhellberg/giphy"
|
||||||
"github.com/thoj/go-ircevent"
|
"github.com/thoj/go-ircevent"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -80,10 +81,14 @@ func (b *Bridge) Send(nick string, message string) error {
|
|||||||
func (b *Bridge) handleMatter() {
|
func (b *Bridge) handleMatter() {
|
||||||
for {
|
for {
|
||||||
message := b.m.Receive()
|
message := b.m.Receive()
|
||||||
switch message.Text {
|
cmd := strings.Fields(message.Text)[0]
|
||||||
|
switch cmd {
|
||||||
case "!users":
|
case "!users":
|
||||||
log.Println("received !users from", message.UserName)
|
log.Println("received !users from", message.UserName)
|
||||||
b.i.SendRaw("NAMES " + b.Config.IRC.Channel)
|
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")
|
texts := strings.Split(message.Text, "\n")
|
||||||
for _, text := range texts {
|
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() {
|
func main() {
|
||||||
NewBridge("matterbot", NewConfig("matterbridge.conf"))
|
NewBridge("matterbot", NewConfig("matterbridge.conf"))
|
||||||
select {}
|
select {}
|
||||||
|
Loading…
Reference in New Issue
Block a user