Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #76 from scottleedavis/issue_65
Browse files Browse the repository at this point in the history
sets ephemeral posts for everything (except /remind list).
  • Loading branch information
scottleedavis authored Apr 28, 2019
2 parents 8afcfda + 7f04ddb commit c87b1b7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 87 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "com.github.scottleedavis.mattermost-plugin-remind",
"name": "Remind Bot Mattermost Plugin",
"description": "Sets Reminders",
"version": "0.1.6",
"version": "0.1.7",
"server": {
"executables": {
"linux-amd64": "server/dist/plugin-linux-amd64",
Expand Down
137 changes: 52 additions & 85 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,25 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo
location := p.location(user)

if strings.HasSuffix(args.Command, T("help")) {
// post := model.Post{
// ChannelId: args.ChannelId,
// PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
// UserId: p.remindUserId,
// Message: T("help.response"),
// }

// if _, pErr := p.API.CreatePost(&post); pErr != nil {
// p.API.LogError(fmt.Sprintf("%v", pErr))
// }
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
Text: fmt.Sprintf(T("help.response")),
Username: botName,
}, nil
post := model.Post{
ChannelId: args.ChannelId,
UserId: p.remindUserId,
Message: T("help.response"),
}
p.API.SendEphemeralPost(user.Id, &post)
return &model.CommandResponse{}, nil
}

if strings.HasSuffix(args.Command, T("list")) {
listMessage := p.ListReminders(user, args.ChannelId)
if listMessage != "" {
// post := model.Post{
// ChannelId: args.ChannelId,
// PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
// UserId: p.remindUserId,
// Message: listMessage,
// }

// if _, pErr := p.API.CreatePost(&post); pErr != nil {
// p.API.LogError(fmt.Sprintf("%v", pErr))
// }
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
Text: fmt.Sprintf(listMessage),
Username: botName,
}, nil
}
// p.API.SendEphemeralPost(user.Id, p.ListReminders(user, args.ChannelId))
return &model.CommandResponse{}, nil
}

Expand All @@ -97,82 +80,66 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo
response, err := p.ScheduleReminder(&request)

if err != nil {
// post := model.Post{
// ChannelId: args.ChannelId,
// PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
// UserId: p.remindUserId,
// Message: T("exception.response"),
// }

// if _, pErr := p.API.CreatePost(&post); pErr != nil {
// p.API.LogError(fmt.Sprintf("%v", pErr))
// }
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
Text: fmt.Sprintf(T("exception.response")),
Username: botName,
}, nil
post := model.Post{
ChannelId: args.ChannelId,
UserId: p.remindUserId,
Message: T("exception.response"),
}
p.API.SendEphemeralPost(user.Id, &post)
return &model.CommandResponse{}, nil
}

post := model.Post{
ChannelId: args.ChannelId,
UserId: p.remindUserId,
Message: response,
}
p.API.SendEphemeralPost(user.Id, &post)
return &model.CommandResponse{}, nil

// post := model.Post{
// ChannelId: args.ChannelId,
// PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
// UserId: p.remindUserId,
// Message: response,
// }

// if _, pErr := p.API.CreatePost(&post); pErr != nil {
// p.API.LogError(fmt.Sprintf("%v", pErr))
// }
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
Text: fmt.Sprintf(response),
Username: botName,
}, nil
}

// debug & troubleshooting commands

// clear all reminders for current user
if strings.HasSuffix(args.Command, "__clear") {
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
Text: fmt.Sprintf(p.DeleteReminders(user)),
Username: botName,
}, nil
post := model.Post{
ChannelId: args.ChannelId,
UserId: p.remindUserId,
Message: p.DeleteReminders(user),
}
p.API.SendEphemeralPost(user.Id, &post)
return &model.CommandResponse{}, nil
}

// display the plugin version
if strings.HasSuffix(args.Command, "__version") {
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
Text: fmt.Sprintf(manifest.Version),
Username: botName,
}, nil
post := model.Post{
ChannelId: args.ChannelId,
UserId: p.remindUserId,
Message: manifest.Version,
}
p.API.SendEphemeralPost(user.Id, &post)
return &model.CommandResponse{}, nil
}

// display the locale & location of user
if strings.HasSuffix(args.Command, "__user") {
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
Text: fmt.Sprintf(locale + " " + location.String()),
Username: botName,
}, nil
post := model.Post{
ChannelId: args.ChannelId,
UserId: p.remindUserId,
Message: locale + " " + location.String(),
}
p.API.SendEphemeralPost(user.Id, &post)
return &model.CommandResponse{}, nil
}

// post := model.Post{
// ChannelId: args.ChannelId,
// PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
// UserId: p.remindUserId,
// Message: T("exception.response"),
// }

// if _, pErr := p.API.CreatePost(&post); pErr != nil {
// p.API.LogError(fmt.Sprintf("%v", pErr))
// }
return &model.CommandResponse{
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
Text: fmt.Sprintf(T("exception.response")),
Username: botName,
}, nil
post := model.Post{
ChannelId: args.ChannelId,
UserId: p.remindUserId,
Message: T("exception.response"),
}
p.API.SendEphemeralPost(user.Id, &post)
return &model.CommandResponse{}, nil

}
2 changes: 1 addition & 1 deletion server/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ var manifest = struct {
Version string
}{
Id: "com.github.scottleedavis.mattermost-plugin-remind",
Version: "0.1.6",
Version: "0.1.7",
}

0 comments on commit c87b1b7

Please sign in to comment.