Skip to content
This repository was archived by the owner on May 28, 2022. It is now read-only.

Commit 44bc66a

Browse files
committed
Merge branch 'release/v3.2.0'
2 parents 8180ec3 + 5579645 commit 44bc66a

File tree

8 files changed

+143
-80
lines changed

8 files changed

+143
-80
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v3.2.0] 2022-01-24
11+
12+
### Added
13+
14+
- type hint
15+
16+
### Fixed
17+
18+
- 以下のNoteクラスのメソッドでnote_idが必須になっていたのを修正
19+
- `add_clips`
20+
- `create_renote`
21+
- `create_quote`
22+
- `get_note`
23+
- `get_replies`
24+
- `get_reaction`
25+
- `delete`
26+
- 以下の引数が正常な動作になりました
27+
- `noExtractMentions`
28+
- `noExtractHashtags`
29+
- `noExtractEmojis`
30+
1031
## [v3.1.0] 2022-01-23
1132

1233
### Added

docs/mi.rst

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,13 @@ User
7272
:members:
7373

7474
Chat
75-
~~~~~~~~~~~~
75+
~~~~
7676

7777
.. attributetable:: Chat
7878

7979
.. autoclass:: Chat()
8080
:members:
8181

82-
Drive
83-
~~~~~
84-
85-
.. attributetable:: Drive
86-
87-
.. autoclass:: Drive()
88-
:members:
89-
9082
Emoji
9183
~~~~~
9284

@@ -135,9 +127,9 @@ Properties
135127
File
136128
~~~~
137129

138-
.. attributetable:: Header
130+
.. attributetable:: File
139131

140-
.. autoclass:: Header()
132+
.. autoclass:: File()
141133
:members:
142134

143135
Reaction

mi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__copyright__ = "Copyright 2021-present yupix"
55
__author_email__ = "[email protected]"
66
__url__ = "https://github.com/yupix/Mi.py"
7-
__version__ = "3.1.0"
7+
__version__ = "3.2.0"
88

99
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1010

mi/actions/note.py

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from mi.api.favorite import FavoriteManager
77
from mi.api.reaction import ReactionManager
88
from mi.exception import ContentRequired
9+
from mi.http import HTTPClient, Route
910
from mi.models.note import RawNote
10-
from mi.note import Note, Poll
11+
from mi.note import Note, NoteReaction, Poll
1112
from mi.utils import check_multi_arg, remove_dict_empty
12-
from mi.http import HTTPClient, Route
1313

1414
if TYPE_CHECKING:
1515
from mi.state import ConnectionState
@@ -23,10 +23,13 @@ def __init__(self, state: 'ConnectionState', http: HTTPClient, loop: asyncio.Abs
2323
self.__state = state
2424
self.__http = http
2525
self.__loop = loop
26+
self.__note_id: Optional[str] = note_id
2627
self.favorite = FavoriteManager(state, http, loop, note_id=note_id)
2728
self.reaction = ReactionManager(state, http, loop, note_id=note_id)
2829

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+
3033
data = {'noteId': note_id, 'clipId': clip_id}
3134
return bool(await self.__http.request(Route('POST', '/api/clips/add-note'), json=data, auth=True))
3235

@@ -96,9 +99,9 @@ async def send(self,
9699
"text": content,
97100
"cw": cw,
98101
"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,
102105
"replyId": reply_id,
103106
"renoteId": renote_id,
104107
"channelId": channel_id
@@ -122,39 +125,84 @@ async def send(self,
122125
return Note(RawNote(res["created_note"]), state=self.__state)
123126

124127
async def delete(self, note_id: Optional[str] = None):
128+
note_id = note_id or self.__note_id
129+
125130
data = {"noteId": note_id}
126131
res = await self.__http.request(Route('POST', '/api/notes/delete'), json=data, auth=True)
127132
return bool(res)
128133

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
130136
return await self.send(renote_id=note_id)
131137

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+
143183
return await self.send(content=content, visibility=visibility, visible_user_ids=visible_user_ids, cw=cw,
144184
local_only=local_only, extract_mentions=extract_mentions,
145185
extract_hashtags=extract_hashtags,
146186
extract_emojis=extract_emojis, renote_id=note_id, file_ids=file_ids, poll=poll)
147187

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
149190
res = await self.__http.request(Route('POST', '/api/notes/show'), json={"noteId": note_id}, auth=True, lower=True)
150191
return Note(RawNote(res), state=self.__state)
151192

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
154201
res = await self.__http.request(Route('POST', '/api/notes/replies'),
155202
json={"noteId": note_id, "sinceId": since_id, "untilId": until_id, "limit": limit},
156203
auth=True, lower=True)
157204
return [Note(RawNote(i), state=self.__state) for i in res]
158205

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)

mi/api/reaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def remove(self, note_id: Optional[str] = None) -> bool:
4949
data = remove_dict_empty({"noteId": note_id})
5050
return bool(await self.http.request(Route('POST', '/api/notes/reactions/delete'), json=data, auth=True, lower=True))
5151

52-
async def get_reaction(self, reaction: str, note_id: Optional[str] = None, *, limit: int = 11):
52+
async def get_reaction(self, reaction: str, note_id: Optional[str] = None, *, limit: int = 11) -> List[NoteReaction]:
5353
note_id = note_id or self.__note_id
5454
data = remove_dict_empty({"noteId": note_id, 'limit': limit, 'type': reaction})
5555
res = await self.http.request(Route('POST', '/api/notes/reactions'), json=data, auth=True, lower=True)

mi/models/note.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ def __init__(self, data: Note):
5252
self.cw: Optional[str] = data.get("cw")
5353
self.renote: Optional[RawRenote] = RawRenote(data['renote']) if data.get('renote') else None
5454
self.visibility: Optional[str] = data.get("visibility") # This may be an optional
55-
self.renote_count: int = data["renote_count"]
56-
self.replies_count: int = data["replies_count"]
57-
self.reactions: Dict[str, Any] = data["reactions"]
55+
self.renote_count: Optional[int] = data.get("renote_count") # TODO: Optionalかどうか
56+
self.replies_count: Optional[int] = data.get("replies_count") # TODO: Optionalかどうか
57+
self.reactions: Optional[Dict[str, Any]] = data["reactions"] # TODO: Optionalかどうか
5858
self.emojis: List[RawEmoji] = [RawEmoji(i) for i in data["emojis"]]
5959
self.file_ids: Optional[List[str]] = data["file_ids"]
6060
self.files: List[RawFile] = [RawFile(upper_to_lower(i)) for i in data["files"]]
6161
self.reply_id: Optional[str] = data["reply_id"]
6262
self.renote_id: Optional[str] = data["renote_id"]
6363
self.poll: Optional[RawPoll] = RawPoll(data["poll"]) if data.get("poll") else None
6464
self.visible_user_ids: Optional[List[str]] = data.get("visible_user_ids", [])
65-
self.via_mobile: Optional[bool] = data.get("via_mobile", False)
65+
self.via_mobile: bool = bool(data.get("via_mobile", False))
6666
self.local_only: bool = bool(data.get("local_only", False))
6767
self.extract_mentions: bool = bool(data.get("extract_mentions"))
6868
self.extract_hashtags: bool = bool(data.get("extract_hashtags"))
6969
self.extract_emojis: bool = bool(data.get("extract_emojis"))
70-
self.preview: Optional[bool] = data.get("preview")
70+
self.preview: bool = bool(data.get("preview"))
7171
self.media_ids: Optional[List[str]] = data.get("media_ids")
7272
self.field: Optional[dict] = {}
7373
self.tags: Optional[List[str]] = data.get("tags", [])

0 commit comments

Comments
 (0)