Skip to content

Commit

Permalink
Merge branch 'master' into replay-as-service
Browse files Browse the repository at this point in the history
  • Loading branch information
hloeung authored Feb 16, 2024
2 parents c0e3906 + a531f26 commit 9d976c8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,22 @@ Search

Scrollback
```
/msg mattermost scrollback <channel> <limit>
e.g. /msg mattermost scrollback #bugs 100 shows the last 100 messages of #bugs
/msg mattermost scrollback #<channel>|<user>|<post/thread ID> <limit>
```
e.g. `/msg mattermost scrollback #bugs 100` shows the last 100 messages of *#bugs*
e.g. `/msg mattermost scrollback zdofdf1nctgsj87xgt6oco1a3w 0` shows all messages from the thread with root/parent *zdofdf1nctgsj87xgt6oco1a3w*

Mark messages in a channel/from a user as read (when DisableAutoView is set).
```
/msg mattermost updatelastviewed <channel>
/msg mattermost updatelastviewed <username>
```

Part/leave
```
/msg mattermost part #mychannel
```

### Slack user commands

Get a slack token on <https://api.slack.com/custom-integrations/legacy-tokens>
Expand Down Expand Up @@ -250,6 +256,10 @@ running more quickly:

- [Breaking out of the Slack walled garden](https://purpleidea.com/blog/2018/06/22/breaking-out-of-the-slack-walled-garden/)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=42wim/matterircd)](https://github.com/42wim/matterircd/graphs/contributors)

## Related

- [matterircd-complete](https://github.com/hloeung/matterircd-complete) - better irssi/mattermost/matterircd integration
12 changes: 11 additions & 1 deletion matterircd.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PasteBufferTimeout = 2500
Insecure = false

#ignore the Mattermost server version when checking if supported
#ignoreserverversion = false
#IgnoreServerVersion = false

#an array of channels that only will be joined on IRC. JoinExlude and JoinInclude will not be checked
#regexp is supported
Expand All @@ -65,6 +65,10 @@ Insecure = false
#
#JoinOnly = ["#onlythischannel"]

# When set, all scrollback messages are shown in &messages rather than individual channels
#
#CollapseScrollback = false

#an array of channels that won't be joined on IRC.
#regexp is supported
#Messages that get sent to unjoined channels (but you're joined on mattermost) will
Expand All @@ -83,6 +87,9 @@ Insecure = false
#
#JoinInclude = ["#devops","#myteam-marketing"]

#show only messages for channels joined, so nothing in the &messages channel.
#ShowOnlyJoined = false

#PartFake: a bool that defines if you do a /LEAVE or /PART on IRC it will also
#actually leave the channel on mattermost.
#if false it actually leaves the channel on mattermost
Expand Down Expand Up @@ -224,6 +231,9 @@ UseDisplayName = false
#
#JoinInclude = ["#devops","#myteam-marketing"]

#show only messages for channels joined, so nothing in the &messages channel.
#ShowOnlyJoined = false

#This will add a number between 000 and fff to each message
#This number will be referenced when a message is edited/deleted/threaded/reaction
PrefixContext = false
Expand Down
35 changes: 34 additions & 1 deletion mm-go-irckit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,26 @@ func getMattermostChannelName(u *User, channelID string) string {
return channelMembers[0]
}

func part(u *User, toUser *User, args []string, service string) {
if len(args) != 1 {
u.MsgUser(toUser, "need PART #<channel>")
u.MsgUser(toUser, "e.g. PART #bugs")
return
}

channelName := strings.TrimPrefix(args[0], "#")
channelTeamID := u.br.GetMe().TeamID
if len(args) == 2 {
channelTeamID = args[1]
}
channelID := u.br.GetChannelID(channelName, channelTeamID)

err := u.br.Part(channelID)
if err != nil {
u.MsgUser(toUser, fmt.Sprintf("could not part/leave %s", args[0]))
}
}

//nolint:funlen,gocognit,gocyclo,cyclop
func scrollback(u *User, toUser *User, args []string, service string) {
if service == "slack" {
Expand Down Expand Up @@ -587,13 +607,25 @@ func scrollback(u *User, toUser *User, args []string, service string) {
}
}

u.MsgUser(toUser, fmt.Sprintf("scrollback results shown in %s", search))
if !u.v.GetBool(u.br.Protocol() + ".collapsescrollback") { //nolint:goconst
u.MsgUser(toUser, fmt.Sprintf("scrollback results shown in %s", search))
}
}

func formatScrollbackMsg(u *User, channelID string, channel string, user *User, nick string, p *model.Post, msgText string) {
ts := time.Unix(0, p.CreateAt*int64(time.Millisecond))

switch {
case (u.v.GetBool(u.br.Protocol()+".collapsescrollback") && strings.HasPrefix(channel, "#")):
threadMsgID := u.prefixContext(channelID, p.Id, p.RootId, "scrollback")
msg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, msgText)
nick += "/" + channel
u.Srv.Channel("&messages").SpoofMessage(nick, msg)
case u.v.GetBool(u.br.Protocol() + ".collapsescrollback"):
threadMsgID := u.prefixContext(channelID, p.Id, p.RootId, "scrollback")
msg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, msgText)
nick += "/" + channel
u.Srv.Channel("&messages").SpoofMessage(nick, msg)
case (u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext")) && strings.HasPrefix(channel, "#") && nick != systemUser:
threadMsgID := u.prefixContext(channelID, p.Id, p.RootId, "scrollback")
msg := u.formatContextMessage(ts.Format("2006-01-02 15:04"), threadMsgID, msgText)
Expand Down Expand Up @@ -654,6 +686,7 @@ var cmds = map[string]Command{
"logout": {handler: logout, login: true, minParams: 0, maxParams: 0},
"login": {handler: login, minParams: 2, maxParams: 5},
"replay": {handler: replay, login: true, minParams: 1, maxParams: 2},
"part": {handler: part, login: true, minParams: 1, maxParams: 1},
"search": {handler: search, login: true, minParams: 1, maxParams: -1},
"searchusers": {handler: searchUsers, login: true, minParams: 1, maxParams: -1},
"scrollback": {handler: scrollback, login: true, minParams: 2, maxParams: 2},
Expand Down
10 changes: 10 additions & 0 deletions mm-go-irckit/userbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) {
}

if event.ChannelType != "D" && ch.ID() == "&messages" {
if u.v.GetBool(u.br.Protocol() + ".showonlyjoined") {
return
}
nick += "/" + u.Srv.Channel(event.ChannelID).String()
}

Expand Down Expand Up @@ -344,6 +347,13 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) {
}

func (u *User) handleFileEvent(event *bridge.FileEvent) {
if u.v.GetBool(u.br.Protocol()+".showonlyjoined") && event.ChannelType != "D" {
ch := u.getMessageChannel(event.ChannelID, event.Sender)
if ch.ID() == "&messages" {
return
}
}

for _, fname := range event.Files {
fileMsg := "\x1ddownload file - " + fname.Name + "\x1d"
if u.v.GetBool(u.br.Protocol()+".prefixcontext") || u.v.GetBool(u.br.Protocol()+".suffixcontext") {
Expand Down

0 comments on commit 9d976c8

Please sign in to comment.