我正在使用 Windows PowerShell 上的脚本通过 Discord 上的 webhook 发布消息,但发生这种情况时它不会立即发布消息。
脚本如下:
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\Users\AYYA\.chatty\logs"
$watcher.Filter = "highlighted.log"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$action = {
$path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$log = "File: $path $changeType"
$webhookurl = "https://discord.com/api/webhooks/1183179002920321064/jdy2EO4AdnFhQg_ON9TfwCOPcDo8y1H7TYrQUT0HtCI5a7AO2FOd_As1BYUNWqhI0oei"
$content = (Get-Content -Path $path -Tail 1).ToString()
$body = @{
content = $content
} | ConvertTo-Json
Invoke-RestMethod -Uri $webhookurl -Method Post -Body $body -ContentType 'application/json'
}
Register-ObjectEvent -InputObject $watcher -EventName Created -Action $action
Register-ObjectEvent -InputObject $watcher -EventName Changed -Action $action
如何让它更快?