Skip to main content

kovi_onebot/
onebot_api.rs

1use kovi::RuntimeBot;
2use kovi::bot::runtimebot::{
3    CanSendApi, send_api_await_response, send_api_request, send_api_request_with_forget,
4    send_api_request_with_response,
5};
6use kovi::bot::{ApiReturn, SendApi};
7#[cfg(not(feature = "cqstring"))]
8use kovi::message::Message as KoviMessage;
9use log::info;
10use serde::Serialize;
11use serde_json::{Value, json};
12
13#[cfg(feature = "cqstring")]
14use crate::onebot_message::CQMessage;
15#[cfg(not(feature = "cqstring"))]
16use crate::onebot_message::OneBotMessage;
17
18pub enum HonorType {
19    All,
20    Talkative,
21    Performer,
22    Legend,
23    StrongNewbie,
24    Emotion,
25}
26
27pub enum AddRequestType<'a> {
28    Type(&'a str),
29    SubType(&'a str),
30}
31
32/// Kovi提供解析过的返回值的api
33pub trait OnebotTrait: CanSendApi {
34    ///发送群组消息, 并返回消息ID
35    #[cfg(not(feature = "cqstring"))]
36    fn send_group_msg_return<T>(
37        &self,
38        group_id: i64,
39        msg: T,
40    ) -> impl std::future::Future<Output = Result<i32, ApiReturn>>
41    where
42        KoviMessage: From<T>,
43        T: Serialize,
44    {
45        let msg = KoviMessage::from(msg);
46        let group_id = &group_id;
47        info!("[send] [to group {group_id}]: {}", msg.to_human_string());
48
49        let msg = OneBotMessage::from(msg);
50        let send_api = SendApi::new(
51            "send_msg",
52            json!({
53                "message_type":"group",
54                "group_id":group_id,
55                "message":msg,
56                "auto_escape":true,
57            }),
58        );
59
60        let api_rx = send_api_request(self.__get_api_tx(), send_api);
61
62        async move {
63            let r = send_api_await_response(api_rx).await;
64
65            match r {
66                Ok(v) => match v.data.get("message_id").and_then(|v| v.as_i64()) {
67                    Some(b) => Ok(b as i32),
68                    None => Err(v),
69                },
70
71                Err(v) => Err(v),
72            }
73        }
74    }
75
76    ///发送群组消息, 并返回消息ID
77    #[cfg(feature = "cqstring")]
78    fn send_group_msg_return<T>(
79        &self,
80        group_id: i64,
81        msg: T,
82    ) -> impl std::future::Future<Output = Result<i32, ApiReturn>>
83    where
84        CQMessage: From<T>,
85        T: Serialize,
86    {
87        let msg = CQMessage::from(msg);
88        let send_api = SendApi::new(
89            "send_msg",
90            json!({
91                "message_type":"group",
92                "group_id":group_id,
93                "message":msg,
94                "auto_escape":false,
95            }),
96        );
97
98        let group_id = &group_id;
99        info!(
100            "[send] [to group {group_id}]: {}",
101            Message::from(msg).to_human_string()
102        );
103
104        let api_rx = send_api_request(&self.__get_api_tx(), send_api);
105
106        async move {
107            let r = send_api_await_response(api_rx).await;
108            match r {
109                Ok(v) => match v.data.get("message_id").and_then(|v| v.as_i64()) {
110                    Some(b) => Ok(b as i32),
111                    None => Err(v),
112                },
113
114                Err(v) => Err(v),
115            }
116        }
117    }
118
119    #[cfg(not(feature = "cqstring"))]
120    ///发送私聊消息, 并返回消息ID
121    fn send_private_msg_return<T>(
122        &self,
123        user_id: i64,
124        msg: T,
125    ) -> impl std::future::Future<Output = Result<i32, ApiReturn>>
126    where
127        KoviMessage: From<T>,
128        T: Serialize,
129    {
130        let send_api = SendApi::new(
131            "send_msg",
132            json!({"message_type":"private",
133                "user_id":user_id,
134                "message":msg,
135                "auto_escape":true,}),
136        );
137
138        let msg = KoviMessage::from(msg);
139        let user_id = &user_id;
140        info!("[send] [to private {user_id}]: {}", msg.to_human_string());
141
142        let api_rx = send_api_request(self.__get_api_tx(), send_api);
143
144        async move {
145            let r = send_api_await_response(api_rx).await;
146
147            match r {
148                Ok(v) => match v.data.get("message_id").and_then(|v| v.as_i64()) {
149                    Some(b) => Ok(b as i32),
150                    None => Err(v),
151                },
152
153                Err(v) => Err(v),
154            }
155        }
156    }
157
158    #[cfg(feature = "cqstring")]
159    ///发送私聊消息, 并返回消息ID
160    fn send_private_msg_return<T>(
161        &self,
162        user_id: i64,
163        msg: T,
164    ) -> impl std::future::Future<Output = Result<i32, ApiReturn>>
165    where
166        CQMessage: From<T>,
167        T: Serialize,
168    {
169        let msg = CQMessage::from(msg);
170        let send_api = SendApi::new(
171            "send_msg",
172            json!({"message_type":"private",
173                "user_id":user_id,
174                "message":msg,
175                "auto_escape":false,}),
176        );
177
178        let user_id = &user_id;
179        info!(
180            "[send] [to private {user_id}]: {}",
181            Message::from(msg).to_human_string()
182        );
183
184        let api_rx = send_api_request(&self.__get_api_tx(), send_api);
185
186        async move {
187            let r = send_api_await_response(api_rx).await;
188            match r {
189                Ok(v) => match v.data.get("message_id").and_then(|v| v.as_i64()) {
190                    Some(b) => Ok(b as i32),
191                    None => Err(v),
192                },
193
194                Err(v) => Err(v),
195            }
196        }
197    }
198
199    /// 是否能发送图片
200    fn can_send_image(&self) -> impl std::future::Future<Output = Result<bool, ApiReturn>> {
201        let send_api = SendApi::new("can_send_image", json!({}));
202
203        let api_rx = send_api_request(self.__get_api_tx(), send_api);
204
205        async move {
206            let r = send_api_await_response(api_rx).await;
207            match r {
208                Ok(v) => match v.data.get("yes").and_then(|v| v.as_bool()) {
209                    Some(b) => Ok(b),
210                    None => Err(v),
211                },
212
213                Err(v) => Err(v),
214            }
215        }
216    }
217
218    /// 是否能发送语音
219    fn can_send_record(&self) -> impl std::future::Future<Output = Result<bool, ApiReturn>> {
220        let send_api = SendApi::new("can_send_record", json!({}));
221
222        let api_rx = send_api_request(self.__get_api_tx(), send_api);
223
224        async move {
225            let r = send_api_await_response(api_rx).await;
226            match r {
227                Ok(v) => match v.data.get("yes").and_then(|v| v.as_bool()) {
228                    Some(b) => Ok(b),
229                    None => Err(v),
230                },
231
232                Err(v) => Err(v),
233            }
234        }
235    }
236
237    #[cfg(not(feature = "cqstring"))]
238    ///发送群组消息,如果需要返回消息id,请使用send_group_msg_return()
239    fn send_group_msg<T>(&self, group_id: i64, msg: T)
240    where
241        KoviMessage: From<T>,
242        T: Serialize,
243    {
244        let msg = KoviMessage::from(msg);
245        let group_id = &group_id;
246        info!("[send] [to group {group_id}]: {}", msg.to_human_string());
247
248        let msg = OneBotMessage::from(msg);
249        let send_api = SendApi::new(
250            "send_msg",
251            json!({
252                    "message_type":"group",
253                    "group_id":group_id,
254                    "message":msg,
255                    "auto_escape":true,
256            }),
257        );
258
259        send_api_request_with_forget(self.__get_api_tx(), send_api);
260    }
261
262    #[cfg(feature = "cqstring")]
263    ///发送群组消息,如果需要返回消息id,请使用send_group_msg_return()
264    fn send_group_msg<T>(&self, group_id: i64, msg: T)
265    where
266        CQMessage: From<T>,
267        T: Serialize,
268    {
269        let msg = CQMessage::from(msg);
270        let send_api = SendApi::new(
271            "send_msg",
272            json!({
273                    "message_type":"group",
274                    "group_id":group_id,
275                    "message":msg,
276                    "auto_escape":false,
277            }),
278        );
279        let group_id = &group_id;
280        info!(
281            "[send] [to group {group_id}]: {}",
282            Message::from(msg).to_human_string()
283        );
284        send_api_request_with_forget(&self.__get_api_tx(), send_api);
285    }
286
287    #[cfg(not(feature = "cqstring"))]
288    ///发送私聊消息,如果需要返回消息id,请使用send_private_msg_return()
289    fn send_private_msg<T>(&self, user_id: i64, msg: T)
290    where
291        KoviMessage: From<T>,
292        T: Serialize,
293    {
294        let msg = KoviMessage::from(msg);
295        let user_id = &user_id;
296        info!("[send] [to private {user_id}]: {}", msg.to_human_string());
297
298        let msg = OneBotMessage::from(msg);
299        let send_api = SendApi::new(
300            "send_msg",
301            json!({
302                "message_type":"private",
303                    "user_id":user_id,
304                    "message":msg,
305                    "auto_escape":true,
306            }),
307        );
308
309        send_api_request_with_forget(self.__get_api_tx(), send_api);
310    }
311
312    #[cfg(feature = "cqstring")]
313    ///发送私聊消息,如果需要返回消息id,请使用send_private_msg_return()
314    fn send_private_msg<T>(&self, user_id: i64, msg: T)
315    where
316        CQMessage: From<T>,
317        T: Serialize,
318    {
319        let msg = CQMessage::from(msg);
320        let send_api = SendApi::new(
321            "send_msg",
322            json!({
323                "message_type":"private",
324                    "user_id":user_id,
325                    "message":msg,
326                    "auto_escape":false,
327            }),
328        );
329
330        let user_id = &user_id;
331        info!(
332            "[send] [to private {user_id}]: {}",
333            Message::from(msg).to_human_string()
334        );
335        send_api_request_with_forget(&self.__get_api_tx(), send_api);
336    }
337
338    /// 撤回消息
339    ///
340    /// # Arguments
341    ///
342    /// `message_id`: 消息 ID
343    fn delete_msg(&self, message_id: i32) {
344        let send_api = SendApi::new(
345            "delete_msg",
346            json!({
347                "message_id":message_id,
348            }),
349        );
350
351        send_api_request_with_forget(self.__get_api_tx(), send_api);
352    }
353
354    /// 点赞,有些服务端会返回点赞失败,所以需要返回值的话请使用 send_like_return()
355    /// # Arguments
356    ///
357    /// `user_id`
358    ///
359    /// `times`: 次数
360    fn send_like(&self, user_id: i64, times: usize) {
361        let send_api = SendApi::new(
362            "send_like",
363            json!({
364                                "user_id":user_id,
365                    "times":times,
366            }),
367        );
368
369        send_api_request_with_forget(self.__get_api_tx(), send_api);
370    }
371
372    /// 群组踢人
373    /// # Arguments
374    ///
375    /// `group_id`
376    ///
377    /// `user_id`
378    ///
379    /// `reject_add_request`: 是否拒绝此人的加群请求,传入true则拒绝
380    fn set_group_kick(&self, group_id: i64, user_id: i64, reject_add_request: bool) {
381        let send_api = SendApi::new(
382            "set_group_kick",
383            json!({
384                "group_id":group_id,
385                    "user_id":user_id,
386                    "reject_add_request":reject_add_request,
387            }),
388        );
389
390        send_api_request_with_forget(self.__get_api_tx(), send_api);
391    }
392
393    /// 群组单人禁言
394    ///
395    /// # Arguments
396    ///
397    /// `group_id`
398    ///
399    /// `user_id`
400    ///
401    /// `duration`: 禁言时长,单位秒,0 表示取消禁言
402    fn set_group_ban(&self, group_id: i64, user_id: i64, duration: usize) {
403        let send_api = SendApi::new(
404            "set_group_ban",
405            json!({
406                "group_id":group_id,
407                    "user_id":user_id,
408                    "duration":duration,
409            }),
410        );
411
412        send_api_request_with_forget(self.__get_api_tx(), send_api);
413    }
414    /// 群组匿名用户禁言
415    ///
416    /// # Arguments
417    ///
418    /// `group_id`
419    ///
420    /// `anonymous`: 要禁言的匿名用户对象(群消息上报的 anonymous 字段)
421    ///
422    /// `enable`: 是否禁言
423    fn set_group_anonymous_ban_use_anonymous(
424        &self,
425        group_id: i64,
426        anonymous: Value,
427        duration: usize,
428    ) {
429        let send_api = SendApi::new(
430            "set_group_anonymous_ban",
431            json!({
432                "group_id":group_id,
433                    "anonymous":anonymous,
434                    "duration":duration,
435            }),
436        );
437
438        send_api_request_with_forget(self.__get_api_tx(), send_api);
439    }
440    /// 群组匿名用户禁言
441    ///
442    /// # Arguments
443    ///
444    /// `group_id`
445    ///
446    /// `flag`: 要禁言的匿名用户的 flag(需从群消息上报的数据中获得)
447    ///
448    /// `enable`: 是否禁言
449    fn set_group_anonymous_ban_use_flag(&self, group_id: i64, flag: &str, duration: usize) {
450        let send_api = SendApi::new(
451            "set_group_anonymous_ban",
452            json!({
453                "group_id":group_id,
454                    "flag":flag,
455                    "duration":duration,
456            }),
457        );
458
459        send_api_request_with_forget(self.__get_api_tx(), send_api);
460    }
461
462    /// 群组全员禁言
463    ///
464    /// # Arguments
465    ///
466    /// `group_id`
467    ///
468    /// `enable`: 是否禁言
469    fn set_group_whole_ban(&self, group_id: i64, enable: bool) {
470        let send_api = SendApi::new(
471            "set_group_whole_ban",
472            json!({
473                "group_id":group_id,
474                    "enable":enable,
475            }),
476        );
477
478        send_api_request_with_forget(self.__get_api_tx(), send_api);
479    }
480
481    /// 群组设置管理员
482    ///
483    /// # Arguments
484    ///
485    /// `group_id`
486    ///
487    /// `user_id`
488    ///
489    /// `enable`: true 为设置,false 为取消
490    fn set_group_admin(&self, group_id: i64, user_id: i64, enable: bool) {
491        let send_api = SendApi::new(
492            "set_group_admin",
493            json!({
494                "group_id":group_id,
495                    "user_id":user_id,
496                    "enable":enable,
497            }),
498        );
499
500        send_api_request_with_forget(self.__get_api_tx(), send_api);
501    }
502    /// 群组匿名
503    ///
504    /// # Arguments
505    ///
506    /// `group_id`
507    ///
508    /// `enable`: true 为设置,false 为取消
509    fn set_group_anonymous(&self, group_id: i64, enable: bool) {
510        let send_api = SendApi::new(
511            "set_group_anonymous",
512            json!({
513                "group_id":group_id,
514                    "enable":enable,
515            }),
516        );
517
518        send_api_request_with_forget(self.__get_api_tx(), send_api);
519    }
520
521    /// 设置群名片(群备注)
522    ///
523    /// # Arguments
524    ///
525    /// `group_id`
526    ///
527    /// `user_id`
528    ///
529    /// `card`: 群名片内容,不填或空字符串表示删除群名片
530    fn set_group_card(&self, group_id: i64, user_id: i64, card: &str) {
531        let send_api = SendApi::new(
532            "set_group_card",
533            json!({
534                "group_id":group_id,
535                    "user_id":user_id,
536                    "card":card,
537            }),
538        );
539
540        send_api_request_with_forget(self.__get_api_tx(), send_api);
541    }
542
543    /// 设置群名
544    ///
545    /// # Arguments
546    ///
547    /// `group_id`
548    ///
549    /// `group_name`: 新群名
550    fn set_group_name(&self, group_id: i64, group_name: &str) {
551        let send_api = SendApi::new(
552            "set_group_name",
553            json!({
554                "group_id":group_id,
555                    "group_name":group_name,
556            }),
557        );
558
559        send_api_request_with_forget(self.__get_api_tx(), send_api);
560    }
561
562    /// 退出群组
563    ///
564    /// # Arguments
565    ///
566    /// `group_id`
567    ///
568    /// `is_dismiss`: 是否解散,如果登录号是群主,则仅在此项为 true 时能够解散
569    fn set_group_leave(&self, group_id: i64, is_dismiss: bool) {
570        let send_api = SendApi::new(
571            "set_group_leave",
572            json!({
573                "group_id":group_id,
574                    "is_dismiss":is_dismiss,
575            }),
576        );
577
578        send_api_request_with_forget(self.__get_api_tx(), send_api);
579    }
580
581    /// 设置群组专属头衔
582    ///
583    /// # Arguments
584    ///
585    /// `group_id`
586    ///
587    /// `user_id`
588    ///
589    /// `special_title`: 专属头衔,空字符串表示删除专属头衔
590    fn set_group_special_title(&self, group_id: i64, user_id: i64, special_title: &str) {
591        let send_api = SendApi::new(
592            "set_group_special_title",
593            json!({
594                "group_id":group_id,
595                    "user_id":user_id,
596                    "special_title":special_title,
597            }),
598        );
599
600        send_api_request_with_forget(self.__get_api_tx(), send_api);
601    }
602    /// 处理加好友请求
603    ///
604    /// # Arguments
605    ///
606    /// `flag`: 加好友请求的 flag(需从上报的数据中获得)
607    ///
608    /// `approve`: 是否同意请求
609    ///
610    /// `remark`: 添加后的好友备注(仅在同意时有效)
611    fn set_friend_add_request(&self, flag: &str, approve: bool, remark: &str) {
612        let send_api = SendApi::new(
613            "set_friend_add_request",
614            json!({
615                "flag":flag,
616                    "approve":approve,
617                    "remark":remark,
618            }),
619        );
620
621        send_api_request_with_forget(self.__get_api_tx(), send_api);
622    }
623    /// 处理加群请求/邀请
624    ///
625    /// # Arguments
626    ///
627    /// `flag`: 加群请求的 flag(需从上报的数据中获得)
628    ///
629    /// `type`: add 或 invite,请求类型(需要和上报消息中的 sub_type 或 type 字段相符),由于不同服务端实现不一样,Kovi 提供一个枚举,使用需注意服务端要求是 sub_type 还是 type
630    ///
631    /// `approve`: 是否同意请求/邀请
632    ///
633    /// `remark`: 可为空, 拒绝理由(仅在拒绝时有效)
634    fn set_group_add_request(
635        &self,
636        flag: &str,
637        type_: AddRequestType,
638        approve: bool,
639        reason: &str,
640    ) {
641        let (type_, type_value) = match type_ {
642            AddRequestType::SubType(v) => ("sub_type", v),
643            AddRequestType::Type(v) => ("type", v),
644        };
645        let send_api = SendApi::new(
646            "set_group_add_request",
647            json!({
648                "flag":flag,
649                    type_: type_value,
650                    "approve":approve,
651                    "reason":reason,
652            }),
653        );
654
655        send_api_request_with_forget(self.__get_api_tx(), send_api);
656    }
657
658    /// 清理缓存
659    ///
660    /// 用于清理积攒了太多的**OneBot服务端**缓存文件。**并非是对于本框架清除**。
661    fn clean_cache(&self) {
662        let send_api = SendApi::new("clean_cache", json!({}));
663        send_api_request_with_forget(self.__get_api_tx(), send_api);
664    }
665    // //////////////////////////////
666    // 这些是需要处理返回值的api
667    // //////////////////////////////
668
669    /// 获取消息
670    /// # Arguments
671    ///
672    /// `message_id`: 消息ID
673    fn get_msg(
674        &self,
675        message_id: i32,
676    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
677        let send_api = SendApi::new(
678            "get_msg",
679            json!({
680                "message_id":message_id
681            }),
682        );
683
684        send_api_request_with_response(self.__get_api_tx(), send_api)
685    }
686    /// 获取合并转发消息
687    /// # Arguments
688    ///
689    /// `id`: 合并转发 ID
690    fn get_forward_msg(
691        &self,
692        id: &str,
693    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
694        let send_api = SendApi::new(
695            "get_forward_msg",
696            json!({
697                "id":id
698            }),
699        );
700
701        send_api_request_with_response(self.__get_api_tx(), send_api)
702    }
703    /// 获取获取登录号信息
704    fn get_login_info(&self) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
705        let send_api = SendApi::new("get_login_info", json!({}));
706
707        send_api_request_with_response(self.__get_api_tx(), send_api)
708    }
709    /// 获取获取陌生人信息
710    /// # Arguments
711    ///
712    /// `user_id`
713    ///
714    /// `no_cache`: 是否不使用缓存(使用缓存可能更新不及时,但响应更快)
715    fn get_stranger_info(
716        &self,
717        user_id: i64,
718        no_cache: bool,
719    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
720        let send_api = SendApi::new(
721            "get_stranger_info",
722            json!({
723                    "user_id":user_id,
724                    "no_cache":no_cache
725            }),
726        );
727
728        send_api_request_with_response(self.__get_api_tx(), send_api)
729    }
730    /// 获取好友列表
731    fn get_friend_list(&self) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
732        let send_api = SendApi::new("get_friend_list", json!({}));
733
734        send_api_request_with_response(self.__get_api_tx(), send_api)
735    }
736    /// 获取群信息
737    /// # Arguments
738    ///
739    /// `group_id`
740    ///
741    /// `no_cache`: 是否不使用缓存(使用缓存可能更新不及时,但响应更快)
742    fn get_group_info(
743        &self,
744        group_id: i64,
745        no_cache: bool,
746    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
747        let send_api = SendApi::new(
748            "get_group_info",
749            json!({
750                    "group_id":group_id,
751                    "no_cache":no_cache
752            }),
753        );
754
755        send_api_request_with_response(self.__get_api_tx(), send_api)
756    }
757    /// 获取群列表
758    fn get_group_list(&self) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
759        let send_api = SendApi::new("get_group_list", json!({}));
760
761        send_api_request_with_response(self.__get_api_tx(), send_api)
762    }
763    ///获取群成员信息
764    /// # Arguments
765    ///
766    /// `group_id`
767    ///
768    /// `user_id`
769    ///
770    /// `no_cache`: 是否不使用缓存(使用缓存可能更新不及时,但响应更快)
771    fn get_group_member_info(
772        &self,
773        group_id: i64,
774        user_id: i64,
775        no_cache: bool,
776    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
777        let send_api = SendApi::new(
778            "get_group_member_info",
779            json!({
780                "group_id":group_id,
781                    "user_id":user_id,
782                    "no_cache":no_cache
783            }),
784        );
785
786        send_api_request_with_response(self.__get_api_tx(), send_api)
787    }
788    /// 获取群成员列表
789    ///
790    /// # Arguments
791    ///
792    /// `group_id`
793    fn get_group_member_list(
794        &self,
795        group_id: i64,
796    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
797        let send_api = SendApi::new(
798            "get_group_member_list",
799            json!({
800                "group_id":group_id,
801            }),
802        );
803
804        send_api_request_with_response(self.__get_api_tx(), send_api)
805    }
806
807    /// 获取群荣誉信息
808    /// # Arguments
809    ///
810    /// `group_id`
811    ///
812    /// `honor_type`: 要获取的群荣誉类型,可传入 talkative performer legend strong_newbie emotion 以分别获取单个类型的群荣誉数据,或传入 all 获取所有数据。**本框架已包装好了HonorType枚举**
813    fn get_group_honor_info(
814        &self,
815        group_id: i64,
816        honor_type: HonorType,
817    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
818        let honor_type = match honor_type {
819            HonorType::All => "all",
820            HonorType::Talkative => "talkative",
821            HonorType::Performer => "performer",
822            HonorType::Legend => "legend",
823            HonorType::StrongNewbie => "strong_newbie",
824            HonorType::Emotion => "emotion",
825        };
826
827        let send_api = SendApi::new(
828            "get_group_honor_info",
829            json!({
830                "group_id":group_id,
831                    "type":honor_type
832            }),
833        );
834
835        send_api_request_with_response(self.__get_api_tx(), send_api)
836    }
837
838    /// 获取相关接口凭证, 即 Cookies 和 CSRF Token 的合并。
839    ///
840    /// # Arguments
841    ///
842    /// `domain`: 需要获取 cookies 的域名
843    fn get_credentials(
844        &self,
845        domain: &str,
846    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
847        let send_api = SendApi::new(
848            "get_credentials",
849            json!({
850                "domain":domain,
851            }),
852        );
853
854        send_api_request_with_response(self.__get_api_tx(), send_api)
855    }
856
857    /// 获取运行状态
858    fn get_status(&self) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
859        let send_api = SendApi::new("get_status", json!({}));
860
861        send_api_request_with_response(self.__get_api_tx(), send_api)
862    }
863    /// 获取版本信息
864    fn get_version_info(&self) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
865        let send_api = SendApi::new("get_version_info", json!({}));
866        send_api_request_with_response(self.__get_api_tx(), send_api)
867    }
868    /// 获取 Cookies
869    ///
870    /// # Arguments
871    ///
872    /// `domain`: 需要获取 cookies 的域名
873    fn get_cookies(
874        &self,
875        domain: &str,
876    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
877        let send_api = SendApi::new(
878            "get_cookies",
879            json!({
880                "domain":domain,
881            }),
882        );
883        send_api_request_with_response(self.__get_api_tx(), send_api)
884    }
885    /// 获取 CSRF Token
886    fn get_csrf_token(&self) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
887        let send_api = SendApi::new("get_csrf_token", json!({}));
888
889        send_api_request_with_response(self.__get_api_tx(), send_api)
890    }
891    /// 获取语音
892    ///
893    /// # Arguments
894    ///
895    /// `file`: 收到的语音文件名(消息段的 file 参数),如 `0B38145AA44505000B38145AA4450500.silk`
896    ///
897    /// `out_format`: 要转换到的格式,目前支持 `mp3`、`amr`、`wma`、`m4a`、`spx`、`ogg`、`wav`、`flac`
898    fn get_record(
899        &self,
900        file: &str,
901        out_format: &str,
902    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
903        let send_api = SendApi::new(
904            "get_record",
905            json!({
906                "file":file,
907                    "out_format":out_format
908            }),
909        );
910        send_api_request_with_response(self.__get_api_tx(), send_api)
911    }
912    /// 获取图片
913    ///
914    /// # Arguments
915    ///
916    /// `file`: 收到的图片文件名(消息段的 file 参数),如 `6B4DE3DFD1BD271E3297859D41C530F5.jpg`
917    fn get_image(
918        &self,
919        file: &str,
920    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
921        let send_api = SendApi::new(
922            "get_image",
923            json!({
924                "file":file,
925            }),
926        );
927        send_api_request_with_response(self.__get_api_tx(), send_api)
928    }
929
930    /// 点赞,有些服务端会返回点赞失败,不关注返回值的话请使用 send_like()
931    /// # Arguments
932    ///
933    /// `user_id`
934    ///
935    /// `times`: 次数
936    fn send_like_return(
937        &self,
938        user_id: i64,
939        times: usize,
940    ) -> impl std::future::Future<Output = Result<ApiReturn, ApiReturn>> {
941        let send_api = SendApi::new(
942            "send_like",
943            json!({
944                                "user_id":user_id,
945                    "times":times,
946            }),
947        );
948
949        send_api_request_with_response(self.__get_api_tx(), send_api)
950    }
951}
952
953impl OnebotTrait for RuntimeBot {
954}