aiotraq-message 0.2.0__tar.gz → 0.2.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aiotraq-message
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: aiotraq Plugin that supports interactive message sending using Streamlit-style syntax for traQ
5
5
  Home-page: https://github.com/toshi-pono/aiotraq
6
6
  License: MIT
@@ -22,7 +22,7 @@ Project-URL: Repository, https://github.com/toshi-pono/aiotraq
22
22
  Project-URL: Source Code, https://github.com/toshi-pono/aiotraq/tree/main/libs/message
23
23
  Description-Content-Type: text/markdown
24
24
 
25
- # aiotraq-message
25
+ # AiotraQ-Message
26
26
 
27
27
  streamlit 風の構文を用いてインタラクティブなメッセージ送信に対応するプラグインです。
28
28
 
@@ -38,10 +38,12 @@ pip install aiotraq-message
38
38
 
39
39
  ## Requirements
40
40
 
41
- aiotraq-message は aiotraq に依存しています
41
+ AiotraQ-Message は AiotraQ に依存しています
42
42
 
43
- - [aiotraq](https://github.com/toshi-pono/aiotraq/tree/main/libs/aiotraq)
44
- - [aiotraq-bot](https://github.com/toshi-pono/aiotraq/tree/main/libs/bot)
43
+ - [AiotraQ](https://github.com/toshi-pono/aiotraq/tree/main/libs/aiotraq)
44
+ - [AiotraQ-Bot](https://github.com/toshi-pono/aiotraq/tree/main/libs/bot)
45
+
46
+ ![overview](../../docs/docs/overview.svg)
45
47
 
46
48
  ## Usage
47
49
 
@@ -88,6 +90,8 @@ write, spinner, clear などのメソッドを使うことができます
88
90
  - pyplot: matplotlib のグラフを送信します
89
91
  - dataframe: pandas の dataframe を表形式で表示します
90
92
 
93
+ 詳細: [ドキュメント| Components](https://toshi-pono.github.io/aiotraq/docs/api/components/components-overview/)
94
+
91
95
  ## License
92
96
 
93
97
  This project is licensed under the terms of the MIT license.
@@ -1,4 +1,4 @@
1
- # aiotraq-message
1
+ # AiotraQ-Message
2
2
 
3
3
  streamlit 風の構文を用いてインタラクティブなメッセージ送信に対応するプラグインです。
4
4
 
@@ -14,10 +14,12 @@ pip install aiotraq-message
14
14
 
15
15
  ## Requirements
16
16
 
17
- aiotraq-message は aiotraq に依存しています
17
+ AiotraQ-Message は AiotraQ に依存しています
18
18
 
19
- - [aiotraq](https://github.com/toshi-pono/aiotraq/tree/main/libs/aiotraq)
20
- - [aiotraq-bot](https://github.com/toshi-pono/aiotraq/tree/main/libs/bot)
19
+ - [AiotraQ](https://github.com/toshi-pono/aiotraq/tree/main/libs/aiotraq)
20
+ - [AiotraQ-Bot](https://github.com/toshi-pono/aiotraq/tree/main/libs/bot)
21
+
22
+ ![overview](../../docs/docs/overview.svg)
21
23
 
22
24
  ## Usage
23
25
 
@@ -64,6 +66,8 @@ write, spinner, clear などのメソッドを使うことができます
64
66
  - pyplot: matplotlib のグラフを送信します
65
67
  - dataframe: pandas の dataframe を表形式で表示します
66
68
 
69
+ 詳細: [ドキュメント| Components](https://toshi-pono.github.io/aiotraq/docs/api/components/components-overview/)
70
+
67
71
  ## License
68
72
 
69
73
  This project is licensed under the terms of the MIT license.
@@ -1,21 +1,23 @@
1
1
  import asyncio
2
+ import uuid
3
+ from collections import Counter
2
4
  from dataclasses import dataclass
3
5
  from datetime import datetime, timedelta
6
+ from enum import Enum
7
+
4
8
  from aiotraq import AuthenticatedClient
5
- from aiotraq.api.message import post_message, post_direct_message, edit_message
6
- from aiotraq.api.user import get_user_dm_channel
7
9
  from aiotraq.api.file import post_file
10
+ from aiotraq.api.message import (add_message_stamp, edit_message,
11
+ post_direct_message, post_message, remove_message_stamp)
12
+ from aiotraq.api.user import get_user_dm_channel
8
13
  from aiotraq.models.dm_channel import DMChannel
9
14
  from aiotraq.models.file_info import FileInfo
15
+ from aiotraq.models.message import Message
10
16
  from aiotraq.models.post_file_request import PostFileRequest
11
17
  from aiotraq.models.post_message_request import PostMessageRequest
12
- from aiotraq.models.message import Message
13
- import uuid
14
- from enum import Enum
15
-
18
+ from aiotraq.models.post_message_stamp_request import PostMessageStampRequest
16
19
  from aiotraq.types import File
17
20
 
18
-
19
21
  WAIT_QUEUE = 0.01
20
22
  REQUEST_RATE = 0.9
21
23
 
@@ -48,6 +50,8 @@ class MessageEngine:
48
50
  self._access_token = access_token
49
51
  self.updated_at: datetime | None = None
50
52
  self.messages: list[InnerMessage] = []
53
+ self.stamps: list[str] = []
54
+ self.sended_stamps: list[str] = []
51
55
  self.message_id: str | None = None
52
56
  self.user_id = user_id
53
57
  self.embed = embed
@@ -84,6 +88,13 @@ class MessageEngine:
84
88
  self.request_update()
85
89
  return message_id
86
90
 
91
+ def add_stamp(self, stamp_id: str) -> None:
92
+ """
93
+ stamp を追加する
94
+ """
95
+ self.stamps.append(stamp_id)
96
+ self.request_update()
97
+
87
98
  def add_file(self, file: File) -> str:
88
99
  """
89
100
  file を追加する
@@ -134,6 +145,20 @@ class MessageEngine:
134
145
  self.messages = []
135
146
  self.request_update()
136
147
 
148
+ def remove_stamp(self, stamp_id: str) -> None:
149
+ """
150
+ stamp を削除する
151
+ """
152
+ self.stamps = [stamp for stamp in self.stamps if stamp != stamp_id]
153
+ self.request_update()
154
+
155
+ def remove_all_stamp(self) -> None:
156
+ """
157
+ 全ての stamp を削除する
158
+ """
159
+ self.stamps = []
160
+ self.request_update()
161
+
137
162
  async def end(self) -> None:
138
163
  self.is_loop = False
139
164
 
@@ -147,6 +172,7 @@ class MessageEngine:
147
172
  await self.event.wait()
148
173
  self.event.clear()
149
174
  await self.__update_message(c)
175
+ await self.__update_stamps(c)
150
176
 
151
177
  await self.__fflush(c)
152
178
 
@@ -181,6 +207,50 @@ class MessageEngine:
181
207
  self.updated_at = datetime.now()
182
208
  return
183
209
 
210
+ async def __update_stamps(self, c: AuthenticatedClient) -> None:
211
+ remove_stamps = set()
212
+ unsent_stamps = []
213
+
214
+ if len(self.stamps) == 0:
215
+ remove_stamps = set(self.sended_stamps)
216
+ else:
217
+ i = 0
218
+ for stamp in self.stamps:
219
+ if i >= len(self.sended_stamps):
220
+ unsent_stamps.append(stamp)
221
+ continue
222
+ while stamp != self.sended_stamps[i]:
223
+ remove_stamps.add(self.sended_stamps[i])
224
+ i += 1
225
+ if i >= len(self.sended_stamps):
226
+ unsent_stamps.append(stamp)
227
+ break
228
+ else:
229
+ i += 1
230
+ unsent_stamps.extend(self.sended_stamps[i:])
231
+
232
+ if self.message_id is None:
233
+ return
234
+
235
+ for stamp_id in remove_stamps:
236
+ await remove_message_stamp.asyncio_detailed(
237
+ message_id=self.message_id,
238
+ stamp_id=stamp_id,
239
+ client=c,
240
+ )
241
+
242
+ counter = Counter(unsent_stamps)
243
+ result = [(key, counter[key]) for key in dict.fromkeys(unsent_stamps)]
244
+ for stamp_id, count in result:
245
+ body = PostMessageStampRequest(count=count)
246
+ await add_message_stamp.asyncio_detailed(
247
+ message_id=self.message_id,
248
+ stamp_id=stamp_id,
249
+ client=c,
250
+ body=body,
251
+ )
252
+ self.sended_stamps = self.stamps[:]
253
+
184
254
  async def __init_send_message(self, c: AuthenticatedClient) -> None:
185
255
  if self.channel_id is None and self.user_id is None:
186
256
  return
@@ -1,11 +1,14 @@
1
- from contextlib import contextmanager
2
1
  import io
3
- from PIL import Image
2
+ from contextlib import contextmanager
3
+ from typing import Any, Generator
4
+
4
5
  import numpy as np
6
+ import pandas as pd
7
+ from PIL import Image
8
+
5
9
  from aiotraq_message.utils import base64_to_file, bytes_to_file, cv2pil
6
- from typing import Any, Generator
10
+
7
11
  from .engine import MessageEngine
8
- import pandas as pd
9
12
 
10
13
 
11
14
  class TraqMessage:
@@ -44,6 +47,30 @@ class TraqMessage:
44
47
  """
45
48
  self.engine.remove_message(message_id)
46
49
 
50
+ def stamp(self, stamp_id: str) -> None:
51
+ """
52
+ スタンプを押す
53
+
54
+ Args:
55
+ stamp_id (str): スタンプ ID
56
+ """
57
+ self.engine.add_stamp(stamp_id)
58
+
59
+ def clear_stamp(self, stamp_id: str) -> None:
60
+ """
61
+ スタンプを消す
62
+
63
+ Args:
64
+ stamp_id (str): スタンプ ID
65
+ """
66
+ self.engine.remove_stamp(stamp_id)
67
+
68
+ def clear_all_stamp(self) -> None:
69
+ """
70
+ 全てのスタンプを消す
71
+ """
72
+ self.engine.remove_all_stamp()
73
+
47
74
  def image(self, image: str | Image.Image | io.BytesIO | np.ndarray) -> str | None:
48
75
  """
49
76
  画像を表示する
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "aiotraq-message"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "aiotraq Plugin that supports interactive message sending using Streamlit-style syntax for traQ"
5
5
  authors = ["toshi00"]
6
6
  license = "MIT"