YoloWingPixie / lsobot

A log scrapper for DCS World that checks for new carrier landing grades made by humans and sends them to Discord.
MIT License
11 stars 8 forks source link

Read hook URL from file #8

Closed wrycu closed 3 years ago

wrycu commented 3 years ago

This script is super simple to setup, but it's frustrating to check into any sort of public version control since the web hook URL is inside of the primary file.

It's dead simple to read it from a file, and it'd make it easier for people to contribute if they aren't at risk of posting private information. If this increases the complexity for users by too much, consider only using the in-file hook URL if the file doesn't exist or is empty or something, such that users who want to use a file can and users who don't retain their simple flow.

Fwiw, reading from a file is a single line.

$hookUrl = Get-Content "hook_url.txt"
YoloWingPixie commented 3 years ago

This is planned to be implemented shortly and will probably be included in the next release.

YoloWingPixie commented 3 years ago

@wrycu The dev branch now loads options from LsoBot-Config.psd1 when the job runs and no configuration is now needed within LsoBot.ps1 itself.

FWIW, it was not one line of code due to the necessity to maintain user-friendliness in avoiding hard-coded file paths. Powershell jobs run in a context that makes it somewhat of a nuisance to load a config file in the root folder that the script is running on. Long story short, $PSScriptRoot just doesn't work and 3 hours of pain later I figured out what I needed to do.

Go ahead and clone the dev build and try it out. You must use the new LsoBot-Register.ps1 and you must run LsoBot-Register.ps1 within the same folder as LsoBot.ps1, as it includes these lines that are needed to set the location the script is in so LsoBot knows where to load the config from:

$lsoBotfilePath = ".\LsoBot.ps1"
$LsoScriptRoot = $PWD.Path
$LsoScriptRoot.Trim()
$LsoScriptRoot.Split([Environment]::NewLine)[0]

Register-ScheduledJob -Name "LSO Check" -FilePath $lsoBotfilePath -ScheduledJobOption $O -Trigger $T -ArgumentList @($LsoScriptRoot)

LsoBot.ps1:

    param(
    $LsoScriptRoot
)
$configPath = "$LsoScriptRoot\LsoBot-Config.psd1"
Get-Content $configPath
$lsoConfig = Import-PowerShellDataFile $configPath
YoloWingPixie commented 3 years ago

Released on main