Comments (1)
This change may be ideal when we purely design an interface that represents user input. As a matter of fact, all inputs do not necessarily represent text messages; some represent images while some represent video clips. However, go-sarah
has a handy feature to supply a regular expression to be run against user inputs.
Lines 296 to 306 in a7408dc
If the design is to focus on rigorousness, there could be an idea to define an additional interface that represents a text format message, sarah.TextInput
. The above method may check if the given sarah.Input
implements sarah.TextInput
and then run the current logic.
The question is if such rigorousness is preferred. Such changes unintentionally lead to more complexity and cumbersomeness since all sarah.Command
implementation will have to check if the given input implements sarah.TextInput
to do some common tasks. A command implementation can be somewhat like below:
type command struct {
}
func (*command) Execute(ctx context.Context, input sarah.Input) (*sarah.CommandResponse, error) {
textInput, ok := input.(sarah.TextInput)
if !ok {
return nil, nil
}
message := textInput.Message()
// TODO Do something with message
return nil, nil
}
func (*command) Match(sarah.Input) bool {
textInput, ok := input.(sarah.TextInput)
if !ok {
return false
}
return strings.HasPrefix(textInput.Message(), ".dummyPrefix")
}
func (*command) Identifier() string {
panic("example")
}
func (*command) Instruction(input *sarah.HelpInput) string {
panic(`input ".dummyPrefix xxx" to do some good`)
}
This is too complex comparing to current implementation where Input.Message()
is always available with sarah.Input
. Let the current interface stay. The current interface definition actually guides to return an empty message when the input does not represent a text message.
Lines 19 to 22 in a7408dc
from go-sarah.
Related Issues (20)
- Rename example directory to _example
- Add golang 1.16 to Travis CI setting
- Migrate to go-kasumi
- H4K3R HOT 1
- Set up scheduler's logger in favor of robfig/cron improvement
- New HOT 1
- Race condition on live configuration update HOT 1
- Find suitable replacement for forked github.com/robfig/cron. HOT 4
- On JSON deserialization, let time.Duration-type field accept time.ParseDuration friendly format HOT 2
- xmpp adapter HOT 9
- Remove Go 1.6 support
- Mattermost Adapter HOT 4
- Plan v2 release HOT 2
- Rename SentAt() method of sarah.Input to TimeStamp() HOT 1
- sarah.Command also receives sarah.Input to return available help text
- Provide high-level interface to run go-sarah
- Bot supervisor should also receive Bot's noteworthy state in addition to currently handled critical state HOT 1
- Employ xerrors to propagate original error values HOT 1
- Generalize watcher interface
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-sarah.