This commit is contained in:
Morgan Bazalgette
2017-01-14 18:42:10 +01:00
parent 41ee4c90b3
commit 3961e310b1
444 changed files with 179208 additions and 0 deletions

18
vendor/zxq.co/ripple/schiavolib/LICENSE vendored Normal file
View File

@@ -0,0 +1,18 @@
Copyright (c) 2016 Morgan Bazalgette
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,3 @@
# schiavolib
A lightweight library for Schiavo.

View File

@@ -0,0 +1,61 @@
package schiavo
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
)
// Channels to which a message can be sent.
const (
General Channel = "general"
Bunker Channel = "bunk"
ChatLog Channel = "chatlog"
Staff Channel = "staff"
CMs Channel = "cm"
)
// Channel is just a channel on the discord to which you can send messages.
type Channel string
// SchiavoURL is the base URL for schiavo. Change to var when not hardcoded
var SchiavoURL = ""
// Prefix is a prefix that will be appended to all Schiavo messages if set.
var Prefix = ""
// ForceDo is a meme
var ForceDo bool
var shouldDo = os.Getenv("GIN_MODE") == "release" || os.Getenv("SCHIAVO_LOG") != ""
// Send sends a message to a channel.
func (c Channel) Send(m string) error {
if !shouldDo && !ForceDo {
return nil
}
if SchiavoURL == "" {
return nil
}
if Prefix != "" {
m = fmt.Sprintf("**%s** %s", Prefix, m)
}
urgay := SchiavoURL + "/" + string(c) + "?message=" + url.QueryEscape(m)
resp, err := http.Get(urgay)
if err != nil {
return err
}
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return err
}
if string(body) != "ok" {
return errors.New("Schiavo response not ok: " + string(body) + "; status code: " + strconv.Itoa(resp.StatusCode))
}
return nil
}