From 019199831a74ca34e8a45aa3e56ce6806a463bc4 Mon Sep 17 00:00:00 2001 From: eatmoreapple <15055461510@163.com> Date: Wed, 13 Oct 2021 14:58:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bot=E7=9A=84=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=A8=A1=E5=BC=8F=E4=B8=BADesktop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.go | 15 ++++++--------- caller.go | 5 +++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bot.go b/bot.go index 9818b4a..674dd72 100644 --- a/bot.go +++ b/bot.go @@ -348,7 +348,9 @@ func (b *Bot) OnLogout(f func(bot *Bot)) { } // NewBot Bot的构造方法,需要自己传入Caller -func NewBot(caller *Caller) *Bot { +func NewBot() *Bot { + caller := DefaultCaller() + caller.Client.SetMode(Desktop) ctx, cancel := context.WithCancel(context.Background()) return &Bot{Caller: caller, Storage: &Storage{}, context: ctx, cancel: cancel} } @@ -357,15 +359,10 @@ func NewBot(caller *Caller) *Bot { // mode不传入默认为openwechat.Normal,详情见mode // bot := openwechat.DefaultBot(openwechat.Desktop) func DefaultBot(modes ...mode) *Bot { - var m mode - if len(modes) == 0 { - m = Normal - } else { - m = modes[0] + bot := NewBot() + if len(modes) > 0 { + bot.Caller.Client.SetMode(modes[0]) } - caller := DefaultCaller() - caller.Client.mode = m - bot := NewBot(caller) bot.UUIDCallback = PrintlnQrcodeUrl bot.ScanCallBack = func(body []byte) { log.Println("扫码成功,请在手机上确认登录") diff --git a/caller.go b/caller.go index fcc8f37..15991df 100644 --- a/caller.go +++ b/caller.go @@ -401,6 +401,11 @@ func (c *Caller) WebWxRenameChatRoom(request *BaseRequest, info *LoginInfo, newT return parseBaseResponseError(resp) } +// SetMode 设置Client的模式 +func (c *Client) SetMode(mode mode) { + c.mode = mode +} + // 处理响应返回的结果是否正常 func parseBaseResponseError(resp *http.Response) error { defer resp.Body.Close()