From bd0ad9c98cdd008520c1de78c9b36eac01a3ae80 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Mon, 12 Jun 2023 00:06:44 +0200 Subject: [PATCH 1/3] chore: remove whitespace --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 70c54dc..101336d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Cwtch Bot Framework -A specialized Cwtch Bot framework in Go that provides a more lightweight and tailored approach to building chat bots for Cwtch. +A specialized Cwtch Bot framework in Go that provides a more lightweight and tailored approach to building chat bots for Cwtch. For an introduction to building chatbots with the CwtchBot framework check out [the building an echobot tutorial](https://docs.cwtch.im/developing/building-a-cwtch-app/building-an-echobot). -If you'd like to get involved please open an issue, or submit a pull request :) \ No newline at end of file +If you'd like to get involved please open an issue, or submit a pull request :) -- 2.25.1 From 804e6e8d9b63f8a53216902b435aab6efa2c98c2 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Mon, 12 Jun 2023 00:06:58 +0200 Subject: [PATCH 2/3] chore: gofmt import sort --- bot.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bot.go b/bot.go index eb19acf..f100ecf 100644 --- a/bot.go +++ b/bot.go @@ -2,21 +2,22 @@ package bot import ( "crypto/rand" - "cwtch.im/cwtch/app" - "cwtch.im/cwtch/event" - "cwtch.im/cwtch/peer" - "cwtch.im/cwtch/protocol/connections" - "cwtch.im/cwtch/settings" "encoding/base64" "encoding/json" - "git.openprivacy.ca/openprivacy/connectivity" - "git.openprivacy.ca/openprivacy/connectivity/tor" - "git.openprivacy.ca/openprivacy/log" mrand "math/rand" "os" "path" "path/filepath" "time" + + "cwtch.im/cwtch/app" + "cwtch.im/cwtch/event" + "cwtch.im/cwtch/peer" + "cwtch.im/cwtch/protocol/connections" + "cwtch.im/cwtch/settings" + "git.openprivacy.ca/openprivacy/connectivity" + "git.openprivacy.ca/openprivacy/connectivity/tor" + "git.openprivacy.ca/openprivacy/log" ) type CwtchBot struct { -- 2.25.1 From 9fedfb83b0be81672ead678c5df880b9f90ff793 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Mon, 12 Jun 2023 00:07:12 +0200 Subject: [PATCH 3/3] refactor!: options approach for experiments --- bot.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bot.go b/bot.go index f100ecf..618a047 100644 --- a/bot.go +++ b/bot.go @@ -30,21 +30,24 @@ type CwtchBot struct { experiments []string } -func NewCwtchBot(userdir string, peername string) *CwtchBot { - cb := new(CwtchBot) - cb.dir = userdir - cb.peername = peername - cb.engineHooks = connections.DefaultEngineHooks{} - cb.experiments = nil - return cb +// CwtchBotOption modifies a new CwtchBot. +type CwtchBotOption func(c *CwtchBot) + +// WithExperiments specifies the experiments option of a CwtchBot. +func WithExperiments(experiments []string) CwtchBotOption { + return func(c *CwtchBot) { + c.experiments = experiments + } } -func NewCwtchBotWithExperiments(userdir string, peername string, experiments []string) *CwtchBot { +func NewCwtchBot(userdir, peername string, opts ...CwtchBotOption) *CwtchBot { cb := new(CwtchBot) cb.dir = userdir cb.peername = peername cb.engineHooks = connections.DefaultEngineHooks{} - cb.experiments = experiments + for _, optFunc := range opts { + optFunc(cb) + } return cb } -- 2.25.1