package commands import ( "fmt" "strings" "unicode/utf8" "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("\n\r") return } channel, err := session.State.Channel(channelId) if err != nil { fmt.Print("\n\r") return } perms, err := session.State.UserChannelPermissions(session.State.User.ID, channel.ID) if err != nil { fmt.Print("\n\r") return } if perms & discordgo.PermissionSendMessages == 0 { fmt.Print("\n\r") return } length := utf8.RuneCountInString(session.State.User.Username) + 2 curLength := state.GetNameLength() prompt := fmt.Sprintf("[%s]%s", session.State.User.Username, strings.Repeat(" ", (curLength - length) + 1)) if !state.HasNoColor() { prompt = ansi.Color(prompt, "cyan+b") } 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 } }) }