...
 
Commits (3)
......@@ -68,11 +68,13 @@ It's best to learn by example here. This is an example config similar to the one
],
"method": "GET",
"response": [
"XKCD %v: %v %v",
"XKCD %v: %v\nAlt text: %v\n%v",
"num",
"safe_title",
"alt",
"img"
]
],
"errorMessage": "Couldn't find that one, sorry!"
}
},
{
......@@ -111,6 +113,14 @@ It's best to learn by example here. This is an example config similar to the one
"fontpath": "./textile.ttf",
"quality": 100
}
},
{
"name": "CommandReloader",
"type": "reload",
"userwhitelist": ["82984152671985664"],
"options": {
"trigger": "!reload"
}
}
]
}
......
......@@ -11,6 +11,7 @@ require (
github.com/fatih/gomodifytags v0.0.0-20180914191908-141225bf62b6 // indirect
github.com/fatih/motion v0.0.0-20180408211639-218875ebe238 // indirect
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf // indirect
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f
github.com/josharian/impl v0.0.0-20180228163738-3d0f908298c4 // indirect
github.com/jstemmer/gotags v1.4.1 // indirect
github.com/kisielk/errcheck v1.1.0 // indirect
......
......@@ -34,6 +34,8 @@ github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmI
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f h1:ShTPMJQes6tubcjzGMODIVG5hlrCeImaBnZzKF2N8SM=
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/josharian/impl v0.0.0-20180228163738-3d0f908298c4 h1:gmIVMdGlVf5e6Yo6+ZklxdOrvtOvyrAjJyXAbmOznyo=
github.com/josharian/impl v0.0.0-20180228163738-3d0f908298c4/go.mod h1:t4Tr0tn92eq5ISef4cS5plFAMYAqZlAXtgUcKE6y8nw=
github.com/jstemmer/gotags v1.4.1 h1:aWIyXsU3lTDqhsEC49MP85p2cUUWr2ptvdGNqqGA3r4=
......
......@@ -4,7 +4,8 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/bwmarrin/discordgo" // for running the bot
"github.com/bwmarrin/discordgo" // for running the bot
"github.com/gregjones/httpcache"
log "github.com/sirupsen/logrus" // logging suite
"github.com/tidwall/gjson" // for getting items in dot notation
"io/ioutil" // for opening response body
......@@ -32,6 +33,7 @@ type RESTConfig struct {
Responses [][]string `json:"responses"`
ErrorMessage string `json:"errorMessage"`
Headers map[string]string `json:"headers"`
DisableCache bool `json:"disablecache"`
}
// NewRESTCommand generates a new RESTCommand.
......@@ -78,7 +80,16 @@ func NewRESTCommand(config BaseCommand) (command RESTCommand, err error) {
regexp: rgx,
endpointstring: endpoint,
endpointgroups: endpointgroups,
client: http.Client{},
}
// set the client based on if this restcommand is cached
if options.DisableCache {
command.client = http.Client{}
} else {
// use a caching transport to stop the bot from flooding servers with identical requests, if the config allows
command.client = http.Client{
Transport: httpcache.NewMemoryCacheTransport(),
}
command.client = http.Client{}
}
return command, nil
}
......