dshellInterpreter 0.2.8.2__tar.gz → 0.2.9__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.

Files changed (28) hide show
  1. dshellinterpreter-0.2.9/Dshell/DISCORD_COMMANDS/dshell_channel.py +442 -0
  2. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_DshellParser/ast_nodes.py +1 -2
  3. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_DshellTokenizer/dshell_keywords.py +11 -2
  4. {dshellinterpreter-0.2.8.2/dshellInterpreter.egg-info → dshellinterpreter-0.2.9}/PKG-INFO +1 -1
  5. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9/dshellInterpreter.egg-info}/PKG-INFO +1 -1
  6. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/setup.py +1 -1
  7. dshellinterpreter-0.2.8.2/Dshell/DISCORD_COMMANDS/dshell_channel.py +0 -193
  8. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/DISCORD_COMMANDS/__init__.py +0 -0
  9. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/DISCORD_COMMANDS/dshell_member.py +0 -0
  10. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/DISCORD_COMMANDS/dshell_message.py +0 -0
  11. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/DISCORD_COMMANDS/dshell_pastbin.py +0 -0
  12. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/DISCORD_COMMANDS/dshell_role.py +0 -0
  13. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_DshellInterpreteur/__init__.py +0 -0
  14. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_DshellInterpreteur/dshell_interpreter.py +0 -0
  15. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_DshellParser/__init__.py +0 -0
  16. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_DshellParser/dshell_parser.py +0 -0
  17. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_DshellTokenizer/__init__.py +0 -0
  18. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_DshellTokenizer/dshell_token_type.py +0 -0
  19. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_DshellTokenizer/dshell_tokenizer.py +0 -0
  20. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/__init__.py +0 -0
  21. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/Dshell/_utils.py +0 -0
  22. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/LICENSE +0 -0
  23. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/README.md +0 -0
  24. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/dshellInterpreter.egg-info/SOURCES.txt +0 -0
  25. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/dshellInterpreter.egg-info/dependency_links.txt +0 -0
  26. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/dshellInterpreter.egg-info/requires.txt +0 -0
  27. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/dshellInterpreter.egg-info/top_level.txt +0 -0
  28. {dshellinterpreter-0.2.8.2 → dshellinterpreter-0.2.9}/setup.cfg +0 -0
