M DiscordState/state.go => DiscordState/state.go +1 -0
@@ 56,6 56,7 @@ func (State *State) DelMessage(Message *discordgo.Message) {
//RetrieveMessages retrieves last N Messages and puts it in state
func (State *State) RetrieveMessages(Amount int) error {
+ // See: https://godoc.org/github.com/bwmarrin/discordgo#Channel and https://godoc.org/github.com/bwmarrin/discordgo#State for max message count
Messages, err := State.Session.DiscordGo.ChannelMessages(State.Channel.ID, Amount, "", "", "")
if err != nil {
return err
M README.md => README.md +1 -0
@@ 39,6 39,7 @@ Commands available in chat:
| :m [n] | Display last [n] messages: ex. `:m 2` displays last two messages |
| :p | Pulls up the private channel menu |
| :n name | Change nickname to `name` |
+| :! | Print current server information |
| :? | List the available commands |
You can regex the last message sent using a format such as:
M TODO => TODO +5 -0
@@ 30,3 30,8 @@ Features:
Bugs:
* (maybe a Go bug) if you do: `drawterm -G … -c disco` then ctrl+c the terminal (from Linux or so), load maxes and memory allocation spikes on the plan9 server
+
+* The following error at boot:
+
+ Connecting...2019/07/17 23:39:53 [DG0] wsapi.go:552:onEvent() error unmarshalling READY event, json: cannot unmarshal number into Go struct field ReadState.last_message_id of type string
+ PASSED!
M commands.go => commands.go +21 -0
@@ 15,6 15,7 @@ func ParseForCommands(line string) string {
switch line[:2] {
case "s/":
+ // `s/X/Y/` replace X with Y in the last message sent
r := regexp.MustCompile(`s/([^/]+)/([^/]*)/$`)
n := r.FindStringSubmatchIndex(line)
if len(n) < 1 {
@@ 45,9 46,11 @@ func ParseForCommands(line string) string {
}
Msg(TextMsg, "%s → %s\n", m.Content, rep)
return ""
+
case ":?":
// Show help menu
Msg(TextMsg, "Commands: \n")
+ Msg(TextMsg, "s/X/Y/ - Replace X with Y in the last message\n")
Msg(TextMsg, "[:g] - Open guild menu\n")
Msg(TextMsg, "[:p] - Open private message menu\n")
Msg(TextMsg, "[:c] - Open guild channel menu\n")
@@ 55,14 58,22 @@ func ParseForCommands(line string) string {
Msg(TextMsg, "[:c <num>] - Go directly to channel <num>\n")
Msg(TextMsg, "[:m <num>] - Display last <num> messages\n")
Msg(TextMsg, "[:n <name>] - Change username to <name>\n")
+ Msg(TextMsg, "[:!] - Print current server information\n")
+ Msg(TextMsg, "[:?] - Print this menu\n")
return ""
+
case ":g":
+ // Choose a server (guild)
SelectGuild()
return ""
+
case ":p":
+ // Enter DM menu
SelectPrivate()
return ""
+
case ":c":
+ // Choose a channel within the server
opts := strings.Split(line, " ")
if len(opts) == 1 {
SelectChannel()
@@ 98,7 109,9 @@ func ParseForCommands(line string) string {
State.SetChannel(channel.ID)
ShowContent()
return ""
+
case ":m":
+ // Load message backlog -- TODO currently does not retrieve more than n messages
AmountStr := strings.Split(line, " ")
if len(AmountStr) < 2 {
Msg(ErrorMsg, "[:m] No Arguments \n")
@@ 115,7 128,9 @@ func ParseForCommands(line string) string {
State.RetrieveMessages(Amount)
PrintMessages(Amount)
return ""
+
case ":n":
+ // Change nickname
session := State.Session
user := session.User
oldName := user.Username
@@ 127,7 142,13 @@ func ParseForCommands(line string) string {
}
Msg(TextMsg, "%s → %s\n", oldName, newName)
return ""
+
+ case ":!":
+ // Print current server information
+ Msg(TextMsg, GuildInfo(State.Guild))
+ return ""
}
+
return line
}
M helper.go => helper.go +22 -7
@@ 132,7 132,7 @@ func MessagePrint(Time, Username, Content string) {
content := ParseForEmoji(Content)
//var Color color.Attribute
log.SetFlags(0)
- if ! *timeStamp {
+ if !*timeStamp {
log.Printf("%s %s %s\n", Username, Config.PromptChar, content)
} else {
TimeStamp, _ := time.Parse(time.RFC3339, Time)
@@ 147,6 147,7 @@ func dis(a, b int) float64 {
return float64((a - b) * (a - b))
}
+// Turn raw mode on -- rio in Plan9 only
func Rawon() (*os.File, error) {
consctl, err := os.OpenFile("/dev/consctl", os.O_WRONLY, 0200)
if err != nil {
@@ 165,13 166,8 @@ func Rawon() (*os.File, error) {
return consctl, nil
}
+// Turn raw mode off -- rio in Plan9 only
func RawOff(consctl *os.File) error {
- //consctl, err := os.OpenFile("/dev/consctl", os.O_WRONLY, 0200)
- //if err != nil {
- // /* not on Plan 9 */
- // return err
- //}
-
rawoff := []byte("rawoff")
_, err := consctl.Write(rawoff)
if err != nil {
@@ 183,6 179,7 @@ func RawOff(consctl *os.File) error {
return nil
}
+// Return the text currently in /dev/cons -- Plan9 only
func GetCons() string {
cons, err := os.OpenFile("/dev/cons", os.O_RDWR, 0600)
if err != nil {
@@ 192,3 189,21 @@ func GetCons() string {
consScan.Scan()
return consScan.Text()
}
+
+// Nicely stringifies the useful info about a guild -- ends in \n
+func GuildInfo(g *discordgo.Guild) (s string) {
+ s += "\n"
+ s += fmt.Sprintf("Name:\t\t%s\n", g.Name)
+ s += fmt.Sprintf("ID:\t\t\t%s\n", g.ID)
+ s += fmt.Sprintf("Icon:\t\t%s\n", g.Icon)
+ s += fmt.Sprintf("Region:\t\t%s\n", g.Region)
+ s += fmt.Sprintf("Owner ID:\t%s\n", g.OwnerID)
+ s += fmt.Sprintf("Join time:\t%s\n", g.JoinedAt)
+ s += fmt.Sprintf("# Members:\t%d\n", g.MemberCount)
+ s += fmt.Sprintf("# Channels:\t%d\n", len(g.Channels))
+ s += fmt.Sprintf("# Roles:\t%d\n", len(g.Roles))
+ s += fmt.Sprintf("# Emojis:\t%d\n", len(g.Emojis))
+ s += "\n"
+
+ return
+}
M main.go => main.go +1 -1
@@ 68,7 68,7 @@ func main() {
// Attach New Window
InitWindow()
- // Attach Even Handlers
+ // Attach Event Handlers
State.Session.DiscordGo.AddHandler(newMessage)
//State.Session.DiscordGo.AddHandler(newReaction)