-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotctrl
More file actions
executable file
·1855 lines (1810 loc) · 59.6 KB
/
botctrl
File metadata and controls
executable file
·1855 lines (1810 loc) · 59.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
# botctrl - control LifeBot or Corrade bots from the command line
#
# Copyright (c) 2025-2026 Truth & Beauty Lab
#
# Author: Missy Restless <missyrestless@gmail.com>
# Created: 15-Nov-2025
# License: MIT
#
# TODO: get bot details not working yet, need to generate an access token
#
# ----------------- $HOME/.botctrl Format ----------------------
# Entries in ~/.botctrl can be LB_API_KEY, LB_SECRET, or entries
# of the form LB_SECRET_BOT_NAME in order to support multiple bots
#
# Entries can specify a Slurl alias. For example:
# export SLURL_club="http://maps.secondlife.com/secondlife/Scylla/226/32/78"
# A Slurl alias can be used with the -l command line argument, e.g. -l club
#
# Entries can also specify a UUID alias. For example:
# export UUID_couch="xxxxxxxx-yyyy-zzzz-aaaa-bbbbbbbbbbbb"
# A UUID alias can be used with the -u command line argument, e.g. -u couch
# ---------------------------------------------------------------
#
# Command line arguments can be used to override the settings in .botctrl
# NOTE: command line arguments are stored in the shell history
# environment variables are preferable over command line arguments
#
# Set the default Bot name
# Setting in .botctrl overrides, setting on command line with -n name overrides all
LB_BOT_NAME="Anya Ordinary"
CO_BOT_NAME="Easy Islay"
# Set the default action, can be specified with -a action
ACTION="status"
# LifeBots API endpoint
APIURL="https://api.lifebots.cloud/api"
ENDPOINT="${APIURL}/bot.html"
# Set the default login location
LOCATION="Last location"
# Default chat channel
CHANNEL=0
# Default hover height adjustment
HEIGHT="-0.05"
BOLD=$(tput bold 2> /dev/null)
NORM=$(tput sgr0 2> /dev/null)
LINE=$(tput smul 2> /dev/null)
SCRIPT_FULL_PATH="$0"
SCRIPT_NAME=$(basename "${SCRIPT_FULL_PATH}")
usage() {
[ "${nobold}" ] && {
BOLD=
LINE=
NORM=
}
printf "\n${BOLD}${LINE}Usage:${NORM} ${BOLD}${SCRIPT_NAME} [-deih] [-a action] [-A avatar] [-l location] [-n name] [-k apikey] [-C channel] [-c corrade]"
printf "\n [-D data] [-F filter] [-M message] [-N name] [-O name] [-S subject] [-s secret] [-T text] [-u uuid] [-z num]${NORM}"
[ "$1" == "brief" ] && {
printf "\n\n"
exit 1
}
printf "\n${BOLD}${LINE}Where:${NORM}"
printf "\n\t${BOLD}${LINE}-a action${NORM} specifies the API action (sit, teleport, login, ...)"
printf "\n\t${BOLD}${LINE}-l location${NORM} specifies a location for login and teleport actions"
printf "\n\t\tDefault: Last location, teleport action requires a Slurl location"
printf "\n\t${BOLD}${LINE}-n name${NORM} specifies a Bot name, Default: Easy Islay"
printf "\n\t${BOLD}${LINE}-k apikey${NORM} specifies an API Key, use environment instead"
printf "\n\t${BOLD}${LINE}-A avatar${NORM} specifies an avatar UUID for use with giving money or objects"
printf "\n\t${BOLD}${LINE}-C channel${NORM} specifies the channel for a message [default: 0]"
printf "\n\t${BOLD}${LINE}-c corrade${NORM} specifies a Corrade bot name to act upon"
printf "\n\t${BOLD}${LINE}-D data${NORM} specifies a Corrade Manager class member"
printf "\n\t${BOLD}${LINE}-F filter${NORM} specifies a filter to match when listing attachments"
printf "\n\t${BOLD}${LINE}-M message${NORM} specifies the message body for a group notice/im"
printf "\n\t${BOLD}${LINE}-N name${NORM} specifies the name of the recipient of an IM or landmark/notecard"
printf "\n\t${BOLD}${LINE}-O name${NORM} specifies an attachment object name or outfit name"
printf "\n\t${BOLD}${LINE}-S subject${NORM} specifies the subject for a group notice"
printf "\n\t${BOLD}${LINE}-s secret${NORM} specifies a Bot secret, use environment instead"
printf "\n\t${BOLD}${LINE}-T text${NORM} specifies the notecard text or dialog button text for reply to menus"
printf "\n\t${BOLD}${LINE}-u uuid${NORM} specifies a UUID for use with actions that require one (e.g. sit)"
printf "\n\t${BOLD}${LINE}-z num${NORM} specifies a hover height adjustment size [default: -0.05]"
printf "\n\t\tcan also be used to specify a payment amount"
printf "\n\t${BOLD}${LINE}-d${NORM} indicates dryrun mode - tell me what you would do without doing anything"
printf "\n\t${BOLD}${LINE}-e${NORM} displays a list of supported commands and examples then exits"
printf "\n\t${BOLD}${LINE}-i${NORM} retrieves Bot details"
printf "\n\t${BOLD}${LINE}-h${NORM} displays this usage message and exits"
printf "\n\n${BOLD}${LINE}Environment:${NORM}"
printf "\n Entries in ~/.botctrl can be LB_API_KEY, LB_SECRET, or entries"
printf "\n of the form LB_SECRET_BOT_NAME in order to support multiple bots"
printf "\n Entries can specify a Slurl alias. For example:"
printf "\n export SLURL_club='http://maps.secondlife.com/secondlife/Scylla/226/32/78'"
printf "\n A Slurl alias can be used with the -l command line argument, e.g. -l club"
printf "\n Entries can also specify a UUID alias. For example:"
printf "\n export UUID_Mover='xxxxxxxx-yyyy-zzzz-aaaa-bbbbbbbbbbbb'"
printf "\n A UUID alias can be used with the -u command line argument, e.g. -u Mover"
printf "\n\n${BOLD}${LINE}Examples:${NORM}"
printf "\n ${SCRIPT_NAME} # Displays the status of the default Bot"
printf "\n ${SCRIPT_NAME} -a login -l Home # Default Bot login to Home location"
printf "\n ${SCRIPT_NAME} -a touch_prim -n 'Jane Doe' -u Mover # Jane Doe bot touch object with aliased UUID"
printf "\n ${SCRIPT_NAME} -a stand -n Jane -c John # Jane bot sends the stand command to Corrade bot John"
printf "\n ${SCRIPT_NAME} -a teleport -l club # Uses a 'club' location alias defined in .botctrl"
printf "\n\n${BOLD}${LINE}Supported Actions${NORM}"
list_supported_actions
exit 1
}
examples() {
printf "\nThe following actions and commands, along with example command"
printf "\nline invocations, are supported by the ${SCRIPT_NAME} command.\n"
printf "\nactivate_group : activate a group tag"
printf "\n\tExample : activate the specified group tag for bot John Doebot"
printf "\n\t${SCRIPT_NAME} -a activate -n \"John Doebot\" -u \"f8e95201-20af-b85f-a682-7ac25ab9fcaf\""
printf "\n\t\tIf ~/.botctrl contains : export UUID_pay2play=\"f8e95201-20af-b85f-a682-7ac25ab9fcaf\""
printf "\n\t\t${SCRIPT_NAME} -a activate -n \"John Doebot\" -u pay2play"
printf "\nattachments : list bot attachments, optionally specify a filter to match"
printf "\n\tExample : list bot named John Doebot attachments with name containing the string HUD"
printf "\n\t${SCRIPT_NAME} -a attachments -F \"HUD\" -n \"John Doebot\""
printf "\nbot_location : get precise bot location"
printf "\n\tExample : get location of bot named John Doebot"
printf "\n\t${SCRIPT_NAME} -a location -n \"John Doebot\""
printf "\nget_balance : get your bot's L$ balance"
printf "\n\tExample : get the L$ balance of bot John Doebot"
printf "\n\t${SCRIPT_NAME} -a balance -n \"John Doebot\""
printf "\nget_outfit : list currently worn bot outfit"
printf "\n\tExample : list currently worn outfit of bot named John Doebot"
printf "\n\t${SCRIPT_NAME} -a get_outfit -n \"John Doebot\""
printf "\nget_outfits : list available bot outfits"
printf "\n\tExample : list available outfits for bot named John Doebot"
printf "\n\t${SCRIPT_NAME} -a get_outfits -n \"John Doebot\""
printf "\ngive_money : pay another avatar L$ from your bot"
printf "\n\tExample : pay avatar with specified avatar UUID L$300 from bot John Doebot"
printf "\n\t${SCRIPT_NAME} -a give_money -n \"John Doebot\" -A \"3506213c-29c8-4aa1-a38f-e12f6d41b804\" -z 300"
printf "\ngive_money_object : pay an object L$ from your bot"
printf "\n\tExample : pay a tip jar with specified UUID L$100 from bot John Doebot"
printf "\n\t${SCRIPT_NAME} -a give_money_object -n \"John Doebot\" -u \"47cb1fc7-8144-b538-6716-c723fb1332d6\" -z 100"
printf "\nim : send an instant message to an avatar"
printf "\n\tExample : send IM from John Doebot to avatar \"Jane Free\""
printf "\n\t${SCRIPT_NAME} -a im -n \"John Doebot\" -N \"Jane Free\" -M 'Hi Jane, do you want to meetup?'"
printf "\nkey2name : convert an avatar UUID to avatar name"
printf "\n\tExample : use John Doebot bot to get avatar name of specified UUID"
printf "\n\t${SCRIPT_NAME} -a key2name -n \"John Doebot\" -u \"3506213c-29c8-4aa1-a38f-e12f6d41b804\""
printf "\nlistalias : list configured ${SCRIPT_NAME} aliases in $HOME/.botctrl"
printf "\n\tExample : list all configured ${SCRIPT_NAME} aliases"
printf "\n\t${SCRIPT_NAME} -a listalias"
printf "\n\tExample : list configured ${SCRIPT_NAME} bot aliases only"
printf "\n\t${SCRIPT_NAME} -a botalias"
printf "\n\tExample : list configured ${SCRIPT_NAME} location aliases only"
printf "\n\t${SCRIPT_NAME} -a slurlalias"
printf "\n\tExample : list configured ${SCRIPT_NAME} UUID aliases only"
printf "\n\t${SCRIPT_NAME} -a uuidalias"
printf "\nlistinventory : list bot inventory, optionally specify an inventory folder UUID"
printf "\n\tExample : list inventory of bot named John Doebot"
printf "\n\t${SCRIPT_NAME} -a listinventory -n \"John Doebot\""
printf "\nlogin : login bot"
printf "\n\tExample : login bot named John Doebot"
printf "\n\t${SCRIPT_NAME} -a login -n \"John Doebot\""
printf "\nlogout : logout bot"
printf "\n\tExample : logout bot named John Doebot"
printf "\n\t${SCRIPT_NAME} -a logout -n \"John Doebot\""
printf "\nname2key : convert an avatar name to avatar UUID"
printf "\n\tExample : use John Doebot bot to get avatar UUID of Missy Restless"
printf "\n\t${SCRIPT_NAME} -a name2key -n \"John Doebot\" -N \"Missy Restless\""
printf "\nreply_dialog : reply to a dialog menu (requires channel, UUID, and button text)"
printf "\n\tExample : click couch menu button \"Male\" on channel 99999"
printf "\n\t${SCRIPT_NAME} -a reply -n \"John Doebot\" -C 99999 -B Male -u \"a811d6fe-de59-2f4e-ee19-0cc48da48981\""
printf "\nsay_chat_channel : send a message to the specified chat channel"
printf "\n\tExample : send a message on channel 0, visible to everyone nearby"
printf "\n\t${SCRIPT_NAME} -a say -n \"John Doebot\" -C 0 -M \"Hi everyone, you look great\""
printf "\nsend_group_im : send an instant message to a group"
printf "\n\tExample : send IM to a group from bot named John Doebot"
printf "\n\t${SCRIPT_NAME} -a send_group_im -n \"John Doebot\" -u \"f7d3c1b9-a141-9546-7e2d-dfd698c5df7c\" -M \"Meeting at Noon SLT tomorrow\""
printf "\nsend_notice : send an official group notice to all group members"
printf "\n\tExample : send group notice with subject and message from bot named John Doebot"
printf "\n\t${SCRIPT_NAME} -a send_notice -n \"John Doebot\" -u \"f7d3c1b9-a141-9546-7e2d-dfd698c5df7c\" -M \"Meeting at Noon SLT tomorrow\" -S \"Meeting Tomorrow\""
printf "\nset_hoverheight : adjust bot hover height"
printf "\n\tExample : lower hover height of bot John Doebot by 0.05"
printf "\n\t${SCRIPT_NAME} -a height -n \"John Doebot\" -z \"-0.05\""
printf "\nsit : sit on a specified object UUID"
printf "\n\tExample : sit bot named John Doebot on an object"
printf "\n\t${SCRIPT_NAME} -a sit -n \"John Doebot\" -u \"d46e217b-fb5c-4796-bae3-ea016b280210\""
printf "\nstand : make a bot stand up"
printf "\n\tExample : make bot John Doebot stand up"
printf "\n\t${SCRIPT_NAME} -a stand -n \"John Doebot\""
printf "\nstatus : get bot status"
printf "\n\tExample : get status of bot John Doebot (status is default action)"
printf "\n\t${SCRIPT_NAME} -n \"John Doebot\""
printf "\ntakeoff : remove a worn item"
printf "\n\tExample : bot John Doebot remove the specified inventory item"
printf "\n\t${SCRIPT_NAME} -a takeoff -n \"John Doebot\" -u \"d666e910-ba72-0c11-a66e-c3759d8af0f5\""
printf "\nteleport : teleport bot to specified location"
printf "\n\tExample : teleport bot John Doebot to the aliased location \"club\""
printf "\n\tRequires an entry of the following form in $HOME/.botctrl"
printf "\n\t\texport SLURL_club=\"http://maps.secondlife.com/secondlife/Scylla/226/32/78\""
printf "\n\t${SCRIPT_NAME} -a teleport -n \"John Doebot\" -l club"
printf "\ntouch_attachment : touch a specified bot attachment"
printf "\n\tExample : bot John Doebot touch attachment named \"HUD Controller\""
printf "\n\t${SCRIPT_NAME} -a touch_attachment -n \"John Doebot\" -O \"HUD Controller\""
printf "\ntouch_prim : touch a specified object by UUID"
printf "\n\tExample : bot named John Doebot touch an object"
printf "\n\t${SCRIPT_NAME} -a touch_prim -n \"John Doebot\" -u \"f11781d0-763f-52f9-4e23-3a2b97759fa2\""
printf "\n\t\tIf ~/.botctrl contains : export UUID_spoton=\"f11781d0-763f-52f9-4e23-3a2b97759fa2\""
printf "\n\t\t${SCRIPT_NAME} -a touch_prim -n \"John Doebot\" -u spoton"
printf "\nwalkto : walk bot to a location"
printf "\n\tExample : bot named John Doebot walk to X/Y/Z coordinates 100/50/28"
printf "\n\t${SCRIPT_NAME} -a walkto -n \"John Doebot\" -l \"100/50/28\""
printf "\nwear : wear an inventory item (uses \"add\" rather than \"wear\")"
printf "\n\tExample : bot John Doebot wear the specified inventory item"
printf "\n\t${SCRIPT_NAME} -a wear -n \"John Doebot\" -u \"d666e910-ba72-0c11-a66e-c3759d8af0f5\""
printf "\nwear_outfit : wear a specified outfit"
printf "\n\tExample : bot named John Doebot wear the outfit named \"Business Casual\""
printf "\n\t${SCRIPT_NAME} -a wear_outfit -n \"John Doebot\" -O \"Business Casual\""
printf "\n\t\tIf ~/.botctrl contains : export LB_BOT_NAME='John Doebot'"
printf "\n\t\t${SCRIPT_NAME} -a wear_outfit -O \"Business Casual\"\n"
exit 1
}
is_valid_csv() {
local input_string="$1"
# Check if the string contains a comma
if [[ "$input_string" == *","* ]]; then
# Check if the string contains a comma at the beginning or end
if [[ "$input_string" == ","* ]] || [[ "$input_string" == *"," ]]; then
return 1
else
return 0
fi
else
return 1
fi
}
is_valid_uuid() {
local uuid="$1"
if [[ $uuid =~ ^\{?[A-F0-9a-f]{8}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{4}-[A-F0-9a-f]{12}\}?$ ]]; then
return 0 # Valid
else
return 1 # Invalid
fi
}
# Regex to match the basic SLURL format
# secondlife://RegionName/X/Y/Z (X, Y, Z are optional, and can be floats)
# or
# http://maps.secondlife.com/secondlife/RegionName/X/Y/Z
is_valid_slurl() {
local slurl="$1"
if [[ "$slurl" =~ ^secondlife://%[0-9a-fA-F]{2}|[a-zA-Z0-9_]+(/[0-9]+(\.[0-9]+)?(/[0-9]+(\.[0-9]+)?(/[0-9]+(\.[0-9]+)?)?)?)?$ ]]; then
return 0 # Valid SLURL
else
if [[ "$slurl" =~ ^http://maps.secondlife.com/secondlife/%[0-9a-fA-F]{2}|[a-zA-Z0-9_]+(/[0-9]+(\.[0-9]+)?(/[0-9]+(\.[0-9]+)?(/[0-9]+(\.[0-9]+)?)?)?)?$ ]]; then
return 0 # Valid SLURL
else
return 1 # Invalid SLURL
fi
fi
}
# Validate coordinates provided with -l coords are in supported format, X,Y,Z or X/Y/Z.
is_valid_coords() {
local coords="$1"
if [[ "${coords}" =~ ^[[:digit:]]+,[[:digit:]]+,[[:digit:]]+$ ]]; then
return 0 # Valid Coordinates
else
if [[ "${coords}" =~ ^[[:digit:]]+/[[:digit:]]+/[[:digit:]]+$ ]]; then
return 0 # Valid Coordinates
else
return 1 # Invalid Coordinates
fi
fi
}
# TODO: get_details not yet working
get_details() {
local access_token="${LB_SECRET}"
[ "${LB_BOT_ID}" ] || {
echo "No Bot ID set in .botctrl"
usage
}
if [ "${dryrun}" ]; then
echo "curl ${verb} GET ${APIURL}/v1/bots/${LB_BOT_ID} \
-H \"Authorization: Bearer ${access_token}\" \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\""
else
curl ${verb} GET ${APIURL}/v1/bots/${LB_BOT_ID} \
-H "Authorization: Bearer ${access_token}" \
-H "Accept: application/json" \
-H "Content-Type: application/json"
fi
}
show_alias() {
local astr="$1"
local argl="$2"
if env | grep ^${astr}_ >/dev/null; then
env | grep ^${astr}_ | while read entr
do
[ "${entr}" ] && {
alias=$(echo "${entr}" | awk -F '=' '{ print $1 }' | sed -e "s/${astr}_//")
along=$(echo "${entr}" | awk -F '=' '{ print $2 }')
alen=${#alias}
if [ ${alen} -lt 5 ]; then
printf "\n${BOLD}${LINE}-%s %s${NORM}\t\talias for: ${BOLD}-%s %s${NORM}" \
"${argl}" "${alias}" "${argl}" "${along}"
else
printf "\n${BOLD}${LINE}-%s %s${NORM}\talias for: ${BOLD}-%s %s${NORM}" \
"${argl}" "${alias}" "${argl}" "${along}"
fi
}
done
else
printf "\nNo ${astr} aliases defined in ${HOME}/.botctrl"
fi
}
list_aliases() {
local ali="$1"
[ "${ali}" ] || ali="aliases"
case "${ali}" in
botalias*|aliasbot*)
printf "\n${BOLD}${LINE}Bot Name Aliases${NORM}\n"
show_alias BOT_NAME n
;;
localias*|slurlalias*|alias*url*)
printf "\n${BOLD}${LINE}Slurl Aliases${NORM}\n"
show_alias SLURL l
;;
uuidalias*|aliasuu*)
printf "\n${BOLD}${LINE}UUID Aliases${NORM}\n"
show_alias UUID u
;;
*)
printf "\n${BOLD}${LINE}Bot Name Aliases${NORM}\n"
show_alias BOT_NAME n
printf "\n\n${BOLD}${LINE}Slurl Aliases${NORM}\n"
show_alias SLURL l
printf "\n\n${BOLD}${LINE}UUID Aliases${NORM}\n"
show_alias UUID u
;;
esac
echo ""
}
list_supported_actions() {
printf "\nSupported actions for BotControl Configuration:"
printf "\n bot_alias, loc_alias, slurl_alias, uuid_alias, list_alias, alias"
printf "\nSupported actions common to both Corrade and LifeBots:"
printf "\n activate_group, attachments, avatar_picks, get_balance, get_outfit, get_outfits, give_inventory,"
printf "\n give_object, give_money, give_money_object, im, key2name, listinventory, login, logout,"
printf "\n name2key, notecard_create, rebake, say_chat_channel, send_group_im, send_notice,"
printf "\n set_hoverheight, sit, stand, status, takeoff, teleport, touch_prim, walkto, wear, wear_outfit"
printf "\nSupported actions for LifeBots only:"
printf "\n bot_location, reply_dialog, touch_attachment"
printf "\nSupported actions for Corrade only:"
printf "\n attach, conference, conference_detail, conference_list, createlandmark, currentsim, detach"
printf "\n fly, flyto, getattachmentspath, getavatarpickdata, getgroupmemberdata, get_hoverheight,"
printf "\n getmembersonline, getregiontop, getselfdata, inventory cwd, networkmanagerdata\n"
}
get_coords() {
local loc="$1"
# Convert position coordinates from x/y/z to x,y,z
echo "${loc}" | grep / >/dev/null && {
loc=$(echo "${loc}" | awk -F '/' -v OFS=',' '{ print $(NF-2), $(NF-1), $NF }')
}
loc=$(echo "${loc}" | awk -F ',' -v OFS=',' '{ print $(NF-2), $(NF-1), $NF }')
echo "${loc}"
}
set_lb_coords() {
local loc="$1"
# Convert position coordinates to x/y/z
echo "${loc}" | grep , >/dev/null && {
loc=$(echo "${loc}" | awk -F ',' -v OFS='/' '{ print $(NF-2), $(NF-1), $NF }')
}
echo "${loc}"
}
wasURLEscape() {
printf %s "$1" | sed -e "s/ /+/g" \
-e "s%/%\%2F%g" \
-e "s/&/%26/g" \
-e "s/%/%25/g" \
-e "s/=/%3D/g" \
-e "s/|/%7C/g" \
-e "s/\n/%0D%0A/g"
}
fixup_Outfits_JSON() {
# I know, it's ugly, but the JSON return output was uglier
local type_outfit="$1"
if [ "${type_outfit}" == "current" ]; then
printf '\n{\n "action": "get_outfit",\n "outfits": [\n'
else
printf '\n{\n "action": "get_outfits",\n "outfits": [\n'
fi
local name=
local uuid=
local line
while IFS= read -r line; do
if [ "${line}" == "name" ]; then
printf ' {\n "name": '
name=1
else
if [ "${line}" == "item" ]; then
printf ' "uuid": '
uuid=1
else
[ "${name}" ] && {
printf "\"${line}\",\n"
name=
}
[ "${uuid}" ] && {
printf "\"${line}\"\n },\n"
uuid=
}
fi
fi
done
printf ' {\n'
printf ' "name": "BotControlCommandDummyPlaceholder",\n'
printf ' "uuid": "foo-bar-spam"\n'
printf ' }\n'
printf ' ]\n'
printf '}\n'
}
send_corrade_request() {
local cmd="$1"
[ "${cmd}" ] || {
echo "Empty command. Exiting."
usage
}
# If the Corrade configuration specifies WAS ScriptLanguage:
# cgroup=$(wasURLEscape "${CORRADE_GROUP}")
# cpassw=$(wasURLEscape "${CORRADE_PASSW}")
# If the Corrade configuration specifies JSON ScriptLanguage:
local cgroup="${CORRADE_GROUP}"
local cpassw="${CORRADE_PASSW}"
local cuuid=
local POS=
local pos=
local rgn=
COMMON="\"group\": \"${cgroup}\", \"password\": \"${cpassw}\""
case "${cmd}" in
activate|activate_group)
COMMAND="\"command\": \"activate\", \"target\": \"${GROUP_ID}\""
;;
attach|detach)
[ "${UUID}" ] || {
echo "The ${cmd} action requires an inventory item UUID specified with -u UUID"
usage brief
}
if [ "${cmd}" == "attach" ]; then
COMMAND="\"command\": \"attach\", \"attachments\": \"Default\", \"${UUID}\""
else
COMMAND="\"command\": \"detach\", \"type\": \"UUID\", \"attachments\": \"${UUID}\""
fi
;;
avatar_picks|picks)
COMMAND="\"command\": \"getavatarpicks\", \"agent\": \"${AVATAR_UUID}\""
;;
*pick*data)
COMMAND="\"command\": \"getavatarpickdata\", \
\"agent\": \"${AVATAR_UUID}\", \
\"data\": \"Desc\", \
\"item\": \"${UUID}\""
;;
conference|creat*confer*|confer*creat*)
[ "${TEXT}" ] || {
echo "The ${cmd} action requires a comma separated list of avatar name/uuid specified with -T \"av1,av2,...\""
usage brief
}
is_valid_csv "${TEXT}" || {
echo "Not a valid comma separated list: ${TEXT}"
usage brief
}
COMMAND="\"command\": \"conference\", \"action\": \"create\", \"avatars\": \"${TEXT}\""
;;
say*confer*|confer*say)
[ "${UUID}" ] || {
echo "The ${cmd} action requires a conference session UUID specified with -u UUID"
usage brief
}
COMMAND="\"command\": \"tell\", \"entity\": \"conference\", \"session\": \"${UUID}\", \"message\": \"${MESSAGE}\""
;;
list*confer*|confer*list*)
COMMAND="\"command\": \"conference\", \"action\": \"list\""
;;
det*confer*|confer*det*)
[ "${UUID}" ] || {
echo "The ${cmd} action requires a conference session UUID specified with -u UUID"
usage brief
}
COMMAND="\"command\": \"conference\", \"action\": \"detail\", \"session\": \"${UUID}\""
;;
creat*landmark|creat*lm)
[ "${SL_NAME}" ] || {
echo "The ${cmd} action requires a Landmark Name specified with -N name"
usage brief
}
COMMAND="\"command\": \"createlandmark\", \"name\": \"${SL_NAME}\""
;;
creat*notecard|creat*nc|note*creat*|nc*creat*)
COMMAND="\"command\": \"createnotecard\", \"entity\": \"text\", \"name\": \"${SL_NAME}\", \"text\": \"${TEXT}\""
;;
fly|nofly)
local action="start"
[ "${cmd}" == "nofly" ] && action="stop"
COMMAND="\"command\": \"fly\", \"action\": \"${action}\""
;;
flyto|fly_to)
POS=$(get_coords "${LOCATION}")
loc=$(echo "${loc}" | awk -F ',' -v OFS=',' '{ print $(NF-2), $(NF-1), $NF }')
pos="<${POS}>"
COMMAND="\"command\": \"flyto\", \"fly\": \"False\", \"position\": \"${pos} + <0,0,5>\""
;;
*attachments*)
local comm="getattachments"
echo "${cmd}" | grep attachmentspath >/dev/null && comm="getattachmentspath"
COMMAND="\"command\": \"${comm}\""
;;
get_balance|getbalance|balance)
COMMAND="\"command\": \"getbalance\""
;;
get*hover*|get*zoffset)
COMMAND="\"command\": \"avatarzoffset\", \"action\": \"get\", \"offset\": \"${HEIGHT}\""
;;
getcwd|cwd)
COMMAND="\"command\": \"inventory\", \"action\": \"cwd\""
;;
get_outfit*)
local path="/My Inventory/Current Outfit"
echo "${cmd}" | grep get_outfits >/dev/null && path="/My Inventory/My Outfits"
COMMAND="\"command\": \"inventory\", \"path\": \"${path}\", \"follow\": \"True\", \"action\": \"ls\""
;;
give|give_inv*)
COMMAND="\"command\": \"give\", \"entity\": \"avatar\", \"agent\": \"${AVATAR_UUID}\", \"item\": \"${UUID}\""
;;
give_obj*)
COMMAND="\"command\": \"give\", \"entity\": \"object\", \"target\": \"${AVATAR_UUID}\", \"item\": \"${UUID}\""
;;
im)
COMMAND="\"command\": \"tell\", \"entity\": \"avatar\", \"agent\": \"${SL_NAME}\", \"message\": \"${MESSAGE}\""
;;
key2name)
COMMAND="\"command\": \"batchavatarkeytoname\", \"avatars\": \"${UUID}\""
;;
listinventory)
COMMAND="\"command\": \"inventory\", \"action\": \"ls\""
;;
login)
if [ "${LOCATION}" ] && [ "${LOCATION}" != "Last location" ]; then
POS=$(get_coords "${LOCATION}")
pos=$(echo "${POS}" | awk -F ',' -v OFS='/' '{ print $(NF-2), $(NF-1), $NF }')
rgn=$(echo "${LOCATION}" | awk -F '/' '{ print $(NF-3) }' | sed -e "s/%20/ /g")
COMMAND="\"command\": \"login\", \"location\": \"${rgn}/${pos}\""
else
COMMAND="\"command\": \"login\", \"location\": \"last\""
fi
;;
name2key)
COMMAND="\"command\": \"batchavatarnametokey\", \"avatars\": \"${SL_NAME}\""
;;
pay|pay_avatar|give_money)
COMMAND="\"command\": \"pay\", \"entity\": \"avatar\", \"agent\": \"${AVATAR_UUID}\", \"amount\": \"${AMOUNT}\""
;;
pay_object|give_money_object)
COMMAND="\"command\": \"pay\", \"entity\": \"object\", \"target\": \"${OBJECT_UUID}\", \"amount\": \"${AMOUNT}\""
;;
send_group_im)
COMMAND="\"command\": \"tell\", \
\"entity\": \"group\", \
\"target\": \"${GROUP_ID}\", \
\"message\": \"${MESSAGE}\""
;;
send_notice)
COMMAND="\"command\": \"notice\", \
\"action\": \"send\", \
\"target\": \"${GROUP_ID}\", \
\"subject\": \"${SUBJECT}\", \
\"message\": \"${MESSAGE}\""
;;
say_chat_channel)
COMMAND="\"command\": \"tell\", \
\"entity\": \"local\", \
\"type\": \"normal\", \
\"channel\": \"${CHANNEL}\", \
\"message\": \"${MESSAGE}\""
;;
set*hover*|set*zoffset)
COMMAND="\"command\": \"avatarzoffset\", \"action\": \"get\", \"offset\": \"${HEIGHT}\""
;;
sit|touch*)
if [ "${UUID}" ]; then
cuuid="${UUID}"
else
if [ "${OBJ_NAME}" ]; then
cuuid="${OBJ_NAME}"
else
echo "Corrade command ${cmd} requires object uuid or name"
usage brief
fi
fi
if [ "${cmd}" == "sit" ]; then
COMMAND="\"command\": \"sit\", \"item\": \"${cuuid}\", \"range\": \"${CORRADE_RANGE}\", \"deanimate\": \"True\""
else
COMMAND="\"command\": \"touch\", \"item\": \"${cuuid}\", \"range\": \"${CORRADE_RANGE}\""
fi
;;
stand)
COMMAND="\"command\": \"stand\", \"deanimate\": \"True\""
;;
getmembersonline)
COMMAND="\"command\": \"getmembersonline\""
;;
online*|status)
COMMAND="\"command\": \"getgroupmemberdata\", \"agent\": \"${CORRADE_BOT_ID}\", \"data\": \"OnlineStatus\""
;;
curr*sim|position)
COMMAND="\"command\": \"getnetworkdata\", \"data\": \"CurrentSim\""
;;
get*top|top*script*)
COMMAND="\"command\": \"getregiontop\", \
\"type\": \"scripts\",
\"sift\": \"{ 'skip': '1', 'each': '5' }\""
;;
*self*data)
[ "${DATA}" ] || DATA="Health"
COMMAND="\"command\": \"getselfdata\", \"data\": \"${DATA}\""
;;
*member*data)
[ "${DATA}" ] || {
echo "The ${cmd} action requires a GroupMember structure member specified with -D DATA"
usage brief
}
COMMAND="\"command\": \"getgroupmemberdata\", \"agent\": \"${CORRADE_BOT_ID}\", \"data\": \"${DATA}\""
;;
net*manager|net*data)
[ "${DATA}" ] || {
echo "The ${cmd} action requires a NetworkManager member specified with -D DATA"
usage brief
}
COMMAND="\"command\": \"getnetworkdata\", \"data\": \"${DATA}\""
;;
teleport)
POS=$(get_coords "${LOCATION}")
pos="<${POS}>"
rgn=$(echo "${LOCATION}" | awk -F '/' '{ print $(NF-3) }' | sed -e "s/%20/ /g")
COMMAND="\"command\": \"teleport\", \"entity\": \"region\", \"region\": \"${rgn}\", \"position\": \"${pos}\""
;;
unwear|remove|takeoff)
COMMAND="\"command\": \"unwear\", \"type\": \"UUID\", \"wearables\": \"${UUID}\""
;;
walk*)
POS=$(get_coords "${LOCATION}")
pos="<${POS}>"
COMMAND="\"command\": \"walkto\", \"position\": \"${pos}\""
;;
wear)
COMMAND="\"command\": \"wear\", \"replace\": \"False\", \"wearables\": \"${WEARABLE}\""
;;
change*|wear*)
local outfit_folder="/My Inventory/My Outfits/${OUTFIT_NAME}"
COMMAND="\"command\": \"changeappearance\", \"folder\": \"${outfit_folder}\""
;;
*)
# This catches commands like logout which have no additional parameters
# but it also passes commands that do require extra params and will fail
COMMAND="\"command\": \"${cmd}\""
;;
esac
[ "${COMMAND}" ] || {
echo "Corrade command ${cmd} not yet supported"
list_supported_actions
usage brief
}
[ "${CORRADE_BOT_URL}" ] || {
echo "Corrade bot URL not set!"
usage brief
}
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${CORRADE_BOT_URL} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
${COMMAND}
}\""
else
if [ "${have_jq}" ]; then
case "${cmd}" in
get_outfit*)
local outfit_type="current"
echo "${cmd}" | grep get_outfits >/dev/null && outfit_type="outfits"
curl ${verb} -X POST ${CORRADE_BOT_URL} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
${COMMAND}
}" | jq -r '.data[]' | fixup_Outfits_JSON "${outfit_type}" | \
jq 'del(.outfits[] | select(.name == "BotControlCommandDummyPlaceholder"))'
;;
*)
curl ${verb} -X POST ${CORRADE_BOT_URL} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
${COMMAND}
}" | jq -r .
;;
esac
else
curl ${verb} -X POST ${CORRADE_BOT_URL} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
${COMMAND}
}"
fi
fi
}
send_lifebot_request() {
local act="$1"
[ "${act}" ] || {
echo "Empty action. Exiting."
usage
}
COMMON="\"action\": \"${act}\", \
\"apikey\": \"${LB_API_KEY}\", \
\"botname\": \"${BE_BOT_NAME}\", \
\"secret\": \"${LB_SECRET}\", \
\"dataType\": \"json\""
case "${act}" in
listinventory|sit|touch_attachment|touch_prim)
if [ "${dryrun}" ]; then
if [ "${UUID}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"objectname\": \"${OBJ_NAME}\",
\"uuid\": \"${UUID}\",
\"extended\": true
}\""
else
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"objectname\": \"${OBJ_NAME}\"
}\""
fi
else
if [ "${UUID}" ]; then
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"objectname\": \"${OBJ_NAME}\",
\"uuid\": \"${UUID}\",
\"extended\": true
}"
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"objectname\": \"${OBJ_NAME}\"
}"
fi
fi
;;
login|teleport)
if [ "${LOGIN_SITON}" ] && [ "${act}" == "login" ]; then
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"siton\": \"${LOGIN_SITON}\",
\"location\": \"${LOCATION}\"
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"siton\": \"${LOGIN_SITON}\",
\"location\": \"${LOCATION}\"
}"
fi
else
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"location\": \"${LOCATION}\"
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"location\": \"${LOCATION}\"
}"
fi
fi
;;
key2name)
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"key\": \"${UUID}\",
\"request_case\": \"1\"
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"key\": \"${UUID}\",
\"request_case\": \"1\"
}"
fi
;;
name2key)
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"name\": \"${SL_NAME}\",
\"request_case\": \"1\"
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"name\": \"${SL_NAME}\",
\"request_case\": \"1\"
}"
fi
;;
avatar_picks)
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"avatar\": \"${AVATAR_UUID}\"
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"avatar\": \"${AVATAR_UUID}\"
}"
fi
;;
give_inventory)
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"avatar\": \"${AVATAR_UUID}\",
\"object\": \"${UUID}\"
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"avatar\": \"${AVATAR_UUID}\",
\"object\": \"${UUID}\"
}"
fi
;;
give_money|give_money_object)
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"avatar\": \"${AVATAR_UUID}\",
\"object_uuid\": \"${OBJECT_UUID}\",
\"amount\": ${AMOUNT}
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"avatar\": \"${AVATAR_UUID}\",
\"object_uuid\": \"${OBJECT_UUID}\",
\"amount\": ${AMOUNT}
}"
fi
;;
notecard_create)
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"name\": \"${SL_NAME}\",
\"text\": \"${TEXT}\"
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"name\": \"${SL_NAME}\",
\"text\": \"${TEXT}\"
}"
fi
;;
reply_dialog)
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"button\": \"${TEXT}\",
\"channel\": \"${CHANNEL}\",
\"object\": \"${UUID}\"
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"button\": \"${TEXT}\",
\"channel\": \"${CHANNEL}\",
\"object\": \"${UUID}\"
}"
fi
;;
activate_group|im|say_chat_channel|send_group_im|send_notice)
msg_label="message"
[ "${act}" == "send_notice" ] && msg_label="text"
if [ "${dryrun}" ]; then
echo "curl ${verb} -X POST ${ENDPOINT} \
-H \"Accept: application/json\" \
-H \"Content-Type: application/json\" \
-d \"{
${COMMON},
\"slname\": \"${SL_NAME}\",
\"groupuuid\": \"${GROUP_ID}\",
\"subject\": \"${SUBJECT}\",
\"channel\": \"${CHANNEL}\",
\"${msg_label}\": \"${MESSAGE}\",
\"autodelay\": \"1\"
}\""
else
curl ${verb} -X POST ${ENDPOINT} \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{
${COMMON},
\"slname\": \"${SL_NAME}\",