1+ # Section to store log file path and keywords to detect
2+ $chatlogPath = " $env: userprofile \Documents\EVE\logs\Chatlogs"
3+ # edit keyword list to add or remove keywords to detect in local chat log
4+ # keywords are not case sensitive and will match any part of the line.
5+ $keywordList = @ (" wtb" ) # Add your keywords here, separated by commas
6+
7+ # Function to get the latest local chat log file
8+ function Get-LatestLocalChatLog {
9+ return Get-ChildItem - Path $chatlogPath - Filter " Local_*.txt" |
10+ Sort-Object LastWriteTime - Descending |
11+ Select-Object - First 1
12+ }
13+
14+ # Function to send a message to Discord webhook (optional)
15+
16+ function DiscordPing {
17+ param (
18+ [string ]$keyword ,
19+ [string ]$line
20+ )
21+
22+ }
23+
24+ # #####################################
25+
26+ # Discord webhook URL (optional)
27+ # Uncomment the following line to enable Discord notifications
28+ $webhookUrl = " .env" # Replace with your Discord webhook URL
29+
30+ $payload = @ {
31+ content = " Keyword detected: $keyword `n Message: $line "
32+ username = " Chat Monitor"
33+ } | ConvertTo-Json - Depth 3
34+
35+ try {
36+ Invoke-RestMethod - Uri $webhookUrl - Method Post - Body $payload - ContentType " application/json"
37+ } catch {
38+ Write-Warning " Failed to send Discord notification: $ ( $_.Exception.Message ) "
39+ }
40+
41+ # #########################
42+
43+ # Error handling to check its available.
44+
45+ Write-Host " Local Chat Monitor Active" - ForegroundColor Green
46+ $currentLog = Get-LatestLocalChatLog
47+ if (-not $currentLog ) {
48+ Write-Error " No Local chat logs found. Are you sure EVE has chat logging enabled?"
49+ exit
50+ }
51+
52+ # Once the log file is found, initialize variables
53+
54+ $lastFileSize = (Get-Item $currentLog.FullName ).Length
55+ $alreadySeen = @ {}
56+ Write-Host " Monitoring $ ( $currentLog.FullName ) for new messages..." - ForegroundColor Green
57+
58+ while ($true ) {
59+ # Check for new log file
60+ $newLog = Get-LatestLocalChatLog
61+ if ($newLog.FullName -ne $currentLog.FullName ) {
62+ Write-Host " `n New log file detected: $ ( $newLog.Name ) " - ForegroundColor Yellow
63+ $currentLog = $newLog
64+ $lastFileSize = 0 # Reset file size for the new log
65+ $alreadySeen = @ {} # Clear seen messages for the new log
66+ Write-Host " Now monitoring $ ( $currentLog.FullName ) " - ForegroundColor Green
67+ continue
68+ }
69+
70+ try {
71+ # Log file comparison and reading log file - discovered that cant use streamreader as it locks the file and prevents eve from writing to it.
72+ # This is a workaround to read the file without locking it - using Get-Content with -Tail
73+ # Get the current file size and read new lines if the file has grown
74+ $currentFileSize = (Get-Item $currentLog.FullName ).Length
75+ if ($currentFileSize -gt $lastFileSize ) {
76+ $newContent = Get-Content - Path $currentLog.FullName - Tail ($currentFileSize - $lastFileSize )
77+ $lastFileSize = $currentFileSize
78+
79+ foreach ($line in $newContent ) {
80+ foreach ($keyword in $keywordList ) {
81+ if ($line -match $keyword -and -not $alreadySeen.ContainsKey ($line )) {
82+ Write-Host " [$ ( (Get-Date ).ToString(' HH:mm:ss' )) ] Match: $keyword -> $line " - ForegroundColor Magenta
83+ $alreadySeen [$line ] = $true
84+ }
85+ }
86+ }
87+ }
88+ } catch {
89+ Write-Warning " Error reading log file: $ ( $_.Exception.Message ) "
90+ Start-Sleep - Seconds 1
91+ }
92+
93+ Start-Sleep - Milliseconds 100
94+ }
0 commit comments