-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.py
More file actions
41 lines (32 loc) · 1.06 KB
/
Copy pathcontext.py
File metadata and controls
41 lines (32 loc) · 1.06 KB
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
"""Command execution context passed to handlers."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Callable, Dict, List, Optional, TYPE_CHECKING
if TYPE_CHECKING:
from access import AccessControl
@dataclass
class CommandContext:
actor_id: str
channel_id: str
text: str
target_users: List[str]
access: "AccessControl"
score: dict
workdir: str
commands: Dict[str, Callable[..., str]]
reply_channel: str
fip_change: Optional[str] = None
ephemeral: bool = False
@property
def admin(self) -> bool:
return self.access.is_admin(self.actor_id)
def dm_actor(self, ephemeral: bool = True) -> None:
self.reply_channel = self.actor_id
self.ephemeral = ephemeral
def get_context(kwargs: dict) -> CommandContext:
if "context" in kwargs:
return kwargs["context"]
message = kwargs.get("message")
if message is not None and hasattr(message, "context"):
return message.context
raise ValueError("CommandContext not available in kwargs")