commit 2669deeb40ae4bebb045b8c9a644ea174d5aca65 Author: Sacha Ligthert Date: Mon Oct 17 19:39:06 2022 +0200 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..6483942 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +For future reference: + +* `go run intel2noise.go -l "/home/outcast/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs/Etherium_Intel_20220208_175248_93488613.txt" -s c-v6dq,1pf-bc,ex-gbt,z-fet0,BNX-AS,QNXJ-M,4LJ6-Q` + +* Location: /home/outcast/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs +* Intel channels: Etherium_Intel + +``` +Etherium_Intel_20220206_111758_93488613.txt +``` + +# Program Structure: + +## Main: +* Check parameters, for errors, set stuff internally. + +## Main Loop: +* Go into Logs Folder +* Generate a date-stamp +* Find all files in the Folder + * Find `Local_*` + * Find `$IntelChannel_*` +* For each new set of $IntelChannel and Local File, open a go-routine with these two file as parameters + +## The Go-Routine +* Parse Local file and figure out the last system + * If nono are found. Do nothing + * If its found, continue +* ... + +Need more thinky think about: +* Find and cache adjecent systems +* Find and cache characters + + +--- + +# ESI Exploration +Required to find adjacent systems + +Reference: https://esi.evetech.net/ui/ + +* `curl -H "accept: application/json" https://esi.evetech.net/v1/universe/regions/10000027` +* `curl -H "accept: application/json" https://esi.evetech.net/v1/universe/constellations/20000336/` +* `curl -s -H "accept: application/json" https://esi.evetech.net/v4/universe/systems/30002290/ | python3 -m json.tool` +* `curl -s -H "accept: application/json" https://esi.evetech.net/v1/universe/stargates/50000569/ | python3 -m json.tool` diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ee91659 --- /dev/null +++ b/go.mod @@ -0,0 +1,18 @@ +module gitea/EVE-Online/Intel2Noise + +go 1.17 + +require ( + github.com/hajimehoshi/go-mp3 v0.3.2 + github.com/hajimehoshi/oto v1.0.1 +) + +require ( + github.com/fsnotify/fsnotify v1.4.9 // indirect + github.com/nxadm/tail v1.4.8 // indirect + golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 // indirect + golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 // indirect + golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 // indirect + golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 // indirect + gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c23c9ca --- /dev/null +++ b/go.sum @@ -0,0 +1,23 @@ +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/hajimehoshi/go-mp3 v0.3.2 h1:xSYNE2F3lxtOu9BRjCWHHceg7S91IHfXfXp5+LYQI7s= +github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM= +github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI= +github.com/hajimehoshi/oto v1.0.1 h1:8AMnq0Yr2YmzaiqTg/k1Yzd6IygUGk2we9nmjgbgPn4= +github.com/hajimehoshi/oto v1.0.1/go.mod h1:wovJ8WWMfFKvP587mhHgot/MBr4DnNy9m6EepeVGnos= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 h1:idBdZTd9UioThJp8KpM/rTSinK/ChZFBE43/WtIy8zg= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 h1:KYGJGHOQy8oSi1fDlSpcZF0+juKwk/hEMv5SiwHogR0= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 h1:vyLBGJPIl9ZYbcQFM2USFmJBK6KI+t+z6jL0lbwjrnc= +golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872 h1:cGjJzUd8RgBw428LXP65YXni0aiGNA4Bl+ls8SmLOm8= +golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= diff --git a/main.go b/main.go new file mode 100644 index 0000000..002673e --- /dev/null +++ b/main.go @@ -0,0 +1,311 @@ +package main + +import ( + "flag" + "fmt" + "io/fs" + "log" + "os" + "runtime" + "strings" + "time" + + "github.com/nxadm/tail" +) + +// findPath Find the path in which the log files are stored. +func findPath(LogLocation string) (logPath string) { + + if LogLocation != "" { + logPath = LogLocation + return + } + + var err error + var homedir string + var Path string + var Paths []string + var PathsLinux []string + var PathsMac []string + var PathsWindows []string + + // Determine the homedir of the user. + homedir, err = os.UserHomeDir() + if err != nil { + log.Fatal(err) + } + + // Define Paths to check out + PathsLinux = append(PathsLinux, "/Documents/EVE/logs/") + PathsLinux = append(PathsLinux, "/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs/") + + PathsMac = append(PathsMac, "/Documents/EVE/logs/") + PathsMac = append(PathsMac, "/Library/Application Support/EVE Online/p_drive/User/My Documents/EVE/") + + PathsWindows = append(PathsWindows, "C:\\Users\\YourUserName\\Documents\\EVE\\logs") + PathsWindows = append(PathsWindows, "MyDocuments -> EVE -> Logs") + + switch runtime.GOOS { + case "linux": + Paths = PathsLinux + case "darwin": + Paths = PathsMac + case "windows": + Paths = PathsWindows + } + + for _, Path = range Paths { + if _, err := os.Stat(homedir + Path); !os.IsNotExist(err) { + logPath = homedir + Path + } + } + + return +} + +// OrchestrateIntelMonitoring routine to periodically check the logpath for the intel channels. +func OrchestrateIntelMonitoring(logPath string, intelChannel string, LogSystemsRaw string) { + + // Declare variables + var files []fs.FileInfo + var lastName string + var tempName string + + // Enter a for-loop that periodically checks. + for { + files = fetchFileListing(logPath) + tempName = findLatestLog(logPath, intelChannel, files) + + if !strings.EqualFold(lastName, tempName) { + lastName = tempName + fmt.Println("Tracking file:" + lastName) + go TrackLogfile(lastName, LogSystemsRaw) + } + + // Sleep a minute before we check again. + time.Sleep(time.Second * 60) + } + +} + +// TrackLogfile The actual work +func TrackLogfile(logPath string, LogSystemsRaw string) { + // Split the CSV string into different parts + LogSystems := strings.Split(LogSystemsRaw, ",") + + // Do the main loop and start parsing the logfiles + t, err := tail.TailFile(logPath, tail.Config{Follow: true}) + if err != nil { + panic(err) + } + + for line := range t.Lines { + // Cast a line to a text, trim the trash + logLine := string(line.Text) + logLine = strings.Trim(logLine, "\n") + + // Figure out if this is a message we want to deal with + // > is critical in this regard because it is the start of the message + // and everything behind it until it hits ] is the username + splitpos := strings.Index(logLine, ">") + if -1 == splitpos { + continue + } + + // Somehow I cannot filter out this stuff. + // EVE System > Channel MOTD + LineDate, LineTime, LineUser, Payload := ParseChat(logLine) + + if CompareElements(LogSystems, Payload) { + playBeep() + fmt.Println("[", LineDate, LineTime, "]", LineUser, ">", Payload) + } + } + + // We should never reach this +} + +// fetchFileListing As it says on the tin. +func fetchFileListing(logPath string) (files []fs.FileInfo) { + + // Declare Variables + var err error + var folder *os.File + + // Open the folder we need to open. + folder, err = os.Open(logPath) + if err != nil { + log.Fatal(err) + } + + // Read the files UwU + files, err = folder.Readdir(-1) + folder.Close() + if err != nil { + log.Fatal(err) + } + + // Off you go! \o/ + return +} + +// findLatestLog Find the last log-file based on the Internet +func findLatestLog(logPath string, intelChannel string, files []fs.FileInfo) (lastName string) { + + // Declare Variables + var lastTime time.Time + var tempTime time.Time + + for _, file := range files { + file, err := os.Stat(logPath + file.Name()) + if err != nil { + log.Fatal(err) + } + + if strings.EqualFold(intelChannel, file.Name()[:len(intelChannel)]) { + tempTime = file.ModTime() + if tempTime.After(lastTime) { + lastTime = tempTime + lastName = logPath + file.Name() + } + } + } + + // And there you are (or not) + return + +} + +// StartIntelMonitoring -- The Main Loop! +func StartIntelMonitoring(intelChannels string, LogSystemsRaw string, LogLocation string) { + + // Declare variables + var logPath string + var IntelChannelsSplit []string + var IntelChannel string + + // Split the CSV string into different parts + IntelChannelsSplit = strings.Split(intelChannels, ",") + + // Get the path we need to + logPath = findPath(LogLocation) + + for _, IntelChannel = range IntelChannelsSplit { + IntelChannel = strings.ReplaceAll(IntelChannel, " ", "_") + go OrchestrateIntelMonitoring(logPath, IntelChannel, LogSystemsRaw) + } + +} + +// ParseChat Parses a string, returns the payload of the chat +// *sigh* +// This took effing forever to get right. +// "Lets start with Regex, cannot go wrong". +// You have this string: +// ��[ 2022.02.09 10:05:43 ] Kaysee Guru > EX-GBT clr nd +// Cool. Looks easy. +// .*\[ (.*?) (.*?) \] (.*?) > (.*) +// regex101.com says its good +// And no matter what I do just does not work for some magical reason. +// +// Lets do this with splitting by space and compare it with that. Do a bunch of ifs, it works in test aaaaaand.... +// It doesn't work. +// +// By now I have a somewhat reliable version, but it fails to look for the word MOTD. +// I should prolly look into runes() +// This is terrible +func ParseChat(chatline string) (LineDate string, LineTime string, LineUser string, Payload []string) { + logLine := chatline[3:] + + var LinePayload string + var splitpos int + + splitpos = strings.Index(logLine, ">") + LineDate = logLine[2:23] + LineTime = logLine[25:41] + LineUser = logLine[46 : splitpos-2] + LinePayload = logLine[splitpos+4:] + LinePayload = shorten(LinePayload) + Payload = strings.Fields(LinePayload) + + //fmt.Println(logLine) + //fmt.Println(LineDate) + //fmt.Println(LineTime) + //fmt.Println(LineUser) + //fmt.Println(splitpos) + //fmt.Println(LinePayload) + //fmt.Println(Payload) + + return +} + +func shorten(payload string) (logLine string) { + runes := []rune(payload) + for pos, char := range runes { + if pos%2 == 0 && char != 13 { + logLine = logLine + string(char) + } + } + return +} + +// CompareElements Compares a log msg with systems we wish to track +func CompareElements(alerts []string, payload []string) bool { + + for _, word := range payload { + for _, alert := range alerts { + + if strings.EqualFold(word, alert) { + //fmt.Println("Found (EF): ", alert, "in", word) + return true + } //else { + // fmt.Println(word, "!=", alert) + //} + + // In the odd case somebody links "C-V6DQ*" + if len(word) > 6 { + //alert = alert[:len(word)] + word = word[:6] + } + + // In case of partials like "C-V" + if len(word) < 6 && len(word) >= 3 { + //word = word[:5] + alert = alert[:len(word)] + } + + if strings.EqualFold(word, alert) { + //fmt.Println("Found: ", alert, "in", word) + return true + } + } + } + return false +} + +// playBeep Play a beep +// Honestly, I tried to play alert.mp3, but after two executions I got a segfault and thought 0x07 it is! +func playBeep() { + fmt.Print("\a") +} + +// main Something Importang. Dunno +func main() { + + // Handle Parameters + var intelChannels = flag.String("i", "Etherium Intel,Bean-Intel", "Comma-separated list of intel channels.") + LogSystemsRaw := flag.String("s", "c-v6dq,1pf-bc,ex-gbt,z-fet0", "Comma-seperated list of systems to monitor for") + LogLocation := flag.String("l", "", "Location of the log-file to track.") + flag.Parse() + + // Start the main loop + go StartIntelMonitoring(*intelChannels, *LogSystemsRaw, *LogLocation) + + // Go into the eternal loop and sit this one out. + // But bug every hour, reminding them that you are still there. + for { + time.Sleep(time.Second * 3600) + fmt.Println("Hi. This is your hourly reminder that this program is still runnig and hasn't crashed!") + } + +} diff --git a/research/alert.mp3 b/research/alert.mp3 new file mode 100644 index 0000000..7b386d0 Binary files /dev/null and b/research/alert.mp3 differ diff --git a/research/beep.go b/research/beep.go new file mode 100644 index 0000000..a4e9c10 --- /dev/null +++ b/research/beep.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "io" + "log" + "os" + + "github.com/hajimehoshi/oto" + + "github.com/hajimehoshi/go-mp3" +) + +func run() error { + f, err := os.Open("alert.mp3") + if err != nil { + return err + } + defer f.Close() + + d, err := mp3.NewDecoder(f) + if err != nil { + return err + } + + c, err := oto.NewContext(d.SampleRate(), 2, 2, 44100) + if err != nil { + return err + } + defer c.Close() + + p := c.NewPlayer() + defer p.Close() + + fmt.Printf("Length: %d[bytes]\n", d.Length()) + + if _, err := io.Copy(p, d); err != nil { + return err + } + return nil +} + +func main() { + if err := run(); err != nil { + log.Fatal(err) + } +} diff --git a/research/intel2noise.go b/research/intel2noise.go new file mode 100644 index 0000000..32c41d8 --- /dev/null +++ b/research/intel2noise.go @@ -0,0 +1,148 @@ +package main + +import ( + "flag" + "fmt" + "strings" + + "github.com/nxadm/tail" +) + +// ParseChat Parses a string, returns the payload of the chat +// *sigh* +// This took effing forever to get right. +// "Lets start with Regex, cannot go wrong". +// You have this string: +// ��[ 2022.02.09 10:05:43 ] Kaysee Guru > EX-GBT clr nd +// Cool. Looks easy. +// .*\[ (.*?) (.*?) \] (.*?) > (.*) +// regex101.com says its good +// And no matter what I do just does not work for some magical reason. +// +// Lets do this with splitting by space and compare it with that. Do a bunch of ifs, it works in test aaaaaand.... +// It doesn't work. +// +// By now I have a somewhat reliable version, but it fails to look for the word MOTD. +// I should prolly look into runes() +// This is terrible +func ParseChat(chatline string) (LineDate string, LineTime string, LineUser string, Payload []string) { + logLine := chatline[3:] + + //var LineDate string + //var LineTime string + //var LineUser string + var LinePayload string + //var Payload []string + var splitpos int + + splitpos = strings.Index(logLine, ">") + LineDate = logLine[4:24] + LineTime = logLine[24:42] + LineUser = logLine[46 : splitpos-2] + LinePayload = logLine[splitpos+4:] + LinePayload = shorten(LinePayload) + Payload = strings.Fields(LinePayload) + + //fmt.Println(logLine) + //fmt.Println(LineDate) + //fmt.Println(LineTime) + //fmt.Println(LineUser) + //fmt.Println(splitpos) + //fmt.Println(LinePayload) + //fmt.Println(Payload) + + return +} + +func shorten(payload string) (logLine string) { + runes := []rune(payload) + for pos, char := range runes { + if pos%2 == 0 && char != 13 { + logLine = logLine + string(char) + } + } + return +} + +// CompareElements Compares a log msg with systems we wish to track +func CompareElements(alerts []string, payload []string) bool { + + for _, word := range payload { + for _, alert := range alerts { + + if strings.EqualFold(word, alert) { + //fmt.Println("Found (EF): ", alert, "in", word) + return true + } //else { + // fmt.Println(word, "!=", alert) + //} + + // In the odd case somebody links "C-V6DQ*" + if len(word) > 6 { + //alert = alert[:len(word)] + word = word[:6] + } + + // In case of partials like "C-V" + if len(word) < 6 && len(word) >= 3 { + //word = word[:5] + alert = alert[:len(word)] + } + + if strings.EqualFold(word, alert) { + //fmt.Println("Found: ", alert, "in", word) + return true + } + } + } + return false +} + +// playBeep Play a beep +// Honestly, I tried to play alert.mp3, but after two executions I got a segfault and thought 0x07 it is! +func playBeep() { + fmt.Print("\a") +} + +func main() { + + // Deal with parameters first. + LogLocation := flag.String("l", "", "Location of the log-file to track.") + LogSystemsRaw := flag.String("s", "jita,Perimeter,New Caldari,Sobaseki", "comma-seperated list of systems") + //LogAlarm := flag.String("a", "alert.mp3", "Audio file to play when an alert needs to be triggered") + flag.Parse() + + // Split the CSV string into different parts + LogSystems := strings.Split(*LogSystemsRaw, ",") + + // Do the main loop and start parsing the logfiles + t, err := tail.TailFile(*LogLocation, tail.Config{Follow: true}) + if err != nil { + panic(err) + } + + for line := range t.Lines { + // Cast a line to a text, trim the trash + logLine := string(line.Text) + logLine = strings.Trim(logLine, "\n") + + // Figure out if this is a message we want to deal with + // > is critical in this regard because it is the start of the message + // and everything behind it until it hits ] is the username + splitpos := strings.Index(logLine, ">") + if -1 == splitpos { + continue + } + + // Somehow I cannot filter out this stuff. + // EVE System > Channel MOTD + LineDate, LineTime, LineUser, Payload := ParseChat(logLine) + + if CompareElements(LogSystems, Payload) { + playBeep() + fmt.Println("On", LineDate, "at", LineTime, "", LineUser, "posted", Payload) + } + + } + +} diff --git a/research/params.go b/research/params.go new file mode 100644 index 0000000..7409a57 --- /dev/null +++ b/research/params.go @@ -0,0 +1,26 @@ +package main + +import ( + "flag" + "fmt" + "strings" +) + +func main() { + num := flag.Int("n", 5, "# of iterations") + mysystems := flag.String("s", "jita,New Caldari", "comma-seperated list of systems") + flag.Parse() + + n := *num + i := 0 + + for i < n { + fmt.Println("falcon") + i++ + } + + fmt.Println(*mysystems) + s := strings.Split(*mysystems, ",") + fmt.Println(s) + +} diff --git a/research/partial.go b/research/partial.go new file mode 100644 index 0000000..b1e2c38 --- /dev/null +++ b/research/partial.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + chatline := "c-v Morretus Isayeki nv" + words := strings.Fields(chatline) + alerts := [...]string{"C-V6DQ", "1PF-BC", "EX-GBT", "Z-FET0"} + + //var found bool + + for _, word := range words { + for _, alert := range alerts { + + if strings.EqualFold(word, alert) { + fmt.Println("Found: ", alert, "in", word) + } + + // In the odd case somebody links "C-V6DQ*" + if len(word) < 6 { + alert = alert[:len(word)] + } + + // In case of partials like "C-V" + if len(word) > 6 { + word = word[:5] + } + if strings.EqualFold(word, alert) { + fmt.Println("Found: ", alert, "in", word) + } + + fmt.Println(word) + fmt.Println(alert) + fmt.Println("---") + + } + } + + //fmt.Println(string(myString[:3])) + //fmt.Println("Dit") + //fmt.Println(strings.EqualFold(myString[:3], "Dit")) + +} diff --git a/research/regex_funpark.go b/research/regex_funpark.go new file mode 100644 index 0000000..e587ff8 --- /dev/null +++ b/research/regex_funpark.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" + "strings" +) + +// ParseChat Parses a string, returns the payload of the chat +func ParseChat(chatline string) (LineDate string, LineTime string, LineUser string, LinePayload []string) { + words := strings.Fields(chatline) + //fmt.Println(len(words)) + //var LineDate string + //var LineTime string + //var LineUser string + //var LinePayload []string + var SplitFound int + + for i := range words { + + if i == 1 { + LineDate = words[i] + } + + if i == 2 { + LineTime = words[i] + } + + if i >= 5 && SplitFound == 1 { + LinePayload = append(LinePayload, words[i]) + } + + if words[i] == ">" { + SplitFound = 1 + } + + if i >= 4 && SplitFound == 0 { + if LineUser == "" { + LineUser = words[i] + } else { + LineUser = LineUser + " " + words[i] + } + } + + } + //fmt.Println(LineDate) + //fmt.Println(LineTime) + //fmt.Println(LineUser) + //fmt.Println(LinePayload) + return +} + +func main() { + + mystring := "��[ 2022.02.07 19:57:52 ] Samoa Serine > BY-7PY Morretus Isayeki nv" + + LineDate, LineTime, LineUser, Payload := ParseChat(mystring) + fmt.Println("On " + LineDate + " " + LineTime + " " + LineUser + " posted the following: ") + fmt.Println(Payload) + +} diff --git a/research/searchlog.go b/research/searchlog.go new file mode 100644 index 0000000..e3cef68 --- /dev/null +++ b/research/searchlog.go @@ -0,0 +1,162 @@ +package main + +import ( + "flag" + "fmt" + "io/fs" + "log" + "os" + "runtime" + "strings" + "time" +) + +// findPath Find the path in which the log files are stored. +func findPath() (logPath string) { + + var err error + var homedir string + var Path string + var Paths []string + var PathsLinux []string + var PathsMac []string + var PathsWindows []string + + // Determine the homedir of the user. + homedir, err = os.UserHomeDir() + if err != nil { + log.Fatal(err) + } + + // Define Paths to check out + PathsLinux = append(PathsLinux, "/Documents/EVE/logs/") + PathsLinux = append(PathsLinux, "/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs/") + + PathsMac = append(PathsMac, "/Documents/EVE/logs/") + PathsMac = append(PathsMac, "/Library/Application Support/EVE Online/p_drive/User/My Documents/EVE/") + + PathsWindows = append(PathsWindows, "C:\\Users\\YourUserName\\Documents\\EVE\\logs") + PathsWindows = append(PathsWindows, "MyDocuments -> EVE -> Logs") + + switch runtime.GOOS { + case "linux": + Paths = PathsLinux + case "darwin": + Paths = PathsMac + case "windows": + Paths = PathsWindows + } + + for _, Path = range Paths { + if _, err := os.Stat(homedir + Path); !os.IsNotExist(err) { + logPath = homedir + Path + } + } + + return +} + +// OrchestrateIntelMonitoring routine to periodically check the logpath for the intel channels. +func OrchestrateIntelMonitoring(logPath string, intelChannel string) { + + // Declare variables + var files []fs.FileInfo + var lastName string + var tempName string + + // Enter a for-loop that periodically checks. + for { + files = fetchFileListing(logPath) + tempName = findLatestLog(logPath, intelChannel, files) + + if !strings.EqualFold(lastName, tempName) { + lastName = tempName + fmt.Println("Found a new LogFile! Its " + lastName) + } + + // Sleep a minute before we check again. + time.Sleep(time.Second * 60) + } + +} + +// fetchFileListing As it says on the tin. +func fetchFileListing(logPath string) (files []fs.FileInfo) { + + // Declare Variables + var err error + var folder *os.File + + // Open the folder we need to open. + folder, err = os.Open(logPath) + if err != nil { + log.Fatal(err) + } + + // Read the files UwU + files, err = folder.Readdir(-1) + folder.Close() + if err != nil { + log.Fatal(err) + } + + // Off you go! \o/ + return +} + +// findLatestLog Find the last log-file based on the Internet +func findLatestLog(logPath string, intelChannel string, files []fs.FileInfo) (lastName string) { + + // Declare Variables + var lastTime time.Time + var tempTime time.Time + + for _, file := range files { + file, err := os.Stat(logPath + file.Name()) + if err != nil { + log.Fatal(err) + } + + if strings.EqualFold(intelChannel, file.Name()[:len(intelChannel)]) { + tempTime = file.ModTime() + if tempTime.After(lastTime) { + lastTime = tempTime + lastName = logPath + file.Name() + } + } + } + + // And there you are (or not) + return + +} + +// main Something Importang. Dunno +func main() { + + // Declare variables + var logPath string + var IntelChannelsSplit []string + var IntelChannel string + + // Handle Parameters + var intelChannels = flag.String("i", "Etherium Intel,Bean-Intel", "A commaseparated list of intel channels.") + flag.Parse() + + // Split the CSV string into different parts + IntelChannelsSplit = strings.Split(*intelChannels, ",") + + // Get the path we need to + logPath = findPath() + + for _, IntelChannel = range IntelChannelsSplit { + IntelChannel = strings.ReplaceAll(IntelChannel, " ", "_") + go OrchestrateIntelMonitoring(logPath, IntelChannel) + } + + for { + time.Sleep(time.Second * 3600) + fmt.Println("Hi. This is your hourly reminder that this program is still runnig and hasn't crashed!") + } + +} diff --git a/research/tailLocal.go b/research/tailLocal.go new file mode 100644 index 0000000..cbce583 --- /dev/null +++ b/research/tailLocal.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + + "github.com/nxadm/tail" +) + +var logFile = "/home/outcast/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs/Etherium_Intel_20220207_154354_93488613.txt" + +func main() { + t, err := tail.TailFile(logFile, tail.Config{Follow: true}) + if err != nil { + panic(err) + } + + for line := range t.Lines { + fmt.Println(line.Text) + } +}