Skip to content
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

PLAT-10893 Check for duplicate slash commands #195

Merged
merged 5 commits into from
Jun 1, 2021

Conversation

symphony-mariacristina
Copy link
Contributor

@symphony-mariacristina symphony-mariacristina commented May 31, 2021

Ticket

PLAT-10893

Description

Goal of this implementation is to check when registering a new slash command that is not equal to any of the already existing ones. A slash command is considered equal when both name value and mention_bot boolean are the same.

Dependencies

List the other pull requests that should be merged before/along this one.

Checklist

  • Referenced a ticket in the PR title and in the corresponding section
  • Filled properly the description and dependencies, if any
  • Unit tests updated or added
  • Docstrings added or updated
  • Updated the documentation in docs folder

Goal of this implementation is to check when registering a new slash command that is not equal to any of the already existing ones. A slash command is considered equal when both name value and mention_bot boolean are the same.
@@ -81,3 +80,12 @@ def matches(self, context: CommandContext) -> bool:

async def on_activity(self, context: CommandContext):
await self._callback(context)

def __eq__(self, o: object) -> bool:
if isinstance(o, SlashCommandActivity):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to check if "o" is None ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if o is None, it is of type NoneType and isinstance(o, SlashCommandActivity) will return False.
Tested on the Python console:
Screenshot 2021-06-01 at 09 32 04
.

Copy link
Contributor

@symphony-soufiane symphony-soufiane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just left one comment to avoid errors when comparing None object to a command.

mention_bot = True
command_name = "/command"

activity_registry.slash(command_name, mention_bot)(listener)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider having two different listener instances to check we do not blindly make a reference equality check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, I missed that. Done in cd17c57

@symphony-mariacristina symphony-mariacristina merged commit 4743bc1 into finos:2.0 Jun 1, 2021
symphony-elias added a commit that referenced this pull request Jun 7, 2021
* PLAT-10782: Support of multiple bot instances (#194)

* Updated poetry deps

* PLAT-10782: Implemented proper handling of ackId in DatafeedLoopV2 to support multiple bot instances

* Fixed pylint issues

* PLAT-10893 Check for duplicate slash commands (#195)

* PLAT-10893 Check for duplicate slash commands

Goal of this implementation is to check when registering a new slash command that is not equal to any of the already existing ones. A slash command is considered equal when both name value and mention_bot boolean are the same.

* Fixed documentation (#198)

* PLAT-10868 Remove certificates and private keys credentials (#200)

* PLAT-10868 Remove certificates and private keys credentials

* PLAT-10895-Implement built-in help command (#197)

* PLAT-10895-Implement built-in help command

Goal of this PR is to provide the implementation of a build-in help command with lists all the activity registered in the ActivityRegistry.
For each command found the following format will be used " - command_name - description (mention required/mention not required)" (example "/hello - command to say hello (mention required)")
This help command can also be overriden by manually implementing a new SlashCommandActivity, the code will make sure that any duplicates will be removed.

* PLAT-10944: passed bot service account info in RealTimeEventListener.is_accepting_event (#201)

* Bumped version to 2.0b4

Co-authored-by: Mariacristina De Dominicis <65179248+symphony-mariacristina@users.noreply.github.com>
Co-authored-by: symphony-youness <76746033+symphony-youness@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants