~humaid/oww-prot

ca2006a4ecc1f3f34c2e12fe033b6879009ba144 — Humaid AlQassimi 3 years ago f986808 master
Add post limit and fix formatting of posts
1 files changed, 5 insertions(+), 2 deletions(-)

M main.go
M main.go => main.go +5 -2
@@ 24,10 24,13 @@ var (

var (
	ListOwwsExp = regexp.MustCompile(`^(Owws)`)
	PostOwwExp  = regexp.MustCompile(`^[a-zA-Z0-9 ]+: ((?i)Oww)`)
	PostOwwExp  = regexp.MustCompile(`^[a-zA-Z0-9 ]+: ((?i)Oww)( [a-zA-Z0-9]+)?`)
)

func handleConnection(con net.Conn) {
	if len(OwwPosts) == 25 {
		OwwPosts = OwwPosts[15:]
	}
	buf := make([]byte, 1024)
	con.Read(buf)
	buf = bytes.TrimSpace(buf)


@@ 37,7 40,7 @@ func handleConnection(con net.Conn) {
		}
	} else if PostOwwExp.Match(buf) {
		con.Write([]byte("Oww\n"))
		OwwPosts = append(OwwPosts, string(buf))
		OwwPosts = append(OwwPosts, string(PostOwwExp.Find(buf)))
	}
	con.Close()
}