From 0f5b85f2441b346817e3dd96b984d622b03f957e Mon Sep 17 00:00:00 2001 From: henesy Date: Sat, 5 Oct 2019 02:36:09 -0700 Subject: [PATCH] v2.3 release ;; fix @mentions (yay!) ;; migrate fully to github dependencies --- DiscordState/session.go | 2 +- README.md | 8 ++++---- config.go | 2 +- disco.cfg.example | 1 - getdeps.rc | 4 ++-- main.go | 29 +++++++++++++++++++++-------- menu.go | 3 +++ 7 files changed, 32 insertions(+), 17 deletions(-) delete mode 100644 disco.cfg.example diff --git a/DiscordState/session.go b/DiscordState/session.go index 538ecb1b6de7cf396af5576f80995b8aaf8e5441..972d77a1915a15185a1e0ee6d2084ecef8d29bf7 100644 --- a/DiscordState/session.go +++ b/DiscordState/session.go @@ -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 { diff --git a/README.md b/README.md index d4f4d1ffbd0443e8999cdb4ea150145faef2d42f..a3a65b094de81d3f2ba1b3dbf19104250b13af06 100644 --- a/README.md +++ b/README.md @@ -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? diff --git a/config.go b/config.go index 5761fba5d50f8c1a9f3be3368b4606ad4379170c..1a5c1c5ca5f7277101ad58b2589cad57ecbf238a 100644 --- a/config.go +++ b/config.go @@ -1,7 +1,7 @@ package main import ( - "bitbucket.org/mischief/libauth" + "github.com/Plan9-Archive/libauth" "bufio" "fmt" "github.com/mischief/ndb" diff --git a/disco.cfg.example b/disco.cfg.example deleted file mode 100644 index 08b29a78f1b56175a20d998b347d9173ede4f7f7..0000000000000000000000000000000000000000 --- a/disco.cfg.example +++ /dev/null @@ -1 +0,0 @@ -{"username":"REPLACEME@example.com","password":"SDSFSDF879aFDSSKLFjkflsj234IREALLYHOPETHISISAUNIQUEPASSWORD","messagedefault":true,"messages":10} diff --git a/getdeps.rc b/getdeps.rc index 83d27e9aaf419c351b25d7080817262d459ef933..39073dc06cf35d6d224672d714a19830ae0ec8c2 100755 --- a/getdeps.rc +++ b/getdeps.rc @@ -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 diff --git a/main.go b/main.go index 9a256348c74dcf31fdfddce92a6b8e6f417a2978..89a018ddb024930c85ef562adbb3d3bb4395d3b2 100644 --- a/main.go +++ b/main.go @@ -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() } } diff --git a/menu.go b/menu.go index 96803d899e2a1f3eff697bee83455ef977919b6f..8576e799295277dd7fc6dc2e45f75e8e247a3881 100644 --- a/menu.go +++ b/menu.go @@ -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 {