Skip to content

Commit

Permalink
Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gravufo committed Apr 21, 2023
1 parent fb5ddc5 commit 7f9cd4a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 4 additions & 3 deletions server/parrots.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
baseUrl = "https://raw.githubusercontent.com/jmhobbs/cultofthepartyparrot.com/main/"
baseURL = "https://raw.githubusercontent.com/jmhobbs/cultofthepartyparrot.com/main/"
)

var parrotTypes = [...]string{
Expand All @@ -27,7 +27,7 @@ type Parrot struct {
}

func fetchParrotList(parrotType string) (parrots []Parrot, err error) {
resp, err := http.Get(baseUrl + parrotType + ".yaml")
resp, err := http.Get(baseURL + parrotType + ".yaml")
if err != nil {
return
}
Expand Down Expand Up @@ -59,10 +59,11 @@ func fetchParrotList(parrotType string) (parrots []Parrot, err error) {

func fetchParrotGif(parrot *Parrot, parrotType string) (err error) {
// Fetch the gif from GitHub
resp, err := http.Get(baseUrl + parrotType + "/" + parrot.file)
resp, err := http.Get(baseURL + parrotType + "/" + parrot.file)
if err != nil {
return
}
defer resp.Body.Close()
parrot.gif, err = io.ReadAll(resp.Body)
if err != nil {
return
Expand Down
3 changes: 2 additions & 1 deletion server/parrots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestFetchParrotGif(t *testing.T) {
name: "parrot",
file: "hd/parrot.gif",
}
fetchParrotGif(&parrot, "parrots")
err := fetchParrotGif(&parrot, "parrots")
assert.Nil(err)
assert.NotEmpty(parrot.gif)
}
19 changes: 12 additions & 7 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"net/http"
"strings"
"sync"

Expand Down Expand Up @@ -59,7 +60,7 @@ func (p *Plugin) OnDeactivate() error {
}

// ExecuteCommand handle commands that are created by this plugin
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
p.API.LogInfo("Slash command received.")
p.SendEphemeralPost(args.ChannelId, args.UserId, args.RootId, "Starting Party Parrots sync...")
if err := p.ensureConnected(); err != nil {
Expand Down Expand Up @@ -93,10 +94,13 @@ func (p *Plugin) CreateEmoji(parrot Parrot, parrotType string) {
}
// Fetch the gif data from GitHub
p.API.LogInfo(fmt.Sprintf("Fetching gif for %s.", parrot.name))
fetchParrotGif(&parrot, parrotType)
if fetchParrotGif(&parrot, parrotType) != nil {
p.API.LogError(fmt.Sprintf("Failed to fetch %s", parrot.name))
return
}
appErr := p.client.RegisterNewEmoji(parrot.gif, parrot.name, p.UserID)
if appErr != nil && strings.Contains(appErr.Error(), "Name conflicts with existing system emoji name") {
parrot.name = parrot.name + "2"
parrot.name += "2"
if !p.EmojiExists(parrot.name) {
p.API.LogInfo(fmt.Sprintf("Emoji :%s: already exists. Skipping.", parrot.name))
return
Expand All @@ -110,10 +114,7 @@ func (p *Plugin) CreateEmoji(parrot Parrot, parrotType string) {

func (p *Plugin) EmojiExists(name string) bool {
emoji, _ := p.API.GetEmojiByName(name)
if emoji != nil {
return true
}
return false
return emoji != nil
}

// SendEphemeralPost sends an ephemeral post to a user as the bot account
Expand All @@ -132,4 +133,8 @@ func (p *Plugin) UpdateEphemeralPost(message string) {
p.ephemeralPost = p.API.UpdateEphemeralPost(p.UserID, p.ephemeralPost)
}

func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, _ *http.Request) {
fmt.Fprint(w, "Hello, world!")
}

// See https://developers.mattermost.com/extend/plugins/server/reference/

0 comments on commit 7f9cd4a

Please sign in to comment.