-
Notifications
You must be signed in to change notification settings - Fork 33
/
autologs.ps1.txt
79 lines (66 loc) · 2.09 KB
/
autologs.ps1.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
$LOG_FOLDER="$env:USERPROFILE\.runelite\logs"
if (-not(Test-Path -Path "$LOG_FOLDER" -PathType Container)) {
Write-Host "Logs folder not found, expected $LOG_FOLDER"
exit -1
}
$CLIENT_PATH="$LOG_FOLDER\client.log"
$LAUNCHER_PATH="$LOG_FOLDER\launcher.log"
$CLIENT_LOG_FOUND=$(Test-Path -Path "$CLIENT_PATH" -PathType Leaf)
$LAUNCHER_LOG_FOUND=$(Test-Path -Path "$LAUNCHER_PATH" -PathType Leaf)
if ((-not($CLIENT_LOG_FOUND)) -and (-not($LAUNCHER_LOG_FOUND))) {
Write-Host "client.log and launcher.log not found in logs folder."
exit -1
}
$MESSAGE_CONTENT="New autologs!"
$MESSAGE_FILES=@()
if ($CLIENT_LOG_FOUND) {
$MESSAGE_FILES += $CLIENT_PATH
} else {
$MESSAGE_CONTENT="$MESSAGE_CONTENT client.log not found"
}
if ($LAUNCHER_LOG_FOUND) {
$MESSAGE_FILES += $LAUNCHER_PATH
} else {
$MESSAGE_CONTENT="$MESSAGE_CONTENT launcher.log not found"
}
$JVM_CRASH_FILES = Get-ChildItem -File -Path "$LOG_FOLDER" -Filter "jvm_*"
$MAX_JVM_CRASH_FILES = 5
$NUM_JVM_CRASH_FILES = 0
$CUTOFF = (Get-Date).AddDays(-1)
foreach ($crash in $JVM_CRASH_FILES) {
if ($NUM_JVM_CRASH_FILES -ge $MAX_JVM_CRASH_FILES) {
break
}
if (($crash.LastWriteTime) -gt $CUTOFF) {
$MESSAGE_FILES += $crash.FullName
$NUM_JVM_CRASH_FILES += 1
}
}
$FORM_BOUNDARY = [System.Guid]::NewGuid().ToString();
$LF = "`r`n"
$BODY = (
"--$FORM_BOUNDARY",
"Content-Disposition: form-data; name=`"content`"$LF",
$MESSAGE_CONTENT,
""
) -join $LF
$FILE_COUNT = 0
foreach ($FILE in $MESSAGE_FILES) {
$BODY += (
"--$FORM_BOUNDARY",
"Content-Disposition: form-data; name=`"file[$FILE_COUNT]`"; filename=`"$((Get-Item $FILE).Name)`"",
"Content-Type: application/octet-stream$LF",
(Get-Content -Encoding "ASCII" -Path "$FILE" -Raw),
""
) -join $LF
$FILE_COUNT += 1
}
$BODY += "$LF--$FORM_BOUNDARY--$LF"
Write-Host $BODY
Write-Host "Uploading the following files:"
foreach ($FILE in $MESSAGE_FILES) {
Write-Host $FILE
}
$WEBHOOK = "https://api.runelite.net/autologs"
$RESPONSE = Invoke-RestMethod -Uri $WEBHOOK -Method Post -ContentType "multipart/form-data; boundary=`"$FORM_BOUNDARY`"" -Body $BODY
Write-Host "`r`n`r`nDone! MID = $($RESPONSE.id)"