Skip to content

Commit

Permalink
feat: 4.0.1
Browse files Browse the repository at this point in the history
Prepare 4.0.1 stable release.
  • Loading branch information
i0bs authored Dec 19, 2021
2 parents 807e42f + a19f06c commit 0b03073
Show file tree
Hide file tree
Showing 44 changed files with 138 additions and 58 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dist/
.venv
.vscode
__pycache__
.token

*.token
1 change: 0 additions & 1 deletion .token

This file was deleted.

59 changes: 59 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Contributions
=============
Contributions to this open-source project are welcome and always appreciated! Every line of code helps
us ensure a better developed project to users. We will always credit those who help out.

New to contributing
-------------------
If you're new to contributing towards this project, we highly recommend starting off with installing
the library off of pip:

.. code-block:: bash
pip install -U discord-py-interactions
Once you have the library installed in Python, you are able to instantiate and run a basic bot
with a logging level that is set for debugging purposes. This is recommend in order to make it easier
for us to log certain events and procedures internally that may happen before, during or after an
error may be produced:

.. code-block:: python
import interactions
from logging import DEBUG
bot = interactions.Client(token="...", log_level=DEBUG) # you can also use -1.
bot.start()
Since we are an open-source project that unofficially supports the Discord API, we also respect
the `Code of Conduct`_ from their documentation.

Where to start
--------------
Our contributions start with an **Issue**. The issue should explain what the problem you're having is.
Issues are our way and methodology of tracking bugs that may be occuring with this library. In order
to create create in relevance to the issue, you start a **Pull Request**. Linking the issue in this
(known as a PR) allows us to easily identify what bugs have been correlated with the code requesting
to be changed in the source, and allow other developers to contribute where needed.

When a PR is made, you **must** be targeting the ``unstable`` branch. This is our development branch
that we use whenever we're working on any bugfixing, breaking changes and/or overall new features. Our
development workflow for changes is from this branch to ``stable``, and then from there to a release.

Pull Request specifications
***************************
A pull request should adhere to these following requirements:

- Each git commit made on your forked project should use `conventional commits`_.
- The pull request should always be up-to-date with ``unstable``.

Recognizing contributors
------------------------
When a PR is successfully merged into one of the development branches, the GitHub user will automatically
be added to the contributor list of the repository. Additionally, we also provide a role in our support
server for contributors. (You will be notified if you are eligible for this.) The git commit history on a
file will also subsequently be updated by GitHub to include your user signature.

.. _Code of Conduct: https://github.com/discord/discord-api-docs/blob/master/CODE_OF_CONDUCT.md
.. _conventional commits: https://www.conventionalcommits.org/en/v1.0.0/
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ I think I'm all ready!
Feel free to begin making `Pull Requests`_ and `Issues`_ on our GitHub!

