-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSinusbotAPI.java
More file actions
1173 lines (1044 loc) · 37.8 KB
/
SinusbotAPI.java
File metadata and controls
1173 lines (1044 loc) · 37.8 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONObject;
public class SinusbotAPI {
private final String APISTR = "/api/v1";
private String token;
private String ip;
private int port;
/**
* Constructor automatically logs in and grabs token
* @param ip Address of sinusbot
* @param port Port of sinusbot
* @param username Username to web interface
* @param password Password to web interface
* @param botId Bot id - get via /api/v1/botId
*/
public SinusbotAPI(String ip, int port, String username, String password, String botId) {
this.ip = ip;
this.port = port;
JSONObject loginObj = login(username, password, botId);
if (loginObj == null) {
throw new RuntimeException("Login failed!");
} else {
this.token = loginObj.getString("token");
}
}
private String apicall(String api, Map<String, String> args, String requestMethod) {
StringJoiner sj = new StringJoiner(",");
for (Map.Entry<String, String> arg : args.entrySet()) {
sj.add("\"" + arg.getKey() + "\":\"" + arg.getValue() + "\"");
if (api.contains(":" + arg.getKey()))
api = api.replace(":" + arg.getKey(), arg.getValue());
}
byte[] body = ("{" + sj.toString() + "}").getBytes(StandardCharsets.UTF_8);
int length = body.length;
String URL = "http://"+ip+":"+port+APISTR+api;
try {
URL url = new URL(URL);
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod(requestMethod);
http.setRequestProperty("Authorization", "bearer " + token);
if (!args.isEmpty()) {
http.setDoOutput(true);
http.setFixedLengthStreamingMode(length);
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
http.connect();
try(OutputStream os = http.getOutputStream()) {
os.write(body);
}
}
BufferedReader br = new BufferedReader(new InputStreamReader(http.getInputStream()));
return br.lines().collect(Collectors.joining());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private JSONObject apicallObject(String api, Map<String, String> args, String requestMethod) {
String jsonStr = apicall(api, args, requestMethod);
if (jsonStr != null)
return new JSONObject(jsonStr);
return null;
}
private JSONArray apicallArray(String api, Map<String, String> args, String requestMethod) {
String jsonStr = apicall(api, args, requestMethod);
if (jsonStr != null)
return new JSONArray(jsonStr);
return null;
}
/**
* Avatars - Remove avatar
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject avatarDelete(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/avatar", arguments, "DELETE");
}
/**
* Avatars - Upload avatar
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject avatarUpload(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/avatar", arguments, "POST");
}
/**
* Filelist - Add an URL
* @param url the actual url you want to add
* @param title a user defined title that should be displayed
* @param parent the UUID of the folder the url should be placed into
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject addUrl(String url, String title, String parent) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("url", url.toString());
put("title", title.toString());
put("parent", parent.toString());
}};
return apicallObject("/bot/url", arguments, "POST");
}
/**
* Filelist - Create folder
* @param name name of the folder to be created
* @param parent uuid of the parent folder
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject createFolder(String name, String parent) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("name", name.toString());
put("parent", parent.toString());
}};
return apicallObject("/bot/folders", arguments, "POST");
}
/**
* Filelist - Delete file
* @param id uuid of the file that should be deleted
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject deleteFile(String id) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("id", id.toString());
}};
return apicallObject("/bot/files/:id", arguments, "DELETE");
}
/**
* Filelist - List
* @return JSONObject with fields <br>
* <b>mediainfo</b> <br>
* <b>mediainfo.uuid</b> the tracks' unique identifier <br>
* <b>mediainfo.parent</b> the tracks' parents' uuid <br>
* <b>mediainfo.type</b> type of the track <br>
* <b>mediainfo.mimeType</b> the recognized mime-type (currently unsupported) <br>
* <b>mediainfo.title</b> <br>
* <b>mediainfo.artist</b> <br>
* <b>mediainfo.tempTitle</b> this will contain the title of the current track in case of radio streams - if supported by the server <br>
* <b>mediainfo.tempArtist</b> this will contain the artist of the current track in case of radio streams - if supported by the server <br>
* <b>mediainfo.album</b> <br>
* <b>mediainfo.albumArtist</b> <br>
* <b>mediainfo.track</b> <br>
* <b>mediainfo.totalTracks</b> <br>
* <b>mediainfo.copyright</b> <br>
* <b>mediainfo.genre</b> <br>
* <b>mediainfo.thumbnail</b> this file will actually be available at /cache/%thumbnail <br>
* <b>mediainfo.codec</b> audio-codec used in the file (currently unsupported) <br>
* <b>mediainfo.duration</b> duration of the track in milliseconds <br>
* <b>mediainfo.bitrate</b> <br>
* <b>mediainfo.channels</b> <br>
* <b>mediainfo.samplerate</b> <br>
* <b>mediainfo.filesize</b>
*/
public JSONArray getFiles() {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
}};
return apicallArray("/bot/files", arguments, "GET");
}
/**
* Filelist - Update file (tags)
* @param id uuid of the file that should be deleted
* @param title
* @param artist
* @param album
* @param parent new parent-(folder) of the file
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject updateFile(String id, String title, String artist, String album, String parent) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("id", id.toString());
put("title", title.toString());
put("artist", artist.toString());
put("album", album.toString());
put("parent", parent.toString());
}};
return apicallObject("/bot/files/:id", arguments, "PATCH");
}
/**
* Filelist - Upload a file
* @param filename the original name of the file
* @param playlist a playlist the file should be added to after upload
* @param folder the folder UUID the file should be added to after upload
* @return JSONObject with fields <br>
* <b>uuid</b> the tracks' unique identifier <br>
* <b>parent</b> the tracks' parents' uuid <br>
* <b>type</b> type of the track <br>
* <b>mimeType</b> the recognized mime-type (currently unsupported) <br>
* <b>title</b> <br>
* <b>artist</b> <br>
* <b>tempTitle</b> this will contain the title of the current track in case of radio streams - if supported by the server <br>
* <b>tempArtist</b> this will contain the artist of the current track in case of radio streams - if supported by the server <br>
* <b>album</b> <br>
* <b>albumArtist</b> <br>
* <b>track</b> <br>
* <b>totalTracks</b> <br>
* <b>copyright</b> <br>
* <b>genre</b> <br>
* <b>thumbnail</b> this file will actually be available at /cache/%thumbnail <br>
* <b>codec</b> audio-codec used in the file (currently unsupported) <br>
* <b>duration</b> duration of the track in milliseconds <br>
* <b>bitrate</b> <br>
* <b>channels</b> <br>
* <b>samplerate</b> <br>
* <b>filesize</b>
*/
public JSONObject uploadFile(String filename, String playlist, String folder) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("filename", filename.toString());
put("playlist", playlist.toString());
put("folder", folder.toString());
}};
return apicallObject("/bot/upload", arguments, "POST");
}
/**
* Filelist - Upload restrictions
* @return JSONObject with fields <br>
* <b>maxSize</b> the maximum size an uploaded file can have
*/
public JSONObject uploadInfo() {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
}};
return apicallObject("/bot/uploadInfo", arguments, "GET");
}
/**
* General - General Information
* @return JSONObject with fields <br>
* <b>bot</b> <br>
* <b>system</b> <br>
* <b>system.codecs</b> supported codecs <br>
* <b>system.formats</b> supported formats <br>
* <b>usageMemory</b> used memory from the bot (all instances - excluding client resources)
*/
public JSONObject botInfo() {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
}};
return apicallObject("/bot/info", arguments, "GET");
}
/**
* General - Login
* @param username the users' account name
* @param password the users' password
* @param botId the bot id you want to log in to
* @return JSONObject with fields <br>
* <b>token</b> authorization token <br>
* <b>botId</b> id of the bot logged in to
*/
public JSONObject login(String username, String password, String botId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("username", username.toString());
put("password", password.toString());
put("botId", botId.toString());
}};
return apicallObject("/bot/login", arguments, "POST");
}
/**
* Instances - Create
* @return JSONObject with fields <br>
* <b>success</b> <br>
* <b>uuid</b> uuid of the newly created instance
*/
public JSONObject createInstance() {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
}};
return apicallObject("/bot/instances", arguments, "POST");
}
/**
* Instances - Delete
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject deleteInstance() {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
}};
return apicallObject("/bot/instances", arguments, "DELETE");
}
/**
* Instances - List
* @return JSONObject with fields <br>
* <b>instances</b> <br>
* <b>instances.uuid</b> <br>
* <b>instances.nick</b> <br>
* <b>instances.name</b> <br>
* <b>instances.running</b> <br>
* <b>instances.mainInstance</b>
*/
public JSONArray getInstances() {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
}};
return apicallArray("/bot/instances", arguments, "GET");
}
/**
* Instances - Settings
* @param instanceId uuid/id of the instance
* @param nick the nickname the bot should use
* @param serverHost IP/hostname of the teamspeak server to use
* @param serverPort the port to use
* @param serverPassword the password to use
* @param channelName
* @param channelPassword
* @param updateDescription update the client description to contain track information
* @param announce announce new tracks in the channel
* @param annonuceString which string to use when announcing tracks
* @param identity a TeamSpeak identity that the bot should use
* @param enableDucking ducking reduces the volume of music when somebody is talking in the channel
* @param duckingVolume the volume level that should be used when ducking is active
* @param channelCommander if true, the bot tries to become channel commander (required the permission on the ts server)
* @param stickToChannel if true, the bot always tries to go back to its original channel when moved
* @param ttsExternalURL the URL to use for Text-To-Speech (should contain the variables __TEXT and __LOCALE)
* @param ttsDefaultLocale the default locale that should be used for the __LOCALE variable
* @param ignoreChatServer ignores the server chat for commands
* @param ignoreChatPrivate ignores private messages for commands
* @param ignoreChatChannel ignores the channel chat for commands
* @param idleTrack a mediaurl to be played when the bot becomes idle
* @param startupTrack a mediaurl to be played when the bot starts up
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject getSettings(String instanceId, String nick, String serverHost, Integer serverPort, String serverPassword, String channelName, String channelPassword, Boolean updateDescription, Boolean announce, String annonuceString, String identity, Boolean enableDucking, Integer duckingVolume, Boolean channelCommander, Boolean stickToChannel, String ttsExternalURL, String ttsDefaultLocale, Boolean ignoreChatServer, Boolean ignoreChatPrivate, Boolean ignoreChatChannel, String idleTrack, String startupTrack) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("nick", nick.toString());
put("serverHost", serverHost.toString());
put("serverPort", serverPort.toString());
put("serverPassword", serverPassword.toString());
put("channelName", channelName.toString());
put("channelPassword", channelPassword.toString());
put("updateDescription", updateDescription.toString());
put("announce", announce.toString());
put("annonuceString", annonuceString.toString());
put("identity", identity.toString());
put("enableDucking", enableDucking.toString());
put("duckingVolume", duckingVolume.toString());
put("channelCommander", channelCommander.toString());
put("stickToChannel", stickToChannel.toString());
put("ttsExternalURL", ttsExternalURL.toString());
put("ttsDefaultLocale", ttsDefaultLocale.toString());
put("ignoreChatServer", ignoreChatServer.toString());
put("ignoreChatPrivate", ignoreChatPrivate.toString());
put("ignoreChatChannel", ignoreChatChannel.toString());
put("idleTrack", idleTrack.toString());
put("startupTrack", startupTrack.toString());
}};
return apicallObject("/bot/i/:instanceId/settings", arguments, "POST");
}
/**
* Instances - Status
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>v</b> current version of the bot <br>
* <b>currentTrack</b> currently played track <br>
* <b>position</b> <br>
* <b>running</b> <br>
* <b>playing</b> <br>
* <b>shuffle</b> <br>
* <b>repeat</b> <br>
* <b>volume</b> <br>
* <b>needsRestart</b> this gets set after an update has been applied <br>
* <b>playlist</b> <br>
* <b>playlistTrack</b> <br>
* <b>queueLen</b> <br>
* <b>queueVersion</b> <br>
* <b>modes</b> <br>
* <b>downloaded</b> <br>
* <b>serverUID</b> <br>
* <b>flags</b> <br>
* <b>muted</b>
*/
public JSONObject getStatus(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/status", arguments, "POST");
}
/**
* Instances - Shutdown
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject kill(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/kill", arguments, "POST");
}
/**
* Instances - Restart
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject respawn(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/respawn", arguments, "POST");
}
/**
* Instances - Launch
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject spawn(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/spawn", arguments, "POST");
}
/**
* Logging - Recent Bot-Log entries
* @return JSONObject with fields <br>
* <b>entries</b> <br>
* <b>entries.message</b> the log string <br>
* <b>entries.severity</b> severity <br>
* <b>entries.time</b> timestamp (unix-time)
*/
public JSONArray getBotLog() {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
}};
return apicallArray("/bot/log", arguments, "GET");
}
/**
* Logging - Instance-Log
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>entries</b> <br>
* <b>entries.message</b> the log string <br>
* <b>entries.severity</b> severity <br>
* <b>entries.time</b> timestamp (unix-time)
*/
public JSONArray getInstanceLog(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallArray("/bot/i/:instanceId/log", arguments, "GET");
}
/**
* Playback - Decrease volume by 5%
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject decreaseVolume(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/volume/down", arguments, "POST");
}
/**
* Playback - Increase volume by 5%
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject increaseVolume(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/volume/up", arguments, "POST");
}
/**
* Playback - Pause playback
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject pause(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/pause", arguments, "POST");
}
/**
* Playback - Playback a file
* @param instanceId uuid/id of the instance
* @param id uuid of the file to playback
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject playById(String instanceId, String id) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("id", id.toString());
}};
return apicallObject("/bot/i/:instanceId/play/byId/:id", arguments, "POST");
}
/**
* Playback - Playback a file inside a playlist
* @param instanceId uuid/id of the instance
* @param playlistId uuid of the playlist
* @param index number of the track inside the playlist
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject playByList(String instanceId, String playlistId, Integer index) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("playlistId", playlistId.toString());
put("index", index.toString());
}};
return apicallObject("/bot/i/:instanceId/play/byList/:playlistId/:index", arguments, "POST");
}
/**
* Playback - Playback URL
* @param instanceId uuid/id of the instance
* @param url the url that should be played back
* @param plugin name of the plugin that returned this url
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject playUrl(String instanceId, String url, String plugin) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("url", url.toString());
put("plugin", plugin.toString());
}};
return apicallObject("/bot/i/:instanceId/playUrl?url=:url&plugin=:plugin", arguments, "POST");
}
/**
* Playback - recently played tracks
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>body</b> array of uuids
*/
public JSONObject recentTracks(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/recent", arguments, "GET");
}
/**
* Playback - Say (TTS)
* @param instanceId uuid/id of the instance
* @param text the text to say
* @param locale the locale to use - if none is given, the default one will be used
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject say(String instanceId, String text, String locale) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("text", text.toString());
put("locale", locale.toString());
}};
return apicallObject("/bot/i/:instanceId/say", arguments, "POST");
}
/**
* Playback - Seek
* @param instanceId uuid/id of the instance
* @param val position in percent
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject seek(String instanceId, Integer val) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("val", val.toString());
}};
return apicallObject("/bot/i/:instanceId/seek/:val", arguments, "POST");
}
/**
* Playback - Enable/Disable mute
* @param instanceId uuid/id of the instance
* @param val 0 / 1 to disable/enable mute
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject setMute(String instanceId, Integer val) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("val", val.toString());
}};
return apicallObject("/bot/i/:instanceId/mute/:val", arguments, "POST");
}
/**
* Playback - Set the volume
* @param instanceId uuid/id of the instance
* @param volume volume level in percent (0-100)
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject setVolume(String instanceId, Integer volume) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("volume", volume.toString());
}};
return apicallObject("/bot/i/:instanceId/volume/set/:volume", arguments, "POST");
}
/**
* Playback - Stop playback
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject stop(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/stop", arguments, "POST");
}
/**
* Playlists - Next
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject playNext(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/playNext", arguments, "POST");
}
/**
* Playlists - Previous
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject playPrevious(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/playPrevious", arguments, "POST");
}
/**
* Playlists - Enable/Disable repeat
* @param instanceId uuid/id of the instance
* @param val 0 / 1 to disable/enable repeat
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject setRepeat(String instanceId, Integer val) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("val", val.toString());
}};
return apicallObject("/bot/i/:instanceId/repeat/:val", arguments, "POST");
}
/**
* Playlists - Enable/Disable shuffle
* @param instanceId uuid/id of the instance
* @param val 0 / 1 to disable/enable shuffle
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject setShuffle(String instanceId, Integer val) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("val", val.toString());
}};
return apicallObject("/bot/i/:instanceId/shuffle/:val", arguments, "POST");
}
/**
* Queue - Append a track to the queue
* @param instanceId uuid/id of the instance
* @param uuid track uuid
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject appendQueue(String instanceId, String uuid) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("uuid", uuid.toString());
}};
return apicallObject("/bot/i/:instanceId/queue/append/:uuid", arguments, "POST");
}
/**
* Queue - Get list
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>mediainfo</b> list of tracks in the queue
*/
public JSONArray getQueue(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallArray("/bot/i/:instanceId/queue", arguments, "GET");
}
/**
* Queue - Prepend a track to the queue
* @param instanceId uuid/id of the instance
* @param uuid track uuid
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject prependQueue(String instanceId, String uuid) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("uuid", uuid.toString());
}};
return apicallObject("/bot/i/:instanceId/queue/prepend/:uuid", arguments, "POST");
}
/**
* Queue - Remove from queue
* @param instanceId uuid/id of the instance
* @param queuePos the position of the track inside the queue that should be removed
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject removeFromQueue(String instanceId, Integer queuePos) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("queuePos", queuePos.toString());
}};
return apicallObject("/bot/i/:instanceId/queue/:queuePos", arguments, "DELETE");
}
/**
* Radio - Get radio stations
* @param search limit output to stations which match this string
* @return JSONObject with fields <br>
* <b>station</b> <br>
* <b>s.n</b> name of the station <br>
* <b>s.u</b> url of the station <br>
* <b>s.g</b> genre <br>
* <b>s.b</b> bitrate
*/
public JSONArray getRadioStations(String search) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("search", search.toString());
}};
return apicallArray("/bot/stations?q=:search", arguments, "PATCH");
}
/**
* Scripts - List Scripts
* @return JSONObject with fields <br>
* <b>scriptname</b> <br>
* <b>scriptname.name</b> <br>
* <b>scriptname.version</b> <br>
* <b>scriptname.description</b> <br>
* <b>scriptname.author</b> <br>
* <b>scriptname.vars</b> <br>
* <b>scriptname.vars.varname</b> <br>
* <b>scriptname.vars.varname.title</b> <br>
* <b>scriptname.vars.varname.type</b>
*/
public JSONArray getScripts() {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
}};
return apicallArray("/bot/scripts", arguments, "GET");
}
/**
* Scripts - Save Settings
* @param instanceId uuid/id of the instance
* @param ScriptName
* @param ScriptName_enabled
* @param ScriptName_config the JSON-encoded script settings
* @return JSONObject with fields <br>
* <b>success</b>
*/
public JSONObject saveSettings(String instanceId, Object[] ScriptName, Boolean ScriptName_enabled, String ScriptName_config) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("ScriptName", ScriptName.toString());
put("ScriptName_enabled", ScriptName_enabled.toString());
put("ScriptName_config", ScriptName_config.toString());
}};
return apicallObject("/bot/i/:instanceId/scriptSettings", arguments, "POST");
}
/**
* Streaming - Get audio stream
* @param instanceId uuid/id of the instance
* @param token a token acquired by streamToken
* @return
*/
public JSONObject getStream(String instanceId, String token) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
put("token", token.toString());
}};
return apicallObject("/bot/i/:instanceId/stream/:token", arguments, "GET");
}
/**
* Streaming - Get a token for the WebStream
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>success</b> <br>
* <b>token</b> the token that can be used to initiate the WebStream
*/
public JSONObject getStreamToken(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};
return apicallObject("/bot/i/:instanceId/streamToken", arguments, "POST");
}
/**
* TeamSpeak - Channel list
* @param instanceId uuid/id of the instance
* @return JSONObject with fields <br>
* <b>channel</b> <br>
* <b>channel.id</b> <br>
* <b>channel.parent</b> <br>
* <b>channel.name</b> <br>
* <b>channel.topic</b> <br>
* <b>channel.codec</b> <br>
* <b>channel.quality</b> <br>
* <b>channel.maxClients</b> <br>
* <b>channel.order</b> <br>
* <b>channel.perm</b> 1 = is permanent <br>
* <b>channel.sperm</b> 1 = is semi-permanent <br>
* <b>channel.default</b> 1 = is default <br>
* <b>channel.pw</b> 1 = is passworded <br>
* <b>channel.enc</b> 1 = is encrypted <br>
* <b>channel.clients</b> <br>
* <b>channel.clients.id</b> <br>
* <b>channel.clients.uid</b> <br>
* <b>channel.clients.nick</b> <br>
* <b>channel.clients.idle</b> <br>
* <b>channel.clients.recording</b> <br>
* <b>channel.clients.outputMuted</b> <br>
* <b>channel.clients.outputOnlyMuted</b> <br>
* <b>channel.clients.inputMuted</b> <br>
* <b>channel.clients.away</b>
*/
public JSONArray getChannels(String instanceId) {
@SuppressWarnings("serial")
HashMap<String,String> arguments = new HashMap<String,String>() {{
put("instanceId", instanceId.toString());
}};