Skip to content

Commit c77e6f5

Browse files
Sn0wo2fumiama
andauthored
feat: append optional space after at (#103)
Co-authored-by: 源文雨 <[email protected]>
1 parent e92dc8c commit c77e6f5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

bot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Config struct {
2828
MaxProcessTime time.Duration `json:"max_process_time"` // 事件最大处理时间 (默认4min)
2929
MarkMessage bool `json:"mark_message"` // 自动标记消息为已读
3030
KeepAtMeMessage bool `json:"keep_at_me_message"` // 是否保留at me的原始消息
31+
AddSpaceAfterAt bool `json:"at_space"` // 是否在At消息后没有空格时自动添加空格
3132
Driver []Driver `json:"-"` // 通信驱动
3233
}
3334

context.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ func (ctx *Ctx) Send(msg interface{}) message.ID {
113113

114114
// SendChain 快捷发送消息/合并转发-消息链
115115
func (ctx *Ctx) SendChain(msg ...message.Segment) message.ID {
116+
if BotConfig.AddSpaceAfterAt && len(msg) > 0 {
117+
newMsg := make(message.Message, 0, len(msg)*2)
118+
for i := 0; i < len(msg)-1; i++ {
119+
newMsg = append(newMsg, msg[i])
120+
if msg[i].Type != "at" {
121+
continue
122+
}
123+
if msg[i+1].Type != "text" ||
124+
(len(msg[i+1].Data["text"]) > 0 && msg[i+1].Data["text"][0] != ' ') {
125+
newMsg = append(newMsg, message.Text(" "))
126+
}
127+
}
128+
newMsg = append(newMsg, msg[len(msg)-1])
129+
msg = newMsg
130+
}
116131
return ctx.Send((message.Message)(msg))
117132
}
118133

0 commit comments

Comments
 (0)