Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save unchama/bd93f5668b193fad8470859c97c530fb to your computer and use it in GitHub Desktop.
Save unchama/bd93f5668b193fad8470859c97c530fb to your computer and use it in GitHub Desktop.
# 第1引数:ファイルパス
# 第2引数:処理分岐で使用
Param( $1,$2 )
# 第2引数で送信先を振り分ける
# $urlにはwebhookのURLを指定する
if($2 -eq "example1"){
$url = "https://discordapp.com/api/webhooks/~~~~~"
}elseif($2 -eq "example2"){
$url = "https://discordapp.com/api/webhooks/~~~~~"
}else{
$url = "https://discordapp.com/api/webhooks/~~~~~"
}
$FilePath = $1
# windows版curlのパスを指定(こんなことしなくても環境変数でパス通しちゃえばcurlだけで使えるようになる)
# windows版curlはggって調達する↓
# https://www.google.com/search?q=curl+windows
$CurlExecutable = "C:\Scripts\curl-7.60.0-win64-mingw\bin\curl.exe"
Write-Host "CurlFile" $CurlFile
$CurlArguments = '--request', 'POST',
"$url",
'--header', "'content-type: multipart/form-data'",
'--form', "file=@$FilePath"
'-v'
& $CurlExecutable @CurlArguments
# 第1引数:送るメッセージ
# 第2引数:処理分岐で使用
Param( $1,$2 )
$DATE = Get-Date -DisplayHint DateTime
# 第2引数でメッセージにホスト名を含めたり含めなかったりする
if($2 -eq "example1"){
$HOSTNAME = ""
}else{
$HOSTNAME = hostname
}
$HEADER = "[ " + $DATE + " / " + $HOSTNAME + " ]"
$MSG = $1
# 第2引数で送信先を振り分ける
# $urlにはwebhookのURLを指定する
if($2 -eq "example1"){
$url = "https://discordapp.com/api/webhooks/~~~~~"
}elseif($2 -eq "example2"){
$url = "https://discordapp.com/api/webhooks/~~~~~"
}else{
$url = "https://discordapp.com/api/webhooks/~~~~~"
}
$content = @"
$HEADER
$MSG
"@
$payload = [PSCustomObject]@{
content = $content
}
$json = $payload | ConvertTo-Json
$json_utf8 = [System.Text.Encoding]::UTF8.GetBytes($json)
$headers = @{
"Content-Type" = "application/json"
}
Invoke-RestMethod -Uri $url -Method Post -Body $json_utf8 -Headers $headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment