send mode impl, wip default guild/channel setting
This commit is contained in:
parent
10ba1af405
commit
7a69523b09
6 changed files with 173 additions and 20 deletions
54
commands/send.go
Normal file
54
commands/send.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Cynosphere/comcord/state"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/ergochat/readline"
|
||||
"github.com/mgutz/ansi"
|
||||
)
|
||||
|
||||
func SendMode(session *discordgo.Session) {
|
||||
channelId := state.GetCurrentChannel()
|
||||
if channelId == "" {
|
||||
fmt.Print("<not in a channel>\n\r")
|
||||
return
|
||||
}
|
||||
|
||||
state.SetInPrompt(true)
|
||||
|
||||
length := len(session.State.User.Username) + 2
|
||||
curLength := state.GetNameLength()
|
||||
|
||||
prompt := fmt.Sprintf("%s[%s]%s%s", ansi.ColorCode("cyan+b"), session.State.User.Username, strings.Repeat(" ", (curLength - length) + 1), ansi.ColorCode("reset"))
|
||||
|
||||
input, _ := readline.NewFromConfig(&readline.Config{
|
||||
Prompt: prompt,
|
||||
UniqueEditLine: true,
|
||||
})
|
||||
defer input.Close()
|
||||
|
||||
out, err := input.Readline()
|
||||
out = strings.TrimSpace(out)
|
||||
input.Close()
|
||||
|
||||
if out == "" {
|
||||
if err == readline.ErrInterrupt {
|
||||
fmt.Print("^C<no message sent>\n\r")
|
||||
} else {
|
||||
fmt.Print(prompt, "<no message sent>\n\r")
|
||||
}
|
||||
} else {
|
||||
fmt.Print(prompt, out, "\n\r")
|
||||
_, err := session.ChannelMessageSend(channelId, out)
|
||||
|
||||
if err != nil {
|
||||
fmt.Print("<failed to send message: ", err, ">\n\r")
|
||||
}
|
||||
|
||||
// TODO: update afk state
|
||||
}
|
||||
state.SetInPrompt(false)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue