Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
surskitt committed Feb 24, 2020
2 parents c03b643 + 46f9b91 commit 4afe93b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.0

- Add random fact plugin

## 1.2.0

- Add quote of the day plugin
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
_ "github.com/shanedabes/ircbot/plugins/choose"
_ "github.com/shanedabes/ircbot/plugins/clock"
_ "github.com/shanedabes/ircbot/plugins/donger"
_ "github.com/shanedabes/ircbot/plugins/fact"
_ "github.com/shanedabes/ircbot/plugins/lastfm"
_ "github.com/shanedabes/ircbot/plugins/qod"
_ "github.com/shanedabes/ircbot/plugins/qwantz"
Expand Down
38 changes: 38 additions & 0 deletions plugins/fact/fact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fact

import (
"github.com/go-chat-bot/bot"
"github.com/go-chat-bot/plugins/web"
)

const (
url = "https://uselessfacts.jsph.pl/random.json?language=en"
)

type json struct {
Text string `json:"text"`
}

func (j json) String() string {
return j.Text
}

func fact(command *bot.Cmd) (msg string, err error) {
j := &json{}
err = web.GetJSON(url, j)

if err != nil {
return "", err
}

return j.String(), nil
}

func init() {
bot.RegisterCommand(
"fact",
"Post a random fact from uselessfacts.jsph.pl",
"",
fact,
)
}
17 changes: 17 additions & 0 deletions plugins/fact/fact_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fact

import (
"testing"

"github.com/stretchr/testify/assert"
)

var (
j = json{
Text: "fact",
}
)

func TestString(t *testing.T) {
assert.Equal(t, j.String(), "fact")
}

0 comments on commit 4afe93b

Please sign in to comment.