dshellInterpreter 0.2.21.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Dshell/DISCORD_COMMANDS/__init__.py +7 -0
- Dshell/DISCORD_COMMANDS/dshell_channel.py +612 -0
- Dshell/DISCORD_COMMANDS/dshell_interaction.py +89 -0
- Dshell/DISCORD_COMMANDS/dshell_member.py +274 -0
- Dshell/DISCORD_COMMANDS/dshell_message.py +444 -0
- Dshell/DISCORD_COMMANDS/dshell_pastbin.py +28 -0
- Dshell/DISCORD_COMMANDS/dshell_role.py +128 -0
- Dshell/DISCORD_COMMANDS/utils/__init__.py +8 -0
- Dshell/DISCORD_COMMANDS/utils/utils_global.py +155 -0
- Dshell/DISCORD_COMMANDS/utils/utils_list.py +109 -0
- Dshell/DISCORD_COMMANDS/utils/utils_member.py +30 -0
- Dshell/DISCORD_COMMANDS/utils/utils_message.py +78 -0
- Dshell/DISCORD_COMMANDS/utils/utils_permissions.py +94 -0
- Dshell/DISCORD_COMMANDS/utils/utils_string.py +157 -0
- Dshell/DISCORD_COMMANDS/utils/utils_thread.py +35 -0
- Dshell/_DshellInterpreteur/__init__.py +4 -0
- Dshell/_DshellInterpreteur/cached_messages.py +4 -0
- Dshell/_DshellInterpreteur/dshell_arguments.py +74 -0
- Dshell/_DshellInterpreteur/dshell_interpreter.py +671 -0
- Dshell/_DshellInterpreteur/errors.py +8 -0
- Dshell/_DshellParser/__init__.py +2 -0
- Dshell/_DshellParser/ast_nodes.py +675 -0
- Dshell/_DshellParser/dshell_parser.py +408 -0
- Dshell/_DshellTokenizer/__init__.py +4 -0
- Dshell/_DshellTokenizer/dshell_keywords.py +193 -0
- Dshell/_DshellTokenizer/dshell_token_type.py +58 -0
- Dshell/_DshellTokenizer/dshell_tokenizer.py +146 -0
- Dshell/__init__.py +3 -0
- Dshell/_utils.py +1 -0
- dshellinterpreter-0.2.21.7.dist-info/METADATA +37 -0
- dshellinterpreter-0.2.21.7.dist-info/RECORD +34 -0
- dshellinterpreter-0.2.21.7.dist-info/WHEEL +5 -0
- dshellinterpreter-0.2.21.7.dist-info/licenses/LICENSE +21 -0
- dshellinterpreter-0.2.21.7.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
from asyncio import sleep
|
|
2
|
+
from re import search
|
|
3
|
+
from typing import Union
|
|
4
|
+
|
|
5
|
+
from discord import MISSING, PermissionOverwrite, Member, Role, Message, CategoryChannel, PartialMessage, VoiceChannel
|
|
6
|
+
from discord.utils import _MissingSentinel
|
|
7
|
+
|
|
8
|
+
from .utils.utils_message import utils_get_message
|
|
9
|
+
from .utils.utils_thread import utils_get_thread
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
'dshell_get_channel',
|
|
13
|
+
'dshell_get_channels',
|
|
14
|
+
'dshell_get_thread',
|
|
15
|
+
'dshell_get_channels_in_category',
|
|
16
|
+
'dshell_create_text_channel',
|
|
17
|
+
'dshell_create_thread_message',
|
|
18
|
+
'dshell_delete_channel',
|
|
19
|
+
'dshell_delete_channels',
|
|
20
|
+
'dshell_delete_thread',
|
|
21
|
+
'dshell_create_voice_channel',
|
|
22
|
+
'dshell_edit_text_channel',
|
|
23
|
+
'dshell_edit_voice_channel',
|
|
24
|
+
'dshell_edit_thread',
|
|
25
|
+
'dshell_create_category',
|
|
26
|
+
'dshell_edit_category',
|
|
27
|
+
'dshell_delete_category',
|
|
28
|
+
'dshell_get_channel_category_id',
|
|
29
|
+
'dshell_get_channel_nsfw',
|
|
30
|
+
'dshell_get_channel_slowmode',
|
|
31
|
+
'dshell_get_channel_topic',
|
|
32
|
+
'dshell_get_channel_threads',
|
|
33
|
+
'dshell_get_channel_position',
|
|
34
|
+
'dshell_get_channel_url',
|
|
35
|
+
'dshell_get_channel_voice_members',
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async def dshell_get_channel(ctx: Message, name):
|
|
40
|
+
"""
|
|
41
|
+
Returns the channel object of the channel where the command was executed or the specified channel.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
if isinstance(name, str):
|
|
45
|
+
return next((c.id for c in ctx.channel.guild.channels if c.name == name), None)
|
|
46
|
+
|
|
47
|
+
raise Exception(f"Channel must be an integer or a string, not {type(name)} !")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
async def dshell_get_channels(ctx: Message, name=None, regex=None):
|
|
51
|
+
"""
|
|
52
|
+
Returns a list of channels with the same name and/or matching the same regex.
|
|
53
|
+
If neither is set, it will return all channels in the server.
|
|
54
|
+
"""
|
|
55
|
+
if name is not None and not isinstance(name, str):
|
|
56
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
57
|
+
|
|
58
|
+
if regex is not None and not isinstance(regex, str):
|
|
59
|
+
raise Exception(f"Regex must be a string, not {type(regex)} !")
|
|
60
|
+
|
|
61
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
62
|
+
channels = ListNode([])
|
|
63
|
+
|
|
64
|
+
for channel in ctx.channel.guild.channels:
|
|
65
|
+
if name is not None and channel.name == str(name):
|
|
66
|
+
channels.add(channel.id)
|
|
67
|
+
|
|
68
|
+
elif regex is not None and search(regex, channel.name):
|
|
69
|
+
channels.add(channel.id)
|
|
70
|
+
|
|
71
|
+
return channels
|
|
72
|
+
|
|
73
|
+
async def dshell_get_channels_in_category(ctx: Message, category=None, name=None, regex=None):
|
|
74
|
+
"""
|
|
75
|
+
Returns a list of channels in a specific category with the same name and/or matching the same regex.
|
|
76
|
+
If neither is set, it will return all channels in the specified category.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
if category is None and ctx.channel.category is not None:
|
|
80
|
+
category = ctx.channel.category.id
|
|
81
|
+
|
|
82
|
+
if category is None:
|
|
83
|
+
raise Exception("Category must be specified !")
|
|
84
|
+
|
|
85
|
+
if not isinstance(category, int):
|
|
86
|
+
raise Exception(f"Category must be an integer, not {type(category)} !")
|
|
87
|
+
|
|
88
|
+
if name is not None and not isinstance(name, str):
|
|
89
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
90
|
+
|
|
91
|
+
if regex is not None and not isinstance(regex, str):
|
|
92
|
+
raise Exception(f"Regex must be a string, not {type(regex)} !")
|
|
93
|
+
|
|
94
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
95
|
+
channels = ListNode([])
|
|
96
|
+
|
|
97
|
+
category_channel = ctx.channel.guild.get_channel(category)
|
|
98
|
+
if category_channel is None or not hasattr(category_channel, 'channels'):
|
|
99
|
+
raise Exception(f"Category {category} not found or does not contain channels !")
|
|
100
|
+
|
|
101
|
+
for channel in category_channel.channels:
|
|
102
|
+
if name is not None and channel.name == str(name):
|
|
103
|
+
channels.add(channel.id)
|
|
104
|
+
|
|
105
|
+
elif regex is not None and search(regex, channel.name):
|
|
106
|
+
channels.add(channel.id)
|
|
107
|
+
|
|
108
|
+
return channels
|
|
109
|
+
|
|
110
|
+
async def dshell_create_text_channel(ctx: Message,
|
|
111
|
+
name,
|
|
112
|
+
category=None,
|
|
113
|
+
position=MISSING,
|
|
114
|
+
slowmode=MISSING,
|
|
115
|
+
topic=MISSING,
|
|
116
|
+
nsfw=MISSING,
|
|
117
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
118
|
+
reason=None):
|
|
119
|
+
"""
|
|
120
|
+
Creates a text channel on the server
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
124
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
125
|
+
|
|
126
|
+
if not isinstance(slowmode, (_MissingSentinel, int)):
|
|
127
|
+
raise Exception(f"Slowmode must be an integer, not {type(slowmode)} !")
|
|
128
|
+
|
|
129
|
+
if not isinstance(topic, (_MissingSentinel, str)):
|
|
130
|
+
raise Exception(f"Topic must be a string, not {type(topic)} !")
|
|
131
|
+
|
|
132
|
+
if not isinstance(nsfw, (_MissingSentinel, bool)):
|
|
133
|
+
raise Exception(f"NSFW must be a boolean, not {type(nsfw)} !")
|
|
134
|
+
|
|
135
|
+
channel_category = ctx.channel.category if category is None else ctx.channel.guild.get_channel(category)
|
|
136
|
+
|
|
137
|
+
created_channel = await ctx.guild.create_text_channel(str(name),
|
|
138
|
+
category=channel_category,
|
|
139
|
+
position=position,
|
|
140
|
+
slowmode_delay=slowmode,
|
|
141
|
+
topic=topic,
|
|
142
|
+
nsfw=nsfw,
|
|
143
|
+
overwrites=permissions,
|
|
144
|
+
reason=reason)
|
|
145
|
+
|
|
146
|
+
return created_channel.id
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
async def dshell_create_voice_channel(ctx: Message,
|
|
150
|
+
name,
|
|
151
|
+
category=None,
|
|
152
|
+
position=MISSING,
|
|
153
|
+
bitrate=MISSING,
|
|
154
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
155
|
+
reason=None):
|
|
156
|
+
"""
|
|
157
|
+
Creates a voice channel on the server
|
|
158
|
+
"""
|
|
159
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
160
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
161
|
+
|
|
162
|
+
if not isinstance(bitrate, (_MissingSentinel, int)):
|
|
163
|
+
raise Exception(f"Bitrate must be an integer, not {type(bitrate)} !")
|
|
164
|
+
|
|
165
|
+
channel_category = ctx.channel.category if category is None else ctx.channel.guild.get_channel(category)
|
|
166
|
+
|
|
167
|
+
created_channel = await ctx.guild.create_voice_channel(str(name),
|
|
168
|
+
category=channel_category,
|
|
169
|
+
position=position,
|
|
170
|
+
bitrate=bitrate,
|
|
171
|
+
overwrites=permissions,
|
|
172
|
+
reason=reason)
|
|
173
|
+
|
|
174
|
+
return created_channel.id
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
async def dshell_delete_channel(ctx: Message, channel=None, reason=None, timeout=0):
|
|
178
|
+
"""
|
|
179
|
+
Deletes a channel.
|
|
180
|
+
You can add a waiting time before it is deleted (in seconds)
|
|
181
|
+
"""
|
|
182
|
+
if not isinstance(timeout, int):
|
|
183
|
+
raise Exception(f'Timeout must be an integer, not {type(timeout)} !')
|
|
184
|
+
|
|
185
|
+
channel_to_delete = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
186
|
+
|
|
187
|
+
if channel_to_delete is None:
|
|
188
|
+
raise Exception(f"Channel {channel} not found !")
|
|
189
|
+
|
|
190
|
+
await sleep(timeout)
|
|
191
|
+
|
|
192
|
+
await channel_to_delete.delete(reason=reason)
|
|
193
|
+
|
|
194
|
+
return channel_to_delete.id
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
async def dshell_delete_channels(ctx: Message, name=None, regex=None, reason=None):
|
|
198
|
+
"""
|
|
199
|
+
Deletes all channels with the same name and/or matching the same regex.
|
|
200
|
+
If neither is set, it will delete all channels with the same name as the one where the command was executed.
|
|
201
|
+
"""
|
|
202
|
+
if name is not None and not isinstance(name, str):
|
|
203
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
204
|
+
|
|
205
|
+
if regex is not None and not isinstance(regex, str):
|
|
206
|
+
raise Exception(f"Regex must be a string, not {type(regex)} !")
|
|
207
|
+
|
|
208
|
+
for channel in ctx.channel.guild.channels:
|
|
209
|
+
|
|
210
|
+
if name is not None and channel.name == str(name):
|
|
211
|
+
await channel.delete(reason=reason)
|
|
212
|
+
|
|
213
|
+
elif regex is not None and search(regex, channel.name):
|
|
214
|
+
await channel.delete(reason=reason)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
async def dshell_edit_text_channel(ctx: Message,
|
|
218
|
+
channel=None,
|
|
219
|
+
name=None,
|
|
220
|
+
category=MISSING,
|
|
221
|
+
position=MISSING,
|
|
222
|
+
slowmode=MISSING,
|
|
223
|
+
topic=MISSING,
|
|
224
|
+
nsfw=MISSING,
|
|
225
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
226
|
+
reason=None):
|
|
227
|
+
"""
|
|
228
|
+
Edits a text channel on the server
|
|
229
|
+
"""
|
|
230
|
+
if name is not None and not isinstance(name, str):
|
|
231
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
232
|
+
|
|
233
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
234
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
235
|
+
|
|
236
|
+
if not isinstance(category, (_MissingSentinel, int)):
|
|
237
|
+
raise Exception(f"Category must be an integer, not {type(category)} !")
|
|
238
|
+
|
|
239
|
+
if not isinstance(slowmode, (_MissingSentinel, int)):
|
|
240
|
+
raise Exception(f"Slowmode must be an integer, not {type(slowmode)} !")
|
|
241
|
+
|
|
242
|
+
if not isinstance(topic, (_MissingSentinel, str)):
|
|
243
|
+
raise Exception(f"Topic must be a string, not {type(topic)} !")
|
|
244
|
+
|
|
245
|
+
if not isinstance(nsfw, (_MissingSentinel, bool)):
|
|
246
|
+
raise Exception(f"NSFW must be a boolean, not {type(nsfw)} !")
|
|
247
|
+
|
|
248
|
+
channel_to_edit = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
249
|
+
new_categoy = ctx.channel.category if isinstance(category, _MissingSentinel) else ctx.channel.guild.get_channel(category)
|
|
250
|
+
|
|
251
|
+
if channel_to_edit is None:
|
|
252
|
+
raise Exception(f"Channel {channel} not found !")
|
|
253
|
+
|
|
254
|
+
await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
|
|
255
|
+
position=position if position is not MISSING else channel_to_edit.position,
|
|
256
|
+
category=new_categoy,
|
|
257
|
+
slowmode_delay=slowmode if slowmode is not MISSING else channel_to_edit.slowmode_delay,
|
|
258
|
+
topic=topic if topic is not MISSING else channel_to_edit.topic,
|
|
259
|
+
nsfw=nsfw if nsfw is not MISSING else channel_to_edit.nsfw,
|
|
260
|
+
overwrites=permissions if permissions is not MISSING else channel_to_edit.overwrites,
|
|
261
|
+
reason=reason)
|
|
262
|
+
|
|
263
|
+
return channel_to_edit.id
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
async def dshell_edit_voice_channel(ctx: Message,
|
|
267
|
+
channel=None,
|
|
268
|
+
name=None,
|
|
269
|
+
category=MISSING,
|
|
270
|
+
position=MISSING,
|
|
271
|
+
bitrate=MISSING,
|
|
272
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
273
|
+
reason=None):
|
|
274
|
+
"""
|
|
275
|
+
Edits a voice channel on the server
|
|
276
|
+
"""
|
|
277
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
278
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
279
|
+
|
|
280
|
+
if not isinstance(category, (_MissingSentinel, int)):
|
|
281
|
+
raise Exception(f"Category must be an integer, not {type(category)} !")
|
|
282
|
+
|
|
283
|
+
if not isinstance(bitrate, (_MissingSentinel, int)):
|
|
284
|
+
raise Exception(f"Bitrate must be an integer, not {type(bitrate)} !")
|
|
285
|
+
|
|
286
|
+
channel_to_edit = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
287
|
+
new_categoy = ctx.channel.category if isinstance(category, _MissingSentinel) else ctx.channel.guild.get_channel(category)
|
|
288
|
+
|
|
289
|
+
if channel_to_edit is None:
|
|
290
|
+
raise Exception(f"Channel {channel} not found !")
|
|
291
|
+
|
|
292
|
+
await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
|
|
293
|
+
position=position if position is not MISSING else channel_to_edit.position,
|
|
294
|
+
category=new_categoy,
|
|
295
|
+
bitrate=bitrate if bitrate is not MISSING else channel_to_edit.bitrate,
|
|
296
|
+
overwrites=permissions if permissions is not MISSING else channel_to_edit.overwrites,
|
|
297
|
+
reason=reason)
|
|
298
|
+
|
|
299
|
+
return channel_to_edit.id
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
async def dshell_create_thread_message(ctx: Message,
|
|
303
|
+
name,
|
|
304
|
+
message: Union[int, str] = None,
|
|
305
|
+
archive=MISSING,
|
|
306
|
+
slowmode=MISSING):
|
|
307
|
+
"""
|
|
308
|
+
Creates a thread from a message.
|
|
309
|
+
"""
|
|
310
|
+
|
|
311
|
+
if message is None:
|
|
312
|
+
message = ctx.id
|
|
313
|
+
|
|
314
|
+
message = utils_get_message(ctx, message)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
if not isinstance(name, str):
|
|
318
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
319
|
+
|
|
320
|
+
if not isinstance(archive, (_MissingSentinel, int)):
|
|
321
|
+
raise Exception(f"Auto archive duration must be an integer, not {type(archive)} !")
|
|
322
|
+
|
|
323
|
+
if not isinstance(archive, _MissingSentinel) and archive not in (60, 1440, 4320, 10080):
|
|
324
|
+
raise Exception("Auto archive duration must be one of the following values: 60, 1440, 4320, 10080 !")
|
|
325
|
+
|
|
326
|
+
if not isinstance(slowmode, (_MissingSentinel, int)):
|
|
327
|
+
raise Exception(f"Slowmode delay must be an integer, not {type(slowmode)} !")
|
|
328
|
+
|
|
329
|
+
if not isinstance(slowmode, _MissingSentinel) and slowmode < 0:
|
|
330
|
+
raise Exception("Slowmode delay must be a positive integer !")
|
|
331
|
+
|
|
332
|
+
if isinstance(message, PartialMessage):
|
|
333
|
+
m = await message.fetch()
|
|
334
|
+
else:
|
|
335
|
+
m = message
|
|
336
|
+
|
|
337
|
+
thread = await m.create_thread(name=name,
|
|
338
|
+
auto_archive_duration=archive,
|
|
339
|
+
slowmode_delay=slowmode)
|
|
340
|
+
|
|
341
|
+
return thread.id
|
|
342
|
+
|
|
343
|
+
async def dshell_edit_thread(ctx: Message,
|
|
344
|
+
thread: Union[int, str] = None,
|
|
345
|
+
name=None,
|
|
346
|
+
archive=MISSING,
|
|
347
|
+
slowmode=MISSING,
|
|
348
|
+
reason=None):
|
|
349
|
+
""" Edits a thread.
|
|
350
|
+
"""
|
|
351
|
+
if thread is None:
|
|
352
|
+
thread = ctx.thread
|
|
353
|
+
|
|
354
|
+
if thread is None:
|
|
355
|
+
raise Exception("Thread must be specified !")
|
|
356
|
+
|
|
357
|
+
thread = await utils_get_thread(ctx, thread)
|
|
358
|
+
|
|
359
|
+
if not isinstance(name, (_MissingSentinel, str)):
|
|
360
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
361
|
+
|
|
362
|
+
if not isinstance(archive, (_MissingSentinel, int)):
|
|
363
|
+
raise Exception(f"Auto archive duration must be an integer, not {type(archive)} !")
|
|
364
|
+
|
|
365
|
+
if not isinstance(archive, _MissingSentinel) and archive not in (60, 1440, 4320, 10080):
|
|
366
|
+
raise Exception("Auto archive duration must be one of the following values: 60, 1440, 4320, 10080 !")
|
|
367
|
+
|
|
368
|
+
if not isinstance(slowmode, (_MissingSentinel, int)):
|
|
369
|
+
raise Exception(f"Slowmode delay must be an integer, not {type(slowmode)} !")
|
|
370
|
+
|
|
371
|
+
if not isinstance(slowmode, _MissingSentinel) and slowmode < 0:
|
|
372
|
+
raise Exception("Slowmode delay must be a positive integer !")
|
|
373
|
+
|
|
374
|
+
await thread.edit(name=name if name is not None else thread.name,
|
|
375
|
+
auto_archive_duration=archive if archive is not MISSING else thread.auto_archive_duration,
|
|
376
|
+
slowmode_delay=slowmode if slowmode is not MISSING else thread.slowmode_delay,
|
|
377
|
+
reason=reason)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
async def dshell_get_thread(ctx: Message, message: Union[int, str] = None):
|
|
381
|
+
"""
|
|
382
|
+
Returns the thread object of the specified thread ID.
|
|
383
|
+
"""
|
|
384
|
+
|
|
385
|
+
if message is None:
|
|
386
|
+
message = ctx.id
|
|
387
|
+
|
|
388
|
+
target_message = utils_get_message(ctx, message)
|
|
389
|
+
if isinstance(target_message, PartialMessage):
|
|
390
|
+
message = await target_message.fetch()
|
|
391
|
+
else:
|
|
392
|
+
message = target_message
|
|
393
|
+
|
|
394
|
+
if not hasattr(message, 'thread'):
|
|
395
|
+
return None
|
|
396
|
+
|
|
397
|
+
thread = message.thread
|
|
398
|
+
|
|
399
|
+
if thread is None:
|
|
400
|
+
return None
|
|
401
|
+
|
|
402
|
+
return thread.id
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
async def dshell_delete_thread(ctx: Message, thread: Union[int, str] = None, reason=None):
|
|
406
|
+
"""
|
|
407
|
+
Deletes a thread.
|
|
408
|
+
"""
|
|
409
|
+
|
|
410
|
+
if thread is None:
|
|
411
|
+
thread = ctx.id
|
|
412
|
+
|
|
413
|
+
target_message = utils_get_message(ctx, thread)
|
|
414
|
+
if isinstance(target_message, PartialMessage):
|
|
415
|
+
thread = await target_message.fetch()
|
|
416
|
+
else:
|
|
417
|
+
thread = target_message
|
|
418
|
+
|
|
419
|
+
if not hasattr(thread, 'thread'):
|
|
420
|
+
raise Exception("The specified message does not have a thread !")
|
|
421
|
+
|
|
422
|
+
if thread.thread is None:
|
|
423
|
+
raise Exception("The specified message does not have a thread !")
|
|
424
|
+
|
|
425
|
+
await thread.thread.delete(reason=reason)
|
|
426
|
+
|
|
427
|
+
return thread.thread.id
|
|
428
|
+
|
|
429
|
+
async def dshell_create_category(ctx: Message,
|
|
430
|
+
name,
|
|
431
|
+
position=MISSING,
|
|
432
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
433
|
+
reason=None):
|
|
434
|
+
"""
|
|
435
|
+
Creates a category on the server
|
|
436
|
+
"""
|
|
437
|
+
|
|
438
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
439
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
440
|
+
|
|
441
|
+
created_category = await ctx.guild.create_category(str(name),
|
|
442
|
+
position=position,
|
|
443
|
+
overwrites=permissions,
|
|
444
|
+
reason=reason)
|
|
445
|
+
|
|
446
|
+
return created_category.id
|
|
447
|
+
|
|
448
|
+
async def dshell_edit_category(ctx: Message,
|
|
449
|
+
category,
|
|
450
|
+
name=None,
|
|
451
|
+
position=MISSING,
|
|
452
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
453
|
+
reason=None):
|
|
454
|
+
"""
|
|
455
|
+
Edits a category on the server
|
|
456
|
+
"""
|
|
457
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
458
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
459
|
+
|
|
460
|
+
category_to_edit = ctx.channel.guild.get_channel(category)
|
|
461
|
+
|
|
462
|
+
if category_to_edit is None or not isinstance(category_to_edit, CategoryChannel):
|
|
463
|
+
raise Exception(f"Category {category} not found or is not a category !")
|
|
464
|
+
|
|
465
|
+
await category_to_edit.edit(name=name if name is not None else category_to_edit.name,
|
|
466
|
+
position=position if position is not MISSING else category_to_edit.position,
|
|
467
|
+
overwrites=permissions if permissions is not MISSING else category_to_edit.overwrites,
|
|
468
|
+
reason=reason)
|
|
469
|
+
|
|
470
|
+
return category_to_edit.id
|
|
471
|
+
|
|
472
|
+
async def dshell_delete_category(ctx: Message, category=None, reason=None):
|
|
473
|
+
"""
|
|
474
|
+
Deletes a category.
|
|
475
|
+
"""
|
|
476
|
+
|
|
477
|
+
if category is None and ctx.channel.category is None:
|
|
478
|
+
raise Exception("Category must be specified !")
|
|
479
|
+
|
|
480
|
+
category_to_delete = ctx.channel.category if category is None else ctx.channel.guild.get_channel(category)
|
|
481
|
+
|
|
482
|
+
if category_to_delete is None or not isinstance(category_to_delete, CategoryChannel):
|
|
483
|
+
raise Exception(f"Category {category} not found or is not a category !")
|
|
484
|
+
|
|
485
|
+
await category_to_delete.delete(reason=reason)
|
|
486
|
+
|
|
487
|
+
return category_to_delete.id
|
|
488
|
+
|
|
489
|
+
############################# CHANNEL INFO ##############################
|
|
490
|
+
|
|
491
|
+
async def dshell_get_channel_category_id(ctx: Message, channel=None):
|
|
492
|
+
"""
|
|
493
|
+
Returns the category ID of a channel.
|
|
494
|
+
"""
|
|
495
|
+
|
|
496
|
+
channel_to_check = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
497
|
+
|
|
498
|
+
if channel_to_check is None:
|
|
499
|
+
raise Exception(f"Channel {channel} not found !")
|
|
500
|
+
|
|
501
|
+
if channel_to_check.category is None:
|
|
502
|
+
return None
|
|
503
|
+
|
|
504
|
+
return channel_to_check.category.id if channel_to_check.category is not None else 0
|
|
505
|
+
|
|
506
|
+
async def dshell_get_channel_nsfw(ctx: Message, channel=None):
|
|
507
|
+
"""
|
|
508
|
+
Returns if the channel is NSFW.
|
|
509
|
+
"""
|
|
510
|
+
|
|
511
|
+
channel_to_check = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
512
|
+
|
|
513
|
+
if channel_to_check is None:
|
|
514
|
+
raise Exception(f"Channel {channel} not found !")
|
|
515
|
+
|
|
516
|
+
return channel_to_check.nsfw
|
|
517
|
+
|
|
518
|
+
async def dshell_get_channel_slowmode(ctx: Message, channel=None):
|
|
519
|
+
"""
|
|
520
|
+
Returns the slowmode delay of a channel.
|
|
521
|
+
"""
|
|
522
|
+
|
|
523
|
+
channel_to_check = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
524
|
+
|
|
525
|
+
if channel_to_check is None:
|
|
526
|
+
raise Exception(f"Channel {channel} not found !")
|
|
527
|
+
|
|
528
|
+
if not hasattr(channel_to_check, 'slowmode_delay'):
|
|
529
|
+
raise Exception(f"Channel {channel} is not a text channel !")
|
|
530
|
+
|
|
531
|
+
return channel_to_check.slowmode_delay
|
|
532
|
+
|
|
533
|
+
async def dshell_get_channel_topic(ctx: Message, channel=None):
|
|
534
|
+
"""
|
|
535
|
+
Returns the topic of a channel.
|
|
536
|
+
"""
|
|
537
|
+
|
|
538
|
+
channel_to_check = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
539
|
+
|
|
540
|
+
if channel_to_check is None:
|
|
541
|
+
raise Exception(f"Channel {channel} not found !")
|
|
542
|
+
|
|
543
|
+
if not hasattr(channel_to_check, 'topic'):
|
|
544
|
+
raise Exception(f"Channel {channel} is not a text channel !")
|
|
545
|
+
|
|
546
|
+
return channel_to_check.topic
|
|
547
|
+
|
|
548
|
+
async def dshell_get_channel_threads(ctx: Message, channel=None):
|
|
549
|
+
"""
|
|
550
|
+
Returns the list of threads in a channel.
|
|
551
|
+
"""
|
|
552
|
+
|
|
553
|
+
channel_to_check = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
554
|
+
|
|
555
|
+
if channel_to_check is None:
|
|
556
|
+
raise Exception(f"Channel {channel} not found !")
|
|
557
|
+
|
|
558
|
+
if not hasattr(channel_to_check, 'threads'):
|
|
559
|
+
raise Exception(f"Channel {channel} is not a text channel !")
|
|
560
|
+
|
|
561
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
562
|
+
threads = ListNode([])
|
|
563
|
+
|
|
564
|
+
for thread in channel_to_check.threads:
|
|
565
|
+
threads.add(thread.id)
|
|
566
|
+
|
|
567
|
+
return threads
|
|
568
|
+
|
|
569
|
+
async def dshell_get_channel_position(ctx: Message, channel=None):
|
|
570
|
+
"""
|
|
571
|
+
Returns the position of a channel.
|
|
572
|
+
"""
|
|
573
|
+
|
|
574
|
+
channel_to_check = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
575
|
+
|
|
576
|
+
if channel_to_check is None:
|
|
577
|
+
raise Exception(f"Channel {channel} not found !")
|
|
578
|
+
|
|
579
|
+
return channel_to_check.position
|
|
580
|
+
|
|
581
|
+
async def dshell_get_channel_url(ctx: Message, channel=None):
|
|
582
|
+
"""
|
|
583
|
+
Returns the URL of a channel.
|
|
584
|
+
"""
|
|
585
|
+
|
|
586
|
+
channel_to_check = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
587
|
+
|
|
588
|
+
if channel_to_check is None:
|
|
589
|
+
raise Exception(f"Channel {channel} not found !")
|
|
590
|
+
|
|
591
|
+
return channel_to_check.jump_url
|
|
592
|
+
|
|
593
|
+
async def dshell_get_channel_voice_members(ctx: Message, channel=None):
|
|
594
|
+
"""
|
|
595
|
+
Returns the list of members in a voice channel.
|
|
596
|
+
"""
|
|
597
|
+
|
|
598
|
+
channel_to_check = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
599
|
+
|
|
600
|
+
if channel_to_check is None:
|
|
601
|
+
raise Exception(f"Channel {channel} not found !")
|
|
602
|
+
|
|
603
|
+
if not isinstance(channel_to_check, VoiceChannel):
|
|
604
|
+
raise Exception(f"Channel {channel} is not a voice channel !")
|
|
605
|
+
|
|
606
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
607
|
+
members = ListNode([])
|
|
608
|
+
|
|
609
|
+
for member in channel_to_check.members:
|
|
610
|
+
members.add(member.id)
|
|
611
|
+
|
|
612
|
+
return members
|