use async_trait::async_trait;
use nagisa_types::event::ReactionKind;
use nagisa_types::prelude::*;
use nagisa_types::vendor::Vendor;
use serde_json::Value;
pub mod milky;
pub mod onebot;
pub use milky::MilkyActions;
pub use onebot::OneBotActions;
#[inline]
pub(crate) fn unsupported(action: &str) -> Error {
Error::Unsupported(action.to_string())
}
#[async_trait]
pub trait ActionInvoker: Send + Sync + 'static {
fn protocol(&self) -> Protocol;
fn vendor(&self) -> Vendor {
Vendor::Other
}
fn supports(&self, _cap: Capability) -> bool {
false
}
async fn send(&self, peer: &Peer, message: &[Segment]) -> Result<MessageId>;
async fn call_raw(&self, action: &str, params: Value) -> Result<Value>;
async fn recall(&self, _id: &MessageId) -> Result<()> {
Err(unsupported("recall"))
}
async fn get_message(&self, _id: &MessageId) -> Result<MessageEvent> {
Err(unsupported("get_message"))
}
async fn get_login_info(&self) -> Result<(Uin, String)> {
Err(unsupported("get_login_info"))
}
async fn get_group_info(&self, _group: Uin, _no_cache: bool) -> Result<GroupInfo> {
Err(unsupported("get_group_info"))
}
async fn get_group_list(&self, _no_cache: bool) -> Result<Vec<GroupInfo>> {
Err(unsupported("get_group_list"))
}
async fn get_group_member_info(&self, _group: Uin, _user: Uin, _no_cache: bool) -> Result<MemberInfo> {
Err(unsupported("get_group_member_info"))
}
async fn get_group_member_list(&self, _group: Uin, _no_cache: bool) -> Result<Vec<MemberInfo>> {
Err(unsupported("get_group_member_list"))
}
async fn get_friend_list(&self, _no_cache: bool) -> Result<Vec<FriendInfo>> {
Err(unsupported("get_friend_list"))
}
async fn set_group_member_mute(&self, _group: Uin, _user: Uin, _duration: u32) -> Result<()> {
Err(unsupported("set_group_member_mute"))
}
async fn set_group_whole_mute(&self, _group: Uin, _enable: bool) -> Result<()> {
Err(unsupported("set_group_whole_mute"))
}
async fn set_group_admin(&self, _group: Uin, _user: Uin, _enable: bool) -> Result<()> {
Err(unsupported("set_group_admin"))
}
async fn set_group_member_card(&self, _group: Uin, _user: Uin, _card: &str) -> Result<()> {
Err(unsupported("set_group_member_card"))
}
async fn set_group_name(&self, _group: Uin, _name: &str) -> Result<()> {
Err(unsupported("set_group_name"))
}
async fn kick_group_member(&self, _group: Uin, _user: Uin, _reject_add: bool) -> Result<()> {
Err(unsupported("kick_group_member"))
}
async fn handle_request(&self, _token: &RequestToken, _approve: bool, _reason: Option<&str>) -> Result<()> {
Err(unsupported("handle_request"))
}
async fn send_reaction(
&self,
_group: Uin,
_seq: i64,
_face_id: &str,
_kind: ReactionKind,
_is_add: bool,
) -> Result<()> {
Err(unsupported("send_reaction"))
}
async fn send_nudge(&self, _peer: &Peer, _target: Uin) -> Result<()> {
Err(unsupported("send_nudge"))
}
async fn upload_group_file(
&self,
_group: Uin,
_src: ResourceSource,
_name: &str,
_parent_folder_id: Option<&str>,
) -> Result<String> {
Err(unsupported("upload_group_file"))
}
async fn upload_private_file(&self, _user: Uin, _src: ResourceSource, _name: &str) -> Result<String> {
Err(unsupported("upload_private_file"))
}
async fn get_user_info(&self, _user: Uin, _no_cache: bool) -> Result<UserInfo> {
Err(unsupported("get_user_info"))
}
async fn get_message_history(
&self,
_peer: &Peer,
_start: Option<&MessageId>,
_count: u32,
) -> Result<Vec<MessageEvent>> {
Err(unsupported("get_message_history"))
}
async fn leave_group(&self, _group: Uin, _dismiss: bool) -> Result<()> {
Err(unsupported("leave_group"))
}
async fn set_group_member_special_title(
&self,
_group: Uin,
_user: Uin,
_title: &str,
_duration: i64,
) -> Result<()> {
Err(unsupported("set_group_member_special_title"))
}
async fn mark_message_as_read(&self, _peer: &Peer, _id: &MessageId) -> Result<()> {
Err(unsupported("mark_message_as_read"))
}
async fn set_essence(&self, _group: Uin, _id: &MessageId, _enable: bool) -> Result<()> {
Err(unsupported("set_essence"))
}
async fn get_group_file_download_url(&self, _group: Uin, _file_id: &str) -> Result<String> {
Err(unsupported("get_group_file_download_url"))
}
async fn delete_group_file(&self, _group: Uin, _file_id: &str) -> Result<()> {
Err(unsupported("delete_group_file"))
}
async fn get_group_requests(&self) -> Result<Vec<Request>> {
Err(unsupported("get_group_requests"))
}
async fn get_cookies(&self, _domain: Option<&str>) -> Result<String> {
Err(unsupported("get_cookies"))
}
async fn get_csrf_token(&self) -> Result<String> {
Err(unsupported("get_csrf_token"))
}
async fn get_credentials(&self, domain: Option<&str>) -> Result<(String, String)> {
let cookies = self.get_cookies(domain).await?;
let csrf = self.get_csrf_token().await?;
Ok((cookies, csrf))
}
async fn get_forward_messages(&self, _forward_id: &str) -> Result<Vec<ForwardNode>> {
Err(unsupported("get_forward_messages"))
}
async fn delete_friend(&self, _user: Uin) -> Result<()> {
Err(unsupported("delete_friend"))
}
async fn send_profile_like(&self, _user: Uin, _count: u32) -> Result<()> {
Err(unsupported("send_profile_like"))
}
async fn send_group_announcement(
&self,
_group: Uin,
_content: &str,
_image: Option<ResourceSource>,
) -> Result<String> {
Err(unsupported("send_group_announcement"))
}
async fn get_group_announcements(&self, _group: Uin) -> Result<Vec<Announcement>> {
Err(unsupported("get_group_announcements"))
}
async fn delete_group_announcement(&self, _group: Uin, _announcement_id: &str) -> Result<()> {
Err(unsupported("delete_group_announcement"))
}
async fn get_essence_messages(&self, _group: Uin) -> Result<Vec<EssenceMessage>> {
Err(unsupported("get_essence_messages"))
}
async fn get_group_files(&self, _group: Uin, _folder_id: Option<&str>) -> Result<GroupFileList> {
Err(unsupported("get_group_files"))
}
async fn get_private_file_download_url(&self, _user: Uin, _file_id: &str, _hash: Option<&str>) -> Result<String> {
Err(unsupported("get_private_file_download_url"))
}
async fn create_group_folder(&self, _group: Uin, _name: &str) -> Result<String> {
Err(unsupported("create_group_folder"))
}
async fn rename_group_folder(&self, _group: Uin, _folder_id: &str, _new_name: &str) -> Result<()> {
Err(unsupported("rename_group_folder"))
}
async fn delete_group_folder(&self, _group: Uin, _folder_id: &str) -> Result<()> {
Err(unsupported("delete_group_folder"))
}
async fn move_group_file(
&self,
_group: Uin,
_file_id: &str,
_source_folder_id: Option<&str>,
_target_folder_id: Option<&str>,
) -> Result<()> {
Err(unsupported("move_group_file"))
}
async fn rename_group_file(
&self,
_group: Uin,
_file_id: &str,
_source_folder_id: Option<&str>,
_new_name: &str,
) -> Result<()> {
Err(unsupported("rename_group_file"))
}
async fn set_group_avatar(&self, _group: Uin, _src: ResourceSource) -> Result<()> {
Err(unsupported("set_group_avatar"))
}
async fn set_self_avatar(&self, _src: ResourceSource) -> Result<()> {
Err(unsupported("set_self_avatar"))
}
async fn set_self_nickname(&self, _name: &str) -> Result<()> {
Err(unsupported("set_self_nickname"))
}
async fn set_self_bio(&self, _bio: &str) -> Result<()> {
Err(unsupported("set_self_bio"))
}
}
pub trait Actions: ActionInvoker + OneBotActions + MilkyActions {}
impl<T: ActionInvoker + OneBotActions + MilkyActions> Actions for T {}