I am trying to find a way to let my Discord server post the data when a channel point redeem gets triggered on a twitch channel.
i could not find a direct way of doing it, so
i used a 3rd party chat bot (called chatty) to log the messages to a log file on my local windows 10 machine
then used a script on windows powershell to post a message using webhooks on discord, the thing is the script posts "File: C:\Users\AYYA.chatty\logs\2023-12-09_highlighted.log Changed" and not the actual data of the log file's last line.
which looks something like the following
example: "[2023-12-09 04:26:54 AM][#Testrider] MOD|SUB/12 @ELCabager There are 1x Eevee in the wondertrade pool! (0x ✨)"
the script that was used is below
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\Users\AYYA\.chatty\logs"
$watcher.Filter = "2023-12-09_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/1182854675947593799/DHgRfZWP547WkDUrwG9LuGtwNrWLs51o6Z0CmgqLa0Gh_jtUmeDj9qxmhvPNOV8_dOkx"
$body = @{
content = $log
} | 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`
For the actual data of the log file's last line, read it using Get-Content
cmdlet as follows:
$content = (Get-Content -Path $path -Tail 1).ToString()
$body = @{
content = $content
} | ConvertTo-Json