Reorganise scripts
This commit is contained in:
parent
5ebf7f9b5c
commit
4ae0656da4
18 changed files with 196 additions and 104 deletions
57
.config/scripts/util/webhook.sh
Executable file
57
.config/scripts/util/webhook.sh
Executable file
|
@ -0,0 +1,57 @@
|
|||
REQUESTED_USER=''
|
||||
NAME='Webhook'
|
||||
PIC=''
|
||||
MSG=''
|
||||
ENDPOINT='_'
|
||||
FILE='_'
|
||||
|
||||
getUser() {
|
||||
/usr/local/bin/gsed -nE "/^\[$REQUESTED_USER\]$/{:l n;/^(\[.*\])?$/q;p;bl}" ~/.config/webhook > /tmp/webhook_config.sh ||
|
||||
sed -nE "/^\[$REQUESTED_USER\]$/{:l n;/^(\[.*\])?$/q;p;bl}" ~/.config/webhook > /tmp/webhook_config.sh;
|
||||
chmod +x /tmp/webhook_config.sh
|
||||
. /tmp/webhook_config.sh
|
||||
rm /tmp/webhook_config.sh
|
||||
}
|
||||
|
||||
printUsage() {
|
||||
echo ""
|
||||
echo "Discord Webhook Wrapper"
|
||||
echo "-c Requested premade config to use"
|
||||
echo "-n Username to use"
|
||||
echo "-p Picture to use"
|
||||
echo "-m Message to send"
|
||||
echo "-e Endpoint to hit"
|
||||
echo ""
|
||||
}
|
||||
|
||||
while getopts 'c:n:p:m:e:f:h' flag; do
|
||||
case "${flag}" in
|
||||
c) REQUESTED_USER="${OPTARG}"; getUser ;;
|
||||
n) NAME="${OPTARG}" ;;
|
||||
p) PIC="${OPTARG}" ;;
|
||||
m) MSG="${OPTARG}" ;;
|
||||
e) ENDPOINT="${OPTARG}" ;;
|
||||
f) FILE="${OPTARG}" ;;
|
||||
*) printUsage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$ENDPOINT" == "_" ]]; then
|
||||
echo "Please provide an endpoint url with -e"
|
||||
exit 1
|
||||
else
|
||||
if [[ "$FILE" == "_" ]]; then
|
||||
curl -i \
|
||||
-H "Accept: multipart/form-data" \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-F "payload_json={\"content\": \"$MSG\", \"username\": \"$NAME\", \"avatar_url\": \"$PIC\"}" \
|
||||
"$ENDPOINT" > /dev/null 2>&1;
|
||||
else
|
||||
curl -i \
|
||||
-F "file1=@${FILE}" \
|
||||
-H "Accept: multipart/form-data" \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-F "payload_json={\"content\": \"$MSG\", \"username\": \"$NAME\", \"avatar_url\": \"$PIC\"}" \
|
||||
"$ENDPOINT" > /dev/null 2>&1;
|
||||
fi
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue