mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add lidl banphrase
This commit is contained in:
parent
8359a525c3
commit
61fc2fb652
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -15,5 +15,5 @@
|
|||
# vendor/
|
||||
|
||||
.env
|
||||
Nourybot
|
||||
nourybot
|
||||
cmd
|
68
cmd/bot/banphrase.go
Normal file
68
cmd/bot/banphrase.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package bot
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type banphraseResponse struct {
|
||||
Banned bool `json:"banned"`
|
||||
InputMessage string `json:"input_message"`
|
||||
BanphraseData banphraseData `json:"banphrase_data"`
|
||||
}
|
||||
|
||||
type banphraseData struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Phrase string `json:"phrase"`
|
||||
Length int `json:"length"`
|
||||
Permanent bool `json:"permanent"`
|
||||
}
|
||||
|
||||
// CheckMessage checks if a message contains
|
||||
// banphrased content.
|
||||
// If a message is allowed it returns
|
||||
// false, "okay"
|
||||
// If a message is not allowed it returns:
|
||||
// true, "[banphrased] monkaS"
|
||||
|
||||
func CheckMessage(text string) (bool, string) {
|
||||
log.Info("fn CheckMessage")
|
||||
|
||||
reqBody, err := json.Marshal(map[string]string{
|
||||
"message": text,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
log.Info(reqBody)
|
||||
|
||||
resp, err := http.Post("https://forsen.tv/api/v1/banphrases/test", "application/json", bytes.NewBuffer(reqBody))
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
var responseObject banphraseResponse
|
||||
json.Unmarshal(body, &responseObject)
|
||||
|
||||
log.Info("Bancheck: ", responseObject.Banned)
|
||||
if responseObject.Banned {
|
||||
return true, "[banphrased] monkaS"
|
||||
} else {
|
||||
return false, "okay"
|
||||
}
|
||||
|
||||
return true, "couldnt check"
|
||||
}
|
|
@ -32,5 +32,11 @@ func (b *Bot) Send(target, text string) {
|
|||
return
|
||||
}
|
||||
|
||||
banned, reason := CheckMessage(text)
|
||||
if banned {
|
||||
b.TwitchClient.Say(target, reason)
|
||||
} else {
|
||||
b.TwitchClient.Say(target, text)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue