-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage_context.py
43 lines (35 loc) · 1.34 KB
/
message_context.py
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
from __future__ import annotations
from dataclasses import dataclass
from dataclasses import field
from typing import Optional
import discord
from command import Command
from exceptions import DiscordMessageMissingException
@dataclass
class MessageContext:
original_message: Optional[discord.Message] = None
result: str = ''
command: Command = field(default_factory=Command.dummy)
input: object = None
attachment: discord.File | None = None
@property
def message(self) -> discord.Message:
"""
Wrapper on discord_message to satisfy my desire to have type hints despite possibilirty of original_message being None.
"""
if self.original_message is None:
raise DiscordMessageMissingException
else:
return self.original_message
def updated(self, *, result: Optional[str] = None, command: Optional[Command] = None, input: object = None) -> MessageContext:
if result is None and command is None:
raise ValueError('Either result or command need to be updated')
return MessageContext(
original_message=self.original_message,
result=result or self.result,
command=command or self.command,
input=input,
)
@classmethod
def empty(cls) -> MessageContext:
return MessageContext()