MCPcopy Index your code
hub / github.com/wechaty/python-wechaty / on_friendship

Method on_friendship

examples/ding-dong-bot-oop.py:183–211  ·  view source on GitHub ↗

when receive a new friendship application, or accept a new friendship Args: friendship (Friendship): contains the status and friendship info, eg: hello text, friend contact object

(self, friendship: Friendship)

Source from the content-addressed store, hash-verified

181 self.login_user = contact
182
183 async def on_friendship(self, friendship: Friendship) -> None:
184 """when receive a new friendship application, or accept a new friendship
185
186 Args:
187 friendship (Friendship): contains the status and friendship info,
188 eg: hello text, friend contact object
189 """
190 MAX_ROOM_MEMBER_COUNT = 500
191 # 1. receive a new friendship from someone
192 if friendship.type() == FriendshipType.FRIENDSHIP_TYPE_RECEIVE:
193 hello_text: str = friendship.hello()
194
195 # accept friendship when there is a keyword in hello text
196 if 'wechaty' in hello_text.lower():
197 await friendship.accept()
198
199 # 2. you have a new friend to your contact list
200 elif friendship.type() == FriendshipType.FRIENDSHIP_TYPE_CONFIRM:
201 # 2.1 invite the user to wechaty group
202 # find the topic of room which contains Wechaty keyword
203 wechaty_rooms: List[Room] = await self.Room.find_all('Wechaty')
204
205 # 2.2 find the suitable room
206 for wechaty_room in wechaty_rooms:
207 members: List[Contact] = await wechaty_room.member_list()
208 if len(members) < MAX_ROOM_MEMBER_COUNT:
209 contact: Contact = friendship.contact()
210 await wechaty_room.add(contact)
211 break
212
213 async def on_room_join(self, room: Room, invitees: List[Contact],
214 inviter: Contact, date: datetime) -> None:

Callers

nothing calls this directly

Calls 7

helloMethod · 0.80
contactMethod · 0.80
typeMethod · 0.45
acceptMethod · 0.45
find_allMethod · 0.45
member_listMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected