~kris/9p

disco

941ae498dd2b65d967a7363ebeab04c3ae42036c — Sean Hinchee 7 years ago 37fd82d
add s/word/words/g style editing of last message sent
2 files changed, 43 insertions(+), 3 deletions(-)

M README.md
M commands.go
M README.md => README.md +7 -3
@@ 33,9 33,13 @@ Commands available in chat:
| :p        | Pulls up the private channel menu |
| :n name   | Change nickname to `name` |

You can regex the last message sent using a format such as:

	s/forsynth/forsyth/g

## Config

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

```
auth=pass


@@ 53,7 57,7 @@ Note that the auth= tuple accepts

for authentication using a factotum key and will ignore the password= tuple.

The factotum key should resemble something to the effect of:
If used, the factotum key should resemble something to the effect of:

	proto=pass server=discordapp.com service=discord user=youremail@domain.com !password=hunter2



@@ 69,7 73,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).
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..

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


M commands.go => commands.go +36 -0
@@ 1,6 1,7 @@
package main

import (
	"regexp"
	"strconv"
	"strings"
	"github.com/bwmarrin/discordgo"


@@ 12,6 13,41 @@ func ParseForCommands(line string) string {
		return line
	}
	switch line[:2] {
	case "s/":
		r := regexp.MustCompile(`s\/((\w|\s)+)\/((\w|\s|)+)\/`)
		n := r.FindStringSubmatchIndex(line)
		if len(n) < 1 {
			return ""
		}
		msg := State.Messages
		for i := len(msg)-1; i >= 0; i-- {
			if (msg[i].ChannelID != State.Channel.ID && msg[i].GuildID != State.Guild.ID) {
				break
			}
			if msg[i].Author.ID != Session.User.ID {
				break
			}
			if strings.Contains(msg[i].Content, line[n[2]:n[3]]) {
				cmd, err := regexp.Compile("(" + line[n[2]:n[3]] + ")")
				if err != nil {
					Msg(ErrorMsg, "%s - invalid regex\n", line)
				}
				rep := cmd.ReplaceAllString(msg[i].Content, "")
				if len(line) == 5 {
					rep = cmd.ReplaceAllString(msg[i].Content, line[n[4]:n[5]])
				}
				data := discordgo.NewMessageEdit(msg[i].ChannelID, msg[i].ID)
				data = data.SetContent(rep)
				_, err = State.Session.DiscordGo.ChannelMessageEditComplex(data)
				if err != nil {
					Msg(ErrorMsg, "%s\n", err)
					return ""
				}
				Msg(TextMsg, "%s -> %s\n", msg[i].Content, rep)
				return ""
			}
		}
		return line
	case ":?":
		// Show help menu
		Msg(TextMsg, "Commands: ")