pub struct MultiWeixinBot { /* private fields */ }Implementations§
Source§impl MultiWeixinBot
impl MultiWeixinBot
Sourcepub fn new(opts: MultiWeixinBotOptions) -> Self
pub fn new(opts: MultiWeixinBotOptions) -> Self
Examples found in repository?
examples/multi_echo.rs (lines 18-21)
7async fn main() -> wx_bot_sdk::Result<()> {
8 let accounts = read_accounts();
9 if accounts.is_empty() {
10 eprintln!("Usage:");
11 eprintln!(" WEIXIN_BOT_TOKENS=\"token1,token2\" cargo run --example multi_echo");
12 eprintln!(" cargo run --example multi_echo -- token1 token2");
13 eprintln!("\n如果已通过扫码登录保存账号,也可以直接运行:");
14 eprintln!(" cargo run --example multi_echo");
15 std::process::exit(1);
16 }
17
18 let multi = MultiWeixinBot::new(MultiWeixinBotOptions {
19 accounts,
20 state_dir: None,
21 });
22
23 println!("starting accounts: {:?}", multi.account_ids());
24 multi
25 .start(MultiStartOptions {
26 long_poll_timeout_ms: None,
27 on_message: handler(|ctx| async move {
28 println!("[{}] 来自 {}: {}", ctx.account_id, ctx.from, ctx.body);
29 Ok(Some(format!("你说了: {}", ctx.body)))
30 }),
31 })
32 .await?;
33
34 tokio::signal::ctrl_c().await?;
35 println!("stopping all accounts...");
36 multi.stop().await?;
37 multi.join().await?;
38 Ok(())
39}Sourcepub async fn start(&self, opts: MultiStartOptions) -> Result<()>
pub async fn start(&self, opts: MultiStartOptions) -> Result<()>
Examples found in repository?
examples/multi_echo.rs (lines 25-31)
7async fn main() -> wx_bot_sdk::Result<()> {
8 let accounts = read_accounts();
9 if accounts.is_empty() {
10 eprintln!("Usage:");
11 eprintln!(" WEIXIN_BOT_TOKENS=\"token1,token2\" cargo run --example multi_echo");
12 eprintln!(" cargo run --example multi_echo -- token1 token2");
13 eprintln!("\n如果已通过扫码登录保存账号,也可以直接运行:");
14 eprintln!(" cargo run --example multi_echo");
15 std::process::exit(1);
16 }
17
18 let multi = MultiWeixinBot::new(MultiWeixinBotOptions {
19 accounts,
20 state_dir: None,
21 });
22
23 println!("starting accounts: {:?}", multi.account_ids());
24 multi
25 .start(MultiStartOptions {
26 long_poll_timeout_ms: None,
27 on_message: handler(|ctx| async move {
28 println!("[{}] 来自 {}: {}", ctx.account_id, ctx.from, ctx.body);
29 Ok(Some(format!("你说了: {}", ctx.body)))
30 }),
31 })
32 .await?;
33
34 tokio::signal::ctrl_c().await?;
35 println!("stopping all accounts...");
36 multi.stop().await?;
37 multi.join().await?;
38 Ok(())
39}Sourcepub async fn stop(&self) -> Result<()>
pub async fn stop(&self) -> Result<()>
Examples found in repository?
examples/multi_echo.rs (line 36)
7async fn main() -> wx_bot_sdk::Result<()> {
8 let accounts = read_accounts();
9 if accounts.is_empty() {
10 eprintln!("Usage:");
11 eprintln!(" WEIXIN_BOT_TOKENS=\"token1,token2\" cargo run --example multi_echo");
12 eprintln!(" cargo run --example multi_echo -- token1 token2");
13 eprintln!("\n如果已通过扫码登录保存账号,也可以直接运行:");
14 eprintln!(" cargo run --example multi_echo");
15 std::process::exit(1);
16 }
17
18 let multi = MultiWeixinBot::new(MultiWeixinBotOptions {
19 accounts,
20 state_dir: None,
21 });
22
23 println!("starting accounts: {:?}", multi.account_ids());
24 multi
25 .start(MultiStartOptions {
26 long_poll_timeout_ms: None,
27 on_message: handler(|ctx| async move {
28 println!("[{}] 来自 {}: {}", ctx.account_id, ctx.from, ctx.body);
29 Ok(Some(format!("你说了: {}", ctx.body)))
30 }),
31 })
32 .await?;
33
34 tokio::signal::ctrl_c().await?;
35 println!("stopping all accounts...");
36 multi.stop().await?;
37 multi.join().await?;
38 Ok(())
39}Sourcepub async fn join(&self) -> Result<()>
pub async fn join(&self) -> Result<()>
Examples found in repository?
examples/multi_echo.rs (line 37)
7async fn main() -> wx_bot_sdk::Result<()> {
8 let accounts = read_accounts();
9 if accounts.is_empty() {
10 eprintln!("Usage:");
11 eprintln!(" WEIXIN_BOT_TOKENS=\"token1,token2\" cargo run --example multi_echo");
12 eprintln!(" cargo run --example multi_echo -- token1 token2");
13 eprintln!("\n如果已通过扫码登录保存账号,也可以直接运行:");
14 eprintln!(" cargo run --example multi_echo");
15 std::process::exit(1);
16 }
17
18 let multi = MultiWeixinBot::new(MultiWeixinBotOptions {
19 accounts,
20 state_dir: None,
21 });
22
23 println!("starting accounts: {:?}", multi.account_ids());
24 multi
25 .start(MultiStartOptions {
26 long_poll_timeout_ms: None,
27 on_message: handler(|ctx| async move {
28 println!("[{}] 来自 {}: {}", ctx.account_id, ctx.from, ctx.body);
29 Ok(Some(format!("你说了: {}", ctx.body)))
30 }),
31 })
32 .await?;
33
34 tokio::signal::ctrl_c().await?;
35 println!("stopping all accounts...");
36 multi.stop().await?;
37 multi.join().await?;
38 Ok(())
39}pub fn bots(&self) -> &[WeixinBot]
Sourcepub fn account_ids(&self) -> Vec<String>
pub fn account_ids(&self) -> Vec<String>
Examples found in repository?
examples/multi_echo.rs (line 23)
7async fn main() -> wx_bot_sdk::Result<()> {
8 let accounts = read_accounts();
9 if accounts.is_empty() {
10 eprintln!("Usage:");
11 eprintln!(" WEIXIN_BOT_TOKENS=\"token1,token2\" cargo run --example multi_echo");
12 eprintln!(" cargo run --example multi_echo -- token1 token2");
13 eprintln!("\n如果已通过扫码登录保存账号,也可以直接运行:");
14 eprintln!(" cargo run --example multi_echo");
15 std::process::exit(1);
16 }
17
18 let multi = MultiWeixinBot::new(MultiWeixinBotOptions {
19 accounts,
20 state_dir: None,
21 });
22
23 println!("starting accounts: {:?}", multi.account_ids());
24 multi
25 .start(MultiStartOptions {
26 long_poll_timeout_ms: None,
27 on_message: handler(|ctx| async move {
28 println!("[{}] 来自 {}: {}", ctx.account_id, ctx.from, ctx.body);
29 Ok(Some(format!("你说了: {}", ctx.body)))
30 }),
31 })
32 .await?;
33
34 tokio::signal::ctrl_c().await?;
35 println!("stopping all accounts...");
36 multi.stop().await?;
37 multi.join().await?;
38 Ok(())
39}Trait Implementations§
Source§impl Clone for MultiWeixinBot
impl Clone for MultiWeixinBot
Source§fn clone(&self) -> MultiWeixinBot
fn clone(&self) -> MultiWeixinBot
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MultiWeixinBot
impl RefUnwindSafe for MultiWeixinBot
impl Send for MultiWeixinBot
impl Sync for MultiWeixinBot
impl Unpin for MultiWeixinBot
impl UnsafeUnpin for MultiWeixinBot
impl UnwindSafe for MultiWeixinBot
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more