Update stdin2discord.bash
All checks were successful
Push commit / report (push) Successful in 3s

This commit is contained in:
a31 2023-09-09 18:53:51 +03:00
parent 939df3fcc4
commit 3a14049973
2 changed files with 26 additions and 26 deletions

26
stdin2discord.bash Normal file
View File

@ -0,0 +1,26 @@
#!/bin/bash
send() {
local _msg=$1
if [[ -z $_msg ]]; then
return
fi
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"content\":\"$_msg\"}" \
"$DISCORD_WEBHOOK"
}
msg=""
while IFS= read -r line; do
if [[ ${#msg}${#line} -ge 2000 ]]; then
send "$msg"
msg=""
else
msg+="$line"
fi
done
send "$msg"

View File

@ -1,26 +0,0 @@
import sys
import requests
import os
def send(_msg: str):
if len(_msg) == 0:
return
r = requests.post(
url=os.environ['DISCORD_WEBHOOK'],
data=f'content=```diff\n{requests.utils.quote(_msg)}```'.encode('utf-8'),
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
)
r.raise_for_status()
msg = ''
for line in sys.stdin:
if len(msg + line) >= 2000:
send(msg)
msg = ''
else:
msg += line
send(msg)