From 2669deeb40ae4bebb045b8c9a644ea174d5aca65 Mon Sep 17 00:00:00 2001 From: Sacha Ligthert Date: Mon, 17 Oct 2022 19:39:06 +0200 Subject: [PATCH] first commit --- README.md | 46 ++++++ go.mod | 18 +++ go.sum | 23 +++ main.go | 311 ++++++++++++++++++++++++++++++++++++++ research/alert.mp3 | Bin 0 -> 6184 bytes research/beep.go | 47 ++++++ research/intel2noise.go | 148 ++++++++++++++++++ research/params.go | 26 ++++ research/partial.go | 46 ++++++ research/regex_funpark.go | 60 ++++++++ research/searchlog.go | 162 ++++++++++++++++++++ research/tailLocal.go | 20 +++ 12 files changed, 907 insertions(+) create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 research/alert.mp3 create mode 100644 research/beep.go create mode 100644 research/intel2noise.go create mode 100644 research/params.go create mode 100644 research/partial.go create mode 100644 research/regex_funpark.go create mode 100644 research/searchlog.go create mode 100644 research/tailLocal.go 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 0000000000000000000000000000000000000000..7b386d0200df2f313dfef08e4af58ba6d799819a GIT binary patch literal 6184 zcmeHLXH-+m+MZAoii8lVlmI~i5h7Bh7;@y3iP^Ax<&lc zA_8~1|3$iQAiW$+&xv#&FM1yEXAh_8Wlwrpi~iI>UjS?@4NlMl@c3U0;NK6nKj)wL z$-qw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+// 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) + } +}