File size: 2,752 Bytes
bf41ce7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62d3481
bf41ce7
 
 
 
 
 
62d3481
bf41ce7
 
 
 
 
 
62d3481
bf41ce7
 
 
 
 
 
62d3481
bf41ce7
 
 
 
 
 
62d3481
bf41ce7
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import json
from typing import Any, Callable, Optional

RISINGBRAIN_COMMAND_IDENTIFIER = "risingbrain_command"


class Command:
    """A class representing a command.

    Attributes:
        name (str): The name of the command.
        description (str): A brief description of what the command does.
    """

    def __init__(
        self,
        name: str,
        description: str,
        prompt: str,
        tags: Any,
        enabled: bool = True,
    ):
        self.name = name
        self.description = description
        self.prompt = prompt
        self.tags = tags
        self.enabled = enabled

    def __call__(self, *args, **kwargs) -> Any:
        if not self.enabled:
            return f"Command '{self.name}' is disabled: {self.disabled_reason}"
        return self.method(*args, **kwargs)

    def __str__(self) -> str:
        return f"'name': {self.name}, 'description': {self.description}"

    def __str_json__(self) -> str:
        return json.dumps(
            {
                "name": self.name,
                "description": self.description,
                "prompt": self.prompt,
                "tags": self.tags,
            }
        )


class CommandRegistry:
    """
    The CommandRegistry class is a manager for a collection of Command objects.
    It allows the registration, modification, and retrieval of Command objects,
    as well as the scanning and loading of command plugins from a specified
    directory.
    """

    def __init__(self):
        """this is default commands for now"""
        self.commands = [
            Command(
                "image",
                "image description",
                "Search a image that #description",
                ["#description"],
                True,
            ),
            Command(
                "notification",
                "send notification or alert",
                "send that #notification",
                ["#notification"],
                True,
            ),
            Command(
                "sms",
                "send a sms",
                "",
                [],
                True,
            ),
            Command(
                "browsing",
                "search browser",
                "Search something that #description",
                ["#description"],
                True,
            ),
            Command(
                "social",
                "search something in social",
                "Search something in twitter or facebook that #description",
                ["#description"],
                True,
            ),
        ]

    def get_all_commands(self) -> Any:
        return self.commands

    def add_command(self, command: Command):
        self.commands.append(command)