From 4aa208ee6949a3433d7ef3e7d4b890108da46daf Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Mon, 10 Jul 2023 21:46:47 -0600 Subject: [PATCH] emote command --- commands/emote.go | 37 +++++++++++++++++++++++++++++++++++++ commands/main.go | 5 +++++ commands/send.go | 4 +--- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 commands/emote.go diff --git a/commands/emote.go b/commands/emote.go new file mode 100644 index 0000000..5c151c2 --- /dev/null +++ b/commands/emote.go @@ -0,0 +1,37 @@ +package commands + +import ( + "fmt" + + "github.com/Cynosphere/comcord/lib" + "github.com/Cynosphere/comcord/state" + "github.com/bwmarrin/discordgo" +) + +func EmoteCommand(session *discordgo.Session) { + channelId := state.GetCurrentChannel() + if channelId == "" { + fmt.Print("\n\r") + return + } + + prompt := ":emote> " + lib.MakePrompt(session, prompt, true, func(session *discordgo.Session, input string, interrupt bool) { + if input == "" { + if interrupt { + fmt.Print("^C\n\r") + } else { + fmt.Print(prompt, "\n\r") + } + } else { + fmt.Print(prompt, input, "\n\r") + _, err := session.ChannelMessageSend(channelId, "*" + input + "*") + + if err != nil { + fmt.Print("\n\r") + } + + // TODO: update afk state + } + }) +} diff --git a/commands/main.go b/commands/main.go index 916ff01..ae9510f 100644 --- a/commands/main.go +++ b/commands/main.go @@ -26,6 +26,11 @@ func Setup() { Run: ClearCommand, Description: "clear", } + + commandMap["e"] = Command{ + Run: EmoteCommand, + Description: "emote", + } } func GetCommand(key string) (Command, bool) { diff --git a/commands/send.go b/commands/send.go index 205a58c..fedc660 100644 --- a/commands/send.go +++ b/commands/send.go @@ -15,11 +15,9 @@ func SendMode(session *discordgo.Session) { channelId := state.GetCurrentChannel() if channelId == "" { fmt.Print("\n\r") - return + return } - state.SetInPrompt(true) - length := utf8.RuneCountInString(session.State.User.Username) + 2 curLength := state.GetNameLength()