onebot_api/message/
segment_builder.rs

1use super::send_segment::*;
2
3#[derive(Default, Debug, Clone)]
4pub struct SegmentBuilder {
5	segments: Vec<SendSegment>,
6}
7
8impl SegmentBuilder {
9	pub fn new() -> Self {
10		Self::default()
11	}
12
13	pub fn build(self) -> Vec<SendSegment> {
14		self.segments
15	}
16
17	pub fn text(mut self, text: String) -> Self {
18		self.segments.push(SendSegment::Text {
19			data: TextData { text },
20		});
21		self
22	}
23
24	pub fn face(mut self, id: String) -> Self {
25		self.segments.push(SendSegment::Face {
26			data: FaceData { id },
27		});
28		self
29	}
30
31	pub fn image(
32		mut self,
33		file: String,
34		image_type: Option<String>,
35		cache: Option<bool>,
36		proxy: Option<bool>,
37		timeout: Option<bool>,
38	) -> Self {
39		self.segments.push(SendSegment::Image {
40			data: ImageData {
41				file,
42				image_type,
43				cache,
44				proxy,
45				timeout,
46			},
47		});
48		self
49	}
50
51	pub fn record(
52		mut self,
53		file: String,
54		magic: String,
55		cache: Option<bool>,
56		proxy: Option<bool>,
57		timeout: Option<bool>,
58	) -> Self {
59		self.segments.push(SendSegment::Record {
60			data: RecordData {
61				file,
62				magic,
63				cache,
64				proxy,
65				timeout,
66			},
67		});
68		self
69	}
70
71	pub fn video(
72		mut self,
73		file: String,
74		cache: Option<bool>,
75		proxy: Option<bool>,
76		timeout: Option<bool>,
77	) -> Self {
78		self.segments.push(SendSegment::Video {
79			data: VideoData {
80				file,
81				cache,
82				proxy,
83				timeout,
84			},
85		});
86		self
87	}
88
89	pub fn at(mut self, qq: String) -> Self {
90		self.segments.push(SendSegment::At {
91			data: AtData { qq },
92		});
93		self
94	}
95
96	pub fn rps(mut self) -> Self {
97		self.segments.push(SendSegment::Rps { data: RpsData {} });
98		self
99	}
100
101	pub fn dice(mut self) -> Self {
102		self.segments.push(SendSegment::Dice { data: DiceData {} });
103		self
104	}
105
106	pub fn shake(mut self) -> Self {
107		self
108			.segments
109			.push(SendSegment::Shake { data: ShakeData {} });
110		self
111	}
112
113	pub fn poke(mut self, poke_type: String, id: String) -> Self {
114		self.segments.push(SendSegment::Poke {
115			data: PokeData { poke_type, id },
116		});
117		self
118	}
119
120	pub fn anonymous(mut self, ignore: Option<bool>) -> Self {
121		self.segments.push(SendSegment::Anonymous {
122			data: AnonymousData { ignore },
123		});
124		self
125	}
126
127	pub fn share(mut self, url: String, title: String, content: String, image: String) -> Self {
128		self.segments.push(SendSegment::Share {
129			data: ShareData {
130				url,
131				title,
132				content,
133				image,
134			},
135		});
136		self
137	}
138
139	pub fn contact(mut self, contact_type: String, id: String) -> Self {
140		self.segments.push(SendSegment::Contact {
141			data: ContactData { contact_type, id },
142		});
143		self
144	}
145
146	pub fn contact_qq(self, id: String) -> Self {
147		self.contact("qq".to_string(), id)
148	}
149
150	pub fn contact_group(self, id: String) -> Self {
151		self.contact("group".to_string(), id)
152	}
153
154	pub fn location(
155		mut self,
156		lat: String,
157		lon: String,
158		title: Option<String>,
159		content: Option<String>,
160	) -> Self {
161		self.segments.push(SendSegment::Location {
162			data: LocationData {
163				lat,
164				lon,
165				title,
166				content,
167			},
168		});
169		self
170	}
171
172	#[allow(clippy::too_many_arguments)]
173	pub fn music(
174		mut self,
175		music_type: String,
176		id: Option<String>,
177		url: Option<String>,
178		audio: Option<String>,
179		title: Option<String>,
180		content: Option<String>,
181		image: Option<String>,
182	) -> Self {
183		self.segments.push(SendSegment::Music {
184			data: MusicData {
185				music_type,
186				id,
187				url,
188				audio,
189				title,
190				content,
191				image,
192			},
193		});
194		self
195	}
196
197	pub fn music_typed(self, music_type: String, id: String) -> Self {
198		self.music(music_type, Some(id), None, None, None, None, None)
199	}
200
201	pub fn music_qq(self, id: String) -> Self {
202		self.music_typed("qq".to_string(), id)
203	}
204
205	pub fn music_163(self, id: String) -> Self {
206		self.music_typed("163".to_string(), id)
207	}
208
209	pub fn music_xm(self, id: String) -> Self {
210		self.music_typed("xm".to_string(), id)
211	}
212
213	pub fn music_custom(
214		self,
215		url: String,
216		audio: String,
217		title: String,
218		content: String,
219		image: String,
220	) -> Self {
221		self.music(
222			"custom".to_string(),
223			None,
224			Some(url),
225			Some(audio),
226			Some(title),
227			Some(content),
228			Some(image),
229		)
230	}
231
232	pub fn reply(mut self, id: String) -> Self {
233		self.segments.push(SendSegment::Reply {
234			data: ReplyData { id },
235		});
236		self
237	}
238
239	pub fn forward(mut self) -> Self {
240		self.segments.push(SendSegment::Forward {
241			data: ForwardData {},
242		});
243		self
244	}
245
246	pub fn node(
247		mut self,
248		id: Option<String>,
249		user_id: Option<String>,
250		nickname: Option<String>,
251		content: Option<Vec<SendSegment>>,
252	) -> Self {
253		self.segments.push(SendSegment::Node {
254			data: NodeData {
255				id,
256				user_id,
257				nickname,
258				content,
259			},
260		});
261		self
262	}
263
264	pub fn node_forward(self, id: String) -> Self {
265		self.node(Some(id), None, None, None)
266	}
267
268	pub fn node_custom(self, user_id: String, nickname: String, content: Vec<SendSegment>) -> Self {
269		self.node(None, Some(user_id), Some(nickname), Some(content))
270	}
271
272	pub fn xml(mut self, data: String) -> Self {
273		self.segments.push(SendSegment::Xml {
274			data: XmlData { data },
275		});
276		self
277	}
278
279	pub fn json(mut self, data: String) -> Self {
280		self.segments.push(SendSegment::Json {
281			data: JsonData { data },
282		});
283		self
284	}
285}