~kris/9p

disco

0f5b85f2441b346817e3dd96b984d622b03f957e — henesy 6 years ago c4092b6 2.3
v2.3 release ;; fix @mentions (yay!) ;; migrate fully to github dependencies
7 files changed, 32 insertions(+), 17 deletions(-)

M DiscordState/session.go
M README.md
M config.go
D disco.cfg.example
M getdeps.rc
M main.go
M menu.go
M DiscordState/session.go => DiscordState/session.go +1 -1
@@ 60,7 60,7 @@ func (Session *Session) NewState(GuildID string, MessageAmount int) (*State, err
	State.Session = Session

	//Set Guild
	for _, guildID := range Session.Guilds {
	for _, guildID := range Session.Guilds {	
		if guildID.ID == GuildID {
			Guild, err := State.Session.DiscordGo.Guild(guildID.ID)
			if err != nil {

M README.md => README.md +4 -4
@@ 9,7 9,7 @@ NDB config is in `$home/lib/disco.ndb` for setting password, should be made auto
### Dependencies

- 9fans.net/go/plan9
- bitbucket.org/mischief/libauth
- github.com/Plan9-Archive/libauth
- github.com/mischief/ndb
- golang.org/x/crypto
- github.com/gorilla/websocket


@@ 18,8 18,8 @@ NDB config is in `$home/lib/disco.ndb` for setting password, should be made auto
### Installation

```
go get bitbucket.org/henesy/disco
go install bitbucket.org/henesy/disco
go get github.com/henesy/disco
go install github.com/henesy/disco
```

## Problems


@@ 82,7 82,7 @@ A: If you want to use `go get` on 9front to install disco and its dependencies (

Q: What if I can't login because of a captcha error?

A: You'll need to sign in to Discord via the web app (thus solving a captcha) using a browser with html5/js. I recommend an http proxy such as [this](https://bitbucket.org/henesy/http-proxy) in conjunction with a system with such a browser..
A: You'll need to sign in to Discord via the web app (thus solving a captcha) using a browser with html5/js. I recommend an http proxy such as [this](https://github.com/henesy/http-proxy) in conjunction with a system with such a browser..

Q: What if I get an error about signing in from a new location?


M config.go => config.go +1 -1
@@ 1,7 1,7 @@
package main

import (
	"bitbucket.org/mischief/libauth"
	"github.com/Plan9-Archive/libauth"
	"bufio"
	"fmt"
	"github.com/mischief/ndb"

D disco.cfg.example => disco.cfg.example +0 -1
@@ 1,1 0,0 @@
{"username":"REPLACEME@example.com","password":"SDSFSDF879aFDSSKLFjkflsj234IREALLYHOPETHISISAUNIQUEPASSWORD","messagedefault":true,"messages":10}

M getdeps.rc => getdeps.rc +2 -2
@@ 38,8 38,8 @@ cd $GOPATH/src

# Other deps

echo Downloading bitbucket.org/mischief/libauth…
go get bitbucket.org/mischief/libauth
echo Downloading github.com/Plan9-Archive/libauth…
go get github.com/Plan9-Archive/libauth

cd $GOPATH/src


M main.go => main.go +21 -8
@@ 3,7 3,7 @@
package main

import (
	"bitbucket.org/henesy/disco/DiscordState"
	"github.com/henesy/disco/DiscordState"
	"bufio"
	"flag"
	"fmt"


@@ 23,7 23,7 @@ const (
)

// Version is current version const
const Version = "2.2" 
const Version = "2.3" 

// Session is global Session
var Session *DiscordState.Session


@@ 121,7 121,7 @@ func main() {
		if line != "" {
			_, err := State.Session.DiscordGo.ChannelMessageSend(State.Channel.ID, line)
			if err != nil {
				fmt.Print("Error: ", err, "\n")
				fmt.Println("Error:", err)
			}
		}
	}


@@ 171,17 171,30 @@ func ParseForMentions(line string) string {

// ReplaceMentions replaces mentions to ID
func ReplaceMentions(input string) string {
	if len(input) < 2 {
		return input
	}
	
	name := input[1:]
	
	// Get up to 1000 members as per documented max starting from the top
	members, err := Session.DiscordGo.GuildMembers(State.Guild.ID, "", 1000)
	if err != nil {
		Msg(ErrorMsg, "Could not Lookup Members: ", err)
		return input
	}

	// Check for guild members that match
	for _, member := range State.Guild.Members {
		if strings.HasPrefix(member.Nick, input[1:]) {
	for _, member := range members {	
		if strings.HasPrefix(member.Nick, name) {
			return member.User.Mention()
		}

		if strings.HasPrefix(member.User.Username, input[1:]) {
		if strings.HasPrefix(member.User.Username, name) {
			return member.User.Mention()
		}
	}

	
	// Walk all PM channels
	userChannels, err := Session.DiscordGo.UserChannels()



@@ 191,7 204,7 @@ func ReplaceMentions(input string) string {

	for _, channel := range userChannels {
		for _, recipient := range channel.Recipients {
			if strings.HasPrefix(input[1:], recipient.Username) {
			if strings.HasPrefix(name, recipient.Username) {
				return recipient.Mention()
			}
		}

M menu.go => menu.go +3 -0
@@ 167,14 167,17 @@ Start:
		ExtraGuildMenuOptions()
		goto Start
	}

	if response == "p" {
		if State != nil {
			SelectPrivate()
		} else {
			State, err = Session.NewState(SelectMap[0], Config.Messages)
			
			if err != nil {
				log.Fatal(err)
			}
			
			SelectPrivate()
		}
	} else {