Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-go@v5.4.0
with:
# The Go version to download (if necessary) and use. Supports semver spec and ranges.
go-version: 1.16.7
go-version: 1.22

- name: Install golangci-lint
uses: golangci/golangci-lint-action@v7
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ Use the following table to find the correct plugin version for your Mattermost s

| Mattermost server | Plugin release | Incompatibility |
| --- | --- | --- |
| 5.20 and higher | v3.1.x+ | breaking plugin manifest change |
| 7.10 and higher | v3.2.x+ | ℹ️ This version might be compatible down to 6.7 versions but has only been tested on 7.10+ |
| 5.20 to 7.10 | v3.1.x+ | breaking plugin manifest change |
| 5.12 to 5.19 | v3.0.x | breaking plugin API change |
| 5.2 to 5.11 | v2.x.x | |
| 4.6 to 5.1 | v1.x.x | |
| below | *not supported* | plugins can't create slash commands |

## Installation and configuration
**In Mattermost 5.20 and later:**
1. In Mattermost, go to **Main Menu > Plugin Marketplace**.
2. Search for the "Dice Roller" plugin, then click **Install** to install it.
3. **Activate the plugin** in the `System Console > Plugins Management > Management` page

If you are running Mattermost 5.19 or earlier, or do not have the Plugin Marketplace enabled, follow these steps:
> [!TIP]
> This plugin was for a few years available in the official Mattermost marketplace, however the Mattermost team [decided to stop hosting community plugins in the marketplace](https://mattermost.atlassian.net/browse/MM-53030) in September 2023, so however you installed your current version, you will need to follow the manual installation steps below.

1. Go to the [Releases page](https://github.com/moussetc/mattermost-plugin-dice-roller/releases) and download the `.tar.gz` package. Supported platforms are: Linux x64, Windows x64, Darwin x64, FreeBSD x64.
2. Use the Mattermost `System Console > Plugins Management > Management` page to upload the `.tar.gz` package
3. **Activate the plugin** in the `System Console > Plugins Management > Management` page
Expand Down
2 changes: 1 addition & 1 deletion build/manifest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost/server/public/model"
"github.com/pkg/errors"
)

Expand Down
43 changes: 25 additions & 18 deletions build/pluginctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
package main

import (
"context"
"errors"
"fmt"
"log"
"net"
"os"
"time"

"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost/server/public/model"
)

const commandTimeout = 120 * time.Second

const helpText = `
Usage:
pluginctl deploy <plugin id> <bundle path>
Expand All @@ -33,7 +37,10 @@ func pluginctl() error {
return errors.New("invalid number of arguments")
}

client, err := getClient()
ctx, cancel := context.WithTimeout(context.Background(), commandTimeout)
defer cancel()

client, err := getClient(ctx)
if err != nil {
return err
}
Expand All @@ -43,19 +50,19 @@ func pluginctl() error {
if len(os.Args) < 4 {
return errors.New("invalid number of arguments")
}
return deploy(client, os.Args[2], os.Args[3])
return deploy(ctx, client, os.Args[2], os.Args[3])
case "disable":
return disablePlugin(client, os.Args[2])
return disablePlugin(ctx, client, os.Args[2])
case "enable":
return enablePlugin(client, os.Args[2])
return enablePlugin(ctx, client, os.Args[2])
case "reset":
return resetPlugin(client, os.Args[2])
return resetPlugin(ctx, client, os.Args[2])
default:
return errors.New("invalid second argument")
}
}

func getClient() (*model.Client4, error) {
func getClient(ctx context.Context) (*model.Client4, error) {
socketPath := os.Getenv("MM_LOCALSOCKETPATH")
if socketPath == "" {
socketPath = model.LocalModeSocketPath
Expand Down Expand Up @@ -91,7 +98,7 @@ func getClient() (*model.Client4, error) {
if adminUsername != "" && adminPassword != "" {
client := model.NewAPIv4Client(siteURL)
log.Printf("Authenticating as %s against %s.", adminUsername, siteURL)
_, _, err := client.Login(adminUsername, adminPassword)
_, _, err := client.Login(ctx, adminUsername, adminPassword)
if err != nil {
return nil, fmt.Errorf("failed to login as %s: %w", adminUsername, err)
}
Expand All @@ -113,21 +120,21 @@ func getUnixClient(socketPath string) (*model.Client4, bool) {

// deploy attempts to upload and enable a plugin via the Client4 API.
// It will fail if plugin uploads are disabled.
func deploy(client *model.Client4, pluginID, bundlePath string) error {
func deploy(ctx context.Context, client *model.Client4, pluginID, bundlePath string) error {
pluginBundle, err := os.Open(bundlePath)
if err != nil {
return fmt.Errorf("failed to open %s: %w", bundlePath, err)
}
defer pluginBundle.Close()

log.Print("Uploading plugin via API.")
_, _, err = client.UploadPluginForced(pluginBundle)
_, _, err = client.UploadPluginForced(ctx, pluginBundle)
if err != nil {
return fmt.Errorf("failed to upload plugin bundle: %s", err.Error())
}

log.Print("Enabling plugin.")
_, err = client.EnablePlugin(pluginID)
_, err = client.EnablePlugin(ctx, pluginID)
if err != nil {
return fmt.Errorf("failed to enable plugin: %s", err.Error())
}
Expand All @@ -136,9 +143,9 @@ func deploy(client *model.Client4, pluginID, bundlePath string) error {
}

// disablePlugin attempts to disable the plugin via the Client4 API.
func disablePlugin(client *model.Client4, pluginID string) error {
func disablePlugin(ctx context.Context, client *model.Client4, pluginID string) error {
log.Print("Disabling plugin.")
_, err := client.DisablePlugin(pluginID)
_, err := client.DisablePlugin(ctx, pluginID)
if err != nil {
return fmt.Errorf("failed to disable plugin: %w", err)
}
Expand All @@ -147,9 +154,9 @@ func disablePlugin(client *model.Client4, pluginID string) error {
}

// enablePlugin attempts to enable the plugin via the Client4 API.
func enablePlugin(client *model.Client4, pluginID string) error {
func enablePlugin(ctx context.Context, client *model.Client4, pluginID string) error {
log.Print("Enabling plugin.")
_, err := client.EnablePlugin(pluginID)
_, err := client.EnablePlugin(ctx, pluginID)
if err != nil {
return fmt.Errorf("failed to enable plugin: %w", err)
}
Expand All @@ -158,13 +165,13 @@ func enablePlugin(client *model.Client4, pluginID string) error {
}

// resetPlugin attempts to reset the plugin via the Client4 API.
func resetPlugin(client *model.Client4, pluginID string) error {
err := disablePlugin(client, pluginID)
func resetPlugin(ctx context.Context, client *model.Client4, pluginID string) error {
err := disablePlugin(ctx, client, pluginID)
if err != nil {
return err
}

err = enablePlugin(client, pluginID)
err = enablePlugin(ctx, client, pluginID)
if err != nil {
return err
}
Expand Down
62 changes: 58 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
module github.com/moussetc/mattermost-plugin-dice-roller

go 1.16
go 1.23.0

toolchain go1.23.6

require (
github.com/mattermost/mattermost-plugin-api v0.0.21
github.com/mattermost/mattermost-server/v6 v6.7.2
github.com/mattermost/mattermost/server/public v0.1.11
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.1
github.com/stretchr/testify v1.10.0
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/beevik/etree v1.1.0 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dyatlov/go-opengraph/opengraph v0.0.0-20220524092352-606d7b1e5f8a // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.7 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.3 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect
github.com/mattermost/gosaml2 v0.8.0 // indirect
github.com/mattermost/ldap v0.0.0-20231116144001-0f480c025956 // indirect
github.com/mattermost/logr/v2 v2.0.22 // indirect
github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/russellhaering/goxmldsig v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/tinylib/msgp v1.2.5 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wiggin77/merror v1.0.5 // indirect
github.com/wiggin77/srslog v1.0.1 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/net v0.39.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34 // indirect
google.golang.org/grpc v1.72.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading