Skip to content

Commit

Permalink
0.0.57 - QOL improvements (#22)
Browse files Browse the repository at this point in the history
* Refactor errors, add readthedocs config file and github actions

* fix readthedocs config file

* Fixed checks.has_permissions and checks._bot_has_permissions (#6)

* Fixed checks.has_permissions

* Remove unused import and whitespace

* Add missing_args to NotEnoughArguments and fix iter method for WrappedArg

* Document using different logging levels with `logs` (#14)

* Bump mock from 4.0.2 to 4.0.3 (#15)

Bumps [mock](https://github.com/testing-cabal/mock) from 4.0.2 to 4.0.3.
- [Release notes](https://github.com/testing-cabal/mock/releases)
- [Changelog](https://github.com/testing-cabal/mock/blob/master/CHANGELOG.rst)
- [Commits](testing-cabal/mock@4.0.2...4.0.3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update hikari requirement from ~=2.0.0.dev96 to ~=2.0.0.dev97 (#16)

Updates the requirements on [hikari](https://github.com/hikari-py/hikari) to permit the latest version.
- [Release notes](https://github.com/hikari-py/hikari/releases)
- [Commits](hikari-py/hikari@2.0.0.dev96...2.0.0.dev97)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update project url

* Run black

* Bump pytest from 6.1.2 to 6.2.1 (#18)

Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.1.2 to 6.2.1.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst)
- [Commits](pytest-dev/pytest@6.1.2...6.2.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Allow get_command to find subcommands without having to call cmd.get_subcommand explicitly

* Fix custom help example (#21)

* Update copyright year, changelog and version number

Co-authored-by: K.M Ahnaf Zamil <57180217+ahnaf-zamil@users.noreply.github.com>
Co-authored-by: davfsa <davfsa@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: lachlan <lachlan_goh@hotmail.com>
  • Loading branch information
5 people committed Jan 1, 2021
1 parent 3709d55 commit 9ef0f5d
Show file tree
Hide file tree
Showing 30 changed files with 103 additions and 58 deletions.
1 change: 0 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ python:
install:
- requirements: requirements.txt
- requirements: docs_requirements.txt

9 changes: 9 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ If you think anything is missing, make a merge request to add it, or contact tho

----

Version 0.0.57
==============

- Add `missing_args` parameter to :obj:`~lightbulb.errors.NotEnoughArguments`

- Fix `__iter__` for :obj:`~lightbulb.converters.WrappedArg`

- Improve :obj:`~lightbulb.command_handler.Bot.get_command` to allow you to get subcommands without having to call :obj:`~lightbulb.commands.Group.get_subcommand`

Version 0.0.56
==============

Expand Down
4 changes: 2 additions & 2 deletions docs/source/custom-help.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Example:

@bot.command()
async def help(ctx):
await ctx.reply(HELP_COMMAND)
await ctx.reply(HELP_MESSAGE)

However, the main flaw of this method is that the command will not be auto generated so you will have to add details
for all of your commands, groups, and plugins manually.
Expand Down Expand Up @@ -99,4 +99,4 @@ The help submodule also provides some useful utilities to help you with your imp

- :obj:`~.lightbulb.help.get_command_signature` - Gets the command signature, useful for displaying the usage of a command.

- :obj:`~lightbulb.help.filter_commands` - Filter a list of commands to remove any that the invoker of the help command cannot use.
- :obj:`~lightbulb.help.filter_commands` - Filter a list of commands to remove any that the invoker of the help command cannot use.
36 changes: 27 additions & 9 deletions docs/source/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,42 @@ Optional: Setting up logging

Lightbulb uses the ``logging`` library for the logging of useful information for debugging and testing purposes. For
example, if the logging level is set to debug, messages will be displayed every time a command, plugin or extension
is added or removed.
is added or removed. This can be changed by using the ``logs`` argument if you want to keep the customization that
``hikari`` does by default. Alternatively, you can use ``logging`` directly.

Example:
Changing the logging level with using the ``logs`` argument:
::

import logging
import lightbulb

# Get the lightbulb logger and set the level to debug
logging.getLogger("lightbulb").setLevel(logging.DEBUG)

bot = lightbulb.Bot(...)
# Set to debug for both lightbulb and hikari
bot = lightbulb.Bot(..., logs="DEBUG")

bot.run()

This code sets the logging level of the lightbulb logger to debug. This will log all commands added or removed, plugins
added or removed, and extensions loaded or unloaded.
Using different logging levels for both ``hikari`` and ``lightbulb``:
::

import logging
import lightbulb

# Set different logging levels for both lightbulb and hikari
bot = lightbulb.Bot(
...,
logs={
"version": 1,
"incremental": True,
"loggers": {
"hikari": {"level": "INFO"},
"hikari.ratelimits": {"level": "TRACE_HIKARI"},
"lightbulb": {"level": "DEBUG"},
},
},
)

bot.run()

.. note::
Usually you should set the logging level to ``logging.INFO`` as setting it to debug can cause a lot
of console spam, possibly impacting the performance of your program.
of console spam, possibly impacting the performance of your program.
20 changes: 10 additions & 10 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,38 @@
Lightbulb
=========

Lightbulb is a command handler library designed for use with `Hikari <https://gitlab.com/nekokatt/hikari>`_
Lightbulb is a command handler library designed for use with `Hikari <https://github.com/hikari-py/hikari>`_

It aims to provide an easy to use interface for building commands with your bot.

This library is currently unfinished but you can help speed up the development by contributing and submitting merge requests to the repository.
It is working in its current state but I'd love to see more functionality added further down the line!

Repository: `View on GitLab <https://gitlab.com/tandemdude/lightbulb>`_
Repository: `View on GitHub <https://github.com/tandemdude/hikari-lightbulb>`_

Docs: `View Here <https://tandemdude.gitlab.io/lightbulb>`_
Docs: `View Here <https://hikari-lightbulb.readthedocs.io/>`_

If you need any help with this library or hikari at any point feel free to join the `Discord Server <https://discord.gg/Jx4cNGG>`_

If you think you have found a bug or other problem with the library, or you would like to suggest a feature,
you should submit an issue on the GitLab repository `here <https://gitlab.com/tandemdude/lightbulb/-/issues>`_.
you should submit an issue on the GitHub repository `here <https://github.com/tandemdude/hikari-lightbulb/issues>`_.
Before doing so you should make sure you are on the latest version of the library and check to see if an issue
already exists for your bug or feature.


**Contributors:**

- `thomm.o#8637 (creator) <https://gitlab.com/tandemdude>`_
- `thomm.o#8637 (creator) <https://github.com/tandemdude>`_

- `davfsa#7026 <https://gitlab.com/davfsa>`_
- `davfsa#7026 <https://github.com/davfsa>`_

- `nekoka#8788 <https://gitlab.com/nekokatt>`_

- `Forbidden#0001 <https://gitlab.com/Forbidden-A>`_
- `Forbidden#0001 <https://github.com/Forbidden-A>`_

- `Dec0Ded#2693 <https://gitlab.com/dec0ded>`_
- `Dec0Ded#2693 <https://github.com/Dec0Dedd>`_

- `Yoda#0660 <https://gitlab.com/YodaPY>`_
- `Yoda#0660 <https://github.com/YodaPY>`_

- `M.A#4999 <https://gitlab.com/MonAaraj>`_

Expand All @@ -52,9 +52,9 @@ already exists for your bug or feature.
:maxdepth: 2

getting-started
changelog
api-reference
utils-api-reference
custom-help
changelog

* :ref:`genindex`
2 changes: 1 addition & 1 deletion docs_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sphinx_rtd_theme~=0.5.0
sphinx~=3.3.1
sphinx~=3.3.1
4 changes: 2 additions & 2 deletions lightbulb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down Expand Up @@ -53,4 +53,4 @@
*events.__all__,
]

__version__ = "0.0.56"
__version__ = "0.0.57"
4 changes: 2 additions & 2 deletions lightbulb/checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down Expand Up @@ -67,7 +67,7 @@ async def foo(ctx):
async def foo(ctx):
...
See https://tandemdude.gitlab.io/lightbulb/api-reference.html#module-lightbulb.checks
See https://hikari-lightbulb.readthedocs.io/en/latest/api-reference.html#module-lightbulb.checks
"""


Expand Down
20 changes: 16 additions & 4 deletions lightbulb/command_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down Expand Up @@ -438,7 +438,18 @@ def get_command(self, name: str) -> typing.Optional[commands.Command]:
Returns:
Optional[ :obj:`~.commands.Command` ]: Command object registered to that name.
"""
return self._commands.get(name)
tokens = name.split()
this = self._commands.get(tokens.pop(0))

if not tokens:
return this
if this is None:
return this

for token in tokens:
this = this.get_subcommand(token)

return this

def get_plugin(self, name: str) -> typing.Optional[plugins.Plugin]:
"""
Expand Down Expand Up @@ -765,8 +776,9 @@ class useful for extracting the arguments from the raw string and the property
positional_args, remainder = sv.deconstruct_str(max_parse=command.arg_details.maximum_arguments)
if remainder and command.arg_details.kwarg_name is None and not command._allow_extra_arguments:
raise errors.TooManyArguments(command)
if len(positional_args) < command.arg_details.minimum_arguments:
raise errors.NotEnoughArguments(command)
if (len(positional_args) + bool(remainder)) < command.arg_details.minimum_arguments:
missing_args = command.arg_details.get_missing_args([*positional_args, *([remainder] if remainder else [])])
raise errors.NotEnoughArguments(command, missing_args)

if not remainder:
remainder = {}
Expand Down
10 changes: 6 additions & 4 deletions lightbulb/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down Expand Up @@ -154,9 +154,7 @@ def __init__(self, command: Command) -> None:
) and not arg.ignore:
self.number_positional_args += 1

self.minimum_arguments = sum(
1 for a in self.args.values() if not a.ignore and a.required and a.argtype != inspect.Parameter.KEYWORD_ONLY
)
self.minimum_arguments = sum(1 for a in self.args.values() if not a.ignore and a.required)
self.maximum_arguments = (
float("inf")
if any(a.kind == inspect.Parameter.VAR_POSITIONAL for a in signature.parameters.values())
Expand All @@ -182,6 +180,10 @@ def parse_arg(self, index: int, arg: inspect.Parameter) -> ArgInfo:

return ArgInfo(ignore, argtype, annotation, required, default)

def get_missing_args(self, args: typing.List[str]) -> typing.List[str]:
required_command_args = [name for name, arg in self.args.items() if not arg.ignore and arg.required]
return required_command_args[len(args) :]


class Command:
"""
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
5 changes: 4 additions & 1 deletion lightbulb/converters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down Expand Up @@ -103,6 +103,9 @@ def __init__(self, seq: str, context: context_.Context) -> None:
super().__init__(seq)
self.context: context_.Context = context

def __iter__(self):
return iter(self.data)


def _resolve_id_from_arg(arg_string: str, regex: typing.Pattern) -> hikari.Snowflake:
if match := regex.match(arg_string):
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/cooldowns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
6 changes: 4 additions & 2 deletions lightbulb/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down Expand Up @@ -101,9 +101,11 @@ class NotEnoughArguments(CommandError):
Exception raised when a command is run without a sufficient number of arguments.
"""

def __init__(self, command: commands.Command) -> None:
def __init__(self, command: commands.Command, missing_args: typing.List[str]) -> None:
self.command: commands.Command = command
"""The command string that was attempted to be invoked."""
self.missing_args: typing.List[str] = missing_args
"""The required arguments that are missing."""


class TooManyArguments(CommandError):
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/events.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/help.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/plugins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/stringview.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/utils/nav.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/utils/pag.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/utils/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Hikari Command Handler.
#
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hikari~=2.0.0.dev96
hikari~=2.0.0.dev97
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down Expand Up @@ -63,7 +63,7 @@ def parse_requirements_file(path):
long_description_content_type="text/markdown",
author="tandemdude",
author_email="tandemdude1@gmail.com",
url="https://gitlab.com/tandemdude/lightbulb",
url="https://github.com/tandemdude/hikari-lightbulb",
packages=find_namespace_packages(include=[name + "*"]),
license="LGPL-3.0-ONLY",
include_package_data=True,
Expand Down
4 changes: 2 additions & 2 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pytest==6.1.2
pytest==6.2.1
pytest-asyncio==0.14.0
pytest-testdox==2.0.1
pytest-randomly==3.5.0
mock==4.0.2
mock==4.0.3
2 changes: 1 addition & 1 deletion tests/test_checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright © Thomm.o 2020
# Copyright © Thomm.o 2021
#
# This file is part of Lightbulb.
#
Expand Down
Loading

0 comments on commit 9ef0f5d

Please sign in to comment.