dshellInterpreter 0.2.8.2__tar.gz → 0.2.20.5__tar.gz
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.
Potentially problematic release.
This version of dshellInterpreter might be problematic. Click here for more details.
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/__init__.py +3 -1
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/dshell_channel.py +461 -0
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/dshell_interaction.py +89 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_member.py +31 -1
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/dshell_message.py +271 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_pastbin.py +5 -7
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_role.py +2 -1
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/utils/__init__.py +8 -0
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/utils/utils_global.py +155 -0
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/utils/utils_list.py +109 -0
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/utils/utils_member.py +30 -0
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/utils/utils_message.py +100 -0
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/utils/utils_permissions.py +79 -0
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/utils/utils_string.py +157 -0
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/utils/utils_thread.py +35 -0
- dshellinterpreter-0.2.20.5/Dshell/_DshellInterpreteur/__init__.py +3 -0
- dshellinterpreter-0.2.20.5/Dshell/_DshellInterpreteur/cached_messages.py +4 -0
- dshellinterpreter-0.2.20.5/Dshell/_DshellInterpreteur/dshell_interpreter.py +686 -0
- dshellinterpreter-0.2.20.5/Dshell/_DshellInterpreteur/errors.py +8 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/_DshellParser/ast_nodes.py +188 -35
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/_DshellParser/dshell_parser.py +114 -73
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/_DshellTokenizer/dshell_keywords.py +76 -60
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/_DshellTokenizer/dshell_token_type.py +1 -1
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/_DshellTokenizer/dshell_tokenizer.py +28 -25
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/__init__.py +1 -0
- {dshellinterpreter-0.2.8.2/dshellInterpreter.egg-info → dshellinterpreter-0.2.20.5}/PKG-INFO +2 -1
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5/dshellInterpreter.egg-info}/PKG-INFO +2 -1
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/dshellInterpreter.egg-info/SOURCES.txt +11 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/dshellInterpreter.egg-info/requires.txt +1 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/setup.py +8 -4
- dshellinterpreter-0.2.8.2/Dshell/DISCORD_COMMANDS/dshell_channel.py +0 -193
- dshellinterpreter-0.2.8.2/Dshell/DISCORD_COMMANDS/dshell_message.py +0 -200
- dshellinterpreter-0.2.8.2/Dshell/_DshellInterpreteur/__init__.py +0 -1
- dshellinterpreter-0.2.8.2/Dshell/_DshellInterpreteur/dshell_interpreter.py +0 -539
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/_DshellParser/__init__.py +0 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/_DshellTokenizer/__init__.py +0 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/_utils.py +0 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/LICENSE +0 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/README.md +0 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/dshellInterpreter.egg-info/dependency_links.txt +0 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/dshellInterpreter.egg-info/top_level.txt +0 -0
- {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/setup.cfg +0 -0
|
@@ -0,0 +1,461 @@
|
|
|
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
|
|
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
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
async def dshell_get_channel(ctx: Message, name):
|
|
31
|
+
"""
|
|
32
|
+
Returns the channel object of the channel where the command was executed or the specified channel.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
if isinstance(name, str):
|
|
36
|
+
return next((c.id for c in ctx.channel.guild.channels if c.name == name), None)
|
|
37
|
+
|
|
38
|
+
raise Exception(f"Channel must be an integer or a string, not {type(name)} !")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
async def dshell_get_channels(ctx: Message, name=None, regex=None):
|
|
42
|
+
"""
|
|
43
|
+
Returns a list of channels with the same name and/or matching the same regex.
|
|
44
|
+
If neither is set, it will return all channels in the server.
|
|
45
|
+
"""
|
|
46
|
+
if name is not None and not isinstance(name, str):
|
|
47
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
48
|
+
|
|
49
|
+
if regex is not None and not isinstance(regex, str):
|
|
50
|
+
raise Exception(f"Regex must be a string, not {type(regex)} !")
|
|
51
|
+
|
|
52
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
53
|
+
channels = ListNode([])
|
|
54
|
+
|
|
55
|
+
for channel in ctx.channel.guild.channels:
|
|
56
|
+
if name is not None and channel.name == str(name):
|
|
57
|
+
channels.add(channel.id)
|
|
58
|
+
|
|
59
|
+
elif regex is not None and search(regex, channel.name):
|
|
60
|
+
channels.add(channel.id)
|
|
61
|
+
|
|
62
|
+
return channels
|
|
63
|
+
|
|
64
|
+
async def dshell_get_channels_in_category(ctx: Message, category=None, name=None, regex=None):
|
|
65
|
+
"""
|
|
66
|
+
Returns a list of channels in a specific category with the same name and/or matching the same regex.
|
|
67
|
+
If neither is set, it will return all channels in the specified category.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
if category is None and ctx.channel.category is not None:
|
|
71
|
+
category = ctx.channel.category.id
|
|
72
|
+
|
|
73
|
+
if category is None:
|
|
74
|
+
raise Exception("Category must be specified !")
|
|
75
|
+
|
|
76
|
+
if not isinstance(category, int):
|
|
77
|
+
raise Exception(f"Category must be an integer, not {type(category)} !")
|
|
78
|
+
|
|
79
|
+
if name is not None and not isinstance(name, str):
|
|
80
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
81
|
+
|
|
82
|
+
if regex is not None and not isinstance(regex, str):
|
|
83
|
+
raise Exception(f"Regex must be a string, not {type(regex)} !")
|
|
84
|
+
|
|
85
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
86
|
+
channels = ListNode([])
|
|
87
|
+
|
|
88
|
+
category_channel = ctx.channel.guild.get_channel(category)
|
|
89
|
+
if category_channel is None or not hasattr(category_channel, 'channels'):
|
|
90
|
+
raise Exception(f"Category {category} not found or does not contain channels !")
|
|
91
|
+
|
|
92
|
+
for channel in category_channel.channels:
|
|
93
|
+
if name is not None and channel.name == str(name):
|
|
94
|
+
channels.add(channel.id)
|
|
95
|
+
|
|
96
|
+
elif regex is not None and search(regex, channel.name):
|
|
97
|
+
channels.add(channel.id)
|
|
98
|
+
|
|
99
|
+
return channels
|
|
100
|
+
|
|
101
|
+
async def dshell_create_text_channel(ctx: Message,
|
|
102
|
+
name,
|
|
103
|
+
category=None,
|
|
104
|
+
position=MISSING,
|
|
105
|
+
slowmode=MISSING,
|
|
106
|
+
topic=MISSING,
|
|
107
|
+
nsfw=MISSING,
|
|
108
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
109
|
+
reason=None):
|
|
110
|
+
"""
|
|
111
|
+
Creates a text channel on the server
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
115
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
116
|
+
|
|
117
|
+
if not isinstance(slowmode, (_MissingSentinel, int)):
|
|
118
|
+
raise Exception(f"Slowmode must be an integer, not {type(slowmode)} !")
|
|
119
|
+
|
|
120
|
+
if not isinstance(topic, (_MissingSentinel, str)):
|
|
121
|
+
raise Exception(f"Topic must be a string, not {type(topic)} !")
|
|
122
|
+
|
|
123
|
+
if not isinstance(nsfw, (_MissingSentinel, bool)):
|
|
124
|
+
raise Exception(f"NSFW must be a boolean, not {type(nsfw)} !")
|
|
125
|
+
|
|
126
|
+
channel_category = ctx.channel.category if category is None else ctx.channel.guild.get_channel(category)
|
|
127
|
+
|
|
128
|
+
created_channel = await ctx.guild.create_text_channel(str(name),
|
|
129
|
+
category=channel_category,
|
|
130
|
+
position=position,
|
|
131
|
+
slowmode_delay=slowmode,
|
|
132
|
+
topic=topic,
|
|
133
|
+
nsfw=nsfw,
|
|
134
|
+
overwrites=permissions,
|
|
135
|
+
reason=reason)
|
|
136
|
+
|
|
137
|
+
return created_channel.id
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
async def dshell_create_voice_channel(ctx: Message,
|
|
141
|
+
name,
|
|
142
|
+
category=None,
|
|
143
|
+
position=MISSING,
|
|
144
|
+
bitrate=MISSING,
|
|
145
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
146
|
+
reason=None):
|
|
147
|
+
"""
|
|
148
|
+
Creates a voice channel on the server
|
|
149
|
+
"""
|
|
150
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
151
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
152
|
+
|
|
153
|
+
if not isinstance(bitrate, (_MissingSentinel, int)):
|
|
154
|
+
raise Exception(f"Bitrate must be an integer, not {type(bitrate)} !")
|
|
155
|
+
|
|
156
|
+
channel_category = ctx.channel.category if category is None else ctx.channel.guild.get_channel(category)
|
|
157
|
+
|
|
158
|
+
created_channel = await ctx.guild.create_voice_channel(str(name),
|
|
159
|
+
category=channel_category,
|
|
160
|
+
position=position,
|
|
161
|
+
bitrate=bitrate,
|
|
162
|
+
overwrites=permissions,
|
|
163
|
+
reason=reason)
|
|
164
|
+
|
|
165
|
+
return created_channel.id
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
async def dshell_delete_channel(ctx: Message, channel=None, reason=None, timeout=0):
|
|
169
|
+
"""
|
|
170
|
+
Deletes a channel.
|
|
171
|
+
You can add a waiting time before it is deleted (in seconds)
|
|
172
|
+
"""
|
|
173
|
+
if not isinstance(timeout, int):
|
|
174
|
+
raise Exception(f'Timeout must be an integer, not {type(timeout)} !')
|
|
175
|
+
|
|
176
|
+
channel_to_delete = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
177
|
+
|
|
178
|
+
if channel_to_delete is None:
|
|
179
|
+
raise Exception(f"Channel {channel} not found !")
|
|
180
|
+
|
|
181
|
+
await sleep(timeout)
|
|
182
|
+
|
|
183
|
+
await channel_to_delete.delete(reason=reason)
|
|
184
|
+
|
|
185
|
+
return channel_to_delete.id
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
async def dshell_delete_channels(ctx: Message, name=None, regex=None, reason=None):
|
|
189
|
+
"""
|
|
190
|
+
Deletes all channels with the same name and/or matching the same regex.
|
|
191
|
+
If neither is set, it will delete all channels with the same name as the one where the command was executed.
|
|
192
|
+
"""
|
|
193
|
+
if name is not None and not isinstance(name, str):
|
|
194
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
195
|
+
|
|
196
|
+
if regex is not None and not isinstance(regex, str):
|
|
197
|
+
raise Exception(f"Regex must be a string, not {type(regex)} !")
|
|
198
|
+
|
|
199
|
+
for channel in ctx.channel.guild.channels:
|
|
200
|
+
|
|
201
|
+
if name is not None and channel.name == str(name):
|
|
202
|
+
await channel.delete(reason=reason)
|
|
203
|
+
|
|
204
|
+
elif regex is not None and search(regex, channel.name):
|
|
205
|
+
await channel.delete(reason=reason)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
async def dshell_edit_text_channel(ctx: Message,
|
|
209
|
+
channel=None,
|
|
210
|
+
name=None,
|
|
211
|
+
category=MISSING,
|
|
212
|
+
position=MISSING,
|
|
213
|
+
slowmode=MISSING,
|
|
214
|
+
topic=MISSING,
|
|
215
|
+
nsfw=MISSING,
|
|
216
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
217
|
+
reason=None):
|
|
218
|
+
"""
|
|
219
|
+
Edits a text channel on the server
|
|
220
|
+
"""
|
|
221
|
+
if name is not None and not isinstance(name, str):
|
|
222
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
223
|
+
|
|
224
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
225
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
226
|
+
|
|
227
|
+
if not isinstance(category, (_MissingSentinel, int)):
|
|
228
|
+
raise Exception(f"Category must be an integer, not {type(category)} !")
|
|
229
|
+
|
|
230
|
+
if not isinstance(slowmode, (_MissingSentinel, int)):
|
|
231
|
+
raise Exception(f"Slowmode must be an integer, not {type(slowmode)} !")
|
|
232
|
+
|
|
233
|
+
if not isinstance(topic, (_MissingSentinel, str)):
|
|
234
|
+
raise Exception(f"Topic must be a string, not {type(topic)} !")
|
|
235
|
+
|
|
236
|
+
if not isinstance(nsfw, (_MissingSentinel, bool)):
|
|
237
|
+
raise Exception(f"NSFW must be a boolean, not {type(nsfw)} !")
|
|
238
|
+
|
|
239
|
+
channel_to_edit = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
240
|
+
new_categoy = ctx.channel.category if isinstance(category, _MissingSentinel) else ctx.channel.guild.get_channel(category)
|
|
241
|
+
|
|
242
|
+
if channel_to_edit is None:
|
|
243
|
+
raise Exception(f"Channel {channel} not found !")
|
|
244
|
+
|
|
245
|
+
await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
|
|
246
|
+
position=position if position is not MISSING else channel_to_edit.position,
|
|
247
|
+
category=new_categoy,
|
|
248
|
+
slowmode_delay=slowmode if slowmode is not MISSING else channel_to_edit.slowmode_delay,
|
|
249
|
+
topic=topic if topic is not MISSING else channel_to_edit.topic,
|
|
250
|
+
nsfw=nsfw if nsfw is not MISSING else channel_to_edit.nsfw,
|
|
251
|
+
overwrites=permissions if permissions is not MISSING else channel_to_edit.overwrites,
|
|
252
|
+
reason=reason)
|
|
253
|
+
|
|
254
|
+
return channel_to_edit.id
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
async def dshell_edit_voice_channel(ctx: Message,
|
|
258
|
+
channel=None,
|
|
259
|
+
name=None,
|
|
260
|
+
category=MISSING,
|
|
261
|
+
position=MISSING,
|
|
262
|
+
bitrate=MISSING,
|
|
263
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
264
|
+
reason=None):
|
|
265
|
+
"""
|
|
266
|
+
Edits a voice channel on the server
|
|
267
|
+
"""
|
|
268
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
269
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
270
|
+
|
|
271
|
+
if not isinstance(category, (_MissingSentinel, int)):
|
|
272
|
+
raise Exception(f"Category must be an integer, not {type(category)} !")
|
|
273
|
+
|
|
274
|
+
if not isinstance(bitrate, (_MissingSentinel, int)):
|
|
275
|
+
raise Exception(f"Bitrate must be an integer, not {type(bitrate)} !")
|
|
276
|
+
|
|
277
|
+
channel_to_edit = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
278
|
+
new_categoy = ctx.channel.category if isinstance(category, _MissingSentinel) else ctx.channel.guild.get_channel(category)
|
|
279
|
+
|
|
280
|
+
if channel_to_edit is None:
|
|
281
|
+
raise Exception(f"Channel {channel} not found !")
|
|
282
|
+
|
|
283
|
+
await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
|
|
284
|
+
position=position if position is not MISSING else channel_to_edit.position,
|
|
285
|
+
category=new_categoy,
|
|
286
|
+
bitrate=bitrate if bitrate is not MISSING else channel_to_edit.bitrate,
|
|
287
|
+
overwrites=permissions if permissions is not MISSING else channel_to_edit.overwrites,
|
|
288
|
+
reason=reason)
|
|
289
|
+
|
|
290
|
+
return channel_to_edit.id
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
async def dshell_create_thread_message(ctx: Message,
|
|
294
|
+
name,
|
|
295
|
+
message: Union[int, str] = None,
|
|
296
|
+
archive=MISSING,
|
|
297
|
+
slowmode=MISSING):
|
|
298
|
+
"""
|
|
299
|
+
Creates a thread from a message.
|
|
300
|
+
"""
|
|
301
|
+
|
|
302
|
+
if message is None:
|
|
303
|
+
message = ctx.id
|
|
304
|
+
|
|
305
|
+
message = utils_get_message(ctx, message)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
if not isinstance(name, str):
|
|
309
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
310
|
+
|
|
311
|
+
if not isinstance(archive, (_MissingSentinel, int)):
|
|
312
|
+
raise Exception(f"Auto archive duration must be an integer, not {type(archive)} !")
|
|
313
|
+
|
|
314
|
+
if not isinstance(archive, _MissingSentinel) and archive not in (60, 1440, 4320, 10080):
|
|
315
|
+
raise Exception("Auto archive duration must be one of the following values: 60, 1440, 4320, 10080 !")
|
|
316
|
+
|
|
317
|
+
if not isinstance(slowmode, (_MissingSentinel, int)):
|
|
318
|
+
raise Exception(f"Slowmode delay must be an integer, not {type(slowmode)} !")
|
|
319
|
+
|
|
320
|
+
if not isinstance(slowmode, _MissingSentinel) and slowmode < 0:
|
|
321
|
+
raise Exception("Slowmode delay must be a positive integer !")
|
|
322
|
+
|
|
323
|
+
if isinstance(message, PartialMessage):
|
|
324
|
+
m = await message.fetch()
|
|
325
|
+
else:
|
|
326
|
+
m = message
|
|
327
|
+
|
|
328
|
+
thread = await m.create_thread(name=name,
|
|
329
|
+
auto_archive_duration=archive,
|
|
330
|
+
slowmode_delay=slowmode)
|
|
331
|
+
|
|
332
|
+
return thread.id
|
|
333
|
+
|
|
334
|
+
async def dshell_edit_thread(ctx: Message,
|
|
335
|
+
thread: Union[int, str] = None,
|
|
336
|
+
name=None,
|
|
337
|
+
archive=MISSING,
|
|
338
|
+
slowmode=MISSING,
|
|
339
|
+
reason=None):
|
|
340
|
+
""" Edits a thread.
|
|
341
|
+
"""
|
|
342
|
+
if thread is None:
|
|
343
|
+
thread = ctx.thread
|
|
344
|
+
|
|
345
|
+
if thread is None:
|
|
346
|
+
raise Exception("Thread must be specified !")
|
|
347
|
+
|
|
348
|
+
thread = await utils_get_thread(ctx, thread)
|
|
349
|
+
|
|
350
|
+
if not isinstance(name, (_MissingSentinel, str)):
|
|
351
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
352
|
+
|
|
353
|
+
if not isinstance(archive, (_MissingSentinel, int)):
|
|
354
|
+
raise Exception(f"Auto archive duration must be an integer, not {type(archive)} !")
|
|
355
|
+
|
|
356
|
+
if not isinstance(archive, _MissingSentinel) and archive not in (60, 1440, 4320, 10080):
|
|
357
|
+
raise Exception("Auto archive duration must be one of the following values: 60, 1440, 4320, 10080 !")
|
|
358
|
+
|
|
359
|
+
if not isinstance(slowmode, (_MissingSentinel, int)):
|
|
360
|
+
raise Exception(f"Slowmode delay must be an integer, not {type(slowmode)} !")
|
|
361
|
+
|
|
362
|
+
if not isinstance(slowmode, _MissingSentinel) and slowmode < 0:
|
|
363
|
+
raise Exception("Slowmode delay must be a positive integer !")
|
|
364
|
+
|
|
365
|
+
await thread.edit(name=name if name is not None else thread.name,
|
|
366
|
+
auto_archive_duration=archive if archive is not MISSING else thread.auto_archive_duration,
|
|
367
|
+
slowmode_delay=slowmode if slowmode is not MISSING else thread.slowmode_delay,
|
|
368
|
+
reason=reason)
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
async def dshell_get_thread(ctx: Message, message: Union[int, str] = None):
|
|
372
|
+
"""
|
|
373
|
+
Returns the thread object of the specified thread ID.
|
|
374
|
+
"""
|
|
375
|
+
|
|
376
|
+
if message is None:
|
|
377
|
+
message = ctx.id
|
|
378
|
+
|
|
379
|
+
target_message = utils_get_message(ctx, message)
|
|
380
|
+
if isinstance(target_message, PartialMessage):
|
|
381
|
+
message = await target_message.fetch()
|
|
382
|
+
else:
|
|
383
|
+
message = target_message
|
|
384
|
+
|
|
385
|
+
if not hasattr(message, 'thread'):
|
|
386
|
+
return None
|
|
387
|
+
|
|
388
|
+
thread = message.thread
|
|
389
|
+
|
|
390
|
+
if thread is None:
|
|
391
|
+
return None
|
|
392
|
+
|
|
393
|
+
return thread.id
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
async def dshell_delete_thread(ctx: Message, thread: Union[int, str] = None, reason=None):
|
|
397
|
+
"""
|
|
398
|
+
Deletes a thread.
|
|
399
|
+
"""
|
|
400
|
+
|
|
401
|
+
if thread is None:
|
|
402
|
+
thread = ctx.id
|
|
403
|
+
|
|
404
|
+
target_message = utils_get_message(ctx, thread)
|
|
405
|
+
if isinstance(target_message, PartialMessage):
|
|
406
|
+
thread = await target_message.fetch()
|
|
407
|
+
else:
|
|
408
|
+
thread = target_message
|
|
409
|
+
|
|
410
|
+
if not hasattr(thread, 'thread'):
|
|
411
|
+
raise Exception("The specified message does not have a thread !")
|
|
412
|
+
|
|
413
|
+
if thread.thread is None:
|
|
414
|
+
raise Exception("The specified message does not have a thread !")
|
|
415
|
+
|
|
416
|
+
await thread.thread.delete(reason=reason)
|
|
417
|
+
|
|
418
|
+
return thread.thread.id
|
|
419
|
+
|
|
420
|
+
async def dshell_create_category(ctx: Message,
|
|
421
|
+
name,
|
|
422
|
+
position=MISSING,
|
|
423
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
424
|
+
reason=None):
|
|
425
|
+
"""
|
|
426
|
+
Creates a category on the server
|
|
427
|
+
"""
|
|
428
|
+
|
|
429
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
430
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
431
|
+
|
|
432
|
+
created_category = await ctx.guild.create_category(str(name),
|
|
433
|
+
position=position,
|
|
434
|
+
overwrites=permissions,
|
|
435
|
+
reason=reason)
|
|
436
|
+
|
|
437
|
+
return created_category.id
|
|
438
|
+
|
|
439
|
+
async def dshell_edit_category(ctx: Message,
|
|
440
|
+
category,
|
|
441
|
+
name=None,
|
|
442
|
+
position=MISSING,
|
|
443
|
+
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
444
|
+
reason=None):
|
|
445
|
+
"""
|
|
446
|
+
Edits a category on the server
|
|
447
|
+
"""
|
|
448
|
+
if not isinstance(position, (_MissingSentinel, int)):
|
|
449
|
+
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
450
|
+
|
|
451
|
+
category_to_edit = ctx.channel.guild.get_channel(category)
|
|
452
|
+
|
|
453
|
+
if category_to_edit is None or not isinstance(category_to_edit, CategoryChannel):
|
|
454
|
+
raise Exception(f"Category {category} not found or is not a category !")
|
|
455
|
+
|
|
456
|
+
await category_to_edit.edit(name=name if name is not None else category_to_edit.name,
|
|
457
|
+
position=position if position is not MISSING else category_to_edit.position,
|
|
458
|
+
overwrites=permissions if permissions is not MISSING else category_to_edit.overwrites,
|
|
459
|
+
reason=reason)
|
|
460
|
+
|
|
461
|
+
return category_to_edit.id
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
__all__ = [
|
|
2
|
+
'dshell_respond_interaction',
|
|
3
|
+
'dshell_defer_interaction',
|
|
4
|
+
'dshell_delete_original_message'
|
|
5
|
+
]
|
|
6
|
+
|
|
7
|
+
from types import NoneType
|
|
8
|
+
from discord import Interaction, Embed, AllowedMentions
|
|
9
|
+
from pycordViews import EasyModifiedViews
|
|
10
|
+
|
|
11
|
+
from .utils.utils_message import utils_autorised_mentions
|
|
12
|
+
|
|
13
|
+
async def dshell_respond_interaction(ctx: Interaction,
|
|
14
|
+
content: str = None,
|
|
15
|
+
delete=None,
|
|
16
|
+
global_mentions: bool = None,
|
|
17
|
+
everyone_mention: bool = True,
|
|
18
|
+
roles_mentions: bool = True,
|
|
19
|
+
users_mentions: bool = True,
|
|
20
|
+
reply_mention: bool = False,
|
|
21
|
+
hide: bool = False,
|
|
22
|
+
embeds=None,
|
|
23
|
+
view=None) -> int:
|
|
24
|
+
"""
|
|
25
|
+
Responds to a message interaction on Discord
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
if not isinstance(ctx, Interaction):
|
|
29
|
+
raise Exception(f'Respond to an interaction must be used in an interaction context, not {type(ctx)} !')
|
|
30
|
+
|
|
31
|
+
if delete is not None and not isinstance(delete, (int, float)):
|
|
32
|
+
raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
|
|
33
|
+
|
|
34
|
+
if not isinstance(hide, bool):
|
|
35
|
+
raise Exception(f'Hide parameter must be a boolean, not {type(hide)} !')
|
|
36
|
+
|
|
37
|
+
allowed_mentions = utils_autorised_mentions(global_mentions,
|
|
38
|
+
everyone_mention,
|
|
39
|
+
roles_mentions,
|
|
40
|
+
users_mentions,
|
|
41
|
+
reply_mention)
|
|
42
|
+
|
|
43
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
44
|
+
|
|
45
|
+
if not isinstance(embeds, (ListNode, Embed, NoneType)):
|
|
46
|
+
raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
|
|
47
|
+
|
|
48
|
+
if embeds is None:
|
|
49
|
+
embeds = ListNode([])
|
|
50
|
+
|
|
51
|
+
elif isinstance(embeds, Embed):
|
|
52
|
+
embeds = ListNode([embeds])
|
|
53
|
+
|
|
54
|
+
if not isinstance(view, (EasyModifiedViews, NoneType)):
|
|
55
|
+
raise Exception(f'View must be an UI bloc or None, not {type(view)} !')
|
|
56
|
+
|
|
57
|
+
sended_message = await ctx.response.send_message(
|
|
58
|
+
content=str(content),
|
|
59
|
+
ephemeral=hide,
|
|
60
|
+
allowed_mentions=allowed_mentions,
|
|
61
|
+
delete_after=delete,
|
|
62
|
+
embeds=embeds,
|
|
63
|
+
view=view)
|
|
64
|
+
|
|
65
|
+
return sended_message.id
|
|
66
|
+
|
|
67
|
+
async def dshell_defer_interaction(ctx: Interaction) -> bool:
|
|
68
|
+
"""
|
|
69
|
+
Defer a message interaction on Discord
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
if not isinstance(ctx, Interaction):
|
|
73
|
+
raise Exception(f'Respond to an interaction must be used in an interaction context, not {type(ctx)} !')
|
|
74
|
+
|
|
75
|
+
await ctx.response.defer()
|
|
76
|
+
|
|
77
|
+
return True
|
|
78
|
+
|
|
79
|
+
async def dshell_delete_original_message(ctx: Interaction) -> int:
|
|
80
|
+
"""
|
|
81
|
+
Delete the original message of an interaction on Discord
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
if not isinstance(ctx, Interaction):
|
|
85
|
+
raise Exception(f'Respond to an interaction must be used in an interaction context, not {type(ctx)} !')
|
|
86
|
+
|
|
87
|
+
await ctx.delete_original_message()
|
|
88
|
+
|
|
89
|
+
return ctx.message.id
|
{dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_member.py
RENAMED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
from datetime import timedelta, datetime, UTC
|
|
2
2
|
|
|
3
|
-
from discord import MISSING, Message, Member, Permissions, Role
|
|
3
|
+
from discord import MISSING, Message, Member, Permissions, Role, Embed
|
|
4
4
|
|
|
5
5
|
__all__ = [
|
|
6
|
+
"dshell_send_private_message",
|
|
6
7
|
"dshell_ban_member",
|
|
7
8
|
"dshell_unban_member",
|
|
8
9
|
"dshell_kick_member",
|
|
@@ -16,6 +17,35 @@ __all__ = [
|
|
|
16
17
|
"dshell_remove_member_roles"
|
|
17
18
|
]
|
|
18
19
|
|
|
20
|
+
async def dshell_send_private_message(ctx: Message, message: str = None, member: int = None, delete: int = None, embeds = None, ):
|
|
21
|
+
"""
|
|
22
|
+
Sends a private message to a member.
|
|
23
|
+
If member is None, sends the message to the author of the command.
|
|
24
|
+
If delete is specified, deletes the message after the specified time in seconds.
|
|
25
|
+
"""
|
|
26
|
+
if delete is not None and not isinstance(delete, (int, float)):
|
|
27
|
+
raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
|
|
28
|
+
|
|
29
|
+
member_to_send = ctx.author if member is None else ctx.channel.guild.get_member(member)
|
|
30
|
+
|
|
31
|
+
if member_to_send is None:
|
|
32
|
+
raise Exception(f'Member {member} not found!')
|
|
33
|
+
|
|
34
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
35
|
+
|
|
36
|
+
if embeds is None:
|
|
37
|
+
embeds = ListNode([])
|
|
38
|
+
|
|
39
|
+
elif isinstance(embeds, Embed):
|
|
40
|
+
embeds = ListNode([embeds])
|
|
41
|
+
|
|
42
|
+
else:
|
|
43
|
+
raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
|
|
44
|
+
|
|
45
|
+
sended_message = await member_to_send.send(message, delete_after=delete, embeds=embeds)
|
|
46
|
+
|
|
47
|
+
return sended_message.id
|
|
48
|
+
|
|
19
49
|
|
|
20
50
|
async def dshell_ban_member(ctx: Message, member: int, reason: str = MISSING):
|
|
21
51
|
"""
|