@@ -0,0 +1,442 @@
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, Thread
6
+ from discord.utils import _MissingSentinel
7
+ from discord import NotFound
8
+
9
+ __all__ = [
10
+ 'dshell_get_channel',
11
+ 'dshell_get_channels',
12
+ 'dshell_get_thread',
13
+ 'dshell_get_channels_in_category',
14
+ 'dshell_create_text_channel',
15
+ 'dshell_create_thread_message',
16
+ 'dshell_delete_channel',
17
+ 'dshell_delete_channels',
18
+ 'dshell_delete_thread',
19
+ 'dshell_create_voice_channel',
20
+ 'dshell_edit_text_channel',
21
+ 'dshell_edit_voice_channel',
22
+ 'dshell_edit_thread'
23
+ ]
24
+
25
+ async def utils_get_message(ctx: Message, message: Union[int, str]) -> Message:
26
+ """
27
+ Returns the message object of the specified message ID or link.
28
+ Message is only available in the same server as the command and in the same channel.
29
+ If the message is a link, it must be in the format: https://discord.com/channels/{guild_id}/{channel_id}/{message_id}
30
+ """
31
+
32
+ if isinstance(message, int):
33
+ return await ctx.channel.fetch_message(message)
34
+
35
+ elif isinstance(message, str):
36
+ match = search(r'https://discord\.com/channels/(\d+)/(\d+)/(\d+)', message)
37
+ if not match:
38
+ raise Exception("Invalid message link format. Use a valid Discord message link.")
39
+ guild_id = int(match.group(1))
40
+ channel_id = int(match.group(2))
41
+ message_id = int(match.group(3))
42
+
43
+ if guild_id != ctx.guild.id:
44
+ raise Exception("The message must be from the same server as the command !")
45
+
46
+ return await ctx.guild.get_channel(channel_id).fetch_message(message_id)
47
+
48
+ raise Exception(f"Message must be an integer or a string, not {type(message)} !")
49
+
50
+ async def utils_get_thread(ctx: Message, thread: Union[int, str]) -> Thread:
51
+ """
52
+ Returns the thread object of the specified thread ID or link.
53
+ Thread is only available in the same server as the command and in the same channel.
54
+ If the thread is a link, it must be in the format: https://discord.com/channels/{guild_id}/{channel_id}/{message_id}
55
+ """
56
+
57
+ if isinstance(thread, int):
58
+ return ctx.channel.get_thread(thread)
59
+
60
+ elif isinstance(thread, str):
61
+ match = search(r'https://discord\.com/channels/(\d+)/(\d+)(/\d+)?', thread)
62
+ if not match:
63
+ raise Exception("Invalid thread link format. Use a valid Discord thread link.")
64
+ guild_id = int(match.group(1))
65
+ message_id = int(match.group(2))
66
+ channel_id = ctx.channel.id if len(match.groups()) == 3 else ctx.channel.id
67
+
68
+ if guild_id != ctx.guild.id:
69
+ raise Exception("The thread must be from the same server as the command !")
70
+
71
+ try:
72
+ c = await ctx.guild.get_channel(channel_id).fetch_message(message_id)
73
+ return c.thread
74
+ except NotFound:
75
+ raise Exception(f"Thread with ID {message_id} not found in channel {channel_id} !")
76
+
77
+ raise Exception(f"Thread must be an integer or a string, not {type(thread)} !")
78
+
79
+
80
+ async def dshell_get_channel(ctx: Message, name):
81
+ """
82
+ Returns the channel object of the channel where the command was executed or the specified channel.
83
+ """
84
+
85
+ if isinstance(name, str):
86
+ return next((c.id for c in ctx.channel.guild.channels if c.name == name), None)
87
+
88
+ raise Exception(f"Channel must be an integer or a string, not {type(name)} !")
89
+
90
+
91
+ async def dshell_get_channels(ctx: Message, name=None, regex=None):
92
+ """
93
+ Returns a list of channels with the same name and/or matching the same regex.
94
+ If neither is set, it will return all channels in the server.
95
+ """
96
+ if name is not None and not isinstance(name, str):
97
+ raise Exception(f"Name must be a string, not {type(name)} !")
98
+
99
+ if regex is not None and not isinstance(regex, str):
100
+ raise Exception(f"Regex must be a string, not {type(regex)} !")
101
+
102
+ from .._DshellParser.ast_nodes import ListNode
103
+ channels = ListNode([])
104
+
105
+ for channel in ctx.channel.guild.channels:
106
+ if name is not None and channel.name == str(name):
107
+ channels.add(channel.id)
108
+
109
+ elif regex is not None and search(regex, channel.name):
110
+ channels.add(channel.id)
111
+
112
+ return channels
113
+
114
+ async def dshell_get_channels_in_category(ctx: Message, category=None, name=None, regex=None):
115
+ """
116
+ Returns a list of channels in a specific category with the same name and/or matching the same regex.
117
+ If neither is set, it will return all channels in the specified category.
118
+ """
119
+
120
+ if category is None and ctx.channel.category is not None:
121
+ category = ctx.channel.category.id
122
+
123
+ if category is None:
124
+ raise Exception("Category must be specified !")
125
+
126
+ if not isinstance(category, int):
127
+ raise Exception(f"Category must be an integer, not {type(category)} !")
128
+
129
+ if name is not None and not isinstance(name, str):
130
+ raise Exception(f"Name must be a string, not {type(name)} !")
131
+
132
+ if regex is not None and not isinstance(regex, str):
133
+ raise Exception(f"Regex must be a string, not {type(regex)} !")
134
+
135
+ from .._DshellParser.ast_nodes import ListNode
136
+ channels = ListNode([])
137
+
138
+ category_channel = ctx.channel.guild.get_channel(category)
139
+ if category_channel is None or not hasattr(category_channel, 'channels'):
140
+ raise Exception(f"Category {category} not found or does not contain channels !")
141
+
142
+ for channel in category_channel.channels:
143
+ if name is not None and channel.name == str(name):
144
+ channels.add(channel.id)
145
+
146
+ elif regex is not None and search(regex, channel.name):
147
+ channels.add(channel.id)
148
+
149
+ return channels
150
+
151
+ async def dshell_create_text_channel(ctx: Message,
152
+ name,
153
+ category=None,
154
+ position=MISSING,
155
+ slowmode=MISSING,
156
+ topic=MISSING,
157
+ nsfw=MISSING,
158
+ permission: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
159
+ reason=None):
160
+ """
161
+ Creates a text channel on the server
162
+ """
163
+
164
+ if not isinstance(position, _MissingSentinel) and not isinstance(position, int):
165
+ raise Exception(f"Position must be an integer, not {type(position)} !")
166
+
167
+ if not isinstance(slowmode, _MissingSentinel) and not isinstance(slowmode, int):
168
+ raise Exception(f"Slowmode must be an integer, not {type(slowmode)} !")
169
+
170
+ if not isinstance(topic, _MissingSentinel) and not isinstance(topic, str):
171
+ raise Exception(f"Topic must be a string, not {type(topic)} !")
172
+
173
+ if not isinstance(nsfw, _MissingSentinel) and not isinstance(nsfw, bool):
174
+ raise Exception(f"NSFW must be a boolean, not {type(nsfw)} !")
175
+
176
+ channel_category = ctx.channel.category if category is None else ctx.channel.guild.get_channel(category)
177
+
178
+ created_channel = await ctx.guild.create_text_channel(str(name),
179
+ category=channel_category,
180
+ position=position,
181
+ slowmode_delay=slowmode,
182
+ topic=topic,
183
+ nsfw=nsfw,
184
+ overwrites=permission,
185
+ reason=reason)
186
+
187
+ return created_channel.id
188
+
189
+
190
+ async def dshell_create_voice_channel(ctx: Message,
191
+ name,
192
+ category=None,
193
+ position=MISSING,
194
+ bitrate=MISSING,
195
+ permission: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
196
+ reason=None):
197
+ """
198
+ Creates a voice channel on the server
199
+ """
200
+ if not isinstance(position, _MissingSentinel) and not isinstance(position, int):
201
+ raise Exception(f"Position must be an integer, not {type(position)} !")
202
+
203
+ if not isinstance(bitrate, _MissingSentinel) and not isinstance(bitrate, int):
204
+ raise Exception(f"Bitrate must be an integer, not {type(bitrate)} !")
205
+
206
+ channel_category = ctx.channel.category if category is None else ctx.channel.guild.get_channel(category)
207
+
208
+ created_channel = await ctx.guild.create_voice_channel(str(name),
209
+ category=channel_category,
210
+ position=position,
211
+ bitrate=bitrate,
212
+ overwrites=permission,
213
+ reason=reason)
214
+
215
+ return created_channel.id
216
+
217
+
218
+ async def dshell_delete_channel(ctx: Message, channel=None, reason=None, timeout=0):
219
+ """
220
+ Deletes a channel.
221
+ You can add a waiting time before it is deleted (in seconds)
222
+ """
223
+ if not isinstance(timeout, int):
224
+ raise Exception(f'Timeout must be an integer, not {type(timeout)} !')
225
+
226
+ channel_to_delete = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
227
+
228
+ if channel_to_delete is None:
229
+ raise Exception(f"Channel {channel} not found !")
230
+
231
+ await sleep(timeout)
232
+
233
+ await channel_to_delete.delete(reason=reason)
234
+
235
+ return channel_to_delete.id
236
+
237
+
238
+ async def dshell_delete_channels(ctx: Message, name=None, regex=None, reason=None):
239
+ """
240
+ Deletes all channels with the same name and/or matching the same regex.
241
+ If neither is set, it will delete all channels with the same name as the one where the command was executed.
242
+ """
243
+ if name is not None and not isinstance(name, str):
244
+ raise Exception(f"Name must be a string, not {type(name)} !")
245
+
246
+ if regex is not None and not isinstance(regex, str):
247
+ raise Exception(f"Regex must be a string, not {type(regex)} !")
248
+
249
+ for channel in ctx.channel.guild.channels:
250
+
251
+ if name is not None and channel.name == str(name):
252
+ await channel.delete(reason=reason)
253
+
254
+ elif regex is not None and search(regex, channel.name):
255
+ await channel.delete(reason=reason)
256
+
257
+
258
+ async def dshell_edit_text_channel(ctx: Message,
259
+ channel=None,
260
+ name=None,
261
+ position=MISSING,
262
+ slowmode=MISSING,
263
+ topic=MISSING,
264
+ nsfw=MISSING,
265
+ permission: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
266
+ reason=None):
267
+ """
268
+ Edits a text channel on the server
269
+ """
270
+
271
+ if not isinstance(position, _MissingSentinel) and not isinstance(position, int):
272
+ raise Exception(f"Position must be an integer, not {type(position)} !")
273
+
274
+ if not isinstance(slowmode, _MissingSentinel) and not isinstance(slowmode, int):
275
+ raise Exception(f"Slowmode must be an integer, not {type(slowmode)} !")
276
+
277
+ if not isinstance(topic, _MissingSentinel) and not isinstance(topic, str):
278
+ raise Exception(f"Topic must be a string, not {type(topic)} !")
279
+
280
+ if not isinstance(nsfw, _MissingSentinel) and not isinstance(nsfw, bool):
281
+ raise Exception(f"NSFW must be a boolean, not {type(nsfw)} !")
282
+
283
+ channel_to_edit = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
284
+
285
+ if channel_to_edit is None:
286
+ raise Exception(f"Channel {channel} not found !")
287
+
288
+ await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
289
+ position=position if position is not MISSING else channel_to_edit.position,
290
+ slowmode_delay=slowmode if slowmode is not MISSING else channel_to_edit.slowmode_delay,
291
+ topic=topic if topic is not MISSING else channel_to_edit.topic,
292
+ nsfw=nsfw if nsfw is not MISSING else channel_to_edit.nsfw,
293
+ overwrites=permission if permission is not MISSING else channel_to_edit.overwrites,
294
+ reason=reason)
295
+
296
+ return channel_to_edit.id
297
+
298
+
299
+ async def dshell_edit_voice_channel(ctx: Message,
300
+ channel=None,
301
+ name=None,
302
+ position=MISSING,
303
+ bitrate=MISSING,
304
+ permission: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
305
+ reason=None):
306
+ """
307
+ Edits a voice channel on the server
308
+ """
309
+ if not isinstance(position, _MissingSentinel) and not isinstance(position, int):
310
+ raise Exception(f"Position must be an integer, not {type(position)} !")
311
+
312
+ if not isinstance(bitrate, _MissingSentinel) and not isinstance(bitrate, int):
313
+ raise Exception(f"Bitrate must be an integer, not {type(bitrate)} !")
314
+
315
+ channel_to_edit = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
316
+
317
+ if channel_to_edit is None:
318
+ raise Exception(f"Channel {channel} not found !")
319
+
320
+ await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
321
+ position=position if position is not MISSING else channel_to_edit.position,
322
+ bitrate=bitrate if bitrate is not MISSING else channel_to_edit.bitrate,
323
+ overwrites=permission if permission is not MISSING else channel_to_edit.overwrites,
324
+ reason=reason)
325
+
326
+ return channel_to_edit.id
327
+
328
+
329
+ async def dshell_create_thread_message(ctx: Message,
330
+ name,
331
+ message: Union[int, str] = None,
332
+ archive=MISSING,
333
+ slowmode=MISSING):
334
+ """
335
+ Creates a thread from a message.
336
+ """
337
+
338
+ if message is None:
339
+ message = ctx.id
340
+
341
+ message = await utils_get_message(ctx, message)
342
+
343
+
344
+ if not isinstance(name, str):
345
+ raise Exception(f"Name must be a string, not {type(name)} !")
346
+
347
+ if not isinstance(archive, _MissingSentinel) and not isinstance(archive, int):
348
+ raise Exception(f"Auto archive duration must be an integer, not {type(archive)} !")
349
+
350
+ if not isinstance(archive, _MissingSentinel) and archive not in (60, 1440, 4320, 10080):
351
+ raise Exception("Auto archive duration must be one of the following values: 60, 1440, 4320, 10080 !")
352
+
353
+ if not isinstance(slowmode, _MissingSentinel) and not isinstance(slowmode, int):
354
+ raise Exception(f"Slowmode delay must be an integer, not {type(slowmode)} !")
355
+
356
+ if not isinstance(slowmode, _MissingSentinel) and slowmode < 0:
357
+ raise Exception("Slowmode delay must be a positive integer !")
358
+
359
+ thread = await message.create_thread(name=name,
360
+ auto_archive_duration=archive,
361
+ slowmode_delay=slowmode)
362
+
363
+ return thread.id
364
+
365
+ async def dshell_edit_thread(ctx: Message,
366
+ thread: Union[int, str] = None,
367
+ name=None,
368
+ archive=MISSING,
369
+ slowmode=MISSING,
370
+ reason=None):
371
+ """ Edits a thread.
372
+ """
373
+ if thread is None:
374
+ thread = ctx.thread
375
+
376
+ if thread is None:
377
+ raise Exception("Thread must be specified !")
378
+
379
+ thread = await utils_get_thread(ctx, thread)
380
+
381
+ if not isinstance(name, _MissingSentinel) and not isinstance(name, str):
382
+ raise Exception(f"Name must be a string, not {type(name)} !")
383
+
384
+ if not isinstance(archive, _MissingSentinel) and not isinstance(archive, int):
385
+ raise Exception(f"Auto archive duration must be an integer, not {type(archive)} !")
386
+
387
+ if not isinstance(archive, _MissingSentinel) and archive not in (60, 1440, 4320, 10080):
388
+ raise Exception("Auto archive duration must be one of the following values: 60, 1440, 4320, 10080 !")
389
+
390
+ if not isinstance(slowmode, _MissingSentinel) and not isinstance(slowmode, int):
391
+ raise Exception(f"Slowmode delay must be an integer, not {type(slowmode)} !")
392
+
393
+ if not isinstance(slowmode, _MissingSentinel) and slowmode < 0:
394
+ raise Exception("Slowmode delay must be a positive integer !")
395
+
396
+ await thread.edit(name=name if name is not None else thread.name,
397
+ auto_archive_duration=archive if archive is not MISSING else thread.auto_archive_duration,
398
+ slowmode_delay=slowmode if slowmode is not MISSING else thread.slowmode_delay,
399
+ reason=reason)
400
+
401
+
402
+ async def dshell_get_thread(ctx: Message, message: Union[int, str] = None):
403
+ """
404
+ Returns the thread object of the specified thread ID.
405
+ """
406
+
407
+ if message is None:
408
+ message = ctx.id
409
+
410
+ message = await utils_get_message(ctx, message)
411
+
412
+ if not hasattr(message, 'thread'):
413
+ return None
414
+
415
+ thread = message.thread
416
+
417
+ if thread is None:
418
+ return None
419
+
420
+ return thread.id
421
+
422
+
423
+ async def dshell_delete_thread(ctx: Message, thread: Union[int, str] = None, reason=None):
424
+ """
425
+ Deletes a thread.
426
+ """
427
+
428
+ if thread is None:
429
+ thread = ctx.id
430
+
431
+ thread = await utils_get_message(ctx, thread)
432
+
433
+ if not hasattr(thread, 'thread'):
434
+ raise Exception("The specified message does not have a thread !")
435
+
436
+ if thread.thread is None:
437
+ raise Exception("The specified message does not have a thread !")
438
+
439
+ await thread.thread.delete(reason=reason)
440
+
441
+ return thread.thread.id
442
+
@@ -426,7 +426,7 @@ class ParamNode(ASTNode):
426
426
  self.body = body
427
427
 
428
428
  def __repr__(self):
429
- return f"<PARAM> - {self.name} *- {self.body}"
429
+ return f"<PARAM> - {self.body}"
430
430
 
431
431
  def to_dict(self):
432
432
  """
@@ -435,7 +435,6 @@ class ParamNode(ASTNode):
435
435
  """
436
436
  return {
437
437
  "type": "ParamNode",
438
- "name": self.name.to_dict(),
439
438
  "body": [token.to_dict() for token in self.body]
440
439
  }
441
440
 
@@ -37,6 +37,15 @@ dshell_commands: dict[str, Callable] = {
37
37
  "dc": dshell_delete_channel, # delete channel
38
38
  "dcs": dshell_delete_channels, # delete several channels by name or regex
39
39
 
40
+ "gc": dshell_get_channel, # get channel
41
+ "gcs": dshell_get_channels, # get channels by name or regex
42
+ "gccs": dshell_get_channels_in_category, # get channels in category
43
+
44
+ "ct": dshell_create_thread_message, # create thread
45
+ "dt": dshell_delete_thread, # delete thread
46
+ "gt": dshell_get_thread, # get thread
47
+ "et": dshell_edit_thread, # edit thread
48
+
40
49
  "bm": dshell_ban_member, # ban member
41
50
  "um": dshell_unban_member, # unban member
42
51
  "km": dshell_kick_member, # kick member
@@ -59,8 +68,8 @@ dshell_commands: dict[str, Callable] = {
59
68
 
60
69
  "ar": dshell_add_reactions, # add reactions to a message
61
70
  "rr": dshell_remove_reactions, # remove reactions from a message
62
- "cmr": dshell_clear_message_reactions,
63
- "cor": dshell_clear_one_reactions
71
+ "cmr": dshell_clear_message_reactions, # clear reactions from a message
72
+ "cor": dshell_clear_one_reactions , # clear one reaction from a message
64
73
 
65
74
  }
66
75
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dshellInterpreter
3
- Version: 0.2.8.2
3
+ Version: 0.2.9
4
4
  Summary: A Discord bot interpreter for creating custom commands and automations.
5
5
  Home-page: https://github.com/BOXERRMD/Dshell_Interpreter
6
6
  Author: Chronos
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dshellInterpreter
3
- Version: 0.2.8.2
3
+ Version: 0.2.9
4
4
  Summary: A Discord bot interpreter for creating custom commands and automations.
5
5
  Home-page: https://github.com/BOXERRMD/Dshell_Interpreter
6
6
  Author: Chronos
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setup(
7
7
  name="dshellInterpreter",
8
- version="0.2.8.2",
8
+ version="0.2.9",
9
9
  author="Chronos",
10
10
  author_email="vagabonwalybi@gmail.com",
11
11
  description="A Discord bot interpreter for creating custom commands and automations.",
@@ -1,193 +0,0 @@
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
6
- from discord.utils import _MissingSentinel
7
-
8
- __all__ = [
9
- 'dshell_create_text_channel',
10
- 'dshell_delete_channel',
11
- 'dshell_delete_channels',
12
- 'dshell_create_voice_channel',
13
- 'dshell_edit_text_channel',
14
- 'dshell_edit_voice_channel'
15
- ]
16
-
17
-
18
- async def dshell_create_text_channel(ctx: Message,
19
- name,
20
- category=None,
21
- position=MISSING,
22
- slowmode=MISSING,
23
- topic=MISSING,
24
- nsfw=MISSING,
25
- permission: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
26
- reason=None):
27
- """
28
- Creates a text channel on the server
29
- """
30
-
31
- if not isinstance(position, _MissingSentinel) and not isinstance(position, int):
32
- raise Exception(f"Position must be an integer, not {type(position)} !")
33
-
34
- if not isinstance(slowmode, _MissingSentinel) and not isinstance(slowmode, int):
35
- raise Exception(f"Slowmode must be an integer, not {type(slowmode)} !")
36
-
37
- if not isinstance(topic, _MissingSentinel) and not isinstance(topic, str):
38
- raise Exception(f"Topic must be a string, not {type(topic)} !")
39
-
40
- if not isinstance(nsfw, _MissingSentinel) and not isinstance(nsfw, bool):
41
- raise Exception(f"NSFW must be a boolean, not {type(nsfw)} !")
42
-
43
- channel_category = ctx.channel.category if category is None else ctx.channel.guild.get_channel(category)
44
-
45
- created_channel = await ctx.guild.create_text_channel(str(name),
46
- category=channel_category,
47
- position=position,
48
- slowmode_delay=slowmode,
49
- topic=topic,
50
- nsfw=nsfw,
51
- overwrites=permission,
52
- reason=reason)
53
-
54
- return created_channel.id
55
-
56
-
57
- async def dshell_create_voice_channel(ctx: Message,
58
- name,
59
- category=None,
60
- position=MISSING,
61
- bitrate=MISSING,
62
- permission: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
63
- reason=None):
64
- """
65
- Creates a voice channel on the server
66
- """
67
- if not isinstance(position, _MissingSentinel) and not isinstance(position, int):
68
- raise Exception(f"Position must be an integer, not {type(position)} !")
69
-
70
- if not isinstance(bitrate, _MissingSentinel) and not isinstance(bitrate, int):
71
- raise Exception(f"Bitrate must be an integer, not {type(bitrate)} !")
72
-
73
- channel_category = ctx.channel.category if category is None else ctx.channel.guild.get_channel(category)
74
-
75
- created_channel = await ctx.guild.create_voice_channel(str(name),
76
- category=channel_category,
77
- position=position,
78
- bitrate=bitrate,
79
- overwrites=permission,
80
- reason=reason)
81
-
82
- return created_channel.id
83
-
84
-
85
- async def dshell_delete_channel(ctx: Message, channel=None, reason=None, timeout=0):
86
- """
87
- Deletes a channel.
88
- You can add a waiting time before it is deleted (in seconds)
89
- """
90
- if not isinstance(timeout, int):
91
- raise Exception(f'Timeout must be an integer, not {type(timeout)} !')
92
-
93
- channel_to_delete = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
94
-
95
- if channel_to_delete is None:
96
- raise Exception(f"Channel {channel} not found !")
97
-
98
- await sleep(timeout)
99
-
100
- await channel_to_delete.delete(reason=reason)
101
-
102
- return channel_to_delete.id
103
-
104
-
105
- async def dshell_delete_channels(ctx: Message, name=None, regex=None, reason=None):
106
- """
107
- Deletes all channels with the same name and/or matching the same regex.
108
- If neither is set, it will delete all channels with the same name as the one where the command was executed.
109
- """
110
- if name is not None and not isinstance(name, str):
111
- raise Exception(f"Name must be a string, not {type(name)} !")
112
-
113
- if regex is not None and not isinstance(regex, str):
114
- raise Exception(f"Regex must be a string, not {type(regex)} !")
115
-
116
- for channel in ctx.channel.guild.channels:
117
-
118
- if name is not None and channel.name == str(name):
119
- await channel.delete(reason=reason)
120
-
121
- elif regex is not None and search(regex, channel.name):
122
- await channel.delete(reason=reason)
123
-
124
-
125
- async def dshell_edit_text_channel(ctx: Message,
126
- channel=None,
127
- name=None,
128
- position=MISSING,
129
- slowmode=MISSING,
130
- topic=MISSING,
131
- nsfw=MISSING,
132
- permission: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
133
- reason=None):
134
- """
135
- Edits a text channel on the server
136
- """
137
-
138
- if not isinstance(position, _MissingSentinel) and not isinstance(position, int):
139
- raise Exception(f"Position must be an integer, not {type(position)} !")
140
-
141
- if not isinstance(slowmode, _MissingSentinel) and not isinstance(slowmode, int):
142
- raise Exception(f"Slowmode must be an integer, not {type(slowmode)} !")
143
-
144
- if not isinstance(topic, _MissingSentinel) and not isinstance(topic, str):
145
- raise Exception(f"Topic must be a string, not {type(topic)} !")
146
-
147
- if not isinstance(nsfw, _MissingSentinel) and not isinstance(nsfw, bool):
148
- raise Exception(f"NSFW must be a boolean, not {type(nsfw)} !")
149
-
150
- channel_to_edit = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
151
-
152
- if channel_to_edit is None:
153
- raise Exception(f"Channel {channel} not found !")
154
-
155
- await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
156
- position=position if position is not MISSING else channel_to_edit.position,
157
- slowmode_delay=slowmode if slowmode is not MISSING else channel_to_edit.slowmode_delay,
158
- topic=topic if topic is not MISSING else channel_to_edit.topic,
159
- nsfw=nsfw if nsfw is not MISSING else channel_to_edit.nsfw,
160
- overwrites=permission if permission is not MISSING else channel_to_edit.overwrites,
161
- reason=reason)
162
-
163
- return channel_to_edit.id
164
-
165
-
166
- async def dshell_edit_voice_channel(ctx: Message,
167
- channel=None,
168
- name=None,
169
- position=MISSING,
170
- bitrate=MISSING,
171
- permission: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
172
- reason=None):
173
- """
174
- Edits a voice channel on the server
175
- """
176
- if not isinstance(position, _MissingSentinel) and not isinstance(position, int):
177
- raise Exception(f"Position must be an integer, not {type(position)} !")
178
-
179
- if not isinstance(bitrate, _MissingSentinel) and not isinstance(bitrate, int):
180
- raise Exception(f"Bitrate must be an integer, not {type(bitrate)} !")
181
-
182
- channel_to_edit = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
183
-
184
- if channel_to_edit is None:
185
- raise Exception(f"Channel {channel} not found !")
186
-
187
- await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
188
- position=position if position is not MISSING else channel_to_edit.position,
189
- bitrate=bitrate if bitrate is not MISSING else channel_to_edit.bitrate,
190
- overwrites=permission if permission is not MISSING else channel_to_edit.overwrites,
191
- reason=reason)
192
-
193
- return channel_to_edit.id