添加消息正文格式化
This commit is contained in:
parent
721846f267
commit
c46fb58824
@ -73,7 +73,7 @@ func main() {
|
||||
groups, err := self.Groups()
|
||||
fmt.Println(groups, err)
|
||||
|
||||
// 阻塞主goroutine, 知道发生异常或者用户主动退出
|
||||
// 阻塞主goroutine, 直到发生异常或者用户主动退出
|
||||
bot.Block()
|
||||
}
|
||||
```
|
||||
|
6
bot.go
6
bot.go
@ -200,7 +200,7 @@ func (b *Bot) webInit() error {
|
||||
if err = b.Caller.WebWxStatusNotify(req, resp, info); err != nil {
|
||||
return err
|
||||
}
|
||||
// 开启协程,轮训获取是否有新的消息返回
|
||||
// 开启协程,轮询获取是否有新的消息返回
|
||||
go func() {
|
||||
if b.GetMessageErrorHandler == nil {
|
||||
b.GetMessageErrorHandler = b.stopAsyncCALL
|
||||
@ -212,7 +212,7 @@ func (b *Bot) webInit() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 轮训请求
|
||||
// 轮询请求
|
||||
// 根据状态码判断是否有新的请求
|
||||
func (b *Bot) asyncCall() error {
|
||||
var (
|
||||
@ -220,7 +220,7 @@ func (b *Bot) asyncCall() error {
|
||||
resp *SyncCheckResponse
|
||||
)
|
||||
for b.Alive() {
|
||||
// 长轮训检查是否有消息返回
|
||||
// 长轮询检查是否有消息返回
|
||||
resp, err = b.Caller.SyncCheck(b.storage.LoginInfo, b.storage.Response)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -310,7 +310,10 @@ func (m *Message) Get(key string) (value interface{}, exist bool) {
|
||||
// 消息初始化,根据不同的消息作出不同的处理
|
||||
func (m *Message) init(bot *Bot) {
|
||||
m.Bot = bot
|
||||
|
||||
// 如果是群消息
|
||||
if m.IsSendByGroup() {
|
||||
// 将Username和正文分开
|
||||
data := strings.Split(m.Content, ":<br/>")
|
||||
m.Content = strings.Join(data[1:], "")
|
||||
m.senderInGroupUserName = data[0]
|
||||
@ -320,6 +323,7 @@ func (m *Message) init(bot *Bot) {
|
||||
if displayName == "" {
|
||||
displayName = receiver.NickName
|
||||
}
|
||||
// 判断是不是@消息
|
||||
atFlag := "@" + displayName
|
||||
index := len(atFlag) + 1 + 1
|
||||
if strings.HasPrefix(m.Content, atFlag) && unicode.IsSpace(rune(m.Content[index])) {
|
||||
@ -335,6 +339,11 @@ func (m *Message) init(bot *Bot) {
|
||||
{
|
||||
m.Content = strings.Replace(m.Content, `<br/>`, "\n", -1)
|
||||
}
|
||||
|
||||
// 格式化文本消息中的emoji表情
|
||||
if m.IsText() {
|
||||
m.Content = FormatEmoji(m.Content)
|
||||
}
|
||||
}
|
||||
|
||||
// 发送消息的结构体
|
||||
|
Loading…
x
Reference in New Issue
Block a user