about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authormjk134 <57556877+mjk134@users.noreply.github.com>2022-07-14 10:20:42 +0000
committerGitHub <noreply@github.com>2022-07-14 10:20:42 +0000
commite5554ce086efa686ddb8ca39d812a184c29e1887 (patch)
tree47f99baa20289d13fa5ee7ac547e667143b0c261
parent498a7d531601f7594718eb59397dff7e2b77ad24 (diff)
downloaddiscobra-master.tar.gz
feat: Add channels for guilds HEAD master
-rw-r--r--discord/channels.py167
-rw-r--r--discord/client.py10
-rw-r--r--discord/guild.py23
3 files changed, 192 insertions, 8 deletions
diff --git a/discord/channels.py b/discord/channels.py
new file mode 100644
index 0000000..3d3f3fd
--- /dev/null
+++ b/discord/channels.py
@@ -0,0 +1,167 @@
+from __future__ import annotations
+from enum import IntEnum
+from typing import TYPE_CHECKING
+
+if TYPE_CHECKING:
+    from discord.guild import Guild
+
+class ChannelType(IntEnum):
+    GUILD_TEXT = 0
+    DM = 1
+    GUILD_VOICE = 2
+    GROUP_DM = 3
+    GUILD_CATEGORY = 4
+    GUILD_NEWS = 5
+    GUILD_NEWS_THREAD = 10
+    GUILD_PUBLIC_THREAD = 11
+    GUILD_PRIVATE_THREAD = 12
+    GUILD_STAGE_VOICE = 13
+    GUILD_DIRECTORY = 14
+
+class GuildChannel:
+    _id: str
+    _guild: Guild
+    _name: str
+    _type: ChannelType
+    _position: int
+    _nsfw: bool
+    _permission_overwrites: list
+    _parent_id: str | None
+    _flags: int
+
+    def __init__(self, data: dict, guild: Guild):
+        self._guild = guild
+        for key, value in data.items():
+            setattr(self, f"_{key}", value)
+
+    def __repr__(self) -> str:
+        return f"<GuildChannel id={self._id} name={self._name}>"
+
+    @property
+    def id(self) -> str:
+        return self._id
+    
+    @property
+    def guild(self) -> Guild:
+        return self._guild
+    
+    @property
+    def name(self) -> str:
+        return self._name
+
+    @property
+    def type(self) -> ChannelType:
+        return self._type.name
+
+    @property
+    def position(self) -> int:
+        return self._position
+
+    @property
+    def nsfw(self) -> bool:
+        return self._nsfw
+
+    @property
+    def permission_overwrites(self) -> list:
+        return self._permission_overwrites
+
+    @property
+    def parent_id(self) -> str:
+        return self._parent_id
+
+    @property
+    def flags(self) -> int:
+        return self._flags
+
+class CategoryChannel(GuildChannel):
+    
+    def __init__(self, data: dict, guild: Guild):
+        super().__init__(data, guild)
+
+    def __repr__(self) -> str:
+        return f"<CategoryChannel id={self._id} name={self._name}>"
+    
+
+class TextChannel(GuildChannel):
+    _rate_limit_per_user: int
+    _topic: str
+    _last_message_id: str
+    _default_auto_archive_duration: int
+
+    @property
+    def rate_limit_per_user(self) -> int:
+        return self._rate_limit_per_user
+
+    @property
+    def topic(self) -> str:
+        return self._topic
+
+    @property
+    def last_message_id(self) -> str:
+        return self._last_message_id
+
+    @property
+    def default_auto_archive_duration(self) -> int:
+        return self._default_auto_archive_duration
+
+    def __init__(self, data: dict, guild: Guild):
+        super().__init__(data, guild)
+        for key, value in data.items():
+            setattr(self, f"_{key}", value)
+
+    def __repr__(self) -> str:
+        return f"<TextChannel id={self._id} name={self._name}>"
+
+class VoiceChannel(GuildChannel):
+    _bitrate: int
+    _user_limit: int
+    _rtc_region: str
+    
+    @property
+    def bitrate(self) -> int:
+        return self._bitrate
+
+    @property
+    def user_limit(self) -> int:
+        return self._user_limit
+
+    @property
+    def rtc_region(self) -> str:
+        return self._rtc_region
+
+    def __init__(self, data: dict, guild: Guild):
+        super().__init__(data, guild)
+        for key, value in data.items():
+            setattr(self, f"_{key}", value)
+
+    def __repr__(self) -> str:
+        return f"<VoiceChannel id={self._id} name={self._name}>"
+
+
+class StageChannel(GuildChannel):
+    pass
+
+class AnnouncementChannel(GuildChannel):
+    _topic: str
+    _last_message_id: str
+    _default_auto_archive_duration: int
+
+    @property
+    def topic(self) -> str:
+        return self._topic
+
+    @property
+    def last_message_id(self) -> str:
+        return self._last_message_id
+
+    @property
+    def default_auto_archive_duration(self) -> int:
+        return self._default_auto_archive_duration
+
+    def __init__(self, data: dict, guild: Guild):
+        super().__init__(data, guild)
+        for key, value in data.items():
+            setattr(self, f"_{key}", value)
+
+    def __repr__(self) -> str:
+        return f"<AnnouncementChannel id={self._id} name={self._name}>"
\ No newline at end of file
diff --git a/discord/client.py b/discord/client.py
index 8901238..6da6aad 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -173,19 +173,19 @@ class Client:
         data = msg['d']
         sequence = msg['s']
 
