6
6
from mi .api .favorite import FavoriteManager
7
7
from mi .api .reaction import ReactionManager
8
8
from mi .exception import ContentRequired
9
+ from mi .http import HTTPClient , Route
9
10
from mi .models .note import RawNote
10
- from mi .note import Note , Poll
11
+ from mi .note import Note , NoteReaction , Poll
11
12
from mi .utils import check_multi_arg , remove_dict_empty
12
- from mi .http import HTTPClient , Route
13
13
14
14
if TYPE_CHECKING :
15
15
from mi .state import ConnectionState
@@ -23,10 +23,13 @@ def __init__(self, state: 'ConnectionState', http: HTTPClient, loop: asyncio.Abs
23
23
self .__state = state
24
24
self .__http = http
25
25
self .__loop = loop
26
+ self .__note_id : Optional [str ] = note_id
26
27
self .favorite = FavoriteManager (state , http , loop , note_id = note_id )
27
28
self .reaction = ReactionManager (state , http , loop , note_id = note_id )
28
29
29
- async def add_clips (self , clip_id : str , note_id : str ) -> bool :
30
+ async def add_clips (self , clip_id : str , note_id : Optional [str ] = None ) -> bool :
31
+ note_id = note_id or self .__note_id
32
+
30
33
data = {'noteId' : note_id , 'clipId' : clip_id }
31
34
return bool (await self .__http .request (Route ('POST' , '/api/clips/add-note' ), json = data , auth = True ))
32
35
@@ -96,9 +99,9 @@ async def send(self,
96
99
"text" : content ,
97
100
"cw" : cw ,
98
101
"localOnly" : local_only ,
99
- "noExtractMentions" : extract_mentions ,
100
- "noExtractHashtags" : extract_hashtags ,
101
- "noExtractEmojis" : extract_emojis ,
102
+ "noExtractMentions" : not extract_mentions ,
103
+ "noExtractHashtags" : not extract_hashtags ,
104
+ "noExtractEmojis" : not extract_emojis ,
102
105
"replyId" : reply_id ,
103
106
"renoteId" : renote_id ,
104
107
"channelId" : channel_id
@@ -122,39 +125,84 @@ async def send(self,
122
125
return Note (RawNote (res ["created_note" ]), state = self .__state )
123
126
124
127
async def delete (self , note_id : Optional [str ] = None ):
128
+ note_id = note_id or self .__note_id
129
+
125
130
data = {"noteId" : note_id }
126
131
res = await self .__http .request (Route ('POST' , '/api/notes/delete' ), json = data , auth = True )
127
132
return bool (res )
128
133
129
- async def create_renote (self , note_id : str ) -> Note :
134
+ async def create_renote (self , note_id : Optional [str ] = None ) -> Note :
135
+ note_id = note_id or self .__note_id
130
136
return await self .send (renote_id = note_id )
131
137
132
- async def create_quote (self , note_id : str ,
133
- content : Optional [str ] = None ,
134
- visibility : str = 'public' ,
135
- visible_user_ids : Optional [List [str ]] = None ,
136
- cw : Optional [str ] = None ,
137
- local_only : bool = False ,
138
- extract_mentions : bool = True ,
139
- extract_hashtags : bool = True ,
140
- extract_emojis : bool = True ,
141
- file_ids = None ,
142
- poll : Optional [Poll ] = None ) -> Note :
138
+ async def create_quote (
139
+ self ,
140
+ content : Optional [str ] = None ,
141
+ visibility : str = 'public' ,
142
+ visible_user_ids : Optional [List [str ]] = None ,
143
+ cw : Optional [str ] = None ,
144
+ local_only : bool = False ,
145
+ extract_mentions : bool = True ,
146
+ extract_hashtags : bool = True ,
147
+ extract_emojis : bool = True ,
148
+ file_ids : Optional [List [str ]] = None ,
149
+ poll : Optional [Poll ] = None ,
150
+ note_id : Optional [str ] = None ,
151
+ ) -> Note :
152
+ """
153
+ Create a note quote.
154
+
155
+ Parameters
156
+ ----------
157
+ content: Optional[str], default=None
158
+ text
159
+ visibility: str, default='public'
160
+ Disclosure range
161
+ visible_user_ids: Optional[List[str]], default=None
162
+ List of users to be published
163
+ cw: Optional[str], default=None
164
+ Text to be displayed when warning is given
165
+ local_only: bool, default=False
166
+ Whether to show only locally or not
167
+ extract_mentions: bool, default=True
168
+ Whether to expand the mention
169
+ extract_hashtags: bool, default=True
170
+ Whether to expand the hashtag
171
+ extract_emojis: bool, default=True
172
+ Whether to expand the emojis
173
+ file_ids: Optional[List[str]], default=None
174
+ The ID list of files to be attached
175
+ poll: Optional[Poll], default=None
176
+ Questionnaire to be created
177
+ note_id: Optional[str], default=None
178
+ Note IDs to target for renote and citations
179
+ """
180
+
181
+ note_id = note_id or self .__note_id
182
+
143
183
return await self .send (content = content , visibility = visibility , visible_user_ids = visible_user_ids , cw = cw ,
144
184
local_only = local_only , extract_mentions = extract_mentions ,
145
185
extract_hashtags = extract_hashtags ,
146
186
extract_emojis = extract_emojis , renote_id = note_id , file_ids = file_ids , poll = poll )
147
187
148
- async def get_note (self , note_id ) -> Note :
188
+ async def get_note (self , note_id : Optional [str ] = None ) -> Note :
189
+ note_id = note_id or self .__note_id
149
190
res = await self .__http .request (Route ('POST' , '/api/notes/show' ), json = {"noteId" : note_id }, auth = True , lower = True )
150
191
return Note (RawNote (res ), state = self .__state )
151
192
152
- async def get_replies (self , note_id : str , since_id : Optional [str ] = None , until_id : Optional [str ] = None ,
153
- limit : int = 10 , ) -> List [Note ]:
193
+ async def get_replies (
194
+ self ,
195
+ since_id : Optional [str ] = None ,
196
+ until_id : Optional [str ] = None ,
197
+ limit : int = 10 ,
198
+ note_id : Optional [str ] = None
199
+ ) -> List [Note ]:
200
+ note_id = note_id or self .__note_id
154
201
res = await self .__http .request (Route ('POST' , '/api/notes/replies' ),
155
202
json = {"noteId" : note_id , "sinceId" : since_id , "untilId" : until_id , "limit" : limit },
156
203
auth = True , lower = True )
157
204
return [Note (RawNote (i ), state = self .__state ) for i in res ]
158
205
159
- def get_reaction (self , note_id : str , reaction : str ):
160
- return ReactionManager (self .__state , self .__http , self .__loop , note_id = note_id )
206
+ async def get_reaction (self , reaction : str , note_id : Optional [str ] = None ) -> List [NoteReaction ]:
207
+ note_id = note_id or self .__note_id
208
+ return await ReactionManager (self .__state , self .__http , self .__loop , note_id = note_id ).get_reaction (reaction )
0 commit comments