Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
Breaking out /slash activities into it's own file

Hey guys, we are making heavy use of the @activites.slash decorator, something along the lines of:

file

But think duplicating that decorator 20 times for various commands. Any ideas/examples of how we can seprate this code out into a separate file and importing back into main? We are currently keeping everything inside of the main.py at the moment and it's getting messy because we have a lot of slash commands building up.

Also if we need to handle multiple slash scenarios is the best approach just continuing to duplicate the @activies.slash decorator over and over again?

  
  
Posted 2 years ago
Edited 2 years ago
Votes Newest

Answers


You can choose to continue using the @slash decorator while splitting your code into multiple classes / files if you like, just that you will still need to instantiate each class in __main__.py and pass the required BDK services along with ActivityRegistry.

# __main__.py
from .my_file import MyClass

async def run():
    config = BdkConfigLoader.load_from_file(Path.joinpath(current_dir, 'resources', 'config.yaml'))

    async with SymphonyBdk(config) as bdk:
        datafeed_loop = bdk.datafeed()
        datafeed_loop.subscribe(MessageListener())

        MyClass(bdk.activities(), bdk.messages())

        await datafeed_loop.start()
# my_file.py
class MyClass():
    def __init__(self, activities: ActivityRegistry, messages: MessageService):
        @activities.slash("/mycommand")
        async def do_something(context: CommandContext):
            await messages.send_message(context.stream_id, "Hello!")
2
2
Posted 2 years ago
Yong Sheng Tan
39 × 2 Administrator
1
1

Thank you very much Yong! I got it working with your advice above!

dk   2 years ago Report
2K Views
1 Answer
2 years ago
2 years ago
Tags