-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
41 lines (32 loc) · 916 Bytes
/
__init__.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
from importlib import import_module
from dataclasses import dataclass
from typing import Callable
from .aulib import (
MessageReference,
ScriptAuthor,
Attachment,
Response,
Message,
Channel,
Guild,
User
)
@dataclass
class ScriptedAutoResponse:
function: Callable[[Message], Response | None]
author: ScriptAuthor
class ScriptedAutoResponseManager:
def __init__(self) -> None:
self.cache: dict[str, Callable] = {}
def get(self, script: str) -> ScriptedAutoResponse:
if script in self.cache:
return self.cache[script]
module = import_module(
f'{__name__}.auto_responses.{script}'
)
self.cache[script] = ScriptedAutoResponse(
function=module.on_message,
author=module.author
)
return self.cache[script]
SCRIPTED_AUTO_RESPONSES = ScriptedAutoResponseManager()