@@ -59,6 +59,7 @@ File options:
59
59
Identity options:
60
60
--username <name> Set username to <name>
61
61
--avatar <url> Set avatar to image located at <url>
62
+ --modify Modify webhook (pass with avatar/username permanantly update webhook)
62
63
63
64
Embedded content options:
64
65
Main:
@@ -136,6 +137,8 @@ while (( "$#" )); do
136
137
--webhook-url=* ) webhook_url=${1/ --webhook-url=/ ' ' } ; shift ;;
137
138
--webhook-url* ) webhook_url=${2} ; shift ; shift ;;
138
139
140
+ --modify* ) modify=1; shift ;;
141
+
139
142
--username=* ) username=${1/ --username=/ ' ' } ; shift ;;
140
143
--username* ) username=${2} ; shift ; shift ;;
141
144
@@ -331,6 +334,28 @@ build_embed() {
331
334
echo " , \" embeds\" : [{ \" _\" : \" _\" ${_title}${_desc}${_eurl}${_color}${_ts}${_author}${_thumb}${_image}${_fields}${_footer} }]"
332
335
}
333
336
337
+ convert_image_link_to_base64 () {
338
+ local _image
339
+ local _image_type
340
+ local _image_base64
341
+
342
+ # save image to temp file
343
+ _image=" $( mktemp) "
344
+ curl -s " ${1} " > " ${_image} "
345
+
346
+ # get image type
347
+ _image_type=" $( file -b --mime-type " ${_image} " ) "
348
+
349
+ # convert to base64
350
+ _image_base64=$( < " $_image " base64)
351
+
352
+ # remove temp file
353
+ rm " ${_image} "
354
+
355
+ # output
356
+ echo " data:${_image_type} ;base64,${_image_base64} "
357
+ }
358
+
334
359
335
360
build () {
336
361
local _content
@@ -344,8 +369,16 @@ build() {
344
369
[[ -z " ${embed_title} " ]] && \
345
370
[[ -z " ${embed_description} " ]] && \
346
371
[[ -z " ${embed_imageurl} " ]] && \
372
+ [[ -z " ${modify} " ]] && \
373
+ [[ -z " ${username} " ]] && \
374
+ [[ -z " ${avatar_url} " ]] && \
347
375
echo " fatal: nothing to build" && exit 1
348
-
376
+
377
+ # if only specified modify but not username/avatar, exit with error
378
+ [[ -n " ${modify} " ]] && \
379
+ [[ -z " ${username} " ]] && \
380
+ [[ -z " ${avatar_url} " ]] && \
381
+ echo " fatal: must pass --username or --avatar with --modify" && exit 1
349
382
# strip 0x prefix and convert hex to dec if necessary
350
383
[[ -n " ${embed_color} " ]] && [[ " ${embed_color} " =~ ^0x[0-9a-fA-F]+$ ]] && embed_color=" $(( embed_color )) "
351
384
@@ -356,8 +389,14 @@ build() {
356
389
# let's build, boys
357
390
[[ -n " ${is_tts} " ]] && _tts=" , \" tts\" : true"
358
391
[[ -n " ${text} " ]] && _content=" , \" content\" : \" ${text} \" "
359
- [[ -n " ${username} " ]] && _username=" , \" username\" : \" ${username} \" "
360
- [[ -n " ${avatar_url} " ]] && _avatar=" , \" avatar_url\" : \" ${avatar_url} \" "
392
+ # if we're modifying, change the username field to name
393
+ [[ -n " ${username} " ]] && [[ -n " ${modify} " ]] && _username=" , \" name\" : \" ${username} \" "
394
+ [[ -n " ${username} " ]] && [[ -z " ${modify} " ]] && _username=" , \" username\" : \" ${username} \" "
395
+ # if avatar_url is set and modify is set, change the avatar_url field to avatar and convert to base64
396
+ # if avatar_url is set and modify is not set, change the avatar_url field to avatar
397
+ [[ -n " ${avatar_url} " ]] && [[ -n " ${modify} " ]] && _avatar=" , \" avatar\" : \" $( convert_image_link_to_base64 " ${avatar_url} " ) \" "
398
+ [[ -n " ${avatar_url} " ]] && [[ -z " ${modify} " ]] && _avatar=" , \" avatar_url\" : \" ${avatar_url} \" "
399
+
361
400
[[ -n " ${embedding} " ]] && _embed=" $( build_embed) "
362
401
363
402
local _prefix=" \" wait\" : true${_tts}${_content}${_username}${_avatar}${_embed} "
@@ -378,6 +417,17 @@ send()
378
417
# dry run?
379
418
[[ -n " ${is_dry} " ]] && [[ " ${is_dry} " -ne 0 ]] && echo " ${1} " && exit 0;
380
419
420
+ # If any arguments except for username, modify and avatar are specified (modify option required), then exit with an error
421
+ if [[ -n " ${username} " ]] || [[ -n " ${avatar_url} " ]] && [[ " ${modify} " = 1 ]]; then
422
+ if [[ -n " ${text} " ]] && [[ -n " ${embed_title} " ]] && [[ -n " ${embed_description} " ]] && [[ -n " ${embed_url} " ]] && [[ -n " ${embed_color} " ]] && [[ -n " ${embed_timestamp} " ]] && [[ -n " ${embed_authorurl} " ]] && [[ -n " ${embed_authoricon} " ]] && [[ -n " ${embed_authorname} " ]] && [[ -n " ${embed_thumbnail} " ]] && [[ -n " ${embed_imageheight} " ]] && [[ -n " ${embed_imagewidth} " ]] && [[ -n " ${embed_imageurl} " ]] && [[ -n " ${embed_footertext} " ]] && [[ -n " ${embed_footericon} " ]] && [[ -n " ${fields} " ]] && [[ -n " ${file_path} " ]]; then
423
+ echo " fatal: no arguments specified (except for username, modify and avatar)" ; exit 1;
424
+ fi
425
+ _result=$( curl -H " Content-Type: application/json" -H " Expect: application/json" -X PATCH " ${webhook_url} " -d " ${_sendme} " 2> /dev/null)
426
+ send_ok=$?
427
+ [[ " ${send_ok} " -ne 0 ]] && echo " fatal: curl failed with code ${send_ok} " && exit $send_ok
428
+ exit 0;
429
+ fi
430
+
381
431
# make the POST request and parse the results
382
432
# results should be empty if there's no problem. otherwise, there should be code and message
383
433
local _result
0 commit comments