fluxgram-plugin 2.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fluxgram/__init__.py +117 -0
- fluxgram/_runtime.py +129 -0
- fluxgram/events.py +875 -0
- fluxgram/models/__init__.py +11 -0
- fluxgram/models/chat.py +16 -0
- fluxgram/models/message.py +16 -0
- fluxgram/models/notifications.py +16 -0
- fluxgram/plugin.py +106 -0
- fluxgram/py.typed +0 -0
- fluxgram/settings.py +208 -0
- fluxgram/storage.py +828 -0
- fluxgram/tasks.py +502 -0
- fluxgram/testing/__init__.py +62 -0
- fluxgram/testing/builders.py +274 -0
- fluxgram/testing/harness.py +759 -0
- fluxgram/testing/scheduler.py +214 -0
- fluxgram/testing/storage.py +334 -0
- fluxgram/ui/__init__.py +7 -0
- fluxgram/ui/_notification_queue.py +44 -0
- fluxgram/ui/bulletins.py +21 -0
- fluxgram/ui/context.py +57 -0
- fluxgram/ui/navigation.py +20 -0
- fluxgram/ui/notifications.py +24 -0
- fluxgram_plugin-2.10.0.dist-info/METADATA +208 -0
- fluxgram_plugin-2.10.0.dist-info/RECORD +28 -0
- fluxgram_plugin-2.10.0.dist-info/WHEEL +5 -0
- fluxgram_plugin-2.10.0.dist-info/licenses/LICENSE +339 -0
- fluxgram_plugin-2.10.0.dist-info/top_level.txt +1 -0
fluxgram/__init__.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
from .plugin import Plugin
|
|
2
|
+
from .settings import SwitchSetting, SelectSetting, SliderSetting, TextSetting
|
|
3
|
+
from .events import (
|
|
4
|
+
ApplicationBackgroundedEvent,
|
|
5
|
+
ApplicationForegroundedEvent,
|
|
6
|
+
BeforeSendEvent,
|
|
7
|
+
ChatClosedEvent,
|
|
8
|
+
ChatOpenedEvent,
|
|
9
|
+
EventChannel,
|
|
10
|
+
EventContext,
|
|
11
|
+
EventSubscription,
|
|
12
|
+
Events,
|
|
13
|
+
ExecutionContext,
|
|
14
|
+
MessageDeletedEvent,
|
|
15
|
+
MessageEditedEvent,
|
|
16
|
+
MessageReceivedEvent,
|
|
17
|
+
PluginSettingChangedEvent,
|
|
18
|
+
)
|
|
19
|
+
from .storage import (
|
|
20
|
+
Storage,
|
|
21
|
+
StorageAccountUnavailableError,
|
|
22
|
+
StorageError,
|
|
23
|
+
StorageInactiveError,
|
|
24
|
+
StorageLimits,
|
|
25
|
+
StorageMigration,
|
|
26
|
+
StorageMigrationError,
|
|
27
|
+
StorageOwnerChangedError,
|
|
28
|
+
StorageQueueFullError,
|
|
29
|
+
StorageQuotaExceededError,
|
|
30
|
+
StorageResult,
|
|
31
|
+
StorageFileScope,
|
|
32
|
+
StorageScope,
|
|
33
|
+
StorageStatistics,
|
|
34
|
+
StorageThreadError,
|
|
35
|
+
StorageTransaction,
|
|
36
|
+
StorageTransactionError,
|
|
37
|
+
StorageTask,
|
|
38
|
+
StorageTypeError,
|
|
39
|
+
StorageUnavailableError,
|
|
40
|
+
)
|
|
41
|
+
from .tasks import (
|
|
42
|
+
CancellationToken,
|
|
43
|
+
TaskCancelledError,
|
|
44
|
+
TaskError,
|
|
45
|
+
TaskHandle,
|
|
46
|
+
TaskInactiveError,
|
|
47
|
+
TaskQueueFullError,
|
|
48
|
+
TaskResult,
|
|
49
|
+
Tasks,
|
|
50
|
+
TaskUnavailableError,
|
|
51
|
+
)
|
|
52
|
+
from .models import (
|
|
53
|
+
ChatInfo,
|
|
54
|
+
ChatNotifications,
|
|
55
|
+
MessageInfo,
|
|
56
|
+
NotificationOverride,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
API_VERSION = 2
|
|
60
|
+
API_MINOR_VERSION = 9
|
|
61
|
+
|
|
62
|
+
__all__ = [
|
|
63
|
+
"Plugin",
|
|
64
|
+
"ApplicationBackgroundedEvent",
|
|
65
|
+
"ApplicationForegroundedEvent",
|
|
66
|
+
"SwitchSetting",
|
|
67
|
+
"SelectSetting",
|
|
68
|
+
"SliderSetting",
|
|
69
|
+
"TextSetting",
|
|
70
|
+
"BeforeSendEvent",
|
|
71
|
+
"ChatClosedEvent",
|
|
72
|
+
"ChatOpenedEvent",
|
|
73
|
+
"MessageDeletedEvent",
|
|
74
|
+
"MessageEditedEvent",
|
|
75
|
+
"MessageReceivedEvent",
|
|
76
|
+
"Events",
|
|
77
|
+
"EventChannel",
|
|
78
|
+
"EventContext",
|
|
79
|
+
"EventSubscription",
|
|
80
|
+
"ExecutionContext",
|
|
81
|
+
"PluginSettingChangedEvent",
|
|
82
|
+
"Storage",
|
|
83
|
+
"StorageScope",
|
|
84
|
+
"StorageTransaction",
|
|
85
|
+
"StorageMigration",
|
|
86
|
+
"StorageLimits",
|
|
87
|
+
"StorageStatistics",
|
|
88
|
+
"StorageResult",
|
|
89
|
+
"StorageFileScope",
|
|
90
|
+
"StorageTask",
|
|
91
|
+
"StorageError",
|
|
92
|
+
"StorageUnavailableError",
|
|
93
|
+
"StorageInactiveError",
|
|
94
|
+
"StorageAccountUnavailableError",
|
|
95
|
+
"StorageOwnerChangedError",
|
|
96
|
+
"StorageQueueFullError",
|
|
97
|
+
"StorageThreadError",
|
|
98
|
+
"StorageTypeError",
|
|
99
|
+
"StorageQuotaExceededError",
|
|
100
|
+
"StorageTransactionError",
|
|
101
|
+
"StorageMigrationError",
|
|
102
|
+
"Tasks",
|
|
103
|
+
"TaskHandle",
|
|
104
|
+
"TaskResult",
|
|
105
|
+
"CancellationToken",
|
|
106
|
+
"TaskError",
|
|
107
|
+
"TaskUnavailableError",
|
|
108
|
+
"TaskInactiveError",
|
|
109
|
+
"TaskQueueFullError",
|
|
110
|
+
"TaskCancelledError",
|
|
111
|
+
"API_VERSION",
|
|
112
|
+
"API_MINOR_VERSION",
|
|
113
|
+
"ChatInfo",
|
|
114
|
+
"ChatNotifications",
|
|
115
|
+
"MessageInfo",
|
|
116
|
+
"NotificationOverride",
|
|
117
|
+
]
|
fluxgram/_runtime.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
from collections.abc import Callable, Iterator
|
|
2
|
+
from contextlib import contextmanager
|
|
3
|
+
from contextvars import ContextVar
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Protocol
|
|
6
|
+
|
|
7
|
+
from .events import LegacyEventsPort
|
|
8
|
+
from .models import ChatInfo
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from .storage import StoragePort
|
|
13
|
+
from .tasks import TasksPort
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Chats(Protocol):
|
|
17
|
+
def get(
|
|
18
|
+
self,
|
|
19
|
+
*,
|
|
20
|
+
account: int,
|
|
21
|
+
dialog_id: int,
|
|
22
|
+
topic_id: int = 0,
|
|
23
|
+
) -> ChatInfo:
|
|
24
|
+
...
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Client(Protocol):
|
|
28
|
+
chats: Chats
|
|
29
|
+
|
|
30
|
+
def _bind_runtime(self, host: Any, generation: int) -> None:
|
|
31
|
+
...
|
|
32
|
+
|
|
33
|
+
def _close(self) -> None:
|
|
34
|
+
...
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class UIThread(Protocol):
|
|
38
|
+
def is_ui_thread(self) -> bool:
|
|
39
|
+
...
|
|
40
|
+
|
|
41
|
+
def post(self, callback: Callable[[], Any]) -> None:
|
|
42
|
+
...
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class BulletinPresenter(Protocol):
|
|
46
|
+
def dismiss(self) -> None:
|
|
47
|
+
...
|
|
48
|
+
|
|
49
|
+
def simple(
|
|
50
|
+
self,
|
|
51
|
+
title: str,
|
|
52
|
+
text: str,
|
|
53
|
+
*,
|
|
54
|
+
on_click: Callable[[], Any] | None = None,
|
|
55
|
+
duration: int = 4000,
|
|
56
|
+
top: bool = True,
|
|
57
|
+
) -> bool:
|
|
58
|
+
...
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class NotificationsService(Protocol):
|
|
62
|
+
def show_message(
|
|
63
|
+
self,
|
|
64
|
+
event: Any,
|
|
65
|
+
*,
|
|
66
|
+
respect_mute: bool = True,
|
|
67
|
+
show_in_current_chat: bool = False,
|
|
68
|
+
duration: int = 5000,
|
|
69
|
+
) -> bool:
|
|
70
|
+
...
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class UIServices(Protocol):
|
|
74
|
+
def create_bulletin_presenter(self, ui: Any) -> BulletinPresenter:
|
|
75
|
+
...
|
|
76
|
+
|
|
77
|
+
def create_notifications(self, ui: Any) -> NotificationsService:
|
|
78
|
+
...
|
|
79
|
+
|
|
80
|
+
def open_chat(
|
|
81
|
+
self,
|
|
82
|
+
account: int,
|
|
83
|
+
dialog_id: int,
|
|
84
|
+
topic_id: int,
|
|
85
|
+
message_id: int,
|
|
86
|
+
) -> bool:
|
|
87
|
+
...
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@dataclass(frozen=True)
|
|
91
|
+
class RuntimeBindings:
|
|
92
|
+
events: LegacyEventsPort
|
|
93
|
+
client: Client
|
|
94
|
+
ui_thread: UIThread
|
|
95
|
+
ui_services: UIServices
|
|
96
|
+
call_ui: Callable[[Callable[[], Any]], Any]
|
|
97
|
+
log: Callable[[str, str], None]
|
|
98
|
+
storage: "StoragePort | None" = None
|
|
99
|
+
tasks: "TasksPort | None" = None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class RuntimeFactory(Protocol):
|
|
103
|
+
def __call__(self, plugin_id: str) -> RuntimeBindings:
|
|
104
|
+
...
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
_factory: ContextVar[RuntimeFactory | None] = ContextVar(
|
|
108
|
+
"fluxgram_runtime_factory",
|
|
109
|
+
default=None,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def create_runtime(plugin_id: str) -> RuntimeBindings:
|
|
114
|
+
factory = _factory.get()
|
|
115
|
+
|
|
116
|
+
if factory is None:
|
|
117
|
+
raise RuntimeError("Plugin instances can only be created by FluxGram")
|
|
118
|
+
|
|
119
|
+
return factory(plugin_id)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@contextmanager
|
|
123
|
+
def runtime_scope(factory: RuntimeFactory) -> Iterator[None]:
|
|
124
|
+
token = _factory.set(factory)
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
yield
|
|
128
|
+
finally:
|
|
129
|
+
_factory.reset(token)
|