Skip to content

Commit

Permalink
New method in base client for subclasses to call, making executing pl…
Browse files Browse the repository at this point in the history
…ugin methods simpler for client implementations
  • Loading branch information
dotchetter committed Jan 7, 2024
1 parent b63e497 commit 495e3b1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pyttman/clients/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,31 @@ def run_client(self, *args, **kwargs) -> None:
associated with.
"""
pass

def execute_plugins(self,
intercept_point: PluginIntercept,
payload: MessageMixin):
"""
Executes plugin methods.
"""
for plugin in self.plugins:
if intercept_point is self.PluginIntercept.before_intents:
plugin.before_intent(payload)
elif intercept_point is self.PluginIntercept.after_intents:
plugin.after_intent(payload)
elif intercept_point is self.PluginIntercept.before_app:
plugin.before_app_start(pyttman.app)
elif intercept_point is self.PluginIntercept.after_app:
plugin.after_app_stops(pyttman.app)

def reply_to_message(self, message: MessageMixin) -> Reply | ReplyStream:
"""
Wrapper for calling the message router for a reply, whilst
calling plugin methods in order.
"""
self.execute_plugins(intercept_point=self.PluginIntercept.before_intents,
payload=message)
reply = self.message_router.get_reply(message)
self.execute_plugins(intercept_point=self.PluginIntercept.after_intents,
payload=message)
return reply

0 comments on commit 495e3b1

Please sign in to comment.