replace zxq.co/ripple/hanayo
This commit is contained in:
18
vendor/zxq.co/ripple/schiavolib/LICENSE
vendored
Normal file
18
vendor/zxq.co/ripple/schiavolib/LICENSE
vendored
Normal 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.
|
3
vendor/zxq.co/ripple/schiavolib/README.md
vendored
Normal file
3
vendor/zxq.co/ripple/schiavolib/README.md
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# schiavolib
|
||||
|
||||
A lightweight library for Schiavo.
|
14
vendor/zxq.co/ripple/schiavolib/schiavo_test.go
vendored
Normal file
14
vendor/zxq.co/ripple/schiavolib/schiavo_test.go
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
package schiavo
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSend(t *testing.T) {
|
||||
err := Bunker.Send("onii-chan be gentle pls >///< '); DROP TABLE users;-- **hello markdown!** Just testing schiavolib ~")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Example() {
|
||||
Bunker.Send("Hello world!")
|
||||
}
|
61
vendor/zxq.co/ripple/schiavolib/schiavolib.go
vendored
Normal file
61
vendor/zxq.co/ripple/schiavolib/schiavolib.go
vendored
Normal 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
|
||||
}
|
46
vendor/zxq.co/ripple/schiavolib/schiavosay/schiavosay.go
vendored
Normal file
46
vendor/zxq.co/ripple/schiavolib/schiavosay/schiavosay.go
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"git.zxq.co/ripple/schiavolib"
|
||||
)
|
||||
|
||||
var (
|
||||
url = "general"
|
||||
messages = make(chan string, 20)
|
||||
)
|
||||
|
||||
func main() {
|
||||
schiavo.ForceDo = true
|
||||
for i := 0; i < 10; i++ {
|
||||
go sender()
|
||||
}
|
||||
fmt.Println("schiavosay")
|
||||
fmt.Print("> ")
|
||||
sc := bufio.NewScanner(os.Stdin)
|
||||
for sc.Scan() {
|
||||
if strings.Index(sc.Text(), "/switch ") == 0 {
|
||||
url = sc.Text()[len("/switch "):]
|
||||
fmt.Println("=> Switched to", url)
|
||||
fmt.Print("> ")
|
||||
continue
|
||||
}
|
||||
messages <- sc.Text()
|
||||
fmt.Print("> ")
|
||||
}
|
||||
}
|
||||
|
||||
func sender() {
|
||||
for m := range messages {
|
||||
err := schiavo.Channel(url).Send(m)
|
||||
if err != nil {
|
||||
fmt.Println()
|
||||
fmt.Println("=>", err)
|
||||
fmt.Print("> ")
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user