shadowcordv2 1.8.0__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.
Files changed (116) hide show
  1. shadowcordv2-1.8.0/LICENSE +21 -0
  2. shadowcordv2-1.8.0/MANIFEST.in +6 -0
  3. shadowcordv2-1.8.0/PKG-INFO +95 -0
  4. shadowcordv2-1.8.0/README.md +39 -0
  5. shadowcordv2-1.8.0/README.rst +46 -0
  6. shadowcordv2-1.8.0/discord/__init__.py +78 -0
  7. shadowcordv2-1.8.0/discord/__main__.py +300 -0
  8. shadowcordv2-1.8.0/discord/abc.py +1689 -0
  9. shadowcordv2-1.8.0/discord/activity.py +842 -0
  10. shadowcordv2-1.8.0/discord/appinfo.py +247 -0
  11. shadowcordv2-1.8.0/discord/asset.py +415 -0
  12. shadowcordv2-1.8.0/discord/audit_logs.py +524 -0
  13. shadowcordv2-1.8.0/discord/backoff.py +105 -0
  14. shadowcordv2-1.8.0/discord/bin/libopus-0.x64.dll +0 -0
  15. shadowcordv2-1.8.0/discord/bin/libopus-0.x86.dll +0 -0
  16. shadowcordv2-1.8.0/discord/channel.py +2081 -0
  17. shadowcordv2-1.8.0/discord/client.py +1675 -0
  18. shadowcordv2-1.8.0/discord/colour.py +329 -0
  19. shadowcordv2-1.8.0/discord/components.py +383 -0
  20. shadowcordv2-1.8.0/discord/context_managers.py +87 -0
  21. shadowcordv2-1.8.0/discord/embeds.py +727 -0
  22. shadowcordv2-1.8.0/discord/emoji.py +255 -0
  23. shadowcordv2-1.8.0/discord/enums.py +612 -0
  24. shadowcordv2-1.8.0/discord/errors.py +277 -0
  25. shadowcordv2-1.8.0/discord/ext/__init__.py +15 -0
  26. shadowcordv2-1.8.0/discord/ext/commands/__init__.py +19 -0
  27. shadowcordv2-1.8.0/discord/ext/commands/_types.py +48 -0
  28. shadowcordv2-1.8.0/discord/ext/commands/bot.py +1118 -0
  29. shadowcordv2-1.8.0/discord/ext/commands/cog.py +472 -0
  30. shadowcordv2-1.8.0/discord/ext/commands/context.py +400 -0
  31. shadowcordv2-1.8.0/discord/ext/commands/converter.py +1182 -0
  32. shadowcordv2-1.8.0/discord/ext/commands/cooldowns.py +390 -0
  33. shadowcordv2-1.8.0/discord/ext/commands/core.py +2307 -0
  34. shadowcordv2-1.8.0/discord/ext/commands/errors.py +997 -0
  35. shadowcordv2-1.8.0/discord/ext/commands/flags.py +618 -0
  36. shadowcordv2-1.8.0/discord/ext/commands/help.py +1339 -0
  37. shadowcordv2-1.8.0/discord/ext/commands/view.py +192 -0
  38. shadowcordv2-1.8.0/discord/ext/tasks/__init__.py +756 -0
  39. shadowcordv2-1.8.0/discord/file.py +127 -0
  40. shadowcordv2-1.8.0/discord/flags.py +1068 -0
  41. shadowcordv2-1.8.0/discord/gateway.py +922 -0
  42. shadowcordv2-1.8.0/discord/guild.py +2944 -0
  43. shadowcordv2-1.8.0/discord/http.py +1969 -0
  44. shadowcordv2-1.8.0/discord/integrations.py +366 -0
  45. shadowcordv2-1.8.0/discord/interactions.py +767 -0
  46. shadowcordv2-1.8.0/discord/invite.py +478 -0
  47. shadowcordv2-1.8.0/discord/iterators.py +753 -0
  48. shadowcordv2-1.8.0/discord/member.py +908 -0
  49. shadowcordv2-1.8.0/discord/mentions.py +151 -0
  50. shadowcordv2-1.8.0/discord/message.py +1829 -0
  51. shadowcordv2-1.8.0/discord/mixins.py +47 -0
  52. shadowcordv2-1.8.0/discord/object.py +92 -0
  53. shadowcordv2-1.8.0/discord/oggparse.py +113 -0
  54. shadowcordv2-1.8.0/discord/opus.py +454 -0
  55. shadowcordv2-1.8.0/discord/partial_emoji.py +232 -0
  56. shadowcordv2-1.8.0/discord/permissions.py +750 -0
  57. shadowcordv2-1.8.0/discord/player.py +745 -0
  58. shadowcordv2-1.8.0/discord/py.typed +0 -0
  59. shadowcordv2-1.8.0/discord/raw_models.py +278 -0
  60. shadowcordv2-1.8.0/discord/reaction.py +211 -0
  61. shadowcordv2-1.8.0/discord/role.py +452 -0
  62. shadowcordv2-1.8.0/discord/shard.py +546 -0
  63. shadowcordv2-1.8.0/discord/stage_instance.py +176 -0
  64. shadowcordv2-1.8.0/discord/state.py +1530 -0
  65. shadowcordv2-1.8.0/discord/sticker.py +523 -0
  66. shadowcordv2-1.8.0/discord/team.py +145 -0
  67. shadowcordv2-1.8.0/discord/template.py +316 -0
  68. shadowcordv2-1.8.0/discord/threads.py +802 -0
  69. shadowcordv2-1.8.0/discord/types/__init__.py +10 -0
  70. shadowcordv2-1.8.0/discord/types/activity.py +114 -0
  71. shadowcordv2-1.8.0/discord/types/appinfo.py +67 -0
  72. shadowcordv2-1.8.0/discord/types/audit_log.py +257 -0
  73. shadowcordv2-1.8.0/discord/types/channel.py +157 -0
  74. shadowcordv2-1.8.0/discord/types/components.py +76 -0
  75. shadowcordv2-1.8.0/discord/types/embed.py +84 -0
  76. shadowcordv2-1.8.0/discord/types/emoji.py +46 -0
  77. shadowcordv2-1.8.0/discord/types/gateway.py +41 -0
  78. shadowcordv2-1.8.0/discord/types/guild.py +168 -0
  79. shadowcordv2-1.8.0/discord/types/integration.py +82 -0
  80. shadowcordv2-1.8.0/discord/types/interactions.py +236 -0
  81. shadowcordv2-1.8.0/discord/types/invite.py +99 -0
  82. shadowcordv2-1.8.0/discord/types/member.py +63 -0
  83. shadowcordv2-1.8.0/discord/types/message.py +138 -0
  84. shadowcordv2-1.8.0/discord/types/raw_models.py +87 -0
  85. shadowcordv2-1.8.0/discord/types/role.py +49 -0
  86. shadowcordv2-1.8.0/discord/types/snowflake.py +28 -0
  87. shadowcordv2-1.8.0/discord/types/sticker.py +93 -0
  88. shadowcordv2-1.8.0/discord/types/team.py +43 -0
  89. shadowcordv2-1.8.0/discord/types/template.py +49 -0
  90. shadowcordv2-1.8.0/discord/types/threads.py +74 -0
  91. shadowcordv2-1.8.0/discord/types/user.py +48 -0
  92. shadowcordv2-1.8.0/discord/types/voice.py +85 -0
  93. shadowcordv2-1.8.0/discord/types/webhook.py +70 -0
  94. shadowcordv2-1.8.0/discord/types/welcome_screen.py +40 -0
  95. shadowcordv2-1.8.0/discord/types/widget.py +63 -0
  96. shadowcordv2-1.8.0/discord/ui/__init__.py +15 -0
  97. shadowcordv2-1.8.0/discord/ui/button.py +290 -0
  98. shadowcordv2-1.8.0/discord/ui/item.py +131 -0
  99. shadowcordv2-1.8.0/discord/ui/select.py +357 -0
  100. shadowcordv2-1.8.0/discord/ui/view.py +529 -0
  101. shadowcordv2-1.8.0/discord/user.py +504 -0
  102. shadowcordv2-1.8.0/discord/utils.py +1019 -0
  103. shadowcordv2-1.8.0/discord/voice_client.py +676 -0
  104. shadowcordv2-1.8.0/discord/webhook/__init__.py +13 -0
  105. shadowcordv2-1.8.0/discord/webhook/async_.py +1589 -0
  106. shadowcordv2-1.8.0/discord/webhook/sync.py +1066 -0
  107. shadowcordv2-1.8.0/discord/widget.py +301 -0
  108. shadowcordv2-1.8.0/pyproject.toml +52 -0
  109. shadowcordv2-1.8.0/requirements.txt +1 -0
  110. shadowcordv2-1.8.0/setup.cfg +4 -0
  111. shadowcordv2-1.8.0/shadowcordv2.egg-info/PKG-INFO +95 -0
  112. shadowcordv2-1.8.0/shadowcordv2.egg-info/SOURCES.txt +114 -0
  113. shadowcordv2-1.8.0/shadowcordv2.egg-info/dependency_links.txt +1 -0
  114. shadowcordv2-1.8.0/shadowcordv2.egg-info/requires.txt +10 -0
  115. shadowcordv2-1.8.0/shadowcordv2.egg-info/top_level.txt +1 -0
  116. shadowcordv2-1.8.0/tests/test_offline_gateway.py +309 -0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-present Rapptz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the "Software"),
