comcord/commands/send.go

48 lines
1.1 KiB
Go
Raw Normal View History

package commands
import (
"fmt"
"strings"
2023-07-09 20:00:49 +00:00
"unicode/utf8"
2023-07-09 04:42:58 +00:00
"github.com/Cynosphere/comcord/lib"
"github.com/Cynosphere/comcord/state"
"github.com/bwmarrin/discordgo"
"github.com/mgutz/ansi"
)
func SendMode(session *discordgo.Session) {
channelId := state.GetCurrentChannel()
if channelId == "" {
fmt.Print("<not in a channel>\n\r")
2023-07-11 03:46:47 +00:00
return
}
2023-07-09 20:00:49 +00:00
length := utf8.RuneCountInString(session.State.User.Username) + 2
curLength := state.GetNameLength()
2023-07-09 04:42:58 +00:00
prompt := fmt.Sprintf("[%s]%s", session.State.User.Username, strings.Repeat(" ", (curLength - length) + 1))
if !state.HasNoColor() {
prompt = ansi.Color(prompt, "cyan+b")
}
2023-07-11 03:41:51 +00:00
lib.MakePrompt(session, prompt, true, func(session *discordgo.Session, input string, interrupt bool) {
if input == "" {
if interrupt {
fmt.Print("^C<no message sent>\n\r")
} else {
fmt.Print(prompt, "<no message sent>\n\r")
}
} else {
2023-07-11 03:41:51 +00:00
fmt.Print(prompt, input, "\n\r")
_, err := session.ChannelMessageSend(channelId, input)
2023-07-11 03:41:51 +00:00
if err != nil {
fmt.Print("<failed to send message: ", err, ">\n\r")
}
2023-07-11 03:41:51 +00:00
// TODO: update afk state
}
})
}