-
-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Message and Event receivers #345
Conversation
73f7f31
to
6bea11c
Compare
application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java
Outdated
Show resolved
Hide resolved
While this adds great functionality, it defeats the original design of the bot? The bot has a SINGLE command listener and manually validates / splits all incoming slash commands to drastically reduce overhead (by only having the correct command respond to the event instead of letting each command manually filter out invalid commands they dont need to respond to) The message system should work the same way? A single listener that internally redirects where applicable? Currently every message listener responds to all message events and have to manually filter the messages they are not interested in, instead of only receiving messages they do want. |
I am not sure I get your concern. I am in no way saying that people should use the new interfaces when all they want to do is to create a slash command. In particular, you should rarely have to use But it is also clear that there are a number of commands that do need more capabilities than just being a slash command (your help system is a good example for this). Hence why we need to introduce those features as well. Or is your concern more about the fact that we have |
This
True enough, but not if we want to add internal routing The fact is that few of our message listeners will want / need global message listening. for example the free system will only need to listen on the help channels. Illum's suggestion of a dad bot would only need to listen on lobby and geek speak. if the bot gets functionality that blocks ppl from talking in snippets (by deleting any posts after the first by the same user in a 24hr period) it would only need to listen to messages in the snippets channel. The way it currently is every single message in every single channel would be sent to every single listener and then every single listener has to filter out the 99% they dont need individually so assuming 12 listeners each message will be filtered 12 times and ignored 11 times, instead of being filtered once and only sent to the one listener that is interested in it. The routing system is already designed and filters slash commands once to send them to the relevant command handler instead of just letting every command manually register its own listener and personally filter out the unneeded commands .... the routing should be expanded and re-used to reduce overhead in message listeners in the same way |
Okay, I think I get your point now. You are suggessting to not only add a general And if someone really has an interest in all channels, they could always also still fall back to I like that idea and will consider it, thanks. |
- Renamed Commands to Features - Renamed CommandSystem to BotCore - Integrated new MessageReceiver and EventReceiver capabilities - Migrated RejoinMuteListener to new EventReceiver
nobody except /free needed it. /free now uses `EventReceiver` which also propagates `ReadyEvent` already.
a38adae
to
a384cf8
Compare
f71255b
to
0608574
Compare
application/src/main/java/org/togetherjava/tjbot/commands/MessageReceiver.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/MessageReceiver.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java
Outdated
Show resolved
Hide resolved
d130924
to
ca887f4
Compare
ca887f4
to
9f4f772
Compare
In a future PR, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good enough for now, it's blocking some other PR's (including #350)
We can change the subscription system for the Message events later one if required.
application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/free/UserStrings.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/free/ChannelMonitor.java
Show resolved
Hide resolved
* Empty lines for readability * Slightly rephrased a user facing string
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have put my suggestions for the refactoring of our MessageReciever
interface. However, you still have to change the imports, variable names, and documentation.
application/src/main/java/org/togetherjava/tjbot/commands/MessageReceiver.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/MessageReceiverAdapter.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/system/BotCore.java
Show resolved
Hide resolved
7 days without real code changes + approval -> merging |
stale
Overview
This implements and closes long awaited #236 and #237 by adding two new interfaces
MessageReceiver
(+MessageReceiverAdapter
) andEventReceiver
to the system.Additionally, some refactoring had to be done to keep a good flow. First of all,
SlashCommand
,MessageReceiver
andEventReceiver
(and soon alsoRoutine
, see #235 ) are summarized under a marker interface calledFeature
. This marks all features that our bot core system supports.Consequently, the previous starting class
Commands
has been renamed toFeatures
and is now the origin of all features, not only commands (we already moved other stuff there in the past to prepare for this).While at it, the existing class
RejoinMuteListener
has been adapted and now implementsEventReceiver
instead.Details
System-wise,
Features#createFeatures
returns a list of all features toBotCore
and it will iterate and filter it based on the type (a sealed interface would be awesome here to not miss any future type).For
SlashCommands
, nothing changed.EventReceivers
are directly forwarded tojda.addEventListener
, since that interface extends JDAsEventListener
.MessageReceivers
subscribe to channels they are interested in by a REGEX pattern matching channel names,BotCore
takes care of the message event forwarding by iterating a simpleMap<Pattern, MessageReceiver>
.Examples
Quick example for a
MessageReceiver
, via itsMessageReceiverAdapter
helper:a quick example for a
EventListener
:and in both cases a simple addition in
Features.java
:Remarks
When merging this, we have to go through our Wiki and do some minor adjusments caused by the renaming of
Commands
(nowFeatures
).This PR competes against #341, which is a different design-approach to this problem, in which
SlashCommands
get the event listening capabilities directly instead of creating separate flows for them. (Which I am not a fan of, since this leads to creation of a behemoth class that can do everything instead of separating capabilities and concerns - SRP.)