.. _quickstart guide: https://discord-interactions.rtfd.io/en/latest/quickstart.html
.. _contribution requirements: https://github.com/goverfl0w/discord-interactions/blob/stable/CONTRIBUTING.md
.. _contribution requirements: https://github.com/goverfl0w/discord-interactions/blob/stable/CONTRIBUTING.rst
.. _MIT License: https://github.com/goverfl0w/discord-interactions/blob/stable/LICENSE
.. _Pull Requests: https://github.com/goverfl0w/discord-interactions/pulls
.. _Issues: https://github.com/goverfl0w/discord-interactions/issues
Binary file added docs/locale/de/LC_MESSAGES/api.cache.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.dispatch.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.enums.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.error.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.gateway.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.http.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.channel.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.guild.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.intents.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.member.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.message.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.misc.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.presence.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.role.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.team.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.user.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/api.models.voice.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/client.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/components.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/enums.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/faq.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/gettingstarted.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/index.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/models.command.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/models.component.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/models.mo
Binary file not shown.
Binary file added docs/locale/de/LC_MESSAGES/quickstart.mo
Binary file not shown.
47 changes: 27 additions & 20 deletions interactions/api/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,30 +245,31 @@ def handle_dispatch(self, event: str, data: dict) -> None:
:type data: dict
"""

def check_sub_command(self, option) -> dict:
_kwargs = dict()
if "options" in option:
if option["type"] == OptionType.SUB_COMMAND_GROUP:
_kwargs["sub_command_group"] = option["name"]
def check_sub_command(option: dict) -> dict:
kwargs = dict()
if option["type"] == OptionType.SUB_COMMAND_GROUP:
kwargs["sub_command_group"] = option["name"]
if option.get("options"):
for group_option in option["options"]:
_kwargs["sub_command"] = group_option["name"]
if "options" in group_option:
kwargs["sub_command"] = group_option["name"]
if group_option.get("options"):
for sub_option in group_option["options"]:
_kwargs[sub_option["name"]] = sub_option["value"]
elif option["type"] == OptionType.SUB_COMMAND:
_kwargs["sub_command"] = option["name"]
kwargs[sub_option["name"]] = sub_option["value"]
elif option["type"] == OptionType.SUB_COMMAND:
kwargs["sub_command"] = option["name"]
if option.get("options"):
for sub_option in option["options"]:
_kwargs[sub_option["name"]] = sub_option["value"]
kwargs[sub_option["name"]] = sub_option["value"]
else:
_kwargs[option["name"]] = option["value"]
kwargs[option["name"]] = option["value"]

return _kwargs
return kwargs

def check_sub_auto(self, option) -> tuple:
if "options" in option:
def check_sub_auto(option: dict) -> tuple:
if option.get("options"):
if option["type"] == OptionType.SUB_COMMAND_GROUP:
for group_option in option["options"]:
if "options" in group_option:
if group_option.get("options"):
for sub_option in option["options"]:
if sub_option.get("focused"):
return sub_option["name"], sub_option["value"]
Expand Down Expand Up @@ -310,18 +311,24 @@ def check_sub_auto(self, option) -> tuple:
_kwargs: dict = dict()
if data["type"] == InteractionType.APPLICATION_COMMAND:
_name = context.data.name
if hasattr(context.data, "options"):
if context.data._json.get("options"):
if context.data.options:
for option in context.data.options:
_kwargs.update(check_sub_command(option))
_kwargs.update(
check_sub_command(
option if isinstance(option, dict) else option._json
)
)
elif data["type"] == InteractionType.MESSAGE_COMPONENT:
_name = context.data.custom_id
elif data["type"] == InteractionType.APPLICATION_COMMAND_AUTOCOMPLETE:
_name = "autocomplete_"
if hasattr(context.data, "options"):
if context.data._json.get("options"):
if context.data.options:
for option in context.data.options:
add_name, add_args = check_sub_auto(option)
add_name, add_args = check_sub_auto(
option if isinstance(option, dict) else option._json
)
if add_name:
_name += add_name
if add_args:
Expand Down
17 changes: 9 additions & 8 deletions interactions/api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(self, token: str) -> None:
f"Python/{version_info[0]}.{version_info[1]} "
f"aiohttp/{http_version}",
}
self.lock = Event(loop=self.loop)
self.lock = Event() if version_info >= (3, 10) else Event(loop=self.loop)

self.lock.set()

Expand Down Expand Up @@ -1859,11 +1859,12 @@ async def get_application_command(
"""
application_id = int(application_id)

if not guild_id:
if guild_id in (None, "None"):
return await self._req.request(Route("GET", f"/applications/{application_id}/commands"))
return await self._req.request(
Route("GET", f"/applications/{application_id}/guilds/{guild_id}/commands")
)
else:
return await self._req.request(
Route("GET", f"/applications/{application_id}/guilds/{guild_id}/commands")
)

