parent
bed25234bb
commit
9fefc8b702
|
@ -22,6 +22,7 @@ type Config struct {
|
|||
} `toml:"server"`
|
||||
DBPath string `toml:"db_path"`
|
||||
MCPath string `toml:"mc_path"`
|
||||
ImgurClientID string `toml:"imgur_client_id"`
|
||||
|
||||
StaffRoles []string `toml:"staff_roles"`
|
||||
Echoes []Echo `toml:"echoes"`
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"go.etztech.xyz/sedbot/config"
|
||||
"go.etztech.xyz/sedbot/database"
|
||||
"go.etztech.xyz/sedbot/imgur"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"go.jolheiser.com/beaver"
|
||||
|
@ -39,6 +40,12 @@ func Bot(cfg *config.Config, db *database.Database) (*discordgo.Session, error)
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Init Jupiter images
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
if err := imgur.Init(cfg.ImgurClientID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, messageRole := range cfg.MessageRoles {
|
||||
if messageRoleMap[messageRole.MessageID] == nil {
|
||||
messageRoleMap[messageRole.MessageID] = make(map[string]string)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package discord
|
||||
|
||||
import "go.etztech.xyz/sedbot/imgur"
|
||||
|
||||
func init() {
|
||||
cmd := command{
|
||||
validate: func(cmd commandInit) bool {
|
||||
return true
|
||||
},
|
||||
run: func(cmd commandInit) (string, error) {
|
||||
if !memeRateLimit.Try() {
|
||||
return "", nil
|
||||
}
|
||||
img := imgur.Images[rand.Intn(len(imgur.Images))-1]
|
||||
return img.Link, nil
|
||||
},
|
||||
help: "Get a Jupiter image",
|
||||
}
|
||||
|
||||
commands["jupiter"] = cmd
|
||||
commands["jup"] = cmd
|
||||
commands["jupjup"] = cmd
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package imgur
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// TODO Make a client for this in a separate module
|
||||
|
||||
var Images []*Image
|
||||
|
||||
type Response struct {
|
||||
Images []*Image `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Datetime int `json:"datetime"`
|
||||
Type string `json:"type"`
|
||||
Animated bool `json:"animated"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Size int `json:"size"`
|
||||
Views int `json:"views"`
|
||||
Bandwidth int `json:"bandwidth"`
|
||||
Deletehash string `json:"deletehash"`
|
||||
Section string `json:"section"`
|
||||
Link string `json:"link"`
|
||||
}
|
||||
|
||||
func Init(clientID string) error {
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "https://api.imgur.com/3/album/TaJVIdQ/images", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Client-ID %s", clientID))
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var imgurResp Response
|
||||
if err := json.NewDecoder(resp.Body).Decode(&imgurResp); err != nil {
|
||||
return err
|
||||
}
|
||||
Images = imgurResp.Images
|
||||
return resp.Body.Close()
|
||||
}
|
|
@ -28,6 +28,9 @@ staff_roles = []
|
|||
# meme_rate is the rate limit for memes
|
||||
meme_rate = "0"
|
||||
|
||||
# Imgur Client ID
|
||||
imgur_client_id = ""
|
||||
|
||||
# Server options
|
||||
[server]
|
||||
# connection address
|
||||
|
|
Loading…
Reference in New Issue