Compare commits
No commits in common. "80a343e4ee06ca9f061a5bc5e3aabd06dfe69f04" and "f21c414f1b12d299e275f69e473aef1ae801d91f" have entirely different histories.
80a343e4ee
...
f21c414f1b
8 changed files with 34 additions and 166 deletions
|
@ -13,12 +13,12 @@ Go is more portable than Node.js
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
- [x] Send mode
|
- [x] Send mode
|
||||||
- [x] Commands
|
- [ ] Commands
|
||||||
- [x] Quit (q)
|
- [x] Quit (q)
|
||||||
- [ ] Switch guilds (G)
|
- [ ] Switch guilds (G)
|
||||||
- [ ] Switch channels (g)
|
- [ ] Switch channels (g)
|
||||||
- [ ] List online users in guild (w)
|
- [ ] List online users in guild (w)
|
||||||
- [x] Emote (e)
|
- [ ] Emote (e)
|
||||||
- Just sends message surrounded in `*`'s
|
- Just sends message surrounded in `*`'s
|
||||||
- [ ] Finger (f)
|
- [ ] Finger (f)
|
||||||
- Shows presence data if available
|
- Shows presence data if available
|
||||||
|
@ -28,8 +28,8 @@ Go is more portable than Node.js
|
||||||
- [ ] Peek (p)
|
- [ ] Peek (p)
|
||||||
- [ ] Cross-guild peek (P)
|
- [ ] Cross-guild peek (P)
|
||||||
- [ ] List channels (l)
|
- [ ] List channels (l)
|
||||||
- [x] List guilds (L)
|
- [ ] List guilds (L)
|
||||||
- [x] Clear (c)
|
- [ ] Clear (c)
|
||||||
- [ ] Surf channels forwards (>)
|
- [ ] Surf channels forwards (>)
|
||||||
- [ ] Surf channels backwards (<)
|
- [ ] Surf channels backwards (<)
|
||||||
- [ ] AFK toggle (A)
|
- [ ] AFK toggle (A)
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
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("<not in a channel>\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<no message sent>\n\r")
|
|
||||||
} else {
|
|
||||||
fmt.Print(prompt, "<no message sent>\n\r")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Print(prompt, input, "\n\r")
|
|
||||||
_, err := session.ChannelMessageSend(channelId, "*" + input + "*")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Print("<failed to send message: ", err, ">\n\r")
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: update afk state
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
package commands
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GuildListing struct {
|
|
||||||
Name string
|
|
||||||
Members int
|
|
||||||
Online int
|
|
||||||
}
|
|
||||||
|
|
||||||
func ListGuildsCommand(session *discordgo.Session) {
|
|
||||||
longest := 0
|
|
||||||
guilds := make([]GuildListing, 0)
|
|
||||||
|
|
||||||
for _, guild := range session.State.Guilds {
|
|
||||||
length := utf8.RuneCountInString(guild.Name)
|
|
||||||
if length > longest {
|
|
||||||
longest = length
|
|
||||||
}
|
|
||||||
|
|
||||||
guildWithCounts, err := session.GuildWithCounts(guild.ID)
|
|
||||||
if err != nil {
|
|
||||||
guilds = append(guilds, GuildListing{
|
|
||||||
Name: guild.Name,
|
|
||||||
Members: guild.MemberCount,
|
|
||||||
Online: 0,
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guilds = append(guilds, GuildListing{
|
|
||||||
Name: guild.Name,
|
|
||||||
Members: guildWithCounts.ApproximateMemberCount,
|
|
||||||
Online: guildWithCounts.ApproximatePresenceCount,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Print("\n\r")
|
|
||||||
fmt.Printf(" %*s online total\n\r", longest, "guild-name")
|
|
||||||
fmt.Print(strings.Repeat("-", 80) + "\n\r")
|
|
||||||
for _, guild := range guilds {
|
|
||||||
fmt.Printf(" %*s %6d %5d\n\r", longest, guild.Name, guild.Online, guild.Members)
|
|
||||||
}
|
|
||||||
fmt.Print(strings.Repeat("-", 80) + "\n\r")
|
|
||||||
fmt.Print("\n\r")
|
|
||||||
}
|
|
|
@ -26,16 +26,6 @@ func Setup() {
|
||||||
Run: ClearCommand,
|
Run: ClearCommand,
|
||||||
Description: "clear",
|
Description: "clear",
|
||||||
}
|
}
|
||||||
|
|
||||||
commandMap["e"] = Command{
|
|
||||||
Run: EmoteCommand,
|
|
||||||
Description: "emote",
|
|
||||||
}
|
|
||||||
|
|
||||||
commandMap["L"] = Command{
|
|
||||||
Run: ListGuildsCommand,
|
|
||||||
Description: "list guilds",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCommand(key string) (Command, bool) {
|
func GetCommand(key string) (Command, bool) {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/Cynosphere/comcord/lib"
|
"github.com/Cynosphere/comcord/lib"
|
||||||
"github.com/Cynosphere/comcord/state"
|
"github.com/Cynosphere/comcord/state"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"github.com/ergochat/readline"
|
||||||
"github.com/mgutz/ansi"
|
"github.com/mgutz/ansi"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,6 +19,8 @@ func SendMode(session *discordgo.Session) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.SetInPrompt(true)
|
||||||
|
|
||||||
length := utf8.RuneCountInString(session.State.User.Username) + 2
|
length := utf8.RuneCountInString(session.State.User.Username) + 2
|
||||||
curLength := state.GetNameLength()
|
curLength := state.GetNameLength()
|
||||||
|
|
||||||
|
@ -26,16 +29,25 @@ func SendMode(session *discordgo.Session) {
|
||||||
prompt = ansi.Color(prompt, "cyan+b")
|
prompt = ansi.Color(prompt, "cyan+b")
|
||||||
}
|
}
|
||||||
|
|
||||||
lib.MakePrompt(session, prompt, true, func(session *discordgo.Session, input string, interrupt bool) {
|
input, _ := readline.NewFromConfig(&readline.Config{
|
||||||
if input == "" {
|
Prompt: prompt,
|
||||||
if interrupt {
|
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")
|
fmt.Print("^C<no message sent>\n\r")
|
||||||
} else {
|
} else {
|
||||||
fmt.Print(prompt, "<no message sent>\n\r")
|
fmt.Print(prompt, "<no message sent>\n\r")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Print(prompt, input, "\n\r")
|
fmt.Print(prompt, out, "\n\r")
|
||||||
_, err := session.ChannelMessageSend(channelId, input)
|
_, err := session.ChannelMessageSend(channelId, out)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Print("<failed to send message: ", err, ">\n\r")
|
fmt.Print("<failed to send message: ", err, ">\n\r")
|
||||||
|
@ -43,5 +55,6 @@ func SendMode(session *discordgo.Session) {
|
||||||
|
|
||||||
// TODO: update afk state
|
// TODO: update afk state
|
||||||
}
|
}
|
||||||
})
|
state.SetInPrompt(false)
|
||||||
|
lib.ProcessQueue(session)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/Cynosphere/comcord/commands"
|
|
||||||
"github.com/Cynosphere/comcord/state"
|
"github.com/Cynosphere/comcord/state"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/mgutz/ansi"
|
"github.com/mgutz/ansi"
|
||||||
|
@ -15,8 +14,6 @@ func Ready(session *discordgo.Session, event *discordgo.Ready) {
|
||||||
|
|
||||||
state.SetNameLength(utf8.RuneCountInString(session.State.User.Username) + 2)
|
state.SetNameLength(utf8.RuneCountInString(session.State.User.Username) + 2)
|
||||||
|
|
||||||
commands.ListGuildsCommand(session)
|
|
||||||
|
|
||||||
defaultGuild := state.GetConfigValue("defaultGuild")
|
defaultGuild := state.GetConfigValue("defaultGuild")
|
||||||
defaultChannel := state.GetConfigValue("defaultChannel")
|
defaultChannel := state.GetConfigValue("defaultChannel")
|
||||||
if defaultGuild != "" {
|
if defaultGuild != "" {
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package lib
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Cynosphere/comcord/state"
|
|
||||||
"github.com/bwmarrin/discordgo"
|
|
||||||
"github.com/ergochat/readline"
|
|
||||||
)
|
|
||||||
|
|
||||||
func MakePrompt(session *discordgo.Session, prompt string, uniqueLine bool, callback func(session *discordgo.Session, input string, interrupt bool)) {
|
|
||||||
state.SetInPrompt(true)
|
|
||||||
state.SetPromptText(prompt)
|
|
||||||
|
|
||||||
rl, _ := readline.NewFromConfig(&readline.Config{
|
|
||||||
Prompt: prompt,
|
|
||||||
UniqueEditLine: uniqueLine,
|
|
||||||
})
|
|
||||||
defer rl.Close()
|
|
||||||
|
|
||||||
input, err := rl.Readline()
|
|
||||||
input = strings.TrimSpace(input)
|
|
||||||
rl.Close()
|
|
||||||
|
|
||||||
interrupt := err == readline.ErrInterrupt
|
|
||||||
|
|
||||||
callback(session, input, interrupt)
|
|
||||||
|
|
||||||
state.SetInPrompt(false)
|
|
||||||
state.SetPromptText("")
|
|
||||||
|
|
||||||
ProcessQueue(session)
|
|
||||||
}
|
|
|
@ -15,7 +15,6 @@ type ComcordState struct {
|
||||||
CurrentChannel string
|
CurrentChannel string
|
||||||
NameLength int
|
NameLength int
|
||||||
InPrompt bool
|
InPrompt bool
|
||||||
PromptText string
|
|
||||||
AFK bool
|
AFK bool
|
||||||
MessageQueue []*discordgo.Message
|
MessageQueue []*discordgo.Message
|
||||||
LastChannel map[string]string
|
LastChannel map[string]string
|
||||||
|
@ -35,7 +34,6 @@ func Setup(config map[string]string) {
|
||||||
state.CurrentChannel = ""
|
state.CurrentChannel = ""
|
||||||
state.NameLength = 2
|
state.NameLength = 2
|
||||||
state.InPrompt = false
|
state.InPrompt = false
|
||||||
state.PromptText = ""
|
|
||||||
state.AFK = false
|
state.AFK = false
|
||||||
state.MessageQueue = make([]*discordgo.Message, 0)
|
state.MessageQueue = make([]*discordgo.Message, 0)
|
||||||
state.LastChannel = make(map[string]string)
|
state.LastChannel = make(map[string]string)
|
||||||
|
@ -95,14 +93,6 @@ func SetInPrompt(value bool) {
|
||||||
state.InPrompt = value
|
state.InPrompt = value
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPromptText() string {
|
|
||||||
return state.PromptText
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetPromptText(value string) {
|
|
||||||
state.PromptText = value
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsAFK() bool {
|
func IsAFK() bool {
|
||||||
return state.AFK
|
return state.AFK
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue