First stream reader and answers is working
This commit is contained in:
parent
2e88f8f060
commit
1d3c16cd7b
53
ai/main.go
53
ai/main.go
|
@ -1 +1,54 @@
|
|||
package ai
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"git.postblue.info/keygoller/utils"
|
||||
)
|
||||
|
||||
// ReadFromStream is the main AI function, it reads from the stream of the keys
|
||||
// and then answers if some conditions are met.
|
||||
func ReadFromStream(inputChan chan utils.InputEvent) {
|
||||
var b strings.Builder
|
||||
for {
|
||||
data := <-inputChan
|
||||
b.WriteString(data.KeyString())
|
||||
|
||||
switch b.String() {
|
||||
case b.String():
|
||||
if findPassword(b.String()) {
|
||||
fmt.Println("I LIKE YOUR PASSWORD")
|
||||
b.Reset()
|
||||
}
|
||||
if findLove(b.String()) {
|
||||
fmt.Println("I love you too...")
|
||||
b.Reset()
|
||||
}
|
||||
default:
|
||||
continue
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func findPassword(input string) bool {
|
||||
r, _ := regexp.Compile("PASSWORD")
|
||||
|
||||
if ok := r.MatchString(input); ok {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func findLove(input string) bool {
|
||||
r, _ := regexp.Compile("ILOVEYOU")
|
||||
|
||||
if ok := r.MatchString(input); ok {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
1
go.sum
1
go.sum
|
@ -1,5 +1,6 @@
|
|||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
|
|
30
main.go
30
main.go
|
@ -10,6 +10,7 @@ import (
|
|||
"strings"
|
||||
"syscall"
|
||||
|
||||
"git.postblue.info/keygoller/ai"
|
||||
"git.postblue.info/keygoller/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -111,31 +112,13 @@ func (k *KeyLogger) Close() error {
|
|||
return k.fd.Close()
|
||||
}
|
||||
|
||||
func output(input InputStream) {
|
||||
var res string
|
||||
for {
|
||||
if input.event.KeyString() != "" {
|
||||
res += input.event.KeyString()
|
||||
}
|
||||
fmt.Println(res)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func join(strs ...string) string {
|
||||
var sb strings.Builder
|
||||
for _, str := range strs {
|
||||
sb.WriteString(str)
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("Your keyboard input will be here: ", getKeyboard())
|
||||
// TODO
|
||||
// !) get streaming data from keyboard
|
||||
// 2 unpackage the data to be human readable
|
||||
// 3 stream the data through an api
|
||||
StreamChannel := make(chan utils.InputEvent)
|
||||
keyboard := getKeyboard()
|
||||
klog, err := New(keyboard)
|
||||
if err != nil {
|
||||
|
@ -144,19 +127,20 @@ func main() {
|
|||
}
|
||||
defer klog.Close()
|
||||
events := klog.Read()
|
||||
// stream := InputStream{}
|
||||
var b strings.Builder
|
||||
|
||||
go ai.ReadFromStream(StreamChannel)
|
||||
|
||||
for e := range events {
|
||||
switch e.Type {
|
||||
|
||||
case utils.EvKey:
|
||||
if e.KeyPress() {
|
||||
b.WriteString(e.KeyString())
|
||||
StreamChannel <- e
|
||||
}
|
||||
|
||||
break
|
||||
default:
|
||||
fmt.Println(b.String())
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue