From 87d49af5050f6af34e417b0a69da906a16f91114 Mon Sep 17 00:00:00 2001 From: shanedabes Date: Mon, 24 Feb 2020 14:15:57 +0000 Subject: [PATCH 1/2] Add random fact plugin --- main.go | 1 + plugins/fact/fact.go | 38 ++++++++++++++++++++++++++++++++++++++ plugins/fact/fact_test.go | 17 +++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 plugins/fact/fact.go create mode 100644 plugins/fact/fact_test.go diff --git a/main.go b/main.go index 63a620c..c1a7622 100644 --- a/main.go +++ b/main.go @@ -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" diff --git a/plugins/fact/fact.go b/plugins/fact/fact.go new file mode 100644 index 0000000..9a20122 --- /dev/null +++ b/plugins/fact/fact.go @@ -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, + ) +} diff --git a/plugins/fact/fact_test.go b/plugins/fact/fact_test.go new file mode 100644 index 0000000..0a843c3 --- /dev/null +++ b/plugins/fact/fact_test.go @@ -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") +} From 46f9b91e437da48ecd9d4bb654b46cab8f125765 Mon Sep 17 00:00:00 2001 From: shanedabes Date: Mon, 24 Feb 2020 14:16:41 +0000 Subject: [PATCH 2/2] prepare release --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f42b93e..54cbc6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.3.0 + +- Add random fact plugin + ## 1.2.0 - Add quote of the day plugin