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

Commit

Permalink
Experimental react command
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Perez committed Nov 18, 2020
1 parent 1cc4e20 commit d25e701
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func SetupApplicationWithAccount(app *tview.Application, account string) {
window.RegisterCommand(serverJoinCmd)
window.RegisterCommand(serverLeaveCmd)
window.RegisterCommand(serverCreateCmd)
window.RegisterCommand(commandimpls.NewReaction(discord))
window.RegisterCommand(commandimpls.NewServerCommand(serverJoinCmd, serverLeaveCmd, serverCreateCmd))
window.RegisterCommand(commandimpls.NewNickSetCmd(discord, window))
window.RegisterCommand(commandimpls.NewVimCmd(config.Current))
Expand Down
90 changes: 90 additions & 0 deletions commands/commandimpls/react.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package commandimpls

import (
"fmt"
"io"

"github.com/Bios-Marcel/discordgo"
)

const (
reactionHelp = `[::b]NAME
reaction - show existing message reactions or add new ones
[::b]SYNOPSIS
[::b]React to a message with react channelID messageID emoji
You can get the first two in chat view by pressing 'w' above a message while in vim mode.
Emojis can be seen by issuing react list
Emoji can either be an unicode emoji or a string.
Show reactions of a message react show channelID messageID
[::b]DESCRIPTION
This is a minor mode for vim. See all the shorcuts with Ctrl K, and edit them inside shortcuts/shortcuts.go
Toggle vim with vim on/off/enable/disable
`
)

type Reaction struct {
session *discordgo.Session
}

func NewReaction (s *discordgo.Session) *Reaction{
return &Reaction{session: s}
}

// PrintHelp prints a static help page for this command
func (r Reaction) PrintHelp(writer io.Writer) {
fmt.Fprintln(writer, reactionHelp)
}

func (r Reaction) Execute(writer io.Writer, parameters []string) {
if len(parameters) < 1 {
fmt.Fprintf(writer, "Not enough parameters. Issue man reaction to see help.")
return
}
switch parameters[0] {
case "list":
fmt.Fprintf(writer,"TODO")
case "show":
if len(parameters) < 3 {
fmt.Fprintf(writer, "Not enough arguments provided.")
return
}
message, err := r.session.ChannelMessage(parameters[1], parameters[2])
if err != nil {
fmt.Fprintf(writer, "There was an error obtaining the message.\n%e",err)
return
}
reactions := message.Reactions
for _, reaction := range reactions {
fmt.Fprintf(writer, "%s\n",reaction.Emoji.Name)
}
return

default:
if len(parameters) < 3 {
fmt.Fprintf(writer, "Not enough arguments provided for adding reaction.")
return
}
err := r.session.MessageReactionAdd(parameters[0], parameters[1], parameters[2])
if err != nil {
fmt.Fprintf(writer, "Something wrong ocurred while adding reaction. \n")
return
}
fmt.Fprintf(writer, "Added reaction successfully.")

}
}

// Name returns the primary name for this command. This name will also be
// used for listing the command in the commandlist.
func (r Reaction) Name() string {
return "reaction"
}

// Aliases are a list of aliases for this command. There might be none.
func (r Reaction) Aliases() []string {
return []string{"react", "reaction"}
}
6 changes: 5 additions & 1 deletion shortcuts/shortcuts.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ var (
ToggleBareChat = addShortcut("toggle_bare_chat", "Toggle bare chat",
globalScope, tcell.NewEventKey(tcell.KeyCtrlB, rune(tcell.KeyCtrlB), tcell.ModCtrl),
// FIXME unknown binding
addVimEvent(NullVimEvent,NullVimEvent,NullVimEvent),
addVimEvent(nil,NullVimEvent,NullVimEvent),
)

GuildListMarkRead = addShortcut("guild_mark_read", "Mark server as read",
Expand All @@ -317,6 +317,10 @@ var (
addVimEvent(NullVimEvent,tcell.NewEventKey(tcell.KeyRune, 'm', tcell.ModNone), tcell.NewEventKey(tcell.KeyRune, 'm', tcell.ModNone)),
)

ShowMessageID = addShortcut("show_message_id", "View message id",
chatview, nil,
addVimEvent(NullVimEvent,tcell.NewEventKey(tcell.KeyRune, 'w', tcell.ModNone),NullVimEvent))

VimInsertMode = addShortcut("vim_insert_mode", "Change to Vim insert mode",
globalScope, nil,
addVimEvent(tcell.NewEventKey(tcell.KeyRune, 'i', tcell.ModNone),NullVimEvent,NullVimEvent),
Expand Down
15 changes: 15 additions & 0 deletions ui/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ func NewWindow(app *tview.Application, session *discordgo.Session, readyEvent *d
window.insertQuoteOfMessage(message)
return nil
}
if shortcuts.ShowMessageID.Equals(event) {
if !window.commandMode {
window.SetCommandModeEnabled(true)
}
fmt.Fprintf(window.commandView, "Selected channel ID: %s , Current message ID: %s\n", message.ChannelID, message.ID)
clipboard.WriteAll(fmt.Sprintf("%s %s", message.ChannelID, message.ID))
// window.chatView.formattedMessages
fmt.Fprintf(window.commandView, "ChannelID and MessageID copied to clipboard.\n")
return nil
}

if shortcuts.NewDirectMessage.Equals(event) {
dmError := window.OpenDirectMessage(message.Author.ID)
Expand Down Expand Up @@ -2109,6 +2119,11 @@ func (window *Window) handleNotification(message *discordgo.Message, channel *di
return beeep.Notify("Cordless - "+notificationLocation, message.ContentWithMentionsReplaced(), "assets/information.png")
}

// TODO
func (window *Window) reactToMessage(messageID string, reaction string) {

}

func (window *Window) askForMessageDeletion(messageID string, usedWithSelection bool) {
deleteButtonText := "Delete"
window.ShowDialog(tview.Styles.PrimitiveBackgroundColor,
Expand Down

0 comments on commit d25e701

Please sign in to comment.