2023-07-09 01:17:47 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2023-07-09 20:00:49 +00:00
|
|
|
"unicode/utf8"
|
2023-07-09 01:17:47 +00:00
|
|
|
|
2023-07-09 04:42:58 +00:00
|
|
|
"github.com/Cynosphere/comcord/lib"
|
2023-07-09 01:17:47 +00:00
|
|
|
"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 01:17:47 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 00:30:49 +00:00
|
|
|
channel, err := session.State.Channel(channelId)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Print("<error getting channel: ", err.Error(), ">\n\r")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
perms, err := session.State.UserChannelPermissions(session.State.User.ID, channel.ID)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Print("<failed to check permissions: ", err.Error(), ">\n\r")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if perms & discordgo.PermissionSendMessages == 0 {
|
|
|
|
fmt.Print("<you do not have permission to send messages here>\n\r")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-09 20:00:49 +00:00
|
|
|
length := utf8.RuneCountInString(session.State.User.Username) + 2
|
2023-07-09 01:17:47 +00:00
|
|
|
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-09 01:17:47 +00:00
|
|
|
|
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")
|
|
|
|
}
|
2023-07-09 01:17:47 +00:00
|
|
|
} else {
|
2023-07-11 03:41:51 +00:00
|
|
|
fmt.Print(prompt, input, "\n\r")
|
|
|
|
_, err := session.ChannelMessageSend(channelId, input)
|
2023-07-09 01:17:47 +00:00
|
|
|
|
2023-07-11 03:41:51 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Print("<failed to send message: ", err, ">\n\r")
|
|
|
|
}
|
2023-07-09 01:17:47 +00:00
|
|
|
|
2023-07-11 03:41:51 +00:00
|
|
|
// TODO: update afk state
|
|
|
|
}
|
|
|
|
})
|
2023-07-09 01:17:47 +00:00
|
|
|
}
|