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

Commit dd66dd7

Browse files
authored
Merge pull request #75 from yupix/v1.0.2
v1.0.2
2 parents 186ecf9 + 565d781 commit dd66dd7

File tree

6 files changed

+75
-19
lines changed

6 files changed

+75
-19
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
## [v1.0.2] 2021-12-24
11+
1012
### Added
1113

12-
- add event `on_mention`
13-
- add `favorite`, `add_to_clips`, `add_reaction` and `remove_favorite` method to `Note` class
14-
- add `favorite`, `add_note_to_clips`, `add_reaction_to_note` and `remove_favorite` method to `NoteAction` class
15-
- add class
16-
- NoteActions
17-
- ClientAction
14+
- add event `on_follow` and `follow_request`
15+
- add a new `Following` and `UserAction` class
16+
- add `accept_request` and `reject_request` method to `Following` class
17+
- add `accept_following_request` and `reject_following_request` method to `UserAction` class
1818

1919
### Fixed
2020

21-
- fixed a bug where json arguments were replaced with data in requests.
21+
- Fixed a problem where renote would say the key was missing.
2222

2323
## [v1.0.1] 2021-12-24
2424

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__ = "1.0.1"
7+
__version__ = "1.0.2"
88

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

mi/http.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import aiohttp
88

99
from mi.gateway import MisskeyClientWebSocketResponse
10-
from mi.utils import upper_to_lower
10+
from mi.utils import remove_dict_empty, upper_to_lower
1111
from . import __version__, config, exception
1212

1313

@@ -75,6 +75,10 @@ async def request(self, route: Route, *, files=None, form=None, **kwargs) -> Any
7575
kwargs[key] = {}
7676
kwargs[key]['i'] = self.token
7777

78+
for i in ('json', 'data'):
79+
if kwargs.get(i):
80+
kwargs[i] = remove_dict_empty(kwargs[i])
81+
7882
async with self.__session.request(route.method, route.url, **kwargs) as res:
7983
data = await json_or_text(res)
8084
if is_lower:

mi/state.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from mi.http import Route
1515
from mi.iterators import InstanceIterator
1616
from mi.note import Note, Poll, Reaction
17-
from mi.user import Follower
17+
from mi.user import Follower, Following
1818
from mi.emoji import Emoji
1919
from mi.utils import check_multi_arg, get_cache_key, get_module_logger, key_builder, remove_dict_empty, str_lower, \
2020
upper_to_lower
@@ -46,7 +46,21 @@ async def add_reaction_to_note(self, note_id: str, reaction: str) -> bool:
4646
return bool(await self.http.request(Route('POST', '/api/reactions/create', json=data, auth=True)))
4747

4848

49-
class ClientAction(NoteActions):
49+
class UserAction:
50+
def __init__(self, http: HTTPClient, loop: asyncio.AbstractEventLoop):
51+
self.http = http
52+
self.loop = loop
53+
54+
async def accept_following_request(self, user_id: str) -> bool:
55+
data = {'userId': user_id}
56+
return bool(await self.http.request(Route('POST', '/api/following/requests/accept'), json=data, auth=True))
57+
58+
async def reject_following_request(self, user_id: str) -> bool:
59+
data = {'userId': user_id}
60+
return bool(await self.http.request(Route('POST', '/api/following/requests/reject'), json=data, auth=True))
61+
62+
63+
class ClientAction(NoteActions, UserAction):
5064
pass
5165

5266

@@ -85,6 +99,21 @@ def parse_channel(self, message: Dict[str, Any]) -> None:
8599
def parse_renote(self, message: Dict[str, Any]):
86100
pass
87101

102+
def parse_unfollow(self, message: Dict[str, Any]):
103+
"""
104+
フォローを解除した際のイベントを解析する関数
105+
"""
106+
107+
def parse_receive_follow_request(self, message: Dict[str, Any]):
108+
"""
109+
フォローリクエストを受け取った際のイベントを解析する関数
110+
"""
111+
112+
self.dispatch('follow_request', Following(message, state=self))
113+
114+
def parse_me_updated(self, message: Dict[str, Any]):
115+
pass
116+
88117
def parse_read_all_announcements(self, message: Dict[str, Any]) -> None:
89118
pass # TODO: 実装
90119

@@ -105,7 +134,8 @@ def parse_followed(self, message: Dict[str, Any]) -> None:
105134
"""
106135
フォローイベントを解析する関数
107136
"""
108-
# self.dispatch('follow', Follower(message, state=self))
137+
138+
self.dispatch('follow', User(message, state=self))
109139

110140
def parse_mention(self, message: Dict[str, Any]) -> None:
111141
"""
@@ -159,8 +189,8 @@ def parse_notification(self, message: Dict[str, Any]) -> None:
159189
-------
160190
None
161191
"""
162-
notification_type = str_lower(message['type'])
163-
getattr(self, f'parse_{notification_type}')(message)
192+
#notification_type = str_lower(message['type'])
193+
#getattr(self, f'parse_{notification_type}')(message)
164194

165195
def parse_follow_request_accepted(self, message: Dict[str, Any]) -> None:
166196
pass
@@ -177,8 +207,8 @@ def parse_unread_notification(self, message: Dict[str, Any]) -> None:
177207
message : Dict[str, Any]
178208
Received message
179209
"""
180-
notification_type = str_lower(message['type'])
181-
getattr(self, f'parse_{notification_type}')(message)
210+
#notification_type = str_lower(message['type'])
211+
#getattr(self, f'parse_{notification_type}')(message)
182212

183213
def parse_reaction(self, message: Dict[str, Any]) -> None:
184214
"""
@@ -385,7 +415,7 @@ async def fetch_user(self, user_id: Optional[str] = None, username: Optional[str
385415
return User(data, state=self)
386416

387417
async def post_note(self,
388-
content: Optional[str],
418+
content: Optional[str] = None,
389419
visibility: str = "public",
390420
visible_user_ids: Optional[List[str]] = None,
391421
cw: Optional[str] = None,

mi/user.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if TYPE_CHECKING:
1111
from mi import ConnectionState
1212

13-
__all__ = ['User', 'UserDetails']
13+
__all__ = ['User', 'UserDetails', 'Following']
1414

1515

1616
class Follower:
@@ -22,6 +22,28 @@ def __init__(self, data, state: ConnectionState):
2222
self.user: User = User(data['follower'], state=state)
2323
self._state = state
2424

25+
class Following:
26+
def __init__(self, data, state:ConnectionState):
27+
self.id = data['id']
28+
self.name = data['name']
29+
self.username = data['username']
30+
self.host = data['host']
31+
self.avatar_url = data['avatar_url']
32+
self.avatar_blurhash = data['avatar_blurhash']
33+
self.avatar_color = data['avatar_color']
34+
self.emojis = data['emojis']
35+
self.online_status = data['online_status']
36+
self.is_admin = bool(data['is_admin'])
37+
self.is_bot = bool(data['is_bot'])
38+
self.is_cat = bool(data['is_cat'])
39+
self._state = state
40+
41+
async def accept_request(self) -> bool:
42+
return await self._state.accept_following_request(self.id)
43+
44+
async def reject_request(self) -> bool:
45+
return await self._state.reject_following_request(self.id)
46+
2547

2648
class Channel(BaseModel):
2749
id: Optional[str] = None

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
setup(
3636
name="mi.py",
37-
version="1.0.1",
37+
version="1.0.2",
3838
install_requires=["pydantic", "emoji", 'aiocache', 'aiohttp'],
3939
url="https://github.com/yupix/mi.py",
4040
author="yupix",

0 commit comments

Comments
 (0)