-        if opcode != GatewayEvents.DISPATCH.value:
-            if opcode == GatewayEvents.RECONNECT.value:
+        if opcode != GatewayEvents.DISPATCH:
+            if opcode == GatewayEvents.RECONNECT:
                 return await self.close()
 
-            if opcode == GatewayEvents.HELLO.value:
+            if opcode == GatewayEvents.HELLO:
                 self.heartbeat_interval = data['heartbeat_interval']
                 asyncio.run_coroutine_threadsafe(self.heartbeat(self.heartbeat_interval), self.loop)
                 return await self.identify()
 
-            if opcode == GatewayEvents.HEARTBEAT_ACK.value:
+            if opcode == GatewayEvents.HEARTBEAT_ACK:
                 return await self.heartbeat(self.heartbeat_interval)
 
-            if opcode == GatewayEvents.HEARTBEAT.value:
+            if opcode == GatewayEvents.HEARTBEAT:
                 return await self.heartbeat(self.heartbeat_interval)
 
         event = msg['t']
diff --git a/discord/guild.py b/discord/guild.py
index bf6b826..1359c58 100644
--- a/discord/guild.py
+++ b/discord/guild.py
@@ -1,4 +1,5 @@
 from discord.user import User
+from .channels import AnnouncementChannel, CategoryChannel, ChannelType, GuildChannel, TextChannel, VoiceChannel
 
 class GuildMember:
     """
@@ -56,7 +57,6 @@ class GuildRole:
     def __repr__(self) -> str:
         return f"<GuildRole id={self._id} name={self._name}>"
     
-
 class GuildEmoji:
     _id: str
     _name: str
@@ -78,6 +78,9 @@ class GuildEmoji:
     def __repr__(self) -> str:
         return f"<GuildEmoji id={self._id} name={self._name}>"
 
+class GuildSticker:
+    pass
+
 class Guild:
     _id: str
     _name: str
@@ -93,7 +96,7 @@ class Guild:
     _region: str
     _voice_states: list
     _members: list[GuildMember]
-    _channels: list
+    _channels: list[GuildChannel]
     _threads: list
     _afk_channel_id: str
     _afk_timeout: int
@@ -147,7 +150,7 @@ class Guild:
         return self._roles
 
     @property
-    def channels(self) -> list:
+    def channels(self) -> list[GuildChannel]:
         return self._channels
     
     @property
@@ -167,6 +170,20 @@ class Guild:
                     self._emojis = [GuildEmoji(emoji) for emoji in value]
                 case 'members':
                     self._members = [GuildMember(member) for member in value]
+                case 'channels':
+                    channels = []
+                    for channel in value:
+                        if channel['type'] == ChannelType.GUILD_TEXT:
+                            channels.append(TextChannel(channel, self))
+                        elif channel['type'] == ChannelType.GUILD_VOICE:
+                            channels.append(VoiceChannel(channel, self))
+                        elif channel['type'] == ChannelType.GUILD_CATEGORY:
+                            channels.append(CategoryChannel(channel, self))
+                        elif channel['type'] == ChannelType.GUILD_NEWS:
+                            channels.append(AnnouncementChannel(channel, self))
+                        else:
+                            channels.append(GuildChannel(channel, self))
+                    self._channels = channels
                 case 'welcome_screen':
                     self._welcome_screen = value
                 case 'stickers':
5 -0800 2423 - describe shape-shifting in html docs' href='/akkartik/mu/commit/html/065duplex_list.mu.html?h=main&id=76755b2836b0dadd88f82635f661f9d9df77604d'>76755b28 ^
4690ce81 ^
76755b28 ^
dbe12410 ^

32b8fac2 ^
f5465e12 ^
76755b28 ^
4690ce81 ^
76755b28 ^
dbe12410 ^

32b8fac2 ^
f5465e12 ^
76755b28 ^
4690ce81 ^
76755b28 ^
4690ce81 ^
dbe12410 ^

f5465e12 ^
dbe12410 ^
298f8065 ^
a0decd22 ^




















dbe12410 ^

f5465e12 ^
a0decd22 ^











dbe12410 ^


67db19a0 ^
32b8fac2 ^
f5465e12 ^
76755b28 ^
32b8fac2 ^






4690ce81 ^
32b8fac2 ^
dbe12410 ^

f5465e12 ^
dbe12410 ^
298f8065 ^
a0decd22 ^




dbe12410 ^
a0decd22 ^














dbe12410 ^

a0decd22 ^







dbe12410 ^


f5465e12 ^
dbe12410 ^
298f8065 ^
a0decd22 ^





dbe12410 ^
a0decd22 ^














dbe12410 ^

a0decd22 ^







dbe12410 ^


f5465e12 ^
dbe12410 ^
298f8065 ^
a0decd22 ^



dbe12410 ^
a0decd22 ^














dbe12410 ^

a0decd22 ^







dbe12410 ^


67db19a0 ^
f5465e12 ^
67db19a0 ^

32b8fac2 ^
f5465e12 ^
76755b28 ^
67db19a0 ^
4690ce81 ^
32b8fac2 ^

67db19a0 ^
32b8fac2 ^

67db19a0 ^
f5465e12 ^
f5465e12 ^
32b8fac2 ^
f5465e12 ^
67db19a0 ^
f5465e12 ^
f5465e12 ^
32b8fac2 ^
4690ce81 ^
f5465e12 ^
32b8fac2 ^
67db19a0 ^
4690ce81 ^
dbe12410 ^

f5465e12 ^
dbe12410 ^
298f8065 ^
a0decd22 ^





dbe12410 ^
a0decd22 ^







dbe12410 ^

a0decd22 ^





dbe12410 ^


f5465e12 ^
dbe12410 ^
298f8065 ^
a0decd22 ^



dbe12410 ^
a0decd22 ^







dbe12410 ^

a0decd22 ^




dbe12410 ^


f5465e12 ^
dbe12410 ^
298f8065 ^
a0decd22 ^


dbe12410 ^
a0decd22 ^



dbe12410 ^
a0decd22 ^







0e4a335e ^

a0decd22 ^





0e4a335e ^


298f8065 ^
0e4a335e ^
a0decd22 ^



0e4a335e ^

67db19a0 ^
0e4a335e ^


32b8fac2 ^





f5465e12 ^
76755b28 ^
32b8fac2 ^



0e4a335e ^

32b8fac2 ^

4690ce81 ^
0e4a335e ^

32b8fac2 ^



0e4a335e ^

f5465e12 ^
0e4a335e ^
a0decd22 ^







0e4a335e ^
a0decd22 ^

0e4a335e ^

a0decd22 ^


0e4a335e ^
a0decd22 ^





0e4a335e ^

a0decd22 ^



0e4a335e ^


32b8fac2 ^
a0decd22 ^
0e4a335e ^
a0decd22 ^






0e4a335e ^
a0decd22 ^

0e4a335e ^
32b8fac2 ^
a0decd22 ^
32b8fac2 ^
a0decd22 ^




0e4a335e ^
a0decd22 ^





dbe12410 ^

a0decd22 ^



dbe12410 ^


f5465e12 ^
a0decd22 ^
32b8fac2 ^
a0decd22 ^



32b8fac2 ^
a0decd22 ^

32b8fac2 ^
a0decd22 ^

32b8fac2 ^
a0decd22 ^





32b8fac2 ^


a0decd22 ^



32b8fac2 ^



a0decd22 ^
0e4a335e ^
a0decd22 ^






dbe12410 ^
a0decd22 ^

32b8fac2 ^
a0decd22 ^

0e4a335e ^
a0decd22 ^



dbe12410 ^

a0decd22 ^


dbe12410 ^

0e4a335e ^
67db19a0 ^
32b8fac2 ^
f5465e12 ^
76755b28 ^
4690ce81 ^

32b8fac2 ^
f5465e12 ^
32b8fac2 ^
f5465e12 ^



32b8fac2 ^

f5465e12 ^

32b8fac2 ^
f5465e12 ^
32b8fac2 ^

0e4a335e ^

32b8fac2 ^
f5465e12 ^
76755b28 ^
32b8fac2 ^

4690ce81 ^
32b8fac2 ^
0e4a335e ^

32b8fac2 ^
f5465e12 ^
76755b28 ^

f5465e12 ^
32b8fac2 ^
f5465e12 ^



0e4a335e ^


32b8fac2 ^
f5465e12 ^
76755b28 ^
f5465e12 ^


76755b28 ^
f5465e12 ^
d2bd40bf ^
f5465e12 ^








0e4a335e ^
dbe12410 ^


a654e4ec ^
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