dshellInterpreter 0.2.13__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.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/__init__.py +1 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_channel.py +78 -7
- dshellinterpreter-0.2.20.5/Dshell/DISCORD_COMMANDS/dshell_interaction.py +89 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_message.py +84 -35
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_pastbin.py +5 -7
- 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/_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.13 → dshellinterpreter-0.2.20.5}/Dshell/_DshellParser/ast_nodes.py +187 -33
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/_DshellParser/dshell_parser.py +114 -73
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/_DshellTokenizer/dshell_keywords.py +63 -58
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/_DshellTokenizer/dshell_token_type.py +1 -1
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/_DshellTokenizer/dshell_tokenizer.py +28 -25
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/__init__.py +1 -0
- {dshellinterpreter-0.2.13/dshellInterpreter.egg-info → dshellinterpreter-0.2.20.5}/PKG-INFO +2 -1
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5/dshellInterpreter.egg-info}/PKG-INFO +2 -1
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/dshellInterpreter.egg-info/SOURCES.txt +8 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/dshellInterpreter.egg-info/requires.txt +1 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/setup.py +2 -2
- dshellinterpreter-0.2.13/Dshell/DISCORD_COMMANDS/utils/__init__.py +0 -0
- dshellinterpreter-0.2.13/Dshell/DISCORD_COMMANDS/utils/utils_message.py +0 -28
- dshellinterpreter-0.2.13/Dshell/_DshellInterpreteur/__init__.py +0 -1
- dshellinterpreter-0.2.13/Dshell/_DshellInterpreteur/dshell_interpreter.py +0 -543
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_member.py +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_role.py +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/utils/utils_thread.py +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/_DshellParser/__init__.py +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/_DshellTokenizer/__init__.py +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/_utils.py +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/LICENSE +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/README.md +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/dshellInterpreter.egg-info/dependency_links.txt +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/dshellInterpreter.egg-info/top_level.txt +0 -0
- {dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/setup.cfg +0 -0
{dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_channel.py
RENAMED
|
@@ -2,7 +2,7 @@ from asyncio import sleep
|
|
|
2
2
|
from re import search
|
|
3
3
|
from typing import Union
|
|
4
4
|
|
|
5
|
-
from discord import MISSING, PermissionOverwrite, Member, Role, Message
|
|
5
|
+
from discord import MISSING, PermissionOverwrite, Member, Role, Message, CategoryChannel, PartialMessage
|
|
6
6
|
from discord.utils import _MissingSentinel
|
|
7
7
|
|
|
8
8
|
from .utils.utils_message import utils_get_message
|
|
@@ -21,7 +21,9 @@ __all__ = [
|
|
|
21
21
|
'dshell_create_voice_channel',
|
|
22
22
|
'dshell_edit_text_channel',
|
|
23
23
|
'dshell_edit_voice_channel',
|
|
24
|
-
'dshell_edit_thread'
|
|
24
|
+
'dshell_edit_thread',
|
|
25
|
+
'dshell_create_category',
|
|
26
|
+
'dshell_edit_category'
|
|
25
27
|
]
|
|
26
28
|
|
|
27
29
|
|
|
@@ -206,6 +208,7 @@ async def dshell_delete_channels(ctx: Message, name=None, regex=None, reason=Non
|
|
|
206
208
|
async def dshell_edit_text_channel(ctx: Message,
|
|
207
209
|
channel=None,
|
|
208
210
|
name=None,
|
|
211
|
+
category=MISSING,
|
|
209
212
|
position=MISSING,
|
|
210
213
|
slowmode=MISSING,
|
|
211
214
|
topic=MISSING,
|
|
@@ -215,10 +218,15 @@ async def dshell_edit_text_channel(ctx: Message,
|
|
|
215
218
|
"""
|
|
216
219
|
Edits a text channel on the server
|
|
217
220
|
"""
|
|
221
|
+
if name is not None and not isinstance(name, str):
|
|
222
|
+
raise Exception(f"Name must be a string, not {type(name)} !")
|
|
218
223
|
|
|
219
224
|
if not isinstance(position, (_MissingSentinel, int)):
|
|
220
225
|
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
221
226
|
|
|
227
|
+
if not isinstance(category, (_MissingSentinel, int)):
|
|
228
|
+
raise Exception(f"Category must be an integer, not {type(category)} !")
|
|
229
|
+
|
|
222
230
|
if not isinstance(slowmode, (_MissingSentinel, int)):
|
|
223
231
|
raise Exception(f"Slowmode must be an integer, not {type(slowmode)} !")
|
|
224
232
|
|
|
@@ -229,12 +237,14 @@ async def dshell_edit_text_channel(ctx: Message,
|
|
|
229
237
|
raise Exception(f"NSFW must be a boolean, not {type(nsfw)} !")
|
|
230
238
|
|
|
231
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)
|
|
232
241
|
|
|
233
242
|
if channel_to_edit is None:
|
|
234
243
|
raise Exception(f"Channel {channel} not found !")
|
|
235
244
|
|
|
236
245
|
await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
|
|
237
246
|
position=position if position is not MISSING else channel_to_edit.position,
|
|
247
|
+
category=new_categoy,
|
|
238
248
|
slowmode_delay=slowmode if slowmode is not MISSING else channel_to_edit.slowmode_delay,
|
|
239
249
|
topic=topic if topic is not MISSING else channel_to_edit.topic,
|
|
240
250
|
nsfw=nsfw if nsfw is not MISSING else channel_to_edit.nsfw,
|
|
@@ -247,6 +257,7 @@ async def dshell_edit_text_channel(ctx: Message,
|
|
|
247
257
|
async def dshell_edit_voice_channel(ctx: Message,
|
|
248
258
|
channel=None,
|
|
249
259
|
name=None,
|
|
260
|
+
category=MISSING,
|
|
250
261
|
position=MISSING,
|
|
251
262
|
bitrate=MISSING,
|
|
252
263
|
permissions: dict[Union[Member, Role], PermissionOverwrite] = MISSING,
|
|
@@ -257,16 +268,21 @@ async def dshell_edit_voice_channel(ctx: Message,
|
|
|
257
268
|
if not isinstance(position, (_MissingSentinel, int)):
|
|
258
269
|
raise Exception(f"Position must be an integer, not {type(position)} !")
|
|
259
270
|
|
|
271
|
+
if not isinstance(category, (_MissingSentinel, int)):
|
|
272
|
+
raise Exception(f"Category must be an integer, not {type(category)} !")
|
|
273
|
+
|
|
260
274
|
if not isinstance(bitrate, (_MissingSentinel, int)):
|
|
261
275
|
raise Exception(f"Bitrate must be an integer, not {type(bitrate)} !")
|
|
262
276
|
|
|
263
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)
|
|
264
279
|
|
|
265
280
|
if channel_to_edit is None:
|
|
266
281
|
raise Exception(f"Channel {channel} not found !")
|
|
267
282
|
|
|
268
283
|
await channel_to_edit.edit(name=name if name is not None else channel_to_edit.name,
|
|
269
284
|
position=position if position is not MISSING else channel_to_edit.position,
|
|
285
|
+
category=new_categoy,
|
|
270
286
|
bitrate=bitrate if bitrate is not MISSING else channel_to_edit.bitrate,
|
|
271
287
|
overwrites=permissions if permissions is not MISSING else channel_to_edit.overwrites,
|
|
272
288
|
reason=reason)
|
|
@@ -304,9 +320,14 @@ async def dshell_create_thread_message(ctx: Message,
|
|
|
304
320
|
if not isinstance(slowmode, _MissingSentinel) and slowmode < 0:
|
|
305
321
|
raise Exception("Slowmode delay must be a positive integer !")
|
|
306
322
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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)
|
|
310
331
|
|
|
311
332
|
return thread.id
|
|
312
333
|
|
|
@@ -355,7 +376,11 @@ async def dshell_get_thread(ctx: Message, message: Union[int, str] = None):
|
|
|
355
376
|
if message is None:
|
|
356
377
|
message = ctx.id
|
|
357
378
|
|
|
358
|
-
|
|
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
|
|
359
384
|
|
|
360
385
|
if not hasattr(message, 'thread'):
|
|
361
386
|
return None
|
|
@@ -376,7 +401,11 @@ async def dshell_delete_thread(ctx: Message, thread: Union[int, str] = None, rea
|
|
|
376
401
|
if thread is None:
|
|
377
402
|
thread = ctx.id
|
|
378
403
|
|
|
379
|
-
|
|
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
|
|
380
409
|
|
|
381
410
|
if not hasattr(thread, 'thread'):
|
|
382
411
|
raise Exception("The specified message does not have a thread !")
|
|
@@ -388,3 +417,45 @@ async def dshell_delete_thread(ctx: Message, thread: Union[int, str] = None, rea
|
|
|
388
417
|
|
|
389
418
|
return thread.thread.id
|
|
390
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.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_message.py
RENAMED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
from re import search
|
|
2
2
|
|
|
3
|
-
from discord import Embed, Message
|
|
3
|
+
from discord import Embed, Message, PartialMessage
|
|
4
4
|
from discord.ext import commands
|
|
5
|
-
from discord.abc import Messageable
|
|
6
5
|
|
|
7
|
-
from
|
|
6
|
+
from pycordViews import EasyModifiedViews
|
|
7
|
+
|
|
8
|
+
from .utils.utils_message import utils_get_message, utils_autorised_mentions
|
|
9
|
+
from .._DshellInterpreteur.cached_messages import dshell_cached_messages
|
|
10
|
+
from .._utils import NoneType
|
|
8
11
|
|
|
9
12
|
__all__ = [
|
|
10
13
|
'dshell_send_message',
|
|
@@ -12,16 +15,26 @@ __all__ = [
|
|
|
12
15
|
'dshell_delete_message',
|
|
13
16
|
'dshell_purge_message',
|
|
14
17
|
'dshell_edit_message',
|
|
15
|
-
'
|
|
16
|
-
'dshell_research_regex_in_content',
|
|
18
|
+
'dshell_get_history_messages',
|
|
17
19
|
'dshell_add_reactions',
|
|
18
20
|
'dshell_remove_reactions',
|
|
19
21
|
'dshell_clear_message_reactions',
|
|
20
|
-
'dshell_clear_one_reactions'
|
|
22
|
+
'dshell_clear_one_reactions',
|
|
23
|
+
'dshell_get_content_message'
|
|
21
24
|
]
|
|
22
25
|
|
|
23
26
|
|
|
24
|
-
async def dshell_send_message(ctx: Message,
|
|
27
|
+
async def dshell_send_message(ctx: Message,
|
|
28
|
+
message=None,
|
|
29
|
+
delete=None,
|
|
30
|
+
channel=None,
|
|
31
|
+
global_mentions: bool = None,
|
|
32
|
+
everyone_mention: bool = True,
|
|
33
|
+
roles_mentions: bool = True,
|
|
34
|
+
users_mentions: bool = True,
|
|
35
|
+
reply_mention: bool = False,
|
|
36
|
+
embeds=None,
|
|
37
|
+
view=None) -> int:
|
|
25
38
|
"""
|
|
26
39
|
Sends a message on Discord
|
|
27
40
|
"""
|
|
@@ -30,29 +43,44 @@ async def dshell_send_message(ctx: Message, message=None, delete=None, channel=N
|
|
|
30
43
|
raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
|
|
31
44
|
|
|
32
45
|
channel_to_send = ctx.channel if channel is None else ctx.channel.guild.get_channel(channel)
|
|
46
|
+
allowed_mentions = utils_autorised_mentions(global_mentions, everyone_mention, roles_mentions, users_mentions, reply_mention)
|
|
33
47
|
|
|
34
48
|
if channel_to_send is None:
|
|
35
49
|
raise Exception(f'Channel {channel} not found!')
|
|
36
50
|
|
|
37
51
|
from .._DshellParser.ast_nodes import ListNode
|
|
38
52
|
|
|
53
|
+
if not isinstance(embeds, (ListNode, Embed, NoneType)):
|
|
54
|
+
raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
|
|
55
|
+
|
|
39
56
|
if embeds is None:
|
|
40
57
|
embeds = ListNode([])
|
|
41
58
|
|
|
42
59
|
elif isinstance(embeds, Embed):
|
|
43
60
|
embeds = ListNode([embeds])
|
|
44
61
|
|
|
45
|
-
|
|
46
|
-
raise Exception(f'
|
|
62
|
+
if not isinstance(view, (EasyModifiedViews, NoneType)):
|
|
63
|
+
raise Exception(f'Channel must be an UI or None, not {type(channel_to_send)} !')
|
|
47
64
|
|
|
48
65
|
sended_message = await channel_to_send.send(message,
|
|
49
66
|
delete_after=delete,
|
|
50
|
-
embeds=embeds
|
|
67
|
+
embeds=embeds,
|
|
68
|
+
allowed_mentions=allowed_mentions,
|
|
69
|
+
view=view)
|
|
51
70
|
|
|
52
71
|
return sended_message.id
|
|
53
72
|
|
|
54
73
|
|
|
55
|
-
async def dshell_respond_message(ctx: Message,
|
|
74
|
+
async def dshell_respond_message(ctx: Message,
|
|
75
|
+
message=None,
|
|
76
|
+
content: str = None,
|
|
77
|
+
global_mentions: bool = None,
|
|
78
|
+
everyone_mention: bool = True,
|
|
79
|
+
roles_mentions: bool = True,
|
|
80
|
+
users_mentions: bool = True,
|
|
81
|
+
reply_mention: bool = False,
|
|
82
|
+
delete=None,
|
|
83
|
+
embeds=None):
|
|
56
84
|
"""
|
|
57
85
|
Responds to a message on Discord
|
|
58
86
|
"""
|
|
@@ -60,22 +88,24 @@ async def dshell_respond_message(ctx: Message, message=None, content: str = None
|
|
|
60
88
|
raise Exception(f'Delete parameter must be a number (seconds) or None, not {type(delete)} !')
|
|
61
89
|
|
|
62
90
|
respond_message = ctx if message is None else utils_get_message(ctx, message) # builds a reference to the message (even if it doesn't exist)
|
|
63
|
-
|
|
91
|
+
autorised_mentions = utils_autorised_mentions(global_mentions, everyone_mention, roles_mentions, users_mentions, reply_mention)
|
|
92
|
+
mention_author = True if reply_mention else False
|
|
64
93
|
|
|
65
94
|
from .._DshellParser.ast_nodes import ListNode
|
|
66
95
|
|
|
96
|
+
if not isinstance(embeds, (ListNode, Embed, NoneType)):
|
|
97
|
+
raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
|
|
98
|
+
|
|
67
99
|
if embeds is None:
|
|
68
100
|
embeds = ListNode([])
|
|
69
101
|
|
|
70
102
|
elif isinstance(embeds, Embed):
|
|
71
103
|
embeds = ListNode([embeds])
|
|
72
104
|
|
|
73
|
-
else:
|
|
74
|
-
raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
|
|
75
|
-
|
|
76
105
|
sended_message = await respond_message.reply(
|
|
77
106
|
content=str(content),
|
|
78
107
|
mention_author=mention_author,
|
|
108
|
+
allowed_mentions=autorised_mentions,
|
|
79
109
|
delete_after=delete,
|
|
80
110
|
embeds=embeds)
|
|
81
111
|
|
|
@@ -113,24 +143,34 @@ async def dshell_purge_message(ctx: Message, message_number: int, channel=None,
|
|
|
113
143
|
await purge_channel.purge(limit=message_number, reason=reason)
|
|
114
144
|
|
|
115
145
|
|
|
116
|
-
async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=None):
|
|
146
|
+
async def dshell_edit_message(ctx: Message, message, new_content=None, embeds=None, view=None) -> int:
|
|
117
147
|
"""
|
|
118
148
|
Edits a message
|
|
119
149
|
"""
|
|
120
150
|
edit_message = utils_get_message(ctx, message)
|
|
121
151
|
|
|
152
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
153
|
+
|
|
154
|
+
if not isinstance(embeds, (ListNode, Embed, NoneType)):
|
|
155
|
+
raise Exception(f'Embeds must be a list of Embed objects or a single Embed object, not {type(embeds)} !')
|
|
156
|
+
|
|
157
|
+
if not isinstance(view, (EasyModifiedViews, NoneType)):
|
|
158
|
+
raise Exception(f'View must be an UI bloc or None, not {type(view)} !')
|
|
159
|
+
|
|
122
160
|
if embeds is None:
|
|
123
|
-
embeds = []
|
|
161
|
+
embeds = ListNode([])
|
|
124
162
|
|
|
125
163
|
elif isinstance(embeds, Embed):
|
|
126
|
-
embeds = [embeds]
|
|
164
|
+
embeds = ListNode([embeds])
|
|
127
165
|
|
|
128
|
-
await edit_message.edit(content=new_content, embeds=embeds)
|
|
166
|
+
await edit_message.edit(content=new_content, embeds=embeds, view=view)
|
|
129
167
|
|
|
130
168
|
return edit_message.id
|
|
131
169
|
|
|
132
170
|
|
|
133
|
-
async def
|
|
171
|
+
async def dshell_get_history_messages(ctx: Message,
|
|
172
|
+
channel=None,
|
|
173
|
+
limit=None) -> "ListNode":
|
|
134
174
|
"""
|
|
135
175
|
Searches for messages matching a regex in a channel
|
|
136
176
|
"""
|
|
@@ -145,29 +185,19 @@ async def dshell_get_hystory_messages(ctx: Message, channel=None, limit=None):
|
|
|
145
185
|
|
|
146
186
|
from .._DshellParser.ast_nodes import ListNode
|
|
147
187
|
|
|
188
|
+
cached_messages = dshell_cached_messages.get()
|
|
148
189
|
messages = ListNode([])
|
|
149
190
|
async for message in search_channel.history(limit=limit):
|
|
150
|
-
|
|
191
|
+
message_id = message.id
|
|
192
|
+
messages.add(message_id)
|
|
193
|
+
cached_messages[message_id] = message
|
|
151
194
|
|
|
152
195
|
if not messages:
|
|
153
196
|
raise commands.CommandError(f"No messages in {search_channel.mention}.")
|
|
154
|
-
|
|
197
|
+
dshell_cached_messages.set(cached_messages)
|
|
155
198
|
return messages
|
|
156
199
|
|
|
157
200
|
|
|
158
|
-
async def dshell_research_regex_in_content(ctx: Message, regex, content=None):
|
|
159
|
-
"""
|
|
160
|
-
Searches for a regex in a specific message content
|
|
161
|
-
"""
|
|
162
|
-
|
|
163
|
-
if not isinstance(regex, str):
|
|
164
|
-
raise Exception(f"Regex must be a string, not {type(regex)}!")
|
|
165
|
-
|
|
166
|
-
if not search(regex, str(content) if content is not None else ctx.content):
|
|
167
|
-
return False
|
|
168
|
-
|
|
169
|
-
return True
|
|
170
|
-
|
|
171
201
|
|
|
172
202
|
async def dshell_add_reactions(ctx: Message, reactions, message=None):
|
|
173
203
|
"""
|
|
@@ -220,3 +250,22 @@ async def dshell_clear_one_reactions(ctx: Message, message, emoji):
|
|
|
220
250
|
target_message = ctx if message is None else utils_get_message(ctx, message)
|
|
221
251
|
|
|
222
252
|
await target_message.clear_reaction(emoji)
|
|
253
|
+
|
|
254
|
+
async def dshell_get_content_message(ctx: Message, message=None):
|
|
255
|
+
"""
|
|
256
|
+
Get the content of a message
|
|
257
|
+
"""
|
|
258
|
+
|
|
259
|
+
target_message = ctx if message is None else utils_get_message(ctx, message)
|
|
260
|
+
|
|
261
|
+
if isinstance(target_message, PartialMessage):
|
|
262
|
+
try:
|
|
263
|
+
fetch_target_message = await target_message.fetch()
|
|
264
|
+
except:
|
|
265
|
+
raise Exception(f'Message not found !')
|
|
266
|
+
else:
|
|
267
|
+
fetch_target_message = target_message
|
|
268
|
+
|
|
269
|
+
return fetch_target_message.content
|
|
270
|
+
|
|
271
|
+
|
{dshellinterpreter-0.2.13 → dshellinterpreter-0.2.20.5}/Dshell/DISCORD_COMMANDS/dshell_pastbin.py
RENAMED
|
@@ -6,14 +6,16 @@ __all__ = [
|
|
|
6
6
|
]
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
async def dshell_get_pastbin(ctx: Message, code: str):
|
|
9
|
+
async def dshell_get_pastbin(ctx: Message, code: str) -> "ListNode":
|
|
10
10
|
"""
|
|
11
11
|
Get a pastbin from a code snippet.
|
|
12
12
|
"""
|
|
13
13
|
if not isinstance(code, str):
|
|
14
14
|
raise Exception(f'Code must be a string, not {type(code)} !')
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
from .._DshellParser.ast_nodes import ListNode
|
|
17
|
+
|
|
18
|
+
content = ListNode([]) # Initialize content to an empty string
|
|
17
19
|
|
|
18
20
|
with get(f"https://pastebin.com/raw/{code}", stream=True, timeout=10) as response:
|
|
19
21
|
|
|
@@ -21,10 +23,6 @@ async def dshell_get_pastbin(ctx: Message, code: str):
|
|
|
21
23
|
raise Exception(f"Failed to retrieve pastbin with code {code} !")
|
|
22
24
|
|
|
23
25
|
for line in response.iter_lines(decode_unicode=True, chunk_size=512):
|
|
24
|
-
|
|
25
|
-
if len_content < 4000 and len_content + len(line) <= 4000:
|
|
26
|
-
content += line + '\n'
|
|
27
|
-
else:
|
|
28
|
-
break
|
|
26
|
+
content.add(line)
|
|
29
27
|
|
|
30
28
|
return content
|