7
+ to deal in the Software without restriction, including without limitation
8
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ and/or sell copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include README.rst
2
+ include LICENSE
3
+ include requirements.txt
4
+ include discord/bin/*.dll
5
+ include discord/py.typed
6
+ recursive-include discord/ext *
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.4
2
+ Name: shadowcordv2
3
+ Version: 1.8.0
4
+ Summary: A Discord.py 1.7.3 fork tailored for selfbot usage
5
+ Author: JinxedUp
6
+ License: The MIT License (MIT)
7
+
8
+ Copyright (c) 2015-present Rapptz
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a
11
+ copy of this software and associated documentation files (the "Software"),
12
+ to deal in the Software without restriction, including without limitation
13
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
+ and/or sell copies of the Software, and to permit persons to whom the
15
+ Software is furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in
18
+ all copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26
+ DEALINGS IN THE SOFTWARE.
27
+
28
+ Project-URL: Documentation, https://discordpy.readthedocs.io/en/v1.7.3/
29
+ Project-URL: Issue tracker, https://github.com/JinxedUp/shadowcord/issues
30
+ Classifier: Development Status :: 5 - Production/Stable
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: Natural Language :: English
34
+ Classifier: Operating System :: OS Independent
35
+ Classifier: Programming Language :: Python :: 3.9
36
+ Classifier: Programming Language :: Python :: 3.10
37
+ Classifier: Programming Language :: Python :: 3.11
38
+ Classifier: Programming Language :: Python :: 3.12
39
+ Classifier: Programming Language :: Python :: 3.13
40
+ Classifier: Programming Language :: Python :: 3.14
41
+ Classifier: Topic :: Internet
42
+ Classifier: Topic :: Software Development :: Libraries
43
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
44
+ Classifier: Topic :: Utilities
45
+ Classifier: Typing :: Typed
46
+ Requires-Python: >=3.9
47
+ Description-Content-Type: text/markdown
48
+ License-File: LICENSE
49
+ Requires-Dist: aiohttp<4,>=3.9.0
50
+ Provides-Extra: voice
51
+ Requires-Dist: PyNaCl<1.7,>=1.3.0; extra == "voice"
52
+ Requires-Dist: audioop-lts; python_version >= "3.13" and extra == "voice"
53
+ Provides-Extra: speed
54
+ Requires-Dist: orjson>=3.5.4; extra == "speed"
55
+ Dynamic: license-file
56
+
57
+ # shadowcord
58
+ **A fork of discord.py 1.7.3 originally made by Rapptz for selfbots and compatibility with modern Python**
59
+
60
+ **Project's goal was to bring discord.py 1.7.3 to python 3.13+ while improving the selfbot stealth aspect, new updates are not planned. if you would like to use an maintained discord libraries i recommend using** [Discord.py for bots](https://github.com/Rapptz/discord.py) **and** [Discord.py-self for selfbots](https://github.com/dolfies/discord.py-self)
61
+
62
+ ## Features
63
+ - fully compatible with python 3.9 through 3.14 (including 3.13+, where `audioop` was removed from the standard library) and newer aiohttp versions
64
+ - restored the `discord.webhook` and `discord.ui` packages that were accidentally missing from the published source tree
65
+ - modern `pyproject.toml` packaging (replaces the legacy `setup.py`)
66
+ - event loop handling updated for Python 3.12+ (no more deprecated implicit `asyncio.get_event_loop()` usage)
67
+ - improved stealthy requests for user accounts
68
+ - Rotates realistic browser User-Agent and X-Super-Properties headers for every request
69
+ - WebSocket Identify payload mimics real Discord clients/browsers, with randomized client/OS info
70
+
71
+ ### This fork tries to not change that much how it works compared to discord.py, that means you can use the documentation for 1.7.3 created by Rapptz
72
+ [discord.py 1.7.3 documentation](https://discordpy.readthedocs.io/en/v1.7.3/)
73
+
74
+ Install shadowcord on your computer using:
75
+ ```
76
+ pip install shadowcordv2
77
+ ```
78
+
79
+ With voice support (recommended, includes the `audioop` backport on Python 3.13+):
80
+ ```
81
+ pip install "shadowcordv2[voice]"
82
+ ```
83
+
84
+ If you had the regular `discord.py` installed, uninstall it first so the two packages don't conflict:
85
+ ```
86
+ pip uninstall discord.py
87
+ pip install shadowcordv2
88
+ ```
89
+
90
+ Note: the PyPI package is called `shadowcordv2`, but the import name stays `discord` (same as discord.py):
91
+ ```python
92
+ import discord
93
+ ```
94
+
95
+ Due to the fork being derived from discord.py 1.7.3, most selfbots written for that discord.py version will work with no changes.
@@ -0,0 +1,39 @@
1
+ # shadowcord
2
+ **A fork of discord.py 1.7.3 originally made by Rapptz for selfbots and compatibility with modern Python**
3
+
4
+ **Project's goal was to bring discord.py 1.7.3 to python 3.13+ while improving the selfbot stealth aspect, new updates are not planned. if you would like to use an maintained discord libraries i recommend using** [Discord.py for bots](https://github.com/Rapptz/discord.py) **and** [Discord.py-self for selfbots](https://github.com/dolfies/discord.py-self)
5
+
6
+ ## Features
7
+ - fully compatible with python 3.9 through 3.14 (including 3.13+, where `audioop` was removed from the standard library) and newer aiohttp versions
8
+ - restored the `discord.webhook` and `discord.ui` packages that were accidentally missing from the published source tree
9
+ - modern `pyproject.toml` packaging (replaces the legacy `setup.py`)
10
+ - event loop handling updated for Python 3.12+ (no more deprecated implicit `asyncio.get_event_loop()` usage)
11
+ - improved stealthy requests for user accounts
12
+ - Rotates realistic browser User-Agent and X-Super-Properties headers for every request
13
+ - WebSocket Identify payload mimics real Discord clients/browsers, with randomized client/OS info
14
+
15
+ ### This fork tries to not change that much how it works compared to discord.py, that means you can use the documentation for 1.7.3 created by Rapptz
16
+ [discord.py 1.7.3 documentation](https://discordpy.readthedocs.io/en/v1.7.3/)
17
+
18
+ Install shadowcord on your computer using:
19
+ ```
20
+ pip install shadowcordv2
21
+ ```
22
+
23
+ With voice support (recommended, includes the `audioop` backport on Python 3.13+):
24
+ ```
25
+ pip install "shadowcordv2[voice]"
26
+ ```
27
+
28
+ If you had the regular `discord.py` installed, uninstall it first so the two packages don't conflict:
29
+ ```
30
+ pip uninstall discord.py
31
+ pip install shadowcordv2
32
+ ```
33
+
34
+ Note: the PyPI package is called `shadowcordv2`, but the import name stays `discord` (same as discord.py):
35
+ ```python
36
+ import discord
37
+ ```
38
+
39
+ Due to the fork being derived from discord.py 1.7.3, most selfbots written for that discord.py version will work with no changes.
@@ -0,0 +1,46 @@
1
+ Shadowcord
2
+ ==========
3
+
4
+ .. image:: https://img.shields.io/pypi/v/shadowcordv2.svg
5
+ :target: https://pypi.org/project/shadowcordv2/
6
+ :alt: PyPI version info
7
+ .. image:: https://img.shields.io/pypi/pyversions/shadowcordv2.svg
8
+ :target: https://pypi.org/project/shadowcordv2/
9
+ :alt: PyPI supported Python versions
10
+
11
+ A selfbot fork of discord.py version 1.7.3, optimized for selfbot usage.
12
+
13
+ Installation
14
+ ------------
15
+
16
+ Requires Python 3.9+ (tested up to Python 3.14)
17
+
18
+ To install:
19
+
20
+ .. code:: sh
21
+
22
+ pip install -U shadowcordv2
23
+
24
+ On Python 3.13 and newer, voice support additionally requires the ``audioop``
25
+ backport, which is installed automatically with the ``voice`` extra:
26
+
27
+ .. code:: sh
28
+
29
+ pip install "shadowcordv2[voice]"
30
+
31
+
32
+ -----
33
+
34
+ Same API as discord.py 1.7.3, you can use existing discord.py examples.
35
+
36
+ .. code-block:: python
37
+
38
+ import discord
39
+
40
+ client = discord.Client()
41
+
42
+ @client.event
43
+ async def on_ready():
44
+ print(f"Logged in as {client.user}")
45
+
46
+ client.run('token')
@@ -0,0 +1,78 @@
1
+ """
2
+ Discord API Wrapper
3
+ ~~~~~~~~~~~~~~~~~~~
4
+
5
+ A basic wrapper for the Discord API.
6
+
7
+ :copyright: (c) 2015-present Rapptz
8
+ :license: MIT, see LICENSE for more details.
9
+
10
+ """
11
+
12
+ __title__ = 'discord'
13
+ __author__ = 'Rapptz'
14
+ __license__ = 'MIT'
15
+ __copyright__ = 'Copyright 2015-present Rapptz'
16
+ __version__ = "1.8.0"
17
+
18
+
19
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__)
20
+
21
+ import logging
22
+ from typing import NamedTuple, Literal
23
+
24
+ from .client import Client
25
+ from .appinfo import *
26
+ from .user import *
27
+ from .emoji import *
28
+ from .partial_emoji import *
29
+ from .activity import *
30
+ from .channel import *
31
+ from .guild import *
32
+ from .flags import *
33
+ from .member import *
34
+ from .message import *
35
+ from .asset import *
36
+ from .errors import *
37
+ from .permissions import *
38
+ from .role import *
39
+ from .file import *
40
+ from .colour import *
41
+ from .integrations import *
42
+ from .invite import *
43
+ from .template import *
44
+ from .widget import *
45
+ from .object import *
46
+ from .reaction import *
47
+ from . import utils, opus, abc, ui
48
+ from .enums import *
49
+ from .embeds import *
50
+ from .mentions import *
51
+ from .shard import *
52
+ from .player import *
53
+ from .webhook import *
54
+ from .voice_client import *
55
+ from .audit_logs import *
56
+ from .raw_models import *
57
+ from .team import *
58
+ from .sticker import *
59
+ from .stage_instance import *
60
+ from .interactions import *
61
+ from .components import *
62
+ from .threads import *
63
+
64
+
65
+ class VersionInfo(NamedTuple):
66
+ major: int
67
+ minor: int
68
+ micro: int
69
+ releaselevel: Literal["alpha", "beta", "candidate", "final"]
70
+ serial: int
71
+
72
+
73
+ version_info: VersionInfo = VersionInfo(major=1, minor=8, micro=0, releaselevel='final', serial=0)
74
+
75
+ logging.getLogger(__name__).addHandler(logging.NullHandler())
76
+
77
+ # Explicitly export Client
78
+ __all__ = ['Client']
@@ -0,0 +1,300 @@
1
+ """
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2015-present Rapptz
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a
7
+ copy of this software and associated documentation files (the "Software"),
8
+ to deal in the Software without restriction, including without limitation
9
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
+ and/or sell copies of the Software, and to permit persons to whom the
11
+ Software is furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
+ DEALINGS IN THE SOFTWARE.
23
+ """
24
+
25
+ import argparse
26
+ import sys
27
+ from pathlib import Path
28
+
29
+ import discord
30
+ import pkg_resources
31
+ import aiohttp
32
+ import platform
33
+
34
+ def show_version():
35
+ entries = []
36
+
37
+ entries.append('- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(sys.version_info))
38
+ version_info = discord.version_info
39
+ entries.append('- discord.py v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(version_info))
40
+ if version_info.releaselevel != 'final':
41
+ pkg = pkg_resources.get_distribution('discord.py')
42
+ if pkg:
43
+ entries.append(f' - discord.py pkg_resources: v{pkg.version}')
44
+
45
+ entries.append(f'- aiohttp v{aiohttp.__version__}')
46
+ uname = platform.uname()
47
+ entries.append('- system info: {0.system} {0.release} {0.version}'.format(uname))
48
+ print('\n'.join(entries))
49
+
50
+ def core(parser, args):
51
+ if args.version:
52
+ show_version()
53
+
54
+ _bot_template = """#!/usr/bin/env python3
55
+
56
+ from discord.ext import commands
57
+ import discord
58
+ import config
59
+
60
+ class Bot(commands.{base}):
61
+ def __init__(self, **kwargs):
62
+ super().__init__(command_prefix=commands.when_mentioned_or('{prefix}'), **kwargs)
63
+ for cog in config.cogs:
64
+ try:
65
+ self.load_extension(cog)
66
+ except Exception as exc:
67
+ print(f'Could not load extension {{cog}} due to {{exc.__class__.__name__}}: {{exc}}')
68
+
69
+ async def on_ready(self):
70
+ print(f'Logged on as {{self.user}} (ID: {{self.user.id}})')
71
+
72
+
73
+ bot = Bot()
74
+
75
+ # write general commands here
76
+
77
+ bot.run(config.token)
78
+ """
79
+
80
+ _gitignore_template = """# Byte-compiled / optimized / DLL files
81
+ __pycache__/
82
+ *.py[cod]
83
+ *$py.class
84
+
85
+ # C extensions
86
+ *.so
87
+
88
+ # Distribution / packaging
89
+ .Python
90
+ env/
91
+ build/
92
+ develop-eggs/
93
+ dist/
94
+ downloads/
95
+ eggs/
96
+ .eggs/
97
+ lib/
98
+ lib64/
99
+ parts/
100
+ sdist/
101
+ var/
102
+ *.egg-info/
103
+ .installed.cfg
104
+ *.egg
105
+
106
+ # Our configuration files
107
+ config.py
108
+ """
109
+
110
+ _cog_template = '''from discord.ext import commands
111
+ import discord
112
+
113
+ class {name}(commands.Cog{attrs}):
114
+ """The description for {name} goes here."""
115
+
116
+ def __init__(self, bot):
117
+ self.bot = bot
118
+ {extra}
119
+ def setup(bot):
120
+ bot.add_cog({name}(bot))
121
+ '''
122
+
123
+ _cog_extras = '''
124
+ def cog_unload(self):
125
+ # clean up logic goes here
126
+ pass
127
+
128
+ async def cog_check(self, ctx):
129
+ # checks that apply to every command in here
130
+ return True
131
+
132
+ async def bot_check(self, ctx):
133
+ # checks that apply to every command to the bot
134
+ return True
135
+
136
+ async def bot_check_once(self, ctx):
137
+ # check that apply to every command but is guaranteed to be called only once
138
+ return True
139
+
140
+ async def cog_command_error(self, ctx, error):
141
+ # error handling to every command in here
142
+ pass
143
+
144
+ async def cog_before_invoke(self, ctx):
145
+ # called before a command is called here
146
+ pass
147
+
148
+ async def cog_after_invoke(self, ctx):
149
+ # called after a command is called here
150
+ pass
151
+
152
+ '''
153
+
154
+
155
+ # certain file names and directory names are forbidden
156
+ # see: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
157
+ # although some of this doesn't apply to Linux, we might as well be consistent
158
+ _base_table = {
159
+ '<': '-',
160
+ '>': '-',
161
+ ':': '-',
162
+ '"': '-',
163
+ # '/': '-', these are fine
164
+ # '\\': '-',
165
+ '|': '-',
166
+ '?': '-',
167
+ '*': '-',
168
+ }
169
+
170
+ # NUL (0) and 1-31 are disallowed
171
+ _base_table.update((chr(i), None) for i in range(32))
172
+
173
+ _translation_table = str.maketrans(_base_table)
174
+
175
+ def to_path(parser, name, *, replace_spaces=False):
176
+ if isinstance(name, Path):
177
+ return name
178
+
179
+ if sys.platform == 'win32':
180
+ forbidden = ('CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', \
181
+ 'COM8', 'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9')
182
+ if len(name) <= 4 and name.upper() in forbidden:
183
+ parser.error('invalid directory name given, use a different one')
184
+
185
+ name = name.translate(_translation_table)
186
+ if replace_spaces:
187
+ name = name.replace(' ', '-')
188
+ return Path(name)
189
+
190
+ def newbot(parser, args):
191
+ new_directory = to_path(parser, args.directory) / to_path(parser, args.name)
192
+
193
+ # as a note exist_ok for Path is a 3.5+ only feature
194
+ # since we already checked above that we're >3.5
195
+ try:
196
+ new_directory.mkdir(exist_ok=True, parents=True)
197
+ except OSError as exc:
198
+ parser.error(f'could not create our bot directory ({exc})')
199
+
200
+ cogs = new_directory / 'cogs'
201
+
202
+ try:
203
+ cogs.mkdir(exist_ok=True)
204
+ init = cogs / '__init__.py'
205
+ init.touch()
206
+ except OSError as exc:
207
+ print(f'warning: could not create cogs directory ({exc})')
208
+
209
+ try:
210
+ with open(str(new_directory / 'config.py'), 'w', encoding='utf-8') as fp:
211
+ fp.write('token = "place your token here"\ncogs = []\n')
212
+ except OSError as exc:
213
+ parser.error(f'could not create config file ({exc})')
214
+
215
+ try:
216
+ with open(str(new_directory / 'bot.py'), 'w', encoding='utf-8') as fp:
217
+ base = 'Bot' if not args.sharded else 'AutoShardedBot'
218
+ fp.write(_bot_template.format(base=base, prefix=args.prefix))
219
+ except OSError as exc:
220
+ parser.error(f'could not create bot file ({exc})')
221
+
222
+ if not args.no_git:
223
+ try:
224
+ with open(str(new_directory / '.gitignore'), 'w', encoding='utf-8') as fp:
225
+ fp.write(_gitignore_template)
226
+ except OSError as exc:
227
+ print(f'warning: could not create .gitignore file ({exc})')
228
+
229
+ print('successfully made bot at', new_directory)
230
+
231
+ def newcog(parser, args):
232
+ cog_dir = to_path(parser, args.directory)
233
+ try:
234
+ cog_dir.mkdir(exist_ok=True)
235
+ except OSError as exc:
236
+ print(f'warning: could not create cogs directory ({exc})')
237
+
238
+ directory = cog_dir / to_path(parser, args.name)
239
+ directory = directory.with_suffix('.py')
240
+ try:
241
+ with open(str(directory), 'w', encoding='utf-8') as fp:
242
+ attrs = ''
243
+ extra = _cog_extras if args.full else ''
244
+ if args.class_name:
245
+ name = args.class_name
246
+ else:
247
+ name = str(directory.stem)
248
+ if '-' in name or '_' in name:
249
+ translation = str.maketrans('-_', ' ')
250
+ name = name.translate(translation).title().replace(' ', '')
251
+ else:
252
+ name = name.title()
253
+
254
+ if args.display_name:
255
+ attrs += f', name="{args.display_name}"'
256
+ if args.hide_commands:
257
+ attrs += ', command_attrs=dict(hidden=True)'
258
+ fp.write(_cog_template.format(name=name, extra=extra, attrs=attrs))
259
+ except OSError as exc:
260
+ parser.error(f'could not create cog file ({exc})')
261
+ else:
262
+ print('successfully made cog at', directory)
263
+
264
+ def add_newbot_args(subparser):
265
+ parser = subparser.add_parser('newbot', help='creates a command bot project quickly')
266
+ parser.set_defaults(func=newbot)
267
+
268
+ parser.add_argument('name', help='the bot project name')
269
+ parser.add_argument('directory', help='the directory to place it in (default: .)', nargs='?', default=Path.cwd())
270
+ parser.add_argument('--prefix', help='the bot prefix (default: $)', default='$', metavar='<prefix>')
271
+ parser.add_argument('--sharded', help='whether to use AutoShardedBot', action='store_true')
272
+ parser.add_argument('--no-git', help='do not create a .gitignore file', action='store_true', dest='no_git')
273
+
274
+ def add_newcog_args(subparser):
275
+ parser = subparser.add_parser('newcog', help='creates a new cog template quickly')
276
+ parser.set_defaults(func=newcog)
277
+
278
+ parser.add_argument('name', help='the cog name')
279
+ parser.add_argument('directory', help='the directory to place it in (default: cogs)', nargs='?', default=Path('cogs'))
280
+ parser.add_argument('--class-name', help='the class name of the cog (default: <name>)', dest='class_name')
281
+ parser.add_argument('--display-name', help='the cog name (default: <name>)')
282
+ parser.add_argument('--hide-commands', help='whether to hide all commands in the cog', action='store_true')
283
+ parser.add_argument('--full', help='add all special methods as well', action='store_true')
284
+
285
+ def parse_args():
286
+ parser = argparse.ArgumentParser(prog='discord', description='Tools for helping with discord.py')
287
+ parser.add_argument('-v', '--version', action='store_true', help='shows the library version')
288
+ parser.set_defaults(func=core)
289
+
290
+ subparser = parser.add_subparsers(dest='subcommand', title='subcommands')
291
+ add_newbot_args(subparser)
292
+ add_newcog_args(subparser)
293
+ return parser, parser.parse_args()
294
+
295
+ def main():
296
+ parser, args = parse_args()
297
+ args.func(parser, args)
298
+
299
+ if __name__ == '__main__':
300
+ main()