This commit is contained in:
parent
939df3fcc4
commit
3a14049973
26
stdin2discord.bash
Normal file
26
stdin2discord.bash
Normal 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"
|
@ -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)
|
Loading…
x
Reference in New Issue
Block a user