1use kovi::Message;
2use kovi::bot::runtimebot::{RuntimeBot, send_api_request_with_response};
3use kovi::bot::{ApiReturn, SendApi};
4use kovi::serde_json::{self, json};
5use kovi_onebot::onebot_message::OneBotSegment;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct InvitedRequest {
19 pub request_id: i64,
20 pub invitor_uin: i64,
21 pub invitor_nick: String,
22 pub group_id: i64,
23 pub group_name: String,
24 pub checked: bool,
25 pub actor: i64,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct JoinRequest {
30 pub request_id: i64,
31 pub requester_uin: i64,
32 pub requester_nick: String,
33 pub message: String,
34 pub group_id: i64,
35 pub group_name: String,
36 pub checked: bool,
37 pub actor: i64,
38}
39
40impl InvitedRequest {
41 pub fn new(
42 request_id: i64,
43 invitor_uin: i64,
44 invitor_nick: String,
45 group_id: i64,
46 group_name: String,
47 checked: bool,
48 actor: i64,
49 ) -> Self {
50 Self {
51 request_id,
52 invitor_uin,
53 invitor_nick,
54 group_id,
55 group_name,
56 checked,
57 actor,
58 }
59 }
60}
61
62impl JoinRequest {
63 #[allow(clippy::too_many_arguments)]
64 pub fn new(
65 request_id: i64,
66 requester_uin: i64,
67 requester_nick: String,
68 message: String,
69 group_id: i64,
70 group_name: String,
71 checked: bool,
72 actor: i64,
73 ) -> Self {
74 Self {
75 request_id,
76 requester_uin,
77 requester_nick,
78 message,
79 group_id,
80 group_name,
81 checked,
82 actor,
83 }
84 }
85}
86
87pub trait NapCatApi {
88 fn set_qq_profile(
89 &self,
90 nickname: &str,
91 company: &str,
92 email: &str,
93 college: &str,
94 personal_note: &str,
95 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
96
97 fn get_online_clients(
98 &self,
99 no_cache: bool,
100 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
101
102 fn mark_msg_as_read(
103 &self,
104 message_id: i64,
105 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
106
107 fn send_group_forward_msg(
108 &self,
109 group_id: i64,
110 nodes: Vec<Node>,
111 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
112
113 fn send_private_forward_msg(
114 &self,
115 user_id: i64,
116 nodes: Vec<Node>,
117 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
118
119 fn get_group_msg_history(
120 &self,
121 group_id: i64,
122 message_seq: Option<i64>,
123 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
124
125 fn ocr_image(
126 &self,
127 image: &str,
128 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
129
130 fn get_group_system_msg(
131 &self,
132 invited_requests: Vec<InvitedRequest>,
133 join_requests: Vec<JoinRequest>,
134 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
135
136 fn get_essence_msg_list(
137 &self,
138 group_id: i64,
139 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
140
141 fn set_group_portrait(
142 &self,
143 group_id: i64,
144 file: &str,
145 cache: bool,
146 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
147
148 fn set_essence_msg(
149 &self,
150 message_id: i64,
151 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
152
153 fn delete_essence_msg(
154 &self,
155 message_id: i64,
156 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
157
158 fn set_group_sign(
159 &self,
160 group_id: i64,
161 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
162
163 fn send_group_notice(
164 &self,
165 group_id: i64,
166 content: &str,
167 image: Option<&str>,
168 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
169
170 fn get_group_notice(
171 &self,
172 group_id: i64,
173 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
174
175 fn upload_group_file(
176 &self,
177 group_id: i64,
178 file: &str,
179 name: &str,
180 folder: Option<&str>,
181 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
182
183 fn delete_group_file(
184 &self,
185 group_id: i64,
186 file_id: &str,
187 busid: i64,
188 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
189
190 fn create_group_file_folder(
191 &self,
192 group_id: i64,
193 name: &str,
194 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
195
196 fn delete_group_folder(
197 &self,
198 group_id: i64,
199 folder_id: &str,
200 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
201
202 fn get_group_file_system_info(
203 &self,
204 group_id: i64,
205 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
206
207 fn get_group_root_files(
208 &self,
209 group_id: i64,
210 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
211
212 fn get_group_files_by_folder(
213 &self,
214 group_id: i64,
215 folder_id: &str,
216 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
217
218 fn get_group_file_url(
219 &self,
220 group_id: i64,
221 file_id: &str,
222 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
223
224 fn upload_private_file(
225 &self,
226 user_id: i64,
227 file: &str,
228 name: &str,
229 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
230
231 fn download_file(
232 &self,
233 url: &str,
234 thread_count: i64,
235 headers: Vec<String>,
236 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
237
238 fn ark_share_peer(
239 &self,
240 user_id: Option<&str>,
241 phone_number: Option<&str>,
242 group_id: Option<&str>,
243 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
244
245 fn ark_share_group(
246 &self,
247 group_id: &str,
248 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
249
250 fn get_robot_uin_range(
251 &self,
252 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
253
254 fn set_online_status(
255 &self,
256 status: i64,
257 ext_status: i64,
258 battery_status: i64,
259 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
260
261 fn get_friends_with_category(
262 &self,
263 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
264
265 fn set_qq_avatar(
266 &self,
267 file: &str,
268 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
269
270 fn get_file(
271 &self,
272 file_id: &str,
273 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
274
275 fn forward_friend_single_msg(
276 &self,
277 user_id: i64,
278 message: Vec<Node>,
279 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
280
281 fn forward_group_single_msg(
282 &self,
283 group_id: i64,
284 message: Vec<Node>,
285 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
286
287 fn set_msg_emoji_like(
288 &self,
289 message_id: i64,
290 emoji_id: &str,
291 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
292
293 fn translate_en2zh(
294 &self,
295 words: Vec<String>,
296 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
297
298 fn send_forward_msg(
299 &self,
300 message_type: &str,
301 user_id: Option<i64>,
302 group_id: Option<i64>,
303 message: Vec<Node>,
304 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
305
306 fn send_forward_msg_to_user(
307 &self,
308 user_id: i64,
309 message: Vec<Node>,
310 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
311
312 fn send_forward_msg_to_group(
313 &self,
314 group_id: i64,
315 message: Vec<Node>,
316 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
317
318 fn mark_private_msg_as_read(
319 &self,
320 user_id: i64,
321 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
322
323 fn mark_group_msg_as_read(
324 &self,
325 group_id: i64,
326 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
327
328 fn get_friend_msg_history(
329 &self,
330 user_id: i64,
331 message_seq: &str,
332 count: i64,
333 reverse_order: bool,
334 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
335
336 fn create_collection(
337 &self,
338 brief: &str,
339 raw_data: &str,
340 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
341
342 fn set_self_longnick(
345 &self,
346 long_nick: &str,
347 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
348
349 fn get_friend_list(
358 &self,
359 no_cache: bool,
360 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
361
362 fn get_recent_contact(
363 &self,
364 count: i64,
365 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
366
367 fn mark_all_as_read(
368 &self,
369 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
370
371 fn get_profile_like(
372 &self,
373 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
374
375 fn fetch_custom_face(
376 &self,
377 message_id: i64,
378 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
379
380 fn fetch_emoji_like(
381 &self,
382 message_id: i64,
383 emoji_id: &str,
384 emoji_type: &str,
385 group_id: Option<i64>,
386 user_id: Option<i64>,
387 count: Option<i64>,
388 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
389
390 fn get_group_info_ex(
393 &self,
394 group_id: &str,
395 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
396
397 fn _del_group_notice(
400 &self,
401 group_id: &str,
402 notice_id: &str,
403 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
404
405 fn friend_poke(
408 &self,
409 user_id: i64,
410 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
411
412 fn group_poke(
413 &self,
414 group_id: i64,
415 user_id: i64,
416 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
417
418 fn nc_get_packet_status(
419 &self,
420 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
421
422 fn nc_get_user_status(
423 &self,
424 user_id: i64,
425 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
426
427 fn nc_get_rkey(&self)
428 -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
429
430 fn get_group_shut_list(
431 &self,
432 group_id: i64,
433 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send;
434}
435
436impl NapCatApi for RuntimeBot {
437 fn nc_get_user_status(
438 &self,
439 user_id: i64,
440 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
441 let send_api = SendApi::new(
442 "nc_get_user_status",
443 json!({
444 "user_id": user_id,
445 }),
446 );
447
448 send_api_request_with_response(&self.api_tx, send_api)
449 }
450
451 fn nc_get_rkey(
452 &self,
453 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
454 let send_api = SendApi::new("nc_get_rkey", json!({}));
455
456 send_api_request_with_response(&self.api_tx, send_api)
457 }
458
459 fn nc_get_packet_status(
460 &self,
461 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
462 let send_api = SendApi::new("nc_get_packet_status", json!({}));
463
464 send_api_request_with_response(&self.api_tx, send_api)
465 }
466
467 fn get_group_shut_list(
468 &self,
469 group_id: i64,
470 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
471 let send_api = SendApi::new(
472 "get_group_shut_list",
473 json!({
474 "group_id": group_id,
475 }),
476 );
477
478 send_api_request_with_response(&self.api_tx, send_api)
479 }
480
481 fn _del_group_notice(
482 &self,
483 group_id: &str,
484 notice_id: &str,
485 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
486 let send_api = SendApi::new(
487 "_del_group_notice",
488 json!({
489 "group_id": group_id,
490 "notice_id": notice_id,
491 }),
492 );
493
494 send_api_request_with_response(&self.api_tx, send_api)
495 }
496
497 fn get_friend_list(
498 &self,
499 no_cache: bool,
500 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
501 let send_api = SendApi::new(
502 "get_friend_list",
503 json!({
504 "no_cache": no_cache,
505 }),
506 );
507
508 send_api_request_with_response(&self.api_tx, send_api)
509 }
510
511 fn fetch_emoji_like(
512 &self,
513 message_id: i64,
514 emoji_id: &str,
515 emoji_type: &str,
516 group_id: Option<i64>,
517 user_id: Option<i64>,
518 count: Option<i64>,
519 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
520 let mut map = serde_json::Map::new();
521
522 map.insert("message_id".to_string(), json!(message_id));
523 map.insert("emojiId".to_string(), json!(emoji_id));
524 map.insert("emojiType".to_string(), json!(emoji_type));
525
526 if let Some(gid) = group_id {
527 map.insert("group_id".to_string(), json!(gid));
528 }
529
530 if let Some(uid) = user_id {
531 map.insert("user_id".to_string(), json!(uid));
532 }
533
534 if let Some(i) = count {
535 map.insert("count".to_string(), json!(i));
536 }
537
538 let send_api = SendApi::new("send_forward_msg", serde_json::Value::Object(map));
539
540 send_api_request_with_response(&self.api_tx, send_api)
541 }
542
543 fn create_collection(
544 &self,
545 brief: &str,
546 raw_data: &str,
547 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
548 let send_api = SendApi::new(
549 "create_collection",
550 json!({
551 "brief": brief,
552 "rawData": raw_data,
553 }),
554 );
555
556 send_api_request_with_response(&self.api_tx, send_api)
557 }
558
559 fn get_group_info_ex(
560 &self,
561 group_id: &str,
562 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
563 {
564 let send_api = SendApi::new(
565 "get_group_info_ex",
566 json!({
567 "group_id": group_id
568 }),
569 );
570
571 send_api_request_with_response(&self.api_tx, send_api)
572 }
573 }
574
575 fn friend_poke(
576 &self,
577 user_id: i64,
578 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
579 let send_api = SendApi::new(
580 "friend_poke",
581 json!({
582 "user_id": user_id,
583 }),
584 );
585
586 send_api_request_with_response(&self.api_tx, send_api)
587 }
588
589 fn group_poke(
590 &self,
591 group_id: i64,
592 user_id: i64,
593 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
594 let send_api = SendApi::new(
595 "group_poke",
596 json!({
597 "group_id": group_id,
598 "user_id": user_id,
599 }),
600 );
601
602 send_api_request_with_response(&self.api_tx, send_api)
603 }
604
605 fn mark_private_msg_as_read(
606 &self,
607 user_id: i64,
608 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
609 let send_api = SendApi::new(
610 "mark_private_msg_as_read",
611 json!({
612 "user_id": user_id,
613 }),
614 );
615
616 send_api_request_with_response(&self.api_tx, send_api)
617 }
618
619 fn mark_group_msg_as_read(
620 &self,
621 group_id: i64,
622 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
623 let send_api = SendApi::new(
624 "mark_group_msg_as_read",
625 json!({
626 "group_id": group_id,
627 }),
628 );
629
630 send_api_request_with_response(&self.api_tx, send_api)
631 }
632
633 fn get_recent_contact(
634 &self,
635 count: i64,
636 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
637 let send_api = SendApi::new(
638 "get_recent_contact",
639 json!({
640 "count": count,
641 }),
642 );
643
644 send_api_request_with_response(&self.api_tx, send_api)
645 }
646
647 fn get_profile_like(
648 &self,
649 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
650 let send_api = SendApi::new("get_profile_like", json!({}));
651
652 send_api_request_with_response(&self.api_tx, send_api)
653 }
654
655 fn fetch_custom_face(
656 &self,
657 count: i64,
658 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
659 let send_api = SendApi::new(
660 "fetch_custom_face",
661 json!({
662 "count": count,
663 }),
664 );
665
666 send_api_request_with_response(&self.api_tx, send_api)
667 }
668
669 fn mark_all_as_read(
670 &self,
671 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
672 let send_api = SendApi::new("_mark_all_as_read", json!({}));
673
674 send_api_request_with_response(&self.api_tx, send_api)
675 }
676
677 fn set_self_longnick(
678 &self,
679 long_nick: &str,
680 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
681 let send_api = SendApi::new(
682 "set_self_longnick",
683 json!({
684 "longNick": long_nick,
685 }),
686 );
687
688 send_api_request_with_response(&self.api_tx, send_api)
689 }
690
691 fn get_friend_msg_history(
692 &self,
693 user_id: i64,
694 message_seq: &str,
695 count: i64,
696 reverse_order: bool,
697 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
698 let send_api = SendApi::new(
699 "get_friend_msg_history",
700 json!({
701 "user_id": user_id,
702 "message_seq": message_seq,
703 "count": count,
704 "reverseOrder": reverse_order,
705 }),
706 );
707
708 send_api_request_with_response(&self.api_tx, send_api)
709 }
710
711 fn send_forward_msg(
712 &self,
713 message_type: &str,
714 user_id: Option<i64>,
715 group_id: Option<i64>,
716 message: Vec<Node>,
717 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
718 let mut map = serde_json::Map::new();
719
720 map.insert("message_type".to_string(), json!(message_type));
721
722 if let Some(uid) = user_id {
723 map.insert("user_id".to_string(), json!(uid));
724 }
725
726 if let Some(gid) = group_id {
727 map.insert("group_id".to_string(), json!(gid));
728 }
729
730 map.insert("message".to_string(), json!(message));
731
732 let send_api = SendApi::new("send_forward_msg", serde_json::Value::Object(map));
733
734 send_api_request_with_response(&self.api_tx, send_api)
735 }
736
737 fn send_forward_msg_to_user(
738 &self,
739 user_id: i64,
740 message: Vec<Node>,
741 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
742 let send_api = SendApi::new(
743 "send_forward_msg",
744 json!({
745 "message_type": "private",
746 "user_id": user_id,
747 "message": message,
748 }),
749 );
750
751 send_api_request_with_response(&self.api_tx, send_api)
752 }
753
754 fn send_forward_msg_to_group(
755 &self,
756 group_id: i64,
757 message: Vec<Node>,
758 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
759 let send_api = SendApi::new(
760 "send_forward_msg",
761 json!({
762 "message_type": "group",
763 "group_id": group_id,
764 "message": message,
765 }),
766 );
767
768 send_api_request_with_response(&self.api_tx, send_api)
769 }
770
771 fn translate_en2zh(
772 &self,
773 words: Vec<String>,
774 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
775 let send_api = SendApi::new(
776 "translate_en2zh",
777 json!({
778 "words": words,
779 }),
780 );
781
782 send_api_request_with_response(&self.api_tx, send_api)
783 }
784
785 fn ark_share_peer(
786 &self,
787 user_id: Option<&str>,
788 phone_number: Option<&str>,
789 group_id: Option<&str>,
790 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
791 let mut map = serde_json::Map::new();
792
793 if let Some(uid) = user_id {
794 map.insert("user_id".to_string(), json!(uid));
795 }
796 if let Some(phone) = phone_number {
797 map.insert("phoneNumber".to_string(), json!(phone));
798 }
799 if let Some(gid) = group_id {
800 map.insert("group_id".to_string(), json!(gid));
801 }
802
803 let send_api = SendApi::new("ArkSharePeer", serde_json::Value::Object(map));
804
805 send_api_request_with_response(&self.api_tx, send_api)
806 }
807
808 fn ark_share_group(
809 &self,
810 group_id: &str,
811 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
812 let send_api = SendApi::new(
813 "ArkShareGroup",
814 json!({
815 "group_id": group_id,
816 }),
817 );
818
819 send_api_request_with_response(&self.api_tx, send_api)
820 }
821
822 fn set_msg_emoji_like(
823 &self,
824 message_id: i64,
825 emoji_id: &str,
826 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
827 let send_api = SendApi::new(
828 "set_msg_emoji_like",
829 json!({
830 "message_id": message_id,
831 "emoji_id": emoji_id,
832 }),
833 );
834
835 send_api_request_with_response(&self.api_tx, send_api)
836 }
837
838 fn forward_group_single_msg(
839 &self,
840 group_id: i64,
841 message: Vec<Node>,
842 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
843 let send_api = SendApi::new(
844 "forward_group_single_msg",
845 json!({
846 "group_id": group_id,
847 "message": message,
848 }),
849 );
850
851 send_api_request_with_response(&self.api_tx, send_api)
852 }
853
854 fn forward_friend_single_msg(
855 &self,
856 user_id: i64,
857 message: Vec<Node>,
858 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
859 let send_api = SendApi::new(
860 "forward_friend_single_msg",
861 json!({
862 "user_id": user_id,
863 "message": message,
864 }),
865 );
866
867 send_api_request_with_response(&self.api_tx, send_api)
868 }
869
870 fn get_file(
871 &self,
872 file_id: &str,
873 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
874 let send_api = SendApi::new(
875 "get_file",
876 json!({
877 "file_id": file_id,
878 }),
879 );
880
881 send_api_request_with_response(&self.api_tx, send_api)
882 }
883
884 fn set_qq_avatar(
885 &self,
886 file: &str,
887 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
888 let send_api = SendApi::new(
889 "set_qq_avatar",
890 json!({
891 "file": file,
892 }),
893 );
894
895 send_api_request_with_response(&self.api_tx, send_api)
896 }
897 fn get_friends_with_category(
898 &self,
899 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
900 let send_api = SendApi::new("get_friends_with_category", json!({}));
901
902 send_api_request_with_response(&self.api_tx, send_api)
903 }
904
905 fn set_online_status(
906 &self,
907 status: i64,
908 ext_status: i64,
909 battery_status: i64,
910 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
911 let send_api = SendApi::new(
912 "set_online_status",
913 json!({
914 "status": status,
915 "ext_status": ext_status,
916 "battery_status": battery_status,
917 }),
918 );
919
920 send_api_request_with_response(&self.api_tx, send_api)
921 }
922
923 fn get_robot_uin_range(
924 &self,
925 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
926 let send_api = SendApi::new("get_robot_uin_range", json!({}));
927
928 send_api_request_with_response(&self.api_tx, send_api)
929 }
930
931 fn download_file(
932 &self,
933 url: &str,
934 thread_count: i64,
935 headers: Vec<String>,
936 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
937 let send_api = SendApi::new(
938 "download_file",
939 json!({
940 "url": url,
941 "thread_count": thread_count,
942 "headers": headers,
943 }),
944 );
945
946 send_api_request_with_response(&self.api_tx, send_api)
947 }
948
949 fn upload_private_file(
950 &self,
951 user_id: i64,
952 file: &str,
953 name: &str,
954 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
955 let send_api = SendApi::new(
956 "upload_private_file",
957 json!({
958 "user_id": user_id,
959 "file": file,
960 "name": name,
961 }),
962 );
963
964 send_api_request_with_response(&self.api_tx, send_api)
965 }
966
967 fn get_group_files_by_folder(
968 &self,
969 group_id: i64,
970 folder_id: &str,
971 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
972 let send_api = SendApi::new(
973 "get_group_files_by_folder",
974 json!({
975 "group_id": group_id,
976 "folder_id": folder_id,
977 }),
978 );
979
980 send_api_request_with_response(&self.api_tx, send_api)
981 }
982
983 fn get_group_file_url(
984 &self,
985 group_id: i64,
986 file_id: &str,
987 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
988 let send_api = SendApi::new(
989 "get_group_file_url",
990 json!({
991 "group_id": group_id,
992 "file_id": file_id,
993 }),
994 );
995
996 send_api_request_with_response(&self.api_tx, send_api)
997 }
998
999 fn get_group_root_files(
1000 &self,
1001 group_id: i64,
1002 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1003 let send_api = SendApi::new(
1004 "get_group_root_files",
1005 json!({
1006 "group_id": group_id,
1007 }),
1008 );
1009
1010 send_api_request_with_response(&self.api_tx, send_api)
1011 }
1012
1013 fn get_group_file_system_info(
1014 &self,
1015 group_id: i64,
1016 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1017 let send_api = SendApi::new(
1018 "get_group_file_system_info",
1019 json!({
1020 "group_id": group_id,
1021 }),
1022 );
1023
1024 send_api_request_with_response(&self.api_tx, send_api)
1025 }
1026
1027 fn delete_group_folder(
1028 &self,
1029 group_id: i64,
1030 folder_id: &str,
1031 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1032 let send_api = SendApi::new(
1033 "delete_group_folder",
1034 json!({
1035 "group_id": group_id,
1036 "folder_id": folder_id,
1037 }),
1038 );
1039
1040 send_api_request_with_response(&self.api_tx, send_api)
1041 }
1042
1043 fn create_group_file_folder(
1044 &self,
1045 group_id: i64,
1046 name: &str,
1047 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1048 let send_api = SendApi::new(
1049 "create_group_file_folder",
1050 json!({
1051 "group_id": group_id,
1052 "name": name,
1053 }),
1054 );
1055
1056 send_api_request_with_response(&self.api_tx, send_api)
1057 }
1058
1059 fn delete_group_file(
1060 &self,
1061 group_id: i64,
1062 file_id: &str,
1063 busid: i64,
1064 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1065 let send_api = SendApi::new(
1066 "delete_group_file",
1067 json!({
1068 "group_id": group_id,
1069 "file_id": file_id,
1070 "busid": busid,
1071 }),
1072 );
1073
1074 send_api_request_with_response(&self.api_tx, send_api)
1075 }
1076
1077 fn set_group_sign(
1078 &self,
1079 group_id: i64,
1080 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1081 let send_api = SendApi::new(
1082 "send_group_sign",
1083 json!({
1084 "group_id": group_id,
1085 }),
1086 );
1087
1088 send_api_request_with_response(&self.api_tx, send_api)
1089 }
1090
1091 fn delete_essence_msg(
1092 &self,
1093 message_id: i64,
1094 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1095 let send_api = SendApi::new(
1096 "delete_essence_msg",
1097 json!({
1098 "message_id": message_id,
1099 }),
1100 );
1101
1102 send_api_request_with_response(&self.api_tx, send_api)
1103 }
1104
1105 fn set_essence_msg(
1106 &self,
1107 message_id: i64,
1108 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1109 let send_api = SendApi::new(
1110 "set_essence_msg",
1111 json!({
1112 "message_id": message_id,
1113 }),
1114 );
1115
1116 send_api_request_with_response(&self.api_tx, send_api)
1117 }
1118
1119 fn get_essence_msg_list(
1120 &self,
1121 group_id: i64,
1122 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1123 let send_api = SendApi::new(
1124 "get_essence_msg_list",
1125 json!({
1126 "group_id": group_id,
1127 }),
1128 );
1129
1130 send_api_request_with_response(&self.api_tx, send_api)
1131 }
1132
1133 fn get_group_system_msg(
1134 &self,
1135 invited_requests: Vec<InvitedRequest>,
1136 join_requests: Vec<JoinRequest>,
1137 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1138 let send_api = SendApi::new(
1139 "get_group_system_msg",
1140 json!({
1141 "invited_requests": invited_requests,
1142 "join_requests": join_requests,
1143 }),
1144 );
1145
1146 send_api_request_with_response(&self.api_tx, send_api)
1147 }
1148
1149 fn ocr_image(
1150 &self,
1151 image: &str,
1152 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1153 let send_api = SendApi::new(
1154 "ocr_image",
1155 json!({
1156 "image": image,
1157 }),
1158 );
1159
1160 send_api_request_with_response(&self.api_tx, send_api)
1161 }
1162
1163 fn get_group_msg_history(
1164 &self,
1165 group_id: i64,
1166 message_seq: Option<i64>,
1167 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1168 let send_api = if let Some(message_seq) = message_seq {
1169 SendApi::new(
1170 "get_group_msg_history",
1171 json!({
1172 "group_id": group_id,
1173 "message_seq": message_seq,
1174 }),
1175 )
1176 } else {
1177 SendApi::new(
1178 "get_group_msg_history",
1179 json!({
1180 "group_id": group_id,
1181 }),
1182 )
1183 };
1184
1185 send_api_request_with_response(&self.api_tx, send_api)
1186 }
1187
1188 fn send_private_forward_msg(
1189 &self,
1190 user_id: i64,
1191 nodes: Vec<Node>,
1192 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1193 let send_api = SendApi::new(
1194 "send_private_forward_msg",
1195 json!({
1196 "user_id": user_id,
1197 "message": nodes,
1198 }),
1199 );
1200
1201 send_api_request_with_response(&self.api_tx, send_api)
1202 }
1203
1204 fn send_group_forward_msg(
1205 &self,
1206 group_id: i64,
1207 nodes: Vec<Node>,
1208 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1209 let send_api = SendApi::new(
1210 "send_group_forward_msg",
1211 json!({
1212 "group_id": group_id,
1213 "message": nodes,
1214 }),
1215 );
1216
1217 send_api_request_with_response(&self.api_tx, send_api)
1218 }
1219
1220 fn mark_msg_as_read(
1221 &self,
1222 message_id: i64,
1223 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1224 let send_api = SendApi::new(
1225 "mark_msg_as_read",
1226 json!({
1227 "message_id": message_id,
1228 }),
1229 );
1230
1231 send_api_request_with_response(&self.api_tx, send_api)
1232 }
1233
1234 fn get_online_clients(
1235 &self,
1236 no_cache: bool,
1237 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1238 let send_api = SendApi::new(
1239 "get_online_clients",
1240 json!({
1241 "no_cache": no_cache,
1242 }),
1243 );
1244
1245 send_api_request_with_response(&self.api_tx, send_api)
1246 }
1247
1248 fn set_qq_profile(
1249 &self,
1250 nickname: &str,
1251 company: &str,
1252 email: &str,
1253 college: &str,
1254 personal_note: &str,
1255 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1256 let send_api = SendApi::new(
1257 "set_qq_profile",
1258 json!({
1259 "nickname": nickname,
1260 "company": company,
1261 "email": email,
1262 "college": college,
1263 "personal_note": personal_note,
1264 }),
1265 );
1266
1267 send_api_request_with_response(&self.api_tx, send_api)
1268 }
1269
1270 fn upload_group_file(
1271 &self,
1272 group_id: i64,
1273 file: &str,
1274 name: &str,
1275 folder: Option<&str>,
1276 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1277 let send_api = if let Some(folder) = folder {
1278 SendApi::new(
1279 "upload_group_file",
1280 json!({
1281 "group_id": group_id,
1282 "file": file,
1283 "name": name,
1284 "folder":folder
1285 }),
1286 )
1287 } else {
1288 SendApi::new(
1289 "upload_group_file",
1290 json!({
1291 "group_id": group_id,
1292 "file": file,
1293 "name": name,
1294 }),
1295 )
1296 };
1297
1298 send_api_request_with_response(&self.api_tx, send_api)
1299 }
1300
1301 fn get_group_notice(
1302 &self,
1303 group_id: i64,
1304 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1305 let send_api = SendApi::new(
1306 "_get_group_notice",
1307 json!({
1308 "group_id": group_id,
1309 }),
1310 );
1311
1312 send_api_request_with_response(&self.api_tx, send_api)
1313 }
1314
1315 fn send_group_notice(
1316 &self,
1317 group_id: i64,
1318 content: &str,
1319 image: Option<&str>,
1320 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1321 let send_api = SendApi::new(
1322 "_send_group_notice",
1323 json!({
1324 "group_id": group_id,
1325 "content": content,
1326 "image": image,
1327 }),
1328 );
1329
1330 send_api_request_with_response(&self.api_tx, send_api)
1331 }
1332
1333 fn set_group_portrait(
1334 &self,
1335 group_id: i64,
1336 file: &str,
1337 cache: bool,
1338 ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> + Send {
1339 let send_api = if cache {
1340 SendApi::new(
1341 "set_group_portrait",
1342 json!({
1343 "group_id": group_id,
1344 "file": file,
1345 "cache": 1,
1346 }),
1347 )
1348 } else {
1349 SendApi::new(
1350 "set_group_portrait",
1351 json!({
1352 "group_id": group_id,
1353 "file": file,
1354 "cache": 0,
1355 }),
1356 )
1357 };
1358
1359 send_api_request_with_response(&self.api_tx, send_api)
1360 }
1361}
1362
1363pub type Node = OneBotSegment;
1364
1365pub trait NapCatVec {
1366 fn add_fake_node_from_content(
1378 self,
1379 user_id: &str,
1380 nickname: &str,
1381 content: Message,
1382 ) -> Vec<Node>;
1383
1384 fn add_fake_node_from_id(self, user_id: &str, nickname: &str, id: &str) -> Vec<OneBotSegment>;
1396
1397 fn push_fake_node_from_content(&mut self, user_id: &str, nickname: &str, content: Message);
1409
1410 fn push_fake_node_from_id(&mut self, user_id: &str, nickname: &str, id: &str);
1419
1420 fn add_node_from_id(self, id: &str) -> Vec<Node>;
1432
1433 fn add_node_from_content(self, content: Message) -> Vec<Node>;
1443
1444 fn push_node_from_id(&mut self, id: &str);
1456
1457 fn push_node_from_content(&mut self, content: Message);
1467}
1468
1469impl NapCatVec for Vec<Node> {
1470 fn add_fake_node_from_content(
1471 mut self,
1472 user_id: &str,
1473 nickname: &str,
1474 content: Message,
1475 ) -> Vec<OneBotSegment> {
1476 self.push(OneBotSegment {
1477 type_: "node".to_string(),
1478 data: json!({
1479 "user_id": user_id,
1480 "nickname": nickname,
1481 "content": content,
1482 }),
1483 });
1484 self
1485 }
1486 fn push_fake_node_from_content(&mut self, user_id: &str, nickname: &str, content: Message) {
1487 self.push(OneBotSegment {
1488 type_: "node".to_string(),
1489 data: json!({
1490 "user_id": user_id,
1491 "nickname": nickname,
1492 "content": content,
1493 }),
1494 });
1495 }
1496 fn add_fake_node_from_id(
1497 mut self,
1498 user_id: &str,
1499 nickname: &str,
1500 id: &str,
1501 ) -> Vec<OneBotSegment> {
1502 self.push(OneBotSegment {
1503 type_: "node".to_string(),
1504 data: json!({
1505 "id": id,
1506 "user_id": user_id,
1507 "nickname": nickname,
1508 }),
1509 });
1510 self
1511 }
1512
1513 fn push_fake_node_from_id(&mut self, user_id: &str, nickname: &str, id: &str) {
1514 self.push(OneBotSegment {
1515 type_: "node".to_string(),
1516 data: json!({
1517 "id": id,
1518 "user_id": user_id,
1519 "nickname": nickname,
1520 }),
1521 });
1522 }
1523
1524 fn add_node_from_id(mut self, id: &str) -> Vec<OneBotSegment> {
1525 self.push(OneBotSegment {
1526 type_: "node".to_string(),
1527 data: json!({
1528 "id": id,
1529 }),
1530 });
1531 self
1532 }
1533
1534 fn push_node_from_id(&mut self, id: &str) {
1535 self.push(OneBotSegment {
1536 type_: "node".to_string(),
1537 data: json!({
1538 "id": id,
1539 }),
1540 });
1541 }
1542
1543 fn add_node_from_content(mut self, content: Message) -> Vec<OneBotSegment> {
1544 self.push(OneBotSegment {
1545 type_: "node".to_string(),
1546 data: json!({
1547 "content": content,
1548 }),
1549 });
1550 self
1551 }
1552
1553 fn push_node_from_content(&mut self, content: Message) {
1554 self.push(OneBotSegment {
1555 type_: "node".to_string(),
1556 data: json!({
1557 "content": content,
1558 }),
1559 });
1560 }
1561}