~kris/9p

disco

7fb042d7283879fb3eac8723637d13b14c95915c — henesy 6 years ago 0f5b85f
.hgignore → .gitignore ;; add usage to readme ;; make vet tool pass
5 files changed, 33 insertions(+), 23 deletions(-)

R .hgignore => .gitignore
M README.md
M config.go
M main.go
M menu.go
R .hgignore => .gitignore +0 -1
@@ 1,4 1,3 @@
syntax: glob
*.patch
*.diff
disco

M README.md => README.md +21 -10
@@ 1,8 1,8 @@
# disco: [Discord](https://discord.gg) client for 9front

Fork of theboxmage's [discord-cli](https://github.com/theboxmage/discordcli)
Fork of theboxmage's [discord-cli](https://github.com/theboxmage/discordcli).

NDB config is in `$home/lib/disco.ndb` for setting password, should be made automatically after first run.
Ndb config is in `$home/lib/disco.ndb` for setting password, should be made automatically after first run. Alternatively, you may use factotum. 

## Install



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

```
go get github.com/henesy/disco
go install github.com/henesy/disco
% go get github.com/henesy/disco
% go install github.com/henesy/disco
```

## Problems

* Does not create accounts for you, this still needs to be done in a browser/app
## Usage

* Does not support 2FA (Discord API explicitly does not allow this)
```
% disco -h
Usage of disco:
  -n	Enable notifications
  -t	Hide timestamps in channel log
  -w string
    	Dimensions to pass through to statusmsg (default "10,10,260,90")
```

## Commands

Commands available in chat:

| Command       | Function    |


@@ 48,7 54,7 @@ You can regex the last message sent using a format such as:

## Config

A basic $home/lib/disco.ndb looks something like:
A basic `$home/lib/disco.ndb` looks something like:

```
auth=pass


@@ 57,7 63,7 @@ messages=10
promptchar=→
timestampchar=>

username=cooldude@mycooldomain.com	password=somepassword1
username=coolperson@mycooldomain.com	password=somepassword1
```

Note that the auth= tuple accepts


@@ 88,3 94,8 @@ Q: What if I get an error about signing in from a new location?

A: Discord has sent you an e-mail with a location confirmation link, click it, no js should be required.

## Problems

* Does not create accounts for you, this still needs to be done in a browser/app
* Does not support 2FA (Discord API explicitly does not allow this)


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

import (
	"github.com/Plan9-Archive/libauth"
	"bufio"
	"fmt"
	"github.com/Plan9-Archive/libauth"
	"github.com/mischief/ndb"
	"log"
	"os"

M main.go => main.go +9 -9
@@ 3,10 3,10 @@
package main

import (
	"github.com/henesy/disco/DiscordState"
	"bufio"
	"flag"
	"fmt"
	"github.com/henesy/disco/DiscordState"
	"io"
	"log"
	"os"


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

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

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


@@ 161,7 161,7 @@ func ParseForMentions(line string) string {
	r, err := regexp.Compile("@\\w+")

	if err != nil {
		Msg(ErrorMsg, "Regex Error: ", err)
		Msg(ErrorMsg, "Regex Error: %s\n", err)
	}

	lineByte := r.ReplaceAllStringFunc(line, ReplaceMentions)


@@ 174,18 174,18 @@ 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)
		Msg(ErrorMsg, "Could not Lookup Members: %s\n", err)
		return input
	}

	// Check for guild members that match
	for _, member := range members {	
	for _, member := range members {
		if strings.HasPrefix(member.Nick, name) {
			return member.User.Mention()
		}


@@ 194,7 194,7 @@ func ReplaceMentions(input string) string {
			return member.User.Mention()
		}
	}
	

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



@@ 218,7 218,7 @@ func ParseForEmoji(line string) string {
	r, err := regexp.Compile("<(:\\w+:)[0-9]+>")

	if err != nil {
		Msg(ErrorMsg, "Regex Error: ", err)
		Msg(ErrorMsg, "Regex Error: %s\n", err)
	}

	return r.ReplaceAllString(line, "$1")

M menu.go => menu.go +2 -2
@@ 173,11 173,11 @@ Start:
			SelectPrivate()
		} else {
			State, err = Session.NewState(SelectMap[0], Config.Messages)
			

			if err != nil {
				log.Fatal(err)
			}
			

			SelectPrivate()
		}
	} else {