puniyu_types 0.5.7

puniyu 通用类型库
Documentation
use crate::account::AccountInfo;
use crate::adapter::{AdapterApi, AdapterInfo, Result, SendMsgType};
use crate::contact::ContactType;
use crate::element::Message;

#[derive(Clone)]
pub enum BotId {
	Index(u64),
	SelfId(String),
}

impl From<u64> for BotId {
	fn from(index: u64) -> Self {
		Self::Index(index)
	}
}

impl From<&str> for BotId {
	fn from(self_id: &str) -> Self {
		Self::SelfId(self_id.to_string())
	}
}

impl From<String> for BotId {
	fn from(self_id: String) -> Self {
		Self::SelfId(self_id)
	}
}

#[derive(Clone)]
pub struct Bot {
	/// 适配器信息
	pub adapter: AdapterInfo,
	/// 适配器API
	pub api: &'static dyn AdapterApi,
	/// 账户信息
	pub account: AccountInfo,
}

impl Bot {
	pub async fn send_msg(&self, contact: ContactType, message: Message) -> Result<SendMsgType> {
		self.api.send_msg(contact, message).await
	}
}