Skip to content

Commit

Permalink
Add command to part/leave channels
Browse files Browse the repository at this point in the history
  • Loading branch information
hloeung committed Feb 12, 2024
1 parent b762e5e commit 530ceb7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ Mark messages in a channel/from a user as read (when DisableAutoView is set).
/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
21 changes: 21 additions & 0 deletions mm-go-irckit/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,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 @@ -482,6 +502,7 @@ var cmds = map[string]Command{
"lastsent": {handler: lastsent, login: true, minParams: 0, maxParams: 0},
"logout": {handler: logout, login: true, minParams: 0, maxParams: 0},
"login": {handler: login, minParams: 2, maxParams: 5},
"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

0 comments on commit 530ceb7

Please sign in to comment.