forked from 0x263b/Porygon2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omdb.go
33 lines (26 loc) · 749 Bytes
/
omdb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package omdb
import (
"fmt"
"github.com/Seventy-Two/Cara"
"github.com/Seventy-Two/Cara/web"
"net/url"
)
const (
URL = "http://www.omdbapi.com/?t=%s&y=&plot=short&r=json&tomatoes=true"
)
func omdb(command *bot.Cmd, matches []string) (msg string, err error){
data := &Omdb{}
err = web.GetJSON(fmt.Sprintf(URL, url.QueryEscape(matches[1])), data)
if err != nil {
return fmt.Sprintf("There was a problem with your request."), nil
}
if data.Title == "" {
return fmt.Sprintf("Not found."), nil
}
return fmt.Sprintf("%s (%s) | %s | iMDb: %s RT: %s | %s | %s", data.Title, data.Year, data.Genre, data.ImdbRating, data.TomatoRating, data.Plot, data.Actors), nil
}
func init() {
bot.RegisterCommand(
"^m(?:db|ovie)? (.+)$",
omdb)
}