Comments (3)
If you look at how this bot framework is constructed you have hooks, such as message that respond to anything, and then it's all the way up from there trying to make it easy to do common things. You can definitely write your own message hook and do anything there and shortcut the whole framework.
One level higher, you can override invoke in a command, but that's leveraging some internals and hijacking what we do here half way.
So I think I'd welcome a proper way to do this, I think we want:
match do |client, data|
#=> returns `nil` if not matched
end
Or we could extend match
, command
and operator
with additional conditions, so
command 'foo', if: ->(client, data) do
#=> returns true if should be evaluated
end
Would love a PR!
from slack-ruby-bot.
It seems to me the simplest implementation would be your first suggestion(thats what I was thinking first anyway). All that would need to be done is to amend the logic in commands/base.rb#invoke and we'd be in business.
Something like(this is untested):
def self.invoke(client, data)
self.finalize_routes!
expression, text = parse(client, data)
called = false
routes.each_pair do |route, method|
match = route.match(expression)
match ||= route.match(text) if text
next unless match
next if match.names.include?('bot') && !client.name?(match['bot'])
if method
result = method.call(client, data, match)
elsif self.respond_to?(:call)
result = send(:call, client, data, match)
else
fail NotImplementedError, data.text
end
break unless result
called = true
end
called
end
Although I must say the dsl approach is nice too, just more work...
If you're cool with this approach, I'll try to find time to whip up a PR
from slack-ruby-bot.
I think relying on the return of the method is going to make it very hard to debug for people and also has potential to break backward compatibility. Generally my rule of thumb for these is "what do developers want to write", so I would try the DSL approach, it's more work, but it's something that is not relying on a side effect.
Feel free to disregard what I said though, lets talk it over code that works with passing tests ;)
from slack-ruby-bot.
Related Issues (20)
- Getting lots of 429 rate limit errors on https://slack.com/api/rtm.start calls HOT 7
- Graceful shutdown HOT 1
- Testing other code execution inside a command HOT 8
- Deployment tutorial needs update HOT 2
- DMing self produces Sorry @Slackbot, I don't understand that command! HOT 1
- Migration to non-legacy bots HOT 6
- Consider splitting RSpec shared behaviours and development dependencies HOT 4
- Where can i find more info on the client.say method? HOT 7
- Remove support for Giphy
- Extract attachments text
- without mention in channel bot can't reply HOT 1
- Upload a file? HOT 1
- Pongbot does not run on linux mint 19 HOT 4
- Testing for two outputs from a command HOT 5
- When a command is posted in thread, its again posted as direct message automatically HOT 4
- is there an example for how to implement a conversational bot using slack-ruby-bot? HOT 1
- Missing concurrency - Add faye-websocket to your gemfile -- It's already in my Gemfile HOT 1
- Clarification of MIGRATION.md HOT 8
- Is this repo really legacy, there is still a use case? HOT 3
- Repeated 429 (ratelimited) errors from slack HOT 1
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 slack-ruby-bot.