-
Notifications
You must be signed in to change notification settings - Fork 4
/
disrest_guild.tcl
671 lines (609 loc) · 20 KB
/
disrest_guild.tcl
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
# disrest_guild.tcl --
#
# This file implements the Tcl code for interacting with the Discord HTTP
# API's guild resource.
#
# Copyright (c) 2016, Yixin Zhang
#
# See the file "LICENSE" for information on usage and redistribution of this
# file.
package require http
# All data dictionary keys are required unless stated otherwise.
# discord::rest::GetGuild --
#
# Returns the new guild for the given id.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a guild dictionary to the callback.
proc discord::rest::GetGuild { token guildId {cmd {}} } {
Send $token GET "/guilds/$guildId" {} $cmd
}
# discord::rest::ModifyGuild --
#
# Modify a guild's settings.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# data Dictionary representing a JSON object. Each key is one of
# name, region, verification_level, default_message_notifications,
# afk_channel_id, afk_timeout, icon, owner_id, splash. All keys
# are optional.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a guild dictionary to the callback.
proc discord::rest::ModifyGuild { token guildId data {cmd {}} } {
set spec {
name string
region string
verification_level bare
default_message_notifications bare
afk_channel_id string
afk_timeout bare
icon string
owner_id string
splash string
}
set body [DictToJson $data $spec]
Send $token PATCH "/guilds/$guildId" $body $cmd -type "application/json"
}
# discord::rest::DeleteGuild --
#
# Delete a guild permanently.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a guild dictionary to the callback.
proc discord::rest::DeleteGuild { token guildId {cmd {}} } {
Send $token DELETE "/guilds/$guildId" {} $cmd
}
# discord::rest::GetGuildChannels --
#
# Returns a list of guild channels.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a list of guild channel dictionaries to the callback.
proc discord::rest::GetGuildChannels { token guildId {cmd {}} } {
Send $token GET "/guilds/$guildId/channels" {} $cmd
}
# discord::rest::CreateGuildChannel --
#
# Create a new channel for the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# data Dictionary representing a JSON object. Each key is one of
# name, type, bitrate, user_limit, permission_overwrites. Only
# the key name is required.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a channel dictionary to the callback.
proc discord::rest::CreateGuildChannel { token guildId data {cmd {}} } {
set spec {
name string
type string
bitrate bare
user_limit bare
}
dict set spec permission_overwrites [list array [list object \
[dict get $::discord::JsonSpecs overwrite]]]
set body [DictToJson $data $spec]
Send $token POST "/guilds/$guildId/channels" $body $cmd \
-type "application/json"
}
# discord::rest::ModifyGuildChannelPosition --
#
# Modify the position of a guild channel.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# data List of dictionaries representing JSON objects. Each key is one
# of id, position.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# None.
proc discord::rest::ModifyGuildChannelPosition { token guildId data {cmd {}} } {
set spec {
id string
position bare
}
set body [ListToJsonArray $data object $spec]
Send $token PATCH "/guilds/$guildId/channels" $body $cmd \
-type "application/json"
}
# discord::rest::GetGuildMember --
#
# Returns a guild member for the specified user.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# userId User ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a guild member object to the callback.
proc discord::rest::GetGuildMember { token guildId userId {cmd {}} } {
Send $token GET "/guilds/$guildId/members/$userId" {} $cmd
}
# discord::rest::ListGuildMembers --
#
# Returns a list of guild members that are members of the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# data Dictionary representing a JSON object. Each key is one of
# limit, after. All keys are optional.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a list of guild member dictionaries to the callback.
proc discord::rest::ListGuildMembers { token guildId data {cmd {}} } {
set query [::http::formatQuery {*}$data]
Send $token GET "/guilds/$guildId/members?$query" {} $cmd
}
# discord::rest::AddGuildMember --
#
# Adds a user to the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# userId User ID.
# data Dictionary representing a JSON object. Each key is one of
# access_token, nick, roles, mute, deaf. Only access_token is
# required.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a guild member dictionary to the callback.
proc discord::rest::AddGuildMember { token guildId userId data {cmd {}} } {
set spec {
access_token string
nick string
mute bare
deaf bare
}
dict set spec roles [list array [list object \
[dict get $::discord::JsonSpecs role]]]
set body [DictToJson $data $spec]
Send $token PUT "/guilds/$guildId/members/$userId" $body $cmd \
-type "application/json"
}
# discord::rest::ModifyGuildMember --
#
# Modify attributes of a guild member.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# userId User ID.
# data Dictionary representing a JSON object. Each key is one of
# nick, roles, mute, deaf, channel_id. All keys are optional.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# None.
proc discord::rest::ModifyGuildMember { token guildId userId data {cmd {}} } {
if {[dict exists $data roles]} {
set roleJsonList [list]
foreach role [dict get $data roles] {
lappend roleJsonList [DictToJson $role \
[dict get $::discord::JsonSpecs role]]
}
dict set data roles $roleJsonList
}
set spec {
nick string
roles {array bare}
mute bare
deaf bare
channel_id string
}
set body [DictToJson $data $spec]
Send $token PATCH "/guilds/$guildId/members/$userId" $body $cmd \
-type "application/json"
}
# discord::rest::RemoveGuildMember --
#
# Remove a member from a guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# userId User ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# None.
proc discord::rest::RemoveGuildMember { token guildId userId {cmd {}} } {
Send $token DELETE "/guilds/$guildId/members/$userId" {} $cmd
}
# discord::rest::GetGuildBans --
#
# Returns a list of users that are banned from this guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a list of user dictionaries to the callback.
proc discord::rest::GetGuildBans { token guildId {cmd {}} } {
Send $token GET "/guilds/$guildId/bans" {} $cmd
}
# discord::rest::CreateGuildBan --
#
# Create a guild ban.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# userId User ID.
# data Dictionary representing a JSON object. Only the key
# delete-message-days should be present.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# None.
proc discord::rest::CreateGuildBan { token guildId userId data {cmd {}} } {
set spec {
delete-message-days bare
}
set body [DictToJson $data $spec]
Send $token PUT "/guilds/$guildId/bans/$userId" $body $cmd
}
# discord::rest::RemoveGuildBan --
#
# Remove the ban for a user.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# userId User ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# None.
proc discord::rest::RemoveGuildBan { token guildId userId {cmd {}} } {
Send $token DELETE "/guilds/$guildId/bans/$userId" {} $cmd
}
# discord::rest::GetGuildRoles --
#
# Return a list of roles for the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a list of role dictionaries to the callback.
proc discord::rest::GetGuildRoles { token guildId {cmd {}} } {
Send $token GET "/guilds/$guildId/roles" {} $cmd
}
# discord::rest::CreateGuildRole --
#
# Create a new empty role for the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a role object to the callback.
proc discord::rest::CreateGuildRole { token guildId {cmd {}} } {
Send $token POST "/guilds/$guildId/roles" {} $cmd \
-headers [list Content-Length 0]
}
# discord::rest::BatchModifyGuildRole --
#
# Batch modify a set of guild roles.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# data List of dictionaries representing JSON objects. Each key is one
# of id, name, permissions, position, color, hoist, mentionable.
# All keys are optional.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a role dictionary to the callback.
proc discord::rest::BatchModifyGuildRole { token guildId data {cmd {}} } {
set spec {
id string
name string
permissions bare
position bare
color bare
hoist bare
mentionable bare
}
set body [ListToJsonArray $data object $spec]
Send $token PATCH "/guilds/$guildId/roles" $body $cmd \
-type "application/json"
}
# discord::rest::ModifyGuildRole --
#
# Modify a guild role.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# roleId Role ID.
# data Dictionary representing a JSON object. Each key is one of
# name, permissions, position, color, hoist, mentionable.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a role dictionary to the callback.
proc discord::rest::ModifyGuildRole { token guildId roleId data {cmd {}} } {
set spec {
name string
permissions bare
position bare
color bare
hoist bare
mentionable bare
}
set body [DictToJson $data $spec]
Send $token PATCH "/guilds/$guildId/roles/$roleId" $body $cmd \
-type "application/json"
}
# discord::rest::DeleteGuildRole --
#
# Delete a guild role.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# roleId Role ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a role dictionary to the callback.
proc discord::rest::DeleteGuildRole { token guildId roleId {cmd {}} } {
Send $token DELETE "/guilds/$guildId/roles/$roleId" {} $cmd
}
# discord::rest::GetGuildPruneCount --
#
# Returns the number of members that would be removed in a prune
# operation.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# data Dictionary representing a JSON object. Only the key days should
# be present.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a dictionary with the key 'pruned' to the callback.
proc discord::rest::GetGuildPruneCount { token guildId data {cmd {}} } {
set query [::http::formatQuery {*}$data]
Send $token GET "/guilds/$guildId/prune?$query" {} $cmd
}
# discord::rest::BeginGuildPrune --
#
# Begin a prune operation.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# data Dictionary representing a JSON object. Only the key days should
# be present.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a dictionary with the key 'pruned' to the callback.
proc discord::rest::BeginGuildPrune { token guildId data {cmd {}} } {
set query [::http::formatQuery {*}$data]
Send $token POST "/guilds/$guildId/prune?$query" {} $cmd \
-headers [list Content-Length 0]
}
# discord::rest::GetGuildVoiceRegions --
#
# Returns a list of voice regions for the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a list of voice region dictionaries to the callback.
proc discord::rest::GetGuildVoiceRegions { token guildId {cmd {}} } {
Send $token GET "/guilds/$guildId/regions" {} $cmd
}
# discord::rest::GetGuildInvites --
#
# Returns a list of invites for the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a list of invite dictionaries to the callback.
proc discord::rest::GetGuildInvites { token guildId {cmd {}} } {
Send $token GET "/guilds/$guildId/invites" {} $cmd
}
# discord::rest::GetGuildIntegrations --
#
# Returns a list of integrations for the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a list of integration dictionaries to the callback.
proc discord::rest::GetGuildIntegrations { token guildId {cmd {}} } {
Send $token GET "/guilds/$guildId/integrations" {} $cmd
}
# discord::rest::CreateGuildIntegration --
#
# Attach an integration from the current user to the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# data Dictionary representing a JSON object. Each key is one of
# type, id.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# None.
proc discord::rest::CreateGuildIntegration { token guildId data {cmd {}} } {
set spec {
type string
id string
}
set body [DictToJson $data $spec]
Send $token POST "/guilds/$guildId/integrations" $body $cmd
}
# discord::rest::ModifyGuildIntegration --
#
# Modify the behavior and settings of an integration for the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# integrationId Integration ID.
# data Dictionary representing a JSON object. Each key is one
# of expire_behavior, expire_grace_period,
# enable_emoticons.
# cmd (optional) callback procedure invoked after a response
# is received.
#
# Results:
# None.
proc discord::rest::ModifyGuildIntegration { token guildId integrationId data \
{cmd {}} } {
set spec {
expire_behavior bare
expire_grace_period bare
enable_emoticons bare
}
set body [DictToJson $data $spec]
Send $token PATCH "/guilds/$guildId/integrations/$integrationId" $body $cmd
}
# discord::rest::DeleteGuildIntegration --
#
# Delete the attached integration for the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# integrationId Integration ID.
# cmd (optional) callback procedure invoked after a response
# is received.
#
# Results:
# None.
proc discord::rest::DeleteGuildIntegration { token guildId integrationId \
{cmd {}} } {
Send $token DELETE "/guilds/$guildId/integrations/$integrationId" {} $cmd
}
# discord::rest::SyncGuildIntegration --
#
# Sync an integration.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# integrationId Integration ID.
# cmd (optional) callback procedure invoked after a response
# is received.
#
# Results:
# None.
proc discord::rest::SyncGuildIntegration { token guildId integrationId \
{cmd {}} } {
Send $token POST "/guilds/$guildId/integrations/$integrationId/sync" {} \
$cmd -headers [list Content-Length 0]
}
# discord::rest::GetGuildEmbed --
#
# Returns the guild embed.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a guild embed dictionary to the callback.
proc discord::rest::GetGuildEmbed { token guildId {cmd {}} } {
Send $token GET "/guilds/$guildId/embed" {} $cmd
}
# discord::rest::ModifyGuildEmbed --
#
# Modify a guild embed for the guild.
#
# Arguments:
# token Bot token or OAuth2 bearer token.
# guildId Guild ID.
# data Dictionary representing a JSON object. Each key is one of
# enabled, channel_id. All keys are optional.
# cmd (optional) callback procedure invoked after a response is
# received.
#
# Results:
# Passes a guild embed dictionary to the callback.
proc discord::rest::ModifyGuildEmbed { token guildId data {cmd {}} } {
set body [DictToJson $data [dict get $::discord::JsonSpecs guild_embed]]
Send $token PATCH "/guilds/$guildId/embed" $body $cmd \
-type "application/json"
}