matrix+irc: improve support for IRC NOTICE/[matrix] m.notice

Fixes: #1393.
This commit is contained in:
Simon THOBY
2022-08-14 18:58:54 +02:00
committed by Simon Thoby
parent 09bc5379b7
commit 00b58bce71
10 changed files with 26 additions and 10 deletions

View File

@@ -27,7 +27,7 @@ const (
EventAPIConnected = "api_connected"
EventUserTyping = "user_typing"
EventGetChannelMembers = "get_channel_members"
EventNoticeIRC = "notice_irc"
EventNotice = "notice"
)
const ParentIDNotFound = "msg-parent-not-found"

View File

@@ -201,7 +201,7 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) {
// set NOTICE event
if event.Command == "NOTICE" {
rmsg.Event = config.EventNoticeIRC
rmsg.Event = config.EventNotice
}
// strip action, we made an event if it was an action

View File

@@ -255,7 +255,7 @@ func (b *Birc) doSend() {
switch msg.Event {
case config.EventUserAction:
b.i.Cmd.Action(msg.Channel, username+msg.Text)
case config.EventNoticeIRC:
case config.EventNotice:
b.Log.Debugf("Sending notice to channel %s", msg.Channel)
b.i.Cmd.Notice(msg.Channel, username+msg.Text)
default:

View File

@@ -150,6 +150,7 @@ func (b *Bmatrix) handleMemberChange(ev *event.Event) {
}
}
//nolint: funlen
func (b *Bmatrix) handleMessage(rmsg config.Message, ev *event.Event) {
msg := ev.Content.AsMessage()
if msg == nil {
@@ -169,10 +170,10 @@ func (b *Bmatrix) handleMessage(rmsg config.Message, ev *event.Event) {
rmsg.Avatar = avatarURL
}
// Do we have a /me action
//nolint: exhaustive
switch msg.MsgType {
case event.MsgEmote:
// Do we have a /me action
rmsg.Event = config.EventUserAction
case event.MsgImage, event.MsgVideo, event.MsgFile:
// Do we have attachments? (we only allow images, videos or files msgtypes)
@@ -180,6 +181,9 @@ func (b *Bmatrix) handleMessage(rmsg config.Message, ev *event.Event) {
if err != nil {
b.Log.Errorf("download failed: %#v", err)
}
case event.MsgNotice:
// Support for IRC NOTICE commands/[matrix] m.notice
rmsg.Event = config.EventNotice
default:
if msg.RelatesTo == nil {
break

View File

@@ -195,6 +195,7 @@ func (b *Bmatrix) Start() error {
return nil
}
//nolint: funlen,gocognit,gocyclo
func (b *Bmatrix) Send(msg config.Message) (string, error) {
b.Log.Debugf("=> Sending %#v", msg)
@@ -305,7 +306,7 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
}
// Use notices to send join/leave events
if msg.Event == config.EventJoinLeave {
if msg.Event == config.EventJoinLeave || msg.Event == config.EventNotice {
m.MsgType = event.MsgNotice
} else {
m.MsgType = event.MsgText