async def create_application_command(
self, application_id: Union[int, Snowflake], data: dict, guild_id: Optional[int] = None
Expand All @@ -1881,7 +1882,7 @@ async def create_application_command(

url = (
f"/applications/{application_id}/commands"
if not guild_id
if guild_id in (None, "None")
else f"/applications/{application_id}/guilds/{guild_id}/commands"
)

Expand Down Expand Up @@ -1933,7 +1934,7 @@ async def edit_application_command(
application_id=application_id,
command_id=command_id,
)
if not guild_id
if guild_id in (None, "None")
else Route(
"PATCH",
"/applications/{application_id}/guilds/" "{guild_id}/commands/{command_id}",
Expand Down Expand Up @@ -1965,7 +1966,7 @@ async def delete_application_command(
command_id=command_id,
guild_id=guild_id,
)
if guild_id
if guild_id not in (None, "None")
else Route(
"DELETE",
"/applications/{application_id}/commands/{command_id}",
Expand Down
5 changes: 5 additions & 0 deletions interactions/api/models/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class PresenceActivity(DictSerializerMixin):
"instance",
"flags",
"buttons",
# TODO: document/investigate what these do.
"users",
"status",
"client_status",
"activities",
)

def __init__(self, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions interactions/api/models/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Application(DictSerializerMixin):
"flags",
"type",
"hook",
"tags", # TODO: document/investigate what it does.
)

def __init__(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion interactions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from colorama import Fore, Style, init

__version__ = "4.0.0"
__version__ = "4.0.1"
__repo_url__ = "https://github.com/goverfl0w/discord-interactions"
__authors__ = {
"current": [
Expand Down
10 changes: 5 additions & 5 deletions interactions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ def __init__(
_token = token # noqa: F841
_cache = self.http.cache # noqa: F841

if disable_sync: # you don't need to change this. this is already correct.
if disable_sync:
self.automate_sync = False
log.warning(
"Automatic synchronization has been disabled. Interactions may need to be manually synchronized."
)
else:
self.automate_sync = True

log_names: list = ["client", "context", "dispatch", "gateway", "http"]
log_names: list = ["client", "context", "dispatch", "gateway", "http", "mixin"]
for logger in log_names:
getLogger(logger).setLevel(log_level)

Expand Down Expand Up @@ -203,7 +203,7 @@ async def create(data: ApplicationCommand) -> None:
application_id=command.get("application_id"),
id=command.get("id"),
type=command.get("type"),
guild_id=str(command.get("guild_id")),
guild_id=str(command["guild_id"]) if command.get("guild_id") else None,
name=command.get("name"),
description=command.get("description", ""),
default_permission=command.get("default_permission", False),
Expand Down Expand Up @@ -232,7 +232,7 @@ async def create(data: ApplicationCommand) -> None:
application_id=self.me.id,
data=payload._json,
command_id=result.id,
guild_id=result.guild_id,
guild_id=result._json.get("guild_id"),
)
self.http.cache.interactions.add(
Build(id=payload.name, value=payload)
Expand Down Expand Up @@ -262,7 +262,7 @@ async def create(data: ApplicationCommand) -> None:
request = await self.http.delete_application_command(
application_id=self.me.id,
command_id=command["id"],
guild_id=command["guild_id"],
guild_id=command.get("guild_id"),
)

if request:
Expand Down
14 changes: 12 additions & 2 deletions interactions/decor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,20 @@ def command(
else:
_scope.append(scope)

for guild in _scope:
if _scope:
for guild in _scope:
payload: ApplicationCommand = ApplicationCommand(
type=_type,
guild_id=guild,
name=name,
description=_description,
options=_options,
default_permission=_default_permission,
)
payloads.append(payload)
else:
payload: ApplicationCommand = ApplicationCommand(
type=_type,
guild_id=guild,
name=name,
description=_description,
options=_options,
Expand Down
5 changes: 4 additions & 1 deletion interactions/models/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def __init__(self, **kwargs) -> None:
self.type = OptionType(self.type)
self._json.update({"type": self.type.value})
if self._json.get("options"):
self._json["options"] = [option._json for option in self.options]
if all(isinstance(option, dict) for option in self.options):
self._json["options"] = [option for option in self.options]
else:
self._json["options"] = [option._json for option in self.options]
if self._json.get("choices"):
if isinstance(self._json.get("choices"), dict):
self._json["choices"] = [choice for choice in self.choices]
Expand Down
7 changes: 5 additions & 2 deletions interactions/models/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ class InteractionData(DictSerializerMixin):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.type = ApplicationCommandType(self.type) if self._json.get("type") else None
if self._json.get("type"):
self.type = ApplicationCommandType(self.type)
self._json.update({"type": self.type.value})
else:
self.type = 0
self.resolved = (
InteractionResolvedData(**self.resolved) if self._json.get("resolved") else None
)
Expand All @@ -115,7 +119,6 @@ def __init__(self, **kwargs):
if self._json.get("component_type"):
self.component_type = ComponentType(self.component_type)
self._json.update({"component_type": self.component_type.value})
self._json.update({"type": self.type.value})


class Interaction(DictSerializerMixin):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
install_requires=requirements,
license="MIT License",
long_description=README,
long_description_content_type="text/markdown",
long_description_content_type="text/x-rst",
url="https://github.com/goverfl0w/discord-interactions",
packages=find_packages(),
python_requires=">=3.8.6",
Expand Down
21 changes: 6 additions & 15 deletions simple_bot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import interactions

bot = interactions.Client(token=open(".token").read())
bot = interactions.Client(token=open("bot.token").read(), log_level=-1)


@bot.event
Expand All @@ -9,21 +9,12 @@ async def on_ready():


@bot.command(
name="basic-command",
description="ever wanted a basic command? well, here it is!",
scope=852402668294766612,
options=[
interactions.Option(
type=interactions.OptionType.STRING,
name="option",
description="please PLEASE write in me! UwU :(",
required=True,
)
],
name="global-command",
description="ever wanted a global command? well, here it is!",
)
async def basic_command(ctx, option):
await ctx.send(f"{option}")
async def basic_command(ctx):
await ctx.send("Global commands are back in action, baby!")


bot.load("simple_cog")
# bot.load("simple_cog")
bot.start()

0 comments on commit 0b03073

Please sign in to comment.