summaryrefslogtreecommitdiff
path: root/poezio/core/structs.py
blob: 5866b19f1c3f3608fbc87168856bd49b0e0468b3 (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
"""
Module defining structures useful to the core class and related methods
"""
from dataclasses import dataclass
from typing import Any, Callable, List, Dict

__all__ = [
    'Command',
    'Completion'
    'POSSIBLE_SHOW',
    'Status',
]

POSSIBLE_SHOW = {
    'available': None,
    'chat': 'chat',
    'away': 'away',
    'afk': 'away',
    'dnd': 'dnd',
    'busy': 'dnd',
    'xa': 'xa'
}


@dataclass
class Status:
    __slots__ = ('show', 'message')
    show: str
    message: str


class Completion:
    """
    A completion result essentially currying the input completion call.
    """
    __slots__ = ['func', 'args', 'kwargs', 'comp_list']
    def __init__(
        self,
        func: Callable[..., Any],
        comp_list: List[str],
        *args: Any,
        **kwargs: Any
    ) -> None:
        self.func = func
        self.comp_list = comp_list
        self.args = args
        self.kwargs = kwargs

    def run(self):
        return self.func(self.comp_list, *self.args, **self.kwargs)

@dataclass
class Command:
    __slots__ = ('func', 'desc', 'comp', 'short_desc', 'usage')
    func: Callable[..., Any]
    desc: str
    comp: Callable[['windows.Input'], Completion]
    short_desc: str
    usage: str