summaryrefslogtreecommitdiff
path: root/server/event.py
blob: c5e53f34f5959c55af047d55b43ebc99687689c5 (plain)
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
'''
    A vital class supporting the help command
    but also the GUI request buttons, that are
    required to execute requests.

    Verified: 2021 February 7
    * Follows PEP8
    * Tested Platforms
        * Windows 10
'''

from server.state import ServerStatic


class Event:

    def __init__(self, command, available, namespace, args=()):
        self.__command = command.capitalize()
        self.__available = available.capitalize()
        self.__namespace = namespace.capitalize()
        self.__args = args

    def __call__(self):
        getattr(ServerStatic,
                self.__available.upper()).append(
                    self.__command.lower())

        self.__args_str = ''.join([
            self.__required(required, (
                ServerStatic.ARG_SEPARATOR
                + name + self.__response(response, name)))
            for name, required, response in self.__args])

        ServerStatic.HELP.append((self.__available,
                                  self.__namespace,
                                  self.__command,
                                  self.__args_str))

        if not ServerStatic.TERMINAL:
            namespace = ServerStatic.GUI_HELP.get(
                self.__namespace, False)
            namespace_obj = [self.__available,
                             self.__command,
                             self.__args_str,
                             self.__args]

            if namespace:
                namespace.append(namespace_obj)
            else:
                ServerStatic.GUI_HELP[
                    self.__namespace] = [namespace_obj]

    def __response(self, response, name):
        if response:
            return f' [{name}]'
        else:
            return ''

    def __required(self, required, arg):
        if required:
            return f'{arg} '
        else:
            return f'({arg}) '