2
2
title : Friendship
3
3
---
4
4
5
- 发送、接收好友请求和好友确认事件。
5
+ # class Friendship()
6
+ > 发送、接收好友请求和好友确认事件。
7
+ > [ 示例/Friend-Bot] ( https://github.com/wechaty/python-wechaty-getting-started/blob/master/examples/advanced/friendship-bot.py )
6
8
7
- ## Friendship
8
9
9
- 发送、接收好友请求和好友确认事件。
10
+ ::: wechaty.user.friendship.Friendship.search
10
11
11
- 1 . 发送请求
12
- 2 . 接收请求\( in friend event\)
13
- 3 . 接受请求\( friend event\)
14
-
15
- [ 示例/Friend-Bot] ( https://github.com/wechaty/python-wechaty-getting-started/blob/master/examples/advanced/friendship-bot.py )
16
-
17
- ** 类型** : 全局类
18
-
19
- * [ Friendship] ( friendship.md#Friendship )
20
- * _ 实例方法_
21
- * [ .accept\(\) ] ( friendship.md#Friendship+accept ) ⇒ ` None `
22
- * [ .hello\(\) ] ( friendship.md#Friendship+hello ) ⇒ ` str `
23
- * [ .contact\(\) ] ( friendship.md#Friendship+contact ) ⇒ ` Contact `
24
- * [ .type\(\) ] ( friendship.md#Friendship+type ) ⇒ ` FriendshipType `
25
- * _ 静态方法_
26
- * [ ~~ .send\(\) ~~ ] ( friendship.md#Friendship.send )
27
- * [ .add\( contact, hello\) ] ( friendship.md#Friendship.add ) ⇒ ` None `
28
-
29
- ### friendship.accept\(\) ⇒ ` None `
30
-
31
- 接受朋友请求
32
-
33
- ** 类型** : [ ` Friendship ` ] ( friendship.md#Friendship ) 的实例方法
34
-
35
- #### 示例
12
+ ::: wechaty.user.friendship.Friendship.add
13
+ ### 示例代码
14
+ ``` python
15
+ memberList = await room.memberList()
16
+ for member in memberList:
17
+ await bot.Friendship.add(member, ' Nice to meet you! I am wechaty bot!' )
18
+ ```
36
19
20
+ ::: wechaty.user.friendship.Friendship.contact
21
+ ### 示例代码
37
22
``` python
38
23
import asyncio
39
24
from wechaty import Wechaty, Friendship
@@ -44,97 +29,45 @@ class MyBot(Wechaty):
44
29
async on_friendship(self , friendship: Friendship) -> None :
45
30
contact = friendship.contact()
46
31
await contact.ready()
47
-
48
- if friendship.type() == FriendshipType.FRIENDSHIP_TYPE_RECEIVE :
49
- log_msg = ' accepted automatically'
50
- await friendship.accept()
51
- # if want to send msg, you need to delay sometimes
52
-
53
- print (' waiting to send message ...' )
54
- await asyncio.sleep(3 )
55
- await contact.say(' hello from wechaty ...' )
56
- print (' after accept ...' )
57
- elif friendship.type() == FriendshipType.FRIENDSHIP_TYPE_CONFIRM :
58
- log_msg = ' friend ship confirmed with ' + contact.name
59
-
32
+ log_msg = f ' receive "friendship" message from { contact.name} '
60
33
print (log_msg)
61
34
35
+
62
36
asyncio.run(MyBot().start())
63
37
```
64
38
65
- ### friendship.hello\(\) ⇒ ` str `
66
-
67
- Get verify message from
68
-
69
- ** 类型** : [ ` Friendship ` ] ( friendship.md#Friendship ) 的实例方法
70
-
71
- ** 示例**
72
-
73
- _ \( If request content is \` ding\` , then accept the friendship\) _
74
-
39
+ ::: wechaty.user.friendship.Friendship.accept
40
+ ### 示例代码
75
41
``` python
76
42
import asyncio
77
43
from wechaty import Wechaty, Friendship
78
44
79
-
80
45
class MyBot (Wechaty ):
81
46
82
47
async on_friendship(self , friendship: Friendship) -> None :
83
48
contact = friendship.contact()
84
49
await contact.ready()
85
50
86
- if friendship.type() == FriendshipType.FRIENDSHIP_TYPE_RECEIVE and friendship.hello() == ' ding ' :
87
- log_msg = ' accepted automatically because verify messsage is "ding" '
51
+ if friendship.type() == FriendshipType.FRIENDSHIP_TYPE_RECEIVE :
52
+ log_msg = ' accepted automatically'
88
53
await friendship.accept()
89
54
# if want to send msg, you need to delay sometimes
90
55
91
56
print (' waiting to send message ...' )
92
57
await asyncio.sleep(3 )
93
58
await contact.say(' hello from wechaty ...' )
94
59
print (' after accept ...' )
60
+ elif friendship.type() == FriendshipType.FRIENDSHIP_TYPE_CONFIRM :
61
+ log_msg = ' friend ship confirmed with ' + contact.name
95
62
96
- asyncio.run(MyBot().start())
97
- ```
98
-
99
- ### friendship.contact\(\) ⇒ ` Contact `
100
-
101
- 获取邀请的联系人对象
102
-
103
- ** 类型** : [ ` Friendship ` ] ( friendship.md#Friendship ) 的实例方法
104
-
105
- #### 示例
106
-
107
- ``` python
108
- import asyncio
109
- from wechaty import Wechaty, Friendship
110
-
111
-
112
- class MyBot (Wechaty ):
113
-
114
- async on_friendship(self , friendship: Friendship) -> None :
115
- contact = friendship.contact()
116
- await contact.ready()
117
- log_msg = f ' receive "friendship" message from { contact.name} '
118
63
print (log_msg)
119
64
120
-
121
65
asyncio.run(MyBot().start())
122
66
```
123
67
124
- ### friendship.type\(\) ⇒ ` FriendshipType `
125
-
126
- 返回Friendship请求的类型
127
-
128
- > 提示: FriendshipType在这里是枚举类型. < ; /br> ;
129
- >
130
- > * FriendshipType.FriendshipTypeFRIENDSHIP_TYPE_UNSPECIFIED
131
- > * FriendshipType.FRIENDSHIP_TYPE_CONFIRM
132
- > * FriendshipType.FRIENDSHIP_TYPE_RECEIVE
133
- > * FriendshipType.FRIENDSHIP_TYPE_VERIFY
134
-
135
- ** 类型** : [ ` Friendship ` ] ( friendship.md#Friendship ) 的实例方法
136
-
137
- ** 示例** _ \( If request content is \` ding\` , then accept the friendship\) _
68
+ ::: wechaty.user.friendship.Friendship.hello
69
+ ### 示例代码
70
+ > 自动接受好友请求中包含消息为 ` ding ` 的好友请求
138
71
139
72
``` python
140
73
import asyncio
@@ -160,32 +93,6 @@ class MyBot(Wechaty):
160
93
asyncio.run(MyBot().start())
161
94
```
162
95
163
- ### ~~ Friendship.send\(\) ~~
164
-
165
- _ ** 已弃用** _
166
-
167
- 请使用[ Friendship\# add] ( friendship.md#friendship-add-contact-hello-promise )
168
-
169
- ** 类型** : [ ` Friendship ` ] ( friendship.md#Friendship ) 的静态方法
170
-
171
- ### Friendship.add\( contact, hello\) ⇒ ` Promise <void> `
172
-
173
- Send a Friend Request to a ` contact ` with message ` hello ` .
174
-
175
- The best practice is to send friend request once per minute. Remeber not to do this too frequently, or your account may be blocked.
96
+ ::: wechaty.user.friendship.Friendship.type
176
97
177
- ** 类型** : [ ` Friendship ` ] ( friendship.md#Friendship ) 的静态方法
178
-
179
- | 参数 | 类型 | 描述 |
180
- | :--- | :--- | :--- |
181
- | contact | ` Contact ` | Send friend request to contact |
182
- | hello | ` string ` | The friend request content |
183
-
184
- #### Example
185
-
186
- ``` python
187
- memberList = await room.memberList()
188
- for member in memberList:
189
- await bot.Friendship.add(member, ' Nice to meet you! I am wechaty bot!' )
190
-
191
- ```
98
+ ::: wechaty.user.friendship.Friendship.from_json
0